Project a render texure onto a 2d plane

Hi, I am fairly new to Shaders, so bear with me please.

In my scene I have 2d objects. I want to take an existing render texture and project it directly onto those planes so that the render texture only shows where those objects are.

So far I have failed to get the coordinates for the objects properly. I have access to the render texture, but it shows up squished and in the completely wrong space. I would show you code, but it’s such a mess due to me not knowing what I’m doing that it would be better to start from scratch.

My searches have not turned up anything that would help me (that I can comprehend at this point).

Thanks

You want screen space UVs.

struct v2f {
    // other stuff, like the pos and uv
 
    // use a number for the TEXCOORD# that isn't already used
    float4 projPos : TEXCOORD4;
};

// in the vertex function
o.projPos = ComputeScreenPos (o.vertex);

// in the fragment shader
float2 screenUV = i.projPos.xy / i.projPos.w;
fixed4 myColor = tex2D(_MyRenderTexture, screenUV);
1 Like

Thank you so much! I knew it something small eluding me. It works beautifully now.