Rendering Textures without Perspective Correction

Hi There!

I’m trying to render textured 3D objects without perspecitve correction. My plan is to paint the texture’s perspective myself for some objects.

I tried to find a way to change the interpolation mode of the fragment shader.

GLSL for example has options like:
flat: the value is not interpolated. The value given to the fragment shader is the value from the Provoking Vertex for that primitive.
smooth: performs a perspective correct interpolation.
noperspective: performs a linear interpolation in window space.

Is there anything similar in Unity’s ShaderLab? I found one example on the web which tries to undo perspective correction. Unfortunately it didn’t do the job.

Any help or ideas would be very welcome!!!

I think you would need to use a custom vertex shader. Not sure how you would do it with a surface shader. The basic idea is to ensure that the w value of the vertex clip position is 1 or -1.

o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos /= abs(o.pos.w);

Hi! Thanks for answering.
I’ve got a custom vertex and a fragment shader. The object itself should be rendered with perspective, only its texture needs to be rendered without perspective. The texture should look similar to a window into an image (=texture) behind my 3D Object. Then I can make that texture as large as my screen and use Photoshop to paint the details into the right positions of the 3D Objects…

Here’s the solution for this problem. Credits to Gibbonator! For more information about the issue I recommend this post: Getting a pixel's screen-space coordinate in a fragment shader - Questions & Answers - Unity Discussions

Vertex Shader:
output.pos = mul(UNITY_MATRIX_MVP, input.vertex)
output.pos/=output.pos.w
output.uv[0]=(output.pos[0]+1)/2;
output.uv[1]=(output.pos[1]+1)/2;

Fragment Shader:
return tex2D(_MainTex, input.uv);

I know this is old, but in case someone stumbles over it: just put the keyword ‘noperspective’ in front of the variable declaration.