Hello eveybody, I am trying to create a simple Vertex Fragment shader for projector but I am facing some issues. In Orthographic mode the projection is perfect and resize according to the projector property. Unfortunately, in perspective mode, the texture is docked in a corner of the projector and doesn't resize. Could you tell me what I am doing wrong ? Thank you very much. Code (CSharp): struct vertOut { float4 pos : POSITION; float2 uv : TEXCOORD0; }; struct fragOut { float4 col : COLOR; }; vertOut vert(appdata_base IN) { vertOut o; o.pos = mul(UNITY_MATRIX_MVP, IN.vertex); o.uv = TRANSFORM_TEX(mul(_Projector, IN.vertex).xy, _Mask); return o; } fragOut frag(vertOut IN) { fragOut o; float4 mask = tex2D(_Mask, saturate(IN.uv)); o.col = mask; return o; } Here is an other solution which fixe the position and size in both mode but I can't avoid the repetition. The texture is not clamped. Code (CSharp): struct vertOut { float4 pos : POSITION; float4 uv : TEXCOORD0; }; struct fragOut { float4 col : COLOR; }; vertOut vert(appdata_base IN) { vertOut o; o.pos = mul(UNITY_MATRIX_MVP, IN.vertex); o.uv = mul(_Projector, IN.vertex); return o; } fragOut frag(vertOut IN) { fragOut o; float4 mask = tex2Dproj(_Mask, IN.uv); o.col = mask; return o; }
I just solved the issue by replacing : Code (CSharp): float4 mask = tex2Dproj(_Mask, IN.uv); Code (CSharp): float4 mask = tex2D(_Mask, saturate(float2(IN.uv.xy) / IN.uv.w));