- Home /
Shader: get back scene pixel color?
I've just started with shaders, and began with writing simple shader, wich inverts all colors behind object. It was fairly easy, based on ShaderLab Docs, just using "Blend OneMinusDstColor". And i've tryed to write similar shader, wich apply grayscale effect to all pixels, behind object. Reading docs on simple ShaderLab tells me, that it is unreachable witout accessing color components, so i have to use CGPROGRAM. But i cant figure out, how to get back color of scene. Ive tryed wack GL_DST_COLOR, but shader copiller dont recognize that. Any one can help, please?
Answer by Pangamini · Nov 21, 2016 at 11:39 AM
Shader doesn't natively access the underlying color. Blending is done in a separate, fixed-function (non-programmable) unit, controlled by the Blend settings (OneMinusDstColor in your case). Blending In the link, you can see the blending is done outside the pixel shader. If you really want to access the underlying pixels, for special effect such as grayscale, you need to do GrabPass. Basically, an unity's feature that captures the screen into a texture which you can access from the shader. Works exactly as you want (lets you sample any pixel, not just under the current fragment) but it's a lot more expensive to execute than blending. But since you can access any pixel (it's just texture sampling) you can do custom effects, such as blurring or refraction.