- Home /
Unity GLSL shader - getting screen coordinates
I am porting a shader toy shader to Unity GLSL. It's working except I have trouble getting the screen space coordinates I need. What's the equivalent of this:
vec2 coord = gl_FragCoord.xy / iResolution.xy;
I want the normalised coordinate of the current screen fragment.
It seems gl_FragCoord is not available and how do I get the screen size?
Note that I'm using GLSL as the shader language in Unity not CG or HLSL.
Comment
Best Answer
Answer by vibber · Mar 01, 2018 at 10:34 AM
I think I got the answer:
GLSLPROGRAM // here begins the part in Unity's GLSL
#include "UnityCG.glslinc"
vec4 iResolution = _ScreenParams;
Then in main() in fragment shader:
vec2 coord = gl_FragCoord.xy / iResolution.xy;
I must have made a mistake that made me believe I did not have access to gl_FragCoord