add an overlay to the toon shader

Posted By: DLively

add an overlay to the toon shader - 06/22/11 21:25

Hello all -

I would like to have an entity that can use overlay with the toon shader.

I have been studying shaders, and am in no way an expert -
how would I fix this shader, to use overlay, or even trasparency?

Code:
material mtl_toon//Josh Arldt
{
	skin1=bmp_toonlookup;
	effect =
	"
	matrix matWorldViewProj;
	matrix matWorld;vector vecSunDir;
	texture entSkin1;texture mtlSkin1;
	
	technique t0{
		pass p0 // shade it
		{
			zwriteenable= true;
			zenable = true;
			Texture[0]=<mtlSkin1>;
			ColorOp[0]=Modulate;
			ColorArg1[0]=Texture;
			ColorArg2[0]=Texture;
			AddressU[0]=Clamp;
			AddressV[0]=Clamp;
			AddressW[0]=Clamp;
			TexCoordIndex[0]=0;
			Texture[1]=<entSkin1>;
			ColorOp[1]=Modulate;
			ColorArg1[1]=Texture;
			ColorArg2[1]=Current;
			TexCoordIndex[1]=1;
			VertexShaderConstant[0] = <matWorldViewProj>;
			VertexShaderConstant[4] = <matWorld>;
			VertexShaderConstant[7] = <vecSunDir>; 

			VertexShader =		asm
			{
				vs_1_0
				dcl_position  v0
				dcl_normal    v3
				dcl_texcoord0 v7
				dcl_texcoord1 v8
				mov oT2.xy, v7
				dp4 oPos.x, c0, v0
				dp4 oPos.y, c1, v0
				dp4 oPos.z, c2, v0
				dp4 oPos.w, c3, v0
				dp3 r0.x, c4.xyz, v3.xyz
				dp3 r0.y, c5.xyz, v3.xyz
				dp3 r0.z, c6.xyz, v3.xyz
				dp3 oT0.x, r0.xyz, -c7.xyz
				mov oT1.xyz, v8
			};
		}
	}";
}



Any Suggestions?

Regards,
Devon.
Posted By: Hummel

Re: add an overlay to the toon shader - 06/22/11 21:38

IŽll write you a simple effect tomorrow. Nobody should feel compelled to use such an old shader these days.
Posted By: DLively

Re: add an overlay to the toon shader - 06/22/11 22:55

oh?
Thank you very much laugh I hadn't realized that it was "that" old tongue

I do use c-script still, so i dont know if that makes a difference to you.
Posted By: lostclimate

Re: add an overlay to the toon shader - 06/23/11 03:20

lol yes, its programmed to work with dx 8.
Posted By: Hummel

Re: add an overlay to the toon shader - 06/23/11 15:47

Here we go!
The shader has two #defines you can comment out if you dont need them.
The one adds an color intensity shift for shadowed parts and with the other one you can activates a mask (entity skin 2) which defines where the shift shall be stronger/weaker.
The following pic demonstrates the effect:

Up/Left: no color intensity shift
Up/Right: shift without masking
Bottom/Left: the mask
Bottom/Right: intensity shift only for skin using the mask
Middle: light gradiant texture (material skin 1)

These are the user defineable vars:
Code:
//==========================================//
#define USE_COLOR_INTENSITY_SHIFT
#define USE_COLOR_INTENSITY_MASK

float max_colorintensity=4;

float max_sunintensity=1.1;
float min_sunintensity=0.1;
//==========================================//


Variable max_colorintensity determines the strength of the intensity shift if you make use of it.
The other two are quite self-explanatory.
Best is you design the light gradiant texture always so that it starts with total black and ends in total white, then use the two variables to declare the actual min/max values of the sun light strength.
To prevent overhead create multible fx. files and materials if you want some models to use the color intensity shift and others not.

The example is Lite-C but it shouldnt be a problem to use it with C-Skript.
Have fun.

Click to reveal..
shader file content only, for demo follow the download link at the beginning of the post.
Code:
//==========================================//
//#define USE_COLOR_INTENSITY_SHIFT
//#define USE_COLOR_INTENSITY_MASK

float max_colorintensity=4;

float max_sunintensity=1.1;
float min_sunintensity=0.1;
//==========================================//

bool AUTORELOAD;

float4x4 matWorldViewProj;
float4x4 matWorld;

