- Home /
How to get pixel coordinates in an image effect shader
Hi, I want to create a post processing shader. I need the view direction of the current pixel. However I have no idea how to do it.
Answer by ifurkend · May 08, 2021 at 11:50 AM
Screen position https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Screen-Position-Node.html
Answer by Borcam · May 09, 2021 at 05:50 AM
Thanks but I think I forgot to say that I am not using shader graph. This is my frag shader(currently it just inverts the colors)
float4 frag(v2f_img i) : COLOR
{
float4 c = tex2D(_MainTex, i.uv);
c.rgb = 1 - c.rgb;
return c;
}
That "i.uv" is already the pixel coordinates for your image effect shader. If you want to get the pixel projection on the camera plane of a Vector3 point in the world space, You get that by Camera.WorldToScreenPoint in C# script and then set that to your image effect material.
https://docs.unity3d.com/ScriptReference/Camera.WorldToScreenPoint.html
Your answer
Follow this Question
Related Questions
Stereoscopic postscreen effect UV differences (multi pass) 0 Answers
Shaders: How do I make camera view transparent? (Image effect) 1 Answer
How to apply image effect on a specific area of the screen 2 Answers
How would you go about making a retro pixel image shader? 0 Answers
Camera issue 5.3.2 image effects 3 Answers