How do you check the next pixels color?
I'm quite new to shaders and not really sure how to get the col of the next pixel on the screen, please help me!!!
Answer by Pangamini · Feb 09, 2018 at 03:53 PM
If by "screen" you mean the target where you are rendering (the screen buffer or other renderTexture), you can't access that directly in the shader. The only part of the pipeline that accesses it is the blending stage. If you really need some effect that requires information from the target (eg. some distortion), you can use unity's GrabPass, but it's quite costly. It will basically capture the screen content into a separate texture and provide your shader with that. It's different in post-processing, where the previous target content is already provided in the MonoBehaviour's OnRenderImage method.
By screen, i meant I was putting the shader material into my camera and editing everything I see
Answer by Maxence_Marchand · May 22, 2018 at 01:55 PM
It depends how you use your shader. If you use it as a post-processing effect (with Graphics.Blit on a RenderTexture), you can actually get the surrounding pixels' color with some offset. It kinda works like this : float2 offset = 1.0 / _ScreenParams.xy; float4 rightPixel = tex2D(_MainTex, i.uv + float2(offset.x, 0.0));
Inside rightPixel, you'll find the RGBA values of the pixel. Of course, you can access all 8 pixels around the current pixel. It works for fragment shaders, I use it in a Demosaicing shader.
I hope it helped you ^^
Your answer
Follow this Question
Related Questions
Making a pixelation shader to change resolutions in different areas of the screen 0 Answers
How can I have a uniform struct in a Shader? 0 Answers
Is there a way to fetch albedo/spec/roughness/AO and normals (RTs) in a deferred frag. shader? 0 Answers
Fragment shader shows alpha, surface shader doesn't 0 Answers
Avoid looping in shader 0 Answers