float4 vecSunDir;		
float4 vecSunColor;		

texture entSkin1;

texture mtlSkin1;

sampler COLOR_SAMPLER = sampler_state { Texture   = <entSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };
sampler LGRAD_SAMPLER = sampler_state { Texture   = <mtlSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };

#ifdef USE_COLOR_INTENSITY_SHIFT
	#ifdef USE_COLOR_INTENSITY_MASK
		texture entSkin2;
		sampler MASK_SAMPLER = sampler_state { Texture   = <entSkin2>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };
	#endif
#endif


void VS(		
in float4 vPos		   : POSITION,
in float3 normal	   : NORMAL,
in float2 InTex	   : TEXCOORD0,

out float2 OutTex	      : TEXCOORD0,			
out float3 outnormal    : TEXCOORD1,

out float4 Pos	         : POSITION
)
{
	outnormal=mul(normal,matWorld);
	
	Pos = mul(vPos,matWorldViewProj);
	
	OutTex = InTex;
}


void PS(	
in float2 Tex	      : TEXCOORD0,			
in float3 normal     : TEXCOORD1,

out float4 COL :COLOR0
) 
{
	normal      = normalize(normal);

	COL = tex2D(COLOR_SAMPLER,Tex);

	float sun_blub=dot(vecSunDir,normal)*0.5f+0.5f;

	float sun_diff=tex1D(LGRAD_SAMPLER,sun_blub);
	sun_diff=lerp(min_sunintensity,max_sunintensity,sun_diff);

	#ifdef USE_COLOR_INTENSITY_SHIFT

		#ifdef USE_COLOR_INTENSITY_MASK
			COL.rgb=lerp(COL.rgb,pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff))),tex2D(MASK_SAMPLER,Tex));
			#else
			COL.rgb=pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff)));
		#endif

	#endif
	
	COL.rgb=COL.rgb*sun_diff;//*vecSunColor;
//	COL.rgb=tex2D(MASK_SAMPLER,Tex);
}

technique Shading
{
	pass P0
	{	
		zenable=true;
		zwriteenable=true;
		alphablendenable=false;
		alphatestenable=true;
		
		AlphaRef=0;
		AlphaFunc=Greater;
		
		VertexShader = compile vs_2_0 VS();
		PixelShader  = compile ps_2_0 PS();
	}
}



Posted By: DLively

Re: add an overlay to the toon shader - 06/23/11 22:28

Yikes my eyes! tongue ^^Thank you very much^^

It works like a charm!! XD
I never would have been able to do this myself.. tongue However, I do see (somewhat) how you did it... and wow.. Genius tongue 1 small step for man.. well this man tongue

incase anyone else is interested, I implemented the black outline into it. Hope you dont mind laugh

at the end of the .fx file you will see:
Code:
technique Shading
{
	pass P0
	{	
		zenable=true;
		zwriteenable=true;
		alphablendenable=false;
		alphatestenable=true;
		
		AlphaRef=0;
		AlphaFunc=Greater;
		
		VertexShader = compile vs_2_0 VS();
		PixelShader  = compile ps_2_0 PS();
	}
        /////////////////////
        //Add the bottom lines of code for the black outline:
        pass p1 // ink it
	{
		CULLMODE=CW;
		vertexShaderConstant[0]=<matWorldViewProj>;
		vertexShaderConstant[16]=0.9; // outline thickness
		vertexShader =		asm
		{
			vs_1_0
			dcl_position v0
			dcl_normal v3
			dcl_texcoord v7
			mov r0,v0
			mul r1,c16.x,v3
			// Scale the normal
			add r0.xyz,r0.xyz,r1.xyz
			m4x4 oPos,r0,c0
			// Transorm position to clip space
			mov oD0, c0
			mov r0,c0
		};
	}
}


[I just ripped the ink it part from the other toon shader]

Once again, Thank you Hummel!
Do you have a webpage? I'd like to add you to my credits list, and provide a link to your website laugh

Greatest Regards,
Devon
Posted By: Hummel

Re: add an overlay to the toon shader - 06/23/11 23:12

No webpage yet.
Posted By: DLively

Re: add an overlay to the toon shader - 06/23/11 23:44

Please let me know when you do wink
Posted By: Hummel

Re: add an overlay to the toon shader - 06/24/11 16:05

