Contour shading

I im trying to draw the contour of an object with a given color and a given size.

I have created a shader based on toon shading that modify the vertex adding the normal (modeled to achieve the effect)

The problem is that with object with little size is shows correct but with object with a bigger size the contour get a weird offset and i can’t figure out why ?

This is the CGPROGRAM

     	Pass 
      	{				
				ZWrite Off
				ZTest LEqual
				Cull Off
					
				CGPROGRAM 
				// profiles arbfp1
				// vertex vert
				// fragment frag
					
				#include "UnityCG.cginc" 
					
				uniform float4 _Color;
				uniform float _Size;
	 
				void vert (float4 Vertex
					,float4 Normal
					,out float4 oVertex : POSITION
					,uniform float4 _Color
					,uniform float _Size) 
				{
					oVertex = mul (glstate.matrix.mvp, Vertex);
					float4 normal = mul (glstate.matrix.mvp, Normal);
					
					oVertex += normalize (normal) * _Size;
				}
				
				void frag (out float4 oColor : COLOR
					,uniform float4 _Color)
				{
					oColor = _Color;
				}
				
				ENDCG 
			}

.ORG

I wonder why are you extruding in post-perspective space, and not just extruding the vertex in object space?

I didn’t show this lines as they were commented but if is what you mean (work in object space) then i tried it with the same odd result.

				void vert (float4 vertex
					,float4 normal
					,out float4 oVertex : POSITION
					,uniform float _Size) 
				{
					vertex += normal * _Size;
					oVertex = mul (glstate.matrix.mvp, vertex);
				}

.ORG

Somebody there ? :sweat_smile:

.ORG

nope. :smile:

sorry - maybe a silly q but are those separate objects or one?

I can give troubleshooting a shot if you post the current version you are using with the object space transformation in a .unityPackage with a test scene – this seems similar to the Fur shader. Making it easier for people to help generally helps you get your answer. :slight_smile:

Cheers,
-Jon

One, and i used Soften Edges in Maya to get the normal all facing away. I checked it by using Display Vertex Normal.

Im going to post the project so you can see the object and the shader but right now i have work to do :frowning:

.ORG

if it’s just one object then that looks correct to me. i’m guessing that it’s scaling along the normal but relative to the center of the combined bounds. you can see how it’s more exaggerated on the edge objects compared to the middle objects. try them as 3 separate objects and see what happens.