Search Unity

Getting the screenspace of the current fragment

Discussion in 'Shaders' started by zedz, Oct 21, 2021.

  1. zedz

    zedz

    Joined:
    Aug 31, 2013
    Posts:
    255
    I'm tearing out my hair with this, Its close but not perfect

    Code (CSharp):
    1. void surf (Input IN, inout SurfaceOutputStandard o)
    2. {
    3.           float2 pos2D = (IN.screenPos.xy / IN.screenPos.w);
    4. }
    This should work, right, where pos2D = 0,0 bottom left 0.5,0.5 in the middle 1,1 = top right
    thus if I draw various meshes with pos2D as red/green it should result in a smooth gradient, but it doesn't I can see the polygons.
    Most frustrating Anyone with any ideas whats stuffing up

    ignore the shadows in the following but it illustrates whats happening

     
    Last edited: Oct 21, 2021