I added native outline support to the shader. There are some #defines for colored or textured outlines etc.
Also you can choose between outlines with absolute or relative thickness (click pic to enlarge):

Download Link is the same as before.
Posted By: lostclimate

Re: add an overlay to the toon shader - 06/25/11 00:58

truly a beautiful toon shader. any chance of normalmap support? I could follow some tutorial and probably do it myself but it would probably be choppy and inefficient.
Posted By: Hummel

Re: add an overlay to the toon shader - 06/26/11 19:04

tangent space normal mapping added:
Click to reveal..
Code:
//==========================================//
//#define USE_NORMALMAPPING

#define USE_COLOR_INTENSITY_SHIFT
#define USE_COLOR_INTENSITY_MASK

const float max_colorintensity=4;

const float max_sunintensity=1.1;
const float min_sunintensity=0.1;

#define USE_OUTLINES
#define USE_PIXELSIZED_OUTLINES
//#define USE_COLORED_OUTLINES

const float outline_thickness=1.5;
const float3 outline_color=float3(0.5,0.6,0.8);//RGB in range 0..1 (instead of 0..255)

//#define USE_LIGHTING_ON_OUTLINES
#define USE_TEXTURED_OUTLINES
//#define USE_ALPHA_FOR_OUTLINES

const float texoutline_brightness=0.5;//0..darker..1..brighter..
const float texoutline_intensity=2;//0..less..1..more..
//==========================================//

bool AUTORELOAD;

float4x4 matWorldViewProj;
float4x4 matWorld;
float4x4 matWorldView;
float4x4 matView;

float4 vecSunDir;		
float4 vecSunColor;		
float4 vecViewPort;		

texture entSkin1;
texture entSkin3;

texture mtlSkin1;

sampler BUMP_SAMPLER = sampler_state { Texture   = <entSkin3>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };
sampler COLOR_SAMPLER = sampler_state { Texture   = <entSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };
sampler LGRAD_SAMPLER = sampler_state { Texture   = <mtlSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };

#ifdef USE_COLOR_INTENSITY_SHIFT
	#ifdef USE_COLOR_INTENSITY_MASK
		texture entSkin2;
		sampler MASK_SAMPLER = sampler_state { Texture   = <entSkin2>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };
	#endif
#endif

////////////////////////////////////////////
#ifndef USE_COLORED_OUTLINES
	#undef USE_LIGHTING_ON_OUTLINES
	#undef USE_TEXTURED_OUTLINES
	#undef USE_ALPHA_FOR_OUTLINES
#endif

#ifdef USE_ALPHA_FOR_OUTLINES
	#define USE_TEXTURED_OUTLINES
#endif
////////////////////////////////////////////
void VS(		
in float4 vPos		   : POSITION,
in float3 normal	   : NORMAL,
in float2 InTex	   : TEXCOORD0,

#ifdef USE_NORMALMAPPING
	in float4 InTangent	: TEXCOORD2,
#endif

out float2 OutTex	      : TEXCOORD0,

#ifndef USE_NORMALMAPPING		
	out float3 outnormal    : TEXCOORD1,
	#else
	out float3 SunDir    : TEXCOORD1,
#endif

out float4 Pos	         : POSITION
)
{
	
	#ifndef USE_NORMALMAPPING		
		outnormal=mul(normal,matWorld);
		#else
		float3x3 matTangent;

		matTangent[0] = mul(InTangent.xyz,matWorld);	
		matTangent[1] = mul(cross(InTangent.xyz,normal),matWorld)*InTangent.w;
		matTangent[2] = mul(normal,matWorld);
		
		SunDir       = normalize(mul( matTangent,vecSunDir.xyz));			
	#endif

	Pos = mul(vPos,matWorldViewProj);
	
	OutTex = InTex;
}

