Search Unity

Getting an arbitrary point position in Screen Space in a shader

Discussion in 'Shaders' started by melong, Sep 22, 2014.

  1. melong

    melong

    Joined:
    Sep 2, 2011
    Posts:
    22
    Hi,

    I'm trying to get the screen space position of a world space point i set through a property and i assumed this would work:

    Code (CSharp):
    1. Properties
    2. {
    3. ...
    4. _RandomPointWorldPos("Random Point Position In World Space", Vector) = (0.0, 0.0, 0.0, 1.0)
    5. }
    6. SubShader
    7. {
    8. Pass
    9. {
    10. ...
    11. uniform half4 _RandomPointWorldPos;
    12.  
    13. struct vertexOutput
    14. {
    15. float4 pos : SV_POSITION;
    16. half4 screenPos : TEXCOORD0;
    17. half4 randomPointScreenPos : TEXCOORD1;
    18. };
    19.  
    20. vertexOutput vert(vertexInput input)
    21. {
    22. vertexOutput output;
    23.  
    24. output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
    25. output.screenPos = ComputeScreenPos(output.pos);
    26. output.randomPointScreenPos = ComputeScreenPos( mul(UNITY_MATRIX_VP, _RandomPointWorldPos) );
    27.  
    28. return output;
    29. }
    30. ...
    31. }
    32. }
    But it doesn't, as if _RandomPointWorldPos was already in screen pos and the whole ComputeScreenPos Stuff wasn't doing anything.
    Maybe i'm doing it totally wrong here but i don't know how i could resolve this.

    Thanks for your help!