• Advertisement
Sign in to follow this  

Busted Toon Shader

This topic is 4755 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm getting a nasty tesselation-based artifact when I use my Toon shaders. Here is the output: Here's the vertex shader:
void main(float4 position		: POSITION,
		  float4 normal		: NORMAL,

		  out float4 oPosition	: POSITION,
		  out float3 oNormal	: TEXCOORD0,

		  uniform float4x4  modelViewProj,
		  uniform float4x4  modelViewIT)
	oPosition = mul(modelViewProj, position);
	oNormal = mul(modelViewIT, normal).xyz;

And the fragment shader:
void main(float4 position  : TEXCOORD0,
          float3 normal	   : TEXCOORD1,
	  out float4 color : COLOR,
	  uniform float3 lightPosition,
	  uniform float3 eyePosition,
	  uniform float4 Kd,
	  uniform float4 Ks,
	  uniform float	 shininess)
	float3 N = normalize(normal);
	float3 L = normalize(lightPosition - position.xyz);
	float3 V = normalize(eyePosition - position.xyz);

	float intensity = dot(N, L);
	if (intensity > 0.95f) {
		color = float4(1.0f, 0.5f, 0.5f, 1.0f);
	} else if (intensity > 0.5f) {
		color = float4(0.6f, 0.3f, 0.3f, 1.0f);
	} else if (intensity > 0.25f) {
		color = float4(0.4f, 0.2f, 0.2f, 1.0f);
	} else {
		color = float4(0.2f, 0.1f, 0.1f, 1.0f);

I have Phong shaders that work the same way and there are no similar artifacts. Any idea what's happening? T

Share this post

Link to post
Share on other sites
Hi :)

You send your position as a POSITION, but in your fragment-shader you retrieve it as TEXCOORD0, which is in fact your normal! :)

Best regards,

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement