Search code examples
unity-game-enginewindowshadercg

Where can I find CG program window size constants?


I have an Unity Shader where I would like to use the Screen size. I set up it with sliders, to set up the screen size but it's not the best. I only found WPOS but it is only for fragment's coordinates. These are from (0,0) to (width, height) what i need.


Solution

  • There are builtin variables which are given the screen resolution. _ScreenParams will contain the width and height of the current render target. To use this variable, make sure you include "UnityCG.cginc".

    There are several other useful inbuilt variables. You can get more info about them here a link

    It might also be worth looking into writing a script that controls a shader. Although not required in this situation, for other slightly more complex shaders it is usually required.