tex2Dproj with three component coordinate?

I’m trying to use tex2Dproj tex2Dproj, but the three component one, not the one with a shadow comparison value.

basically I’m trying to replace

fixed4 col = tex2D(_MainTex, i.projCoords.xy / i.projCoords.z);

with the following:

fixed4 col = tex2Dproj(_MainTex, i.projCoords.xyz);

but I’m getting the following error:

Shader error in 'myshader': 'tex2Dproj': no matching 2 parameter intrinsic function; Possible intrinsic functions are: tex2Dproj(sampler2D, float4|half4|min10float4|min16float4) at line 211 (on d3d11)

How come unity doesn’t know the version that takes a float3 as argument?

Because Unity doesn’t use Cg anymore. Hasn’t for over half a decade. It’s all HLSL now, regardless of what the many instances “CG” appearing throughout the code (and some documentation). Nvidia stopped supporting Cg nearly a decade ago, and Unity removed it from the engine shortly afterward, finally expunging the last use case of it around Unity 4.7.

HLSL doesn’t have the float3 version of tex2Dproj(), only a float4 version. The “shadow comparison value” aspect of either the Cg or HLSL version of tex2Dproj(tex, float4) doesn’t actually matter as it would only get used if the texture you’re sampling from is using a specific depth texture format and sampler2DShadow. Otherwise tex2Dproj(tex, uv.xyzw) compiles to identical code as tex2D(tex, uv.xy / uv.w).

If you are for some reason looking to not pass a full float4 from the vertex to the fragment shader, you can use tex2Dproj(tex, uv.xyzz).

6 Likes