- Home /
Issue with the merging of a surface shader and vert/frag shader using UNITY_MATRIX_MVP
Hello!
I'm currently trying to perform a merge of two different shaders. The base (right capsule) shader is a Toon Surface Shader, and I am trying to merge in the PS1 style vertex popping effect that you see on the left capsule. The PS1 shader is a vertex/fragment shader.
I have defined a vertex function in the base surface shader and intend to use that to achieve the vertex popping in the toon shader. However, the popping relies on the use of UNITY_MATRIX_MVP in its calculations and simply copy-pasting the PS1 shader vertex calculations into the surface shader is producing the effect you see in the middle.
Here is the vertex function I have defined in the surface shader:
void vert (inout appdata_full v)
{
//Vertex snapping
float4 snapToPixel = mul(UNITY_MATRIX_MVP, v.vertex);
float4 vertex = snapToPixel;
vertex.xyz = snapToPixel.xyz / snapToPixel.w;
vertex.x = floor(160 * vertex.x) / 160;
vertex.y = floor(120 * vertex.y) / 120;
vertex.xyz *= snapToPixel.w;
v.vertex = vertex;
}
The PS1 shader performs the exact same calculation yet the results are different. Can anyone give me any insight as to why this is making the capsule in the middle look really small?
Your answer
Follow this Question
Related Questions
Shadow artifacts on vertex animation shader 1 Answer
'vert': output parameter 'o' not completely initialized 2 Answers
Can you specify both Surface and Vertex/Fragment shaders? 3 Answers
Spherical Hamonics - ShadeSH9 and Surface Shader issue 0 Answers
Shading is visible through object using surface shader 0 Answers