Can't get projective texturing to work as advertised

Hi all,

I’m stumbling onto a very simple problem. For some reason, I can’t get tex2Dproj to work properly in a simple shader, although I did use the recommended UNITY_PROJ_COORD helper

The shader I am trying this with simply transforms the vertices and is supposed to texture the object using its mesh’s UVs, but WITHOUT perspective correction.

No matter what I do, I still get the same perspective corrected mapping with my shader as with the default diffuse shader. I’m probably overlooking some thing stupid, so if anyone cares to have a quick look at that shader code, thanks very much:

Shader "Custom/projective" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
	}
	
	SubShader {
		
		Tags { "RenderType"="Opaque" }
		Pass {

			Lighting Off
		
			CGPROGRAM

			#pragma vertex vert
			#pragma fragment frag

			#include "UnityCG.cginc"

			sampler2D _MainTex;

			struct appdata {
				float4 vertex : POSITION;
				float4 texcoord : TEXCOORD0;
			};


			
			struct v2f {
				float4 pos : SV_POSITION;
				float4 uv : TEXCOORD0;
			};

			v2f vert (appdata v)
			{
				v2f o;

				// Transform the input points.
				o.pos = mul( UNITY_MATRIX_MVP,v.vertex);
				o.uv = float4(v.texcoord.x,v.texcoord.y,0f,1f);

				return o;
			}

			half4 frag( v2f i ) : COLOR {
				half4 c = tex2Dproj(_MainTex, UNITY_PROJ_COORD(i.uv));
				return c;
			}
		ENDCG
		}
	} 
	FallBack "Diffuse"
}

Thanks for any help

Ok, so here a screenshot that shows the problem. The quad is set up so that it looks like a square from the Camera’s viewpoint, but it acutally has one vertex that is pushed back, so one of the two triangles is screen aligned but not the other. With a projector shader, however, the check grid should still look as if it was on a screen aligned quad.


I am also attaching the test project, if anymore cares to have a look and help me out.

1396056–72168–$ProjectorTest.zip (228 KB)

I don’t think that would work. You should dig into the projection shaders in unity. They multiply the texcoords by the projection matrix of the camera. If you need the grid to be flat you could use world space coordinates to texture your quad like a tri-planar shader.