Search Unity

How do I get the pixel's position in fragment shader? not vertex shader..

Discussion in 'Shaders' started by JohnSonLi, May 26, 2016.

  1. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    586
    rt.
    well, I want to get a bright scan line from down to top in my model.this scan line's brightness (in fragment shader) is calculated by this pixel's spacial position.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
  3. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    586
  4. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
  5. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    586
    aucually what I want is the position in word space not in screen space, sv_position is in world space?
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    SV_Position is going to be either clip space position (in the vertex shader and in DX9 pixel shader) or exact pixel coordinate (in the pixel shader). If you want world space position you need to calculate that in the vertex shader and pass it to the pixel shader yourself.

    Look for _Object2World or unity_ObjectToWorld, or really just search for getting world position in unity shader.
     
  7. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    586
    thx anyway, but I still dont know how.....