Tuesday, May 15, 2018

glsl - 2D Hidden Object Silhouette Shader


Right now I am not using any depth information in my engine, but I just found out that it would be neat to be able to render the silhouette of important game objects that are "behind" something with a shader, though I am quite at a loss how to do this in a 2D scene with little to no depth information. I will propably have to use depth information for something like that, but I am not quite sure how.


I guess the abstract concept would be:


zn = depth of pixel that should be rendered
zc = depth of pixel at current position in some sort of buffer
if(zn < zc)
render pixel with a "silhouette" color
else
render pixel with it's intended color


Is this a proof of concept I can follow in my next few workhours? How can I use and access stuff like the Z buffer of the current framebuffer in the shader?


As an example, I most recently saw this in Titan Souls:


left half is obscured, right half is rendered normally


Also remember that I am thinking 2D only, so application of the painter's algorithm might or might not be desirable.


EDIT: So right now, from comments and such, I got the following proof of concept:


activate stencil mechanism to set stencil
render obscuing objects
deactivate stencil
render scene, using painter's algorithm or depth checks to obscure
activate stencil mechanism to check weather or not something got rendered within the stencil area

render important objects again, using a different fragment shader to render pixels within the stencil as a dark shadow

amirite?




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...