void PS(	
in float2 Tex	      : TEXCOORD0,

#ifndef USE_NORMALMAPPING		
	in float3 normal    : TEXCOORD1,
	#else
	in float3 SunDir    : TEXCOORD1,
#endif

out float4 COL :COLOR0
) 
{
	#ifndef USE_NORMALMAPPING		
		normal      = normalize(normal);
		#else
		vecSunDir.xyz      = normalize(SunDir);
		float3 normal = normalize(tex2D(BUMP_SAMPLER,Tex).xyz*2.f-1.f);
	#endif

	COL = tex2D(COLOR_SAMPLER,Tex);
//	COL = tex2D(BUMP_SAMPLER,Tex);

	float sun_blub=dot(vecSunDir,normal)*0.5f+0.5f;

	float sun_diff=tex1D(LGRAD_SAMPLER,sun_blub);
	sun_diff=lerp(min_sunintensity,max_sunintensity,sun_diff);

	#ifdef USE_COLOR_INTENSITY_SHIFT

		#ifdef USE_COLOR_INTENSITY_MASK
			COL.rgb=lerp(COL.rgb,pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff))),tex2D(MASK_SAMPLER,Tex));
			#else
			COL.rgb=pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff)));
		#endif

	#endif
	
	COL.rgb=COL.rgb*sun_diff;//*vecSunColor;
	//	COL.rgb=tex2D(MASK_SAMPLER,Tex);
}

#ifdef USE_OUTLINES		
	void VS_OUTLINES(		
	in float4 vPos		   : POSITION,
	in float3 normal	   : NORMAL,

	#ifdef USE_TEXTURED_OUTLINES
		in float2 InTex	   : TEXCOORD0,
		out float2 OutTex	      : TEXCOORD0,
	#endif

	#ifdef USE_LIGHTING_ON_OUTLINES
		out float3 outnormal    : TEXCOORD1,
	#endif

	out float4 Pos	         : POSITION
	)
	{
		#ifdef USE_PIXELSIZED_OUTLINES
			float3 viewnormal=mul(normal,matWorldView);
			
			Pos = mul(vPos,matWorldViewProj);
			
			float2 sTex=(Pos.xy/Pos.w)*0.5f+0.5f;
			
			sTex+=viewnormal.xy*outline_thickness*vecViewPort.zw;
			
			Pos.xy=(sTex*Pos.w*2.f-Pos.w);
			#else
			Pos = mul(float4(vPos.xyz+normal*outline_thickness*0.2f,1),matWorldViewProj);
		#endif
		
		#ifdef USE_TEXTURED_OUTLINES
			OutTex = InTex;
		#endif
		
		#ifdef USE_LIGHTING_ON_OUTLINES
			outnormal=mul(normal,matWorld);
		#endif
	}

	#ifdef USE_COLORED_OUTLINES

		void PS_OUTLINES(
		#ifdef USE_TEXTURED_OUTLINES
			in float2 Tex	      : TEXCOORD0,
		#endif

		#ifdef USE_LIGHTING_ON_OUTLINES			
			in float3 normal     : TEXCOORD1,
		#endif

		out float4 COL :COLOR0
		) 
		{
			COL.a=1;
			
			#ifdef USE_TEXTURED_OUTLINES
				COL = tex2D(COLOR_SAMPLER,Tex);
				#else
				COL.rgb=outline_color;
			#endif
			
			#ifdef USE_LIGHTING_ON_OUTLINES					
				normal      = normalize(normal);

				float sun_blub=dot(vecSunDir,normal)*0.5f+0.5f;

				float sun_diff=tex1D(LGRAD_SAMPLER,sun_blub);
				sun_diff=lerp(min_sunintensity,max_sunintensity,sun_diff);

				#ifdef USE_COLOR_INTENSITY_SHIFT

					#if defined(USE_COLOR_INTENSITY_MASK) && defined(USE_TEXTURED_OUTLINES)
					COL.rgb=lerp(COL.rgb,pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff))),tex2D(MASK_SAMPLER,Tex));
					#else
					COL.rgb=pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff)));
				#endif

			#endif
			
			COL.rgb=COL.rgb*sun_diff;//*vecSunColor;
		#endif

		#ifdef USE_TEXTURED_OUTLINES	
			#ifndef USE_ALPHA_FOR_OUTLINES
				COL.rgb=pow(COL.rgb,texoutline_intensity)*texoutline_brightness;
			#endif
		#endif	

		#ifndef USE_ALPHA_FOR_OUTLINES
			COL.a=1;
		#endif	
	}
#endif
#endif

