Search Unity

Question Getting object origin screen position in shadergraph. (not screenposition node)

Discussion in 'General Graphics' started by AydinDeveloper, Oct 15, 2020.

  1. AydinDeveloper

    AydinDeveloper

    Joined:
    Sep 8, 2017
    Posts:
    92
    Can you help me create this shader with shader graph?
    Screen position node is calculating Vertex position. I just want the point screen position.

    Shader "Unlit/DepthPoint"
    {
    SubShader
    {
    Tags { "Queue" = "Transparent" }
    LOD 100

    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    // make fog work
    #pragma multi_compile_fog

    #include "UnityCG.cginc"

    struct v2f
    {
    fixed4 pos : SV_POSITION;
    fixed4 objScreenPoint : TEXCOORD0;
    UNITY_VERTEX_OUTPUT_STEREO
    };

    v2f vert(appdata_base v)
    {
    v2f o;
    UNITY_SETUP_INSTANCE_ID(v);
    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    o.pos = UnityObjectToClipPos(v.vertex);
    o.objScreenPoint = ComputeScreenPos(UnityObjectToClipPos(fixed4(0, 0, 0, 1)));
    return o;
    }

    sampler2D _CameraDepthTexture;

    fixed4 frag (v2f i) : SV_Target
    {

    fixed4 depth = tex2D(_CameraDepthTexture, i.objScreenPoint .xy / i.objScreenPoint .w);
    return depth;
    }
    ENDCG
    }
    }
    }
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352