1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases 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:
    490
    why do we need sv_position?
     
  2. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    610
    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:
    327
    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:
    4,947
  5. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    490
    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
     
  6. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    490
    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,522
    "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:
    490
    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:
    490
    all of you are masters.......
     
  12. Aras

    Aras

    Graphics Plumber Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,522
    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:
    610
    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,522
    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.
     
    behram likes this.