Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

what is the difference between "float4 pos:SV_POSITION"and "float4 pos;"

Discussion in 'Shaders' started by JohnSonLi, Jan 8, 2013.

  1. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    549
    why do we need sv_position?
     
  2. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    SV_Position is a semantic, they're used to tell the engine how to move data through the graphics pipeline. You can't just send data between steps (e.g.: from vertex shader to pixel shader), because there are steps in between that you don't see in Shaderlab code.
     
    behram likes this.
  3. Lulucifer

    Lulucifer

    Joined:
    Jul 8, 2012
    Posts:
    354
    As I remember,it is the second time you ask this question,Martin answered it fews month ago
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,438
  5. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    549
    I am a dull boy,and computer graphics is not my major,it is however sometimes too abstract for me...... Thank you all............it takes time
     
    Agent0023 likes this.
  6. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    549
    is sv_position something from the hardware?like video card???some data slot or bus from the video card???
     
  7. Aras

    Aras

    Graphics Plumber Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,526
    "Kind of".

    SV_Position is one of "predefined" semantics, that is telling the GPU "this is the position". That's how it knows which value, well, determines the position on the screen.
     
  8. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    549
    I love you Aras.......
     
  9. Martin-Kraus

    Martin-Kraus

    Joined:
    Feb 18, 2011
    Posts:
    617
    What I never understood is why the Unity documentation is using "SV_POSITION" instead of "POSITION" for the output of the vertex shader (and the input of the fragment shader). Is there a particular reason? Or was it just to use something different to distinguish the vertex attribute from the transformed position?
     
    Last edited: Jan 10, 2013
  10. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,327
    Why doesn't whatever you give the POSITION / SV_POSITION semantic work with the inout keyword? (i.e. you use that as a vert shader parameter instead of passing in a struct.) It compiles, but doesn't render, or at least in the expected way.
     
  11. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    549
    all of you are masters.......
     
  12. Aras

    Aras

    Graphics Plumber Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,526
    Yes, the reason is compatibility with DX11.

    SV_POSITION expands to just POSITION on all other platforms, and SV_Position on DX11. Why Microsoft made DX11 have "SV_Position" for the output position? I don't know ;)
     
    behram likes this.
  13. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    I assume because they want to group together all System Values. I don't really understand what their definition for a System Value is, though. At first they mention that:
    But then they go on to list all the exceptions, where system values are NOT valid at other parts of the pipeline...

    Hopefully NVIDIA documents this stuff at some point. I usually prefer the way they explain things.
     
  14. Yanger_xy

    Yanger_xy

    Joined:
    Dec 4, 2010
    Posts:
    7
    Hi,
    I have the same issue.
    When to use POSITION and when to use SV_POSITION?
     
  15. frogsbo

    frogsbo

    Joined:
    Jan 16, 2014
    Posts:
    79
    SV seems to be a screenspace x y position, with z not doing very much. i do sin(svpos.x) it does straight bars in line with the screen sides.
     
  16. Aras

    Aras

    Graphics Plumber Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,526
    Best use SV_POSITION. This will work on all platforms; whereas "POSITION" will work only on "most of them". For example, I think shaders on PS4 require SV_POSITION.
     
    andrew-lukasik and behram like this.