Search Unity

Screen size in shader?

Discussion in 'Shaders' started by CorruptScanline, May 2, 2010.

  1. CorruptScanline

    CorruptScanline

    Joined:
    Mar 26, 2009
    Posts:
    217
    I remember seeing builtin screen size variables in some shader code at some point. They are equivalent to Screen.height and Screen.width but i cant find anything about them now. Are there really any builtin variables for these values? if not there should be. I really dont want to have to assign these as global shader values because i need it to work without any code besides the shader itself.
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    As far as I know, the only built-in values available from shaders are documented here.
     
  3. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Why do you need it to work without anything but the shader itself? Setting global properties is really easy, and it's not like you can use Unity to render anything without also being able to run a script.
     
  4. CorruptScanline

    CorruptScanline

    Joined:
    Mar 26, 2009
    Posts:
    217
    Thanks, this is for my visual shader editor. I want to make a ScreenSize node. I guess I will have to let the end user make their own node for this if they need it.
     
  5. Jeff-Kesselman

    Jeff-Kesselman

    Joined:
    Apr 5, 2010
    Posts:
    99
    For anyone looking, the answer to this question as of Unity3.5 is _ScreenParams.x and _ScreenParams.y
     
  6. wildermind69

    wildermind69

    Joined:
    Mar 12, 2017
    Posts:
    3
    Thank you Jeff! Was helpful.
     
  7. CyberFox01

    CyberFox01

    Joined:
    Oct 5, 2012
    Posts:
    23
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Rowlan, Tomyn and wolilio like this.
  9. zch1234qq

    zch1234qq

    Joined:
    Dec 24, 2019
    Posts:
    5
  10. DomeCreator

    DomeCreator

    Joined:
    Mar 5, 2020
    Posts:
    29
    As documentation said :
    "x is the width of the camera’s target texture in pixels, y is the height of the camera’s target texture in pixels, z is 1.0 + 1.0/width and w is 1.0 + 1.0/height."

    So if I understand the _ScreenParams refer more to a target texture than the screen size.

    In my case I create a RenderTexture on which the camera will render, so I set the target texture size of that camera and it's not the same as the screen size.
    I may missed something but as I undertand I don't have a way to get the screen size ?