technique Shading
{
pass P0
{	
	zenable=true;
	zwriteenable=true;
	alphablendenable=false;
	alphatestenable=true;
	
	AlphaRef=0;
	AlphaFunc=Greater;
	
	VertexShader = compile vs_2_0 VS();
	PixelShader  = compile ps_2_0 PS();
}

#ifdef USE_OUTLINES		
	pass Outlines
	{
		cullmode=cw;		
		VertexShader = compile vs_2_0 VS_OUTLINES();
		

		#ifdef USE_ALPHA_FOR_OUTLINES
			zenable=true;
			zwriteenable=true;
			alphablendenable=false;
			alphatestenable=true;
			
			AlphaRef=0;
			AlphaFunc=Greater;
		#endif

		
		#ifdef USE_COLORED_OUTLINES
			PixelShader  = compile ps_2_0 PS_OUTLINES();		
		#endif
	}
#endif
}


Posted By: lostclimate

Re: add an overlay to the toon shader - 06/26/11 22:34

hummel, you are awesome
Posted By: Hummel

ToonSid Shader - 06/27/11 19:23

To make it complete: object space normal mapping is now also implemented.

Also you can use the second uv-set for the normalmaps if you need.
Besides that I added a some #defines on the top which make it easier to declare which skins shall be used for the different textures.
New shader:
Click to reveal..
Code:
//==========================================//
#define COLORMAP_TEXTURE entSkin1
#define NORMALMAP_TEXTURE entSkin2
#define INTENSMASK_TEXTURE entSkin3

#define LIGHTGRADIANT_TEXTURE mtlSkin1
//==========================================//

//#define USE_TS_NORMALMAPPING
#define USE_OS_NORMALMAPPING
#define USE_SECOND_UVSET_FOR_NORMALMAPPING

//===================//

#define USE_COLOR_INTENSITY_SHIFT
#define USE_COLOR_INTENSITY_MASK

const float max_colorintensity=4;

const float max_sunintensity=1.1;
const float min_sunintensity=0.1;

//===================//

#define USE_OUTLINES
#define USE_PIXELSIZED_OUTLINES
#define USE_COLORED_OUTLINES

const float outline_thickness=1.5;
const float3 outline_color=float3(0.5,0.6,0.8);//RGB in range 0..1 (instead of 0..255)

//===================// requires USE_COLORED_OUTLINES:

#define USE_LIGHTING_ON_OUTLINES
#define USE_TEXTURED_OUTLINES
//#define USE_ALPHA_FOR_OUTLINES

const float texoutline_brightness=0.8;//0..darker..1..brighter..
const float texoutline_intensity=2;//0..less..1..more..
//==========================================//

bool AUTORELOAD;

float4x4 matWorldViewProj;
float4x4 matWorld;
float4x4 matWorldView;
float4x4 matView;

float4 vecSunDir;		
float4 vecSunColor;		
float4 vecViewPort;		

texture entSkin1;
texture entSkin2;
texture entSkin3;
texture entSkin4;

texture mtlSkin1;
texture mtlSkin2;
texture mtlSkin3;
texture mtlSkin4;

sampler COLOR_SAMPLER = sampler_state { Texture   = <COLORMAP_TEXTURE>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };
sampler LGRAD_SAMPLER = sampler_state { Texture   = <LIGHTGRADIANT_TEXTURE>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };

#if defined(USE_TS_NORMALMAPPING) || defined(USE_OS_NORMALMAPPING)
sampler BUMP_SAMPLER = sampler_state { Texture   = <NORMALMAP_TEXTURE>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };
#endif

#ifdef USE_COLOR_INTENSITY_SHIFT
#ifdef USE_COLOR_INTENSITY_MASK
	sampler MASK_SAMPLER = sampler_state { Texture   = <INTENSMASK_TEXTURE>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear;    AddressU  = clamp; AddressV  = clamp; };
#endif
#endif

////////////////////////////////////////////
#ifndef USE_COLORED_OUTLINES
#undef USE_LIGHTING_ON_OUTLINES
#undef USE_TEXTURED_OUTLINES
#undef USE_ALPHA_FOR_OUTLINES
#endif

#ifdef USE_ALPHA_FOR_OUTLINES
#define USE_TEXTURED_OUTLINES
#endif

#ifdef USE_TS_NORMALMAPPING
#undef USE_OS_NORMALMAPPING
#else
#ifdef USE_OS_NORMALMAPPING
	#undef USE_TS_NORMALMAPPING
#endif
#endif

#if defined(USE_TS_NORMALMAPPING) || defined(USE_OS_NORMALMAPPING)
#define USE_NORMALMAPPING
#else
#undef USE_SECOND_UVSET_FOR_NORMALMAPPING
#endif
////////////////////////////////////////////
void VS(		
in float4 vPos		   : POSITION,
in float3 normal	   : NORMAL,
in float2 InTex	   : TEXCOORD0,

#ifdef USE_SECOND_UVSET_FOR_NORMALMAPPING
in float2 InTex2	   : TEXCOORD1,
#endif

#ifdef USE_TS_NORMALMAPPING
in float4 InTangent	: TEXCOORD2,
#endif

out float2 OutTex	      : TEXCOORD0,

#ifdef USE_SECOND_UVSET_FOR_NORMALMAPPING
out float2 OutTex2	      : TEXCOORD2,
#endif

#ifndef USE_NORMALMAPPING		
out float3 outnormal    : TEXCOORD1,
#else
#ifdef USE_TS_NORMALMAPPING
out float3 SunDir    : TEXCOORD1,
#endif
#endif

out float4 Pos	         : POSITION
)
{

#ifndef USE_NORMALMAPPING		
outnormal=mul(normal,matWorld);
#else
#ifdef USE_TS_NORMALMAPPING
	float3x3 matTangent;

	matTangent[0] = mul(InTangent.xyz,matWorld);	
	matTangent[1] = mul(cross(InTangent.xyz,normal),matWorld)*InTangent.w;
	matTangent[2] = mul(normal,matWorld);

	SunDir       = normalize(mul( matTangent,vecSunDir.xyz));	
#endif		
#endif

Pos = mul(vPos,matWorldViewProj);

OutTex = InTex;

#ifdef USE_SECOND_UVSET_FOR_NORMALMAPPING
OutTex2 = InTex2;
#endif
}

void PS(	
in float2 Tex	      : TEXCOORD0,

#ifdef USE_SECOND_UVSET_FOR_NORMALMAPPING
in float2 Tex2	   : TEXCOORD2,
#endif

#ifndef USE_NORMALMAPPING		
in float3 normal    : TEXCOORD1,
#else
#ifdef USE_TS_NORMALMAPPING
in float3 SunDir    : TEXCOORD1,
#endif
#endif

out float4 COL :COLOR0
) 
{

#ifndef USE_NORMALMAPPING		
normal      = normalize(normal);
#else
#ifdef USE_TS_NORMALMAPPING
	vecSunDir.xyz      = normalize(SunDir);		
	#ifndef USE_SECOND_UVSET_FOR_NORMALMAPPING
		float3 normal = normalize(tex2D(BUMP_SAMPLER,Tex).xyz*2.f-1.f);
		#else
		float3 normal = normalize(tex2D(BUMP_SAMPLER,Tex2).xyz*2.f-1.f);
	#endif
	#else
	matWorld[3]=float4(0,0,0,1);
	#ifndef USE_SECOND_UVSET_FOR_NORMALMAPPING
		float3 normal=normalize(mul(float4(tex2D(BUMP_SAMPLER,Tex).xyz*2.f-1.f,0),matWorld)).xzy;
		#else
		float3 normal=normalize(mul(float4(tex2D(BUMP_SAMPLER,Tex2).xyz*2.f-1.f,0),matWorld)).xzy;
	#endif
	normal.z*=-1.f;
#endif
#endif

COL = tex2D(COLOR_SAMPLER,Tex);

float sun_blub=dot(vecSunDir,normal)*0.5f+0.5f;

float sun_diff=tex1D(LGRAD_SAMPLER,sun_blub);
sun_diff=lerp(min_sunintensity,max_sunintensity,sun_diff);

#ifdef USE_COLOR_INTENSITY_SHIFT

#ifdef USE_COLOR_INTENSITY_MASK
	COL.rgb=lerp(COL.rgb,pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff))),tex2D(MASK_SAMPLER,Tex));
	#else
	COL.rgb=pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff)));
#endif

#endif

COL.rgb=COL.rgb*sun_diff;//*vecSunColor;
//COL=normal.y;
COL.a=1;
}

#ifdef USE_OUTLINES		
void VS_OUTLINES(		
in float4 vPos		   : POSITION,
in float3 normal	   : NORMAL,

#ifdef USE_TEXTURED_OUTLINES
in float2 InTex	   : TEXCOORD0,
out float2 OutTex	      : TEXCOORD0,
#endif

#ifdef USE_LIGHTING_ON_OUTLINES
out float3 outnormal    : TEXCOORD1,
#endif

out float4 Pos	         : POSITION
)
{
#ifdef USE_PIXELSIZED_OUTLINES
	float3 viewnormal=mul(normal,matWorldView);

	Pos = mul(vPos,matWorldViewProj);

	float2 sTex=(Pos.xy/Pos.w)*0.5f+0.5f;

	sTex+=viewnormal.xy*outline_thickness*vecViewPort.zw;

	Pos.xy=(sTex*Pos.w*2.f-Pos.w);
	#else
	Pos = mul(float4(vPos.xyz+normal*outline_thickness*0.2f,1),matWorldViewProj);
#endif

#ifdef USE_TEXTURED_OUTLINES
	OutTex = InTex;
#endif

#ifdef USE_LIGHTING_ON_OUTLINES
	outnormal=mul(normal,matWorld);
#endif
}

#ifdef USE_COLORED_OUTLINES

void PS_OUTLINES(
#ifdef USE_TEXTURED_OUTLINES
	in float2 Tex	      : TEXCOORD0,
#endif

#ifdef USE_LIGHTING_ON_OUTLINES			
	in float3 normal     : TEXCOORD1,
#endif

out float4 COL :COLOR0
) 
{
	COL.a=1;

	#ifdef USE_TEXTURED_OUTLINES
		COL = tex2D(COLOR_SAMPLER,Tex);
		#else
		COL.rgb=outline_color;
	#endif

	#ifdef USE_LIGHTING_ON_OUTLINES					
		normal      = normalize(normal);

		float sun_blub=dot(vecSunDir,normal)*0.5f+0.5f;

		float sun_diff=tex1D(LGRAD_SAMPLER,sun_blub);
		sun_diff=lerp(min_sunintensity,max_sunintensity,sun_diff);

		#ifdef USE_COLOR_INTENSITY_SHIFT

			#if defined(USE_COLOR_INTENSITY_MASK) && defined(USE_TEXTURED_OUTLINES)
			COL.rgb=lerp(COL.rgb,pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff))),tex2D(MASK_SAMPLER,Tex));
			#else
			COL.rgb=pow(COL.rgb,lerp(max_colorintensity,1,min(1,sun_diff)));
		#endif

	#endif

	COL.rgb=COL.rgb*sun_diff;//*vecSunColor;
#endif

#ifdef USE_TEXTURED_OUTLINES	
	#ifndef USE_ALPHA_FOR_OUTLINES
		COL.rgb=pow(COL.rgb,texoutline_intensity)*texoutline_brightness;
	#endif
#endif	

#ifndef USE_ALPHA_FOR_OUTLINES
	COL.a=1;
#endif	
}
#endif
#endif

technique Shading
{
pass P0
{	
zenable=true;
zwriteenable=true;
alphablendenable=false;
alphatestenable=true;

AlphaRef=0;
AlphaFunc=Greater;

VertexShader = compile vs_2_0 VS();
PixelShader  = compile ps_2_0 PS();
}

#ifdef USE_OUTLINES		
pass Outlines
{
cullmode=cw;		
VertexShader = compile vs_2_0 VS_OUTLINES();


#ifdef USE_ALPHA_FOR_OUTLINES
	zenable=true;
	zwriteenable=true;
	alphablendenable=false;
	alphatestenable=true;

	AlphaRef=0;
	AlphaFunc=Greater;
#endif


#ifdef USE_COLORED_OUTLINES
	PixelShader  = compile ps_2_0 PS_OUTLINES();		
#endif
}
#endif
}


Updated the Download Link

Have fun
Posted By: Rackscha

Re: ToonSid Shader - 06/27/11 19:44

Up to the wiki with it, or some other more consistent place than this thread.

SHader is to good to be pushed to teh bottom of forumthreads
Posted By: MTD

Re: ToonSid Shader - 07/02/11 14:56

Very good, but somehow I cant run the test file.
1) It says that the downloaded file is corrupted.
2) Received compile error on mtlFX
And the result is (GeForce 8800 GT):


Posted By: Hummel

Re: ToonSid Shader - 07/02/11 15:49

Quote:
It says that the downloaded file is corrupted.
fixed.
Posted By: lostclimate

Re: ToonSid Shader - 07/03/11 03:50

its what sid would look like if he were *normal*... haha get it. lol puns.
© 2024 lite-C Forums