Search Unity

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:
    586
    why do we need sv_position?
     
  2. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    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:
    358
    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,539
  5. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    586
    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:
    586
    is sv_position something from the hardware?like video card???some data slot or bus from the video card???
     
  7. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    "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.
     
    MohamedU3 and ichenpipi like this.
  8. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    586
    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
    MohamedU3 likes this.
  10. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    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:
    586
    all of you are masters.......
     
  12. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    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 ;)
     
    MohamedU3 and behram like this.
  13. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    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.
     
    MohamedU3 likes this.
  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

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    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.
     
  17. ed022

    ed022

    Joined:
    Jan 11, 2023
    Posts:
    1
    Joined this forum just now just to say that I found this explanation exactly ten years later. (Albeit for the sake of Monogame instead of Unity). I found it shockingly uncanny. Thanks for the info!