Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, 7th_zorro, TedMar), 1,243 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
add an overlay to the toon shader #374973
06/22/11 21:25
06/22/11 21:25
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline OP
Serious User
DLively  Offline OP
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
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.

Last edited by DevoN; 06/22/11 21:27.

A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: add an overlay to the toon shader [Re: DLively] #374974
06/22/11 21:38
06/22/11 21:38
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
IŽll write you a simple effect tomorrow. Nobody should feel compelled to use such an old shader these days.

Re: add an overlay to the toon shader [Re: Hummel] #374983
06/22/11 22:55
06/22/11 22:55
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline OP
Serious User
DLively  Offline OP
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
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.


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: add an overlay to the toon shader [Re: DLively] #374998
06/23/11 03:20
06/23/11 03:20
Joined: Oct 2005
Posts: 4,771
Bay City, MI
lostclimate Offline
Expert
lostclimate  Offline
Expert

Joined: Oct 2005
Posts: 4,771
Bay City, MI
lol yes, its programmed to work with dx 8.

Re: add an overlay to the toon shader [Re: lostclimate] #375098
06/23/11 15:47
06/23/11 15:47
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
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();
	}
}




Re: add an overlay to the toon shader [Re: Hummel] #375169
06/23/11 22:28
06/23/11 22:28
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline OP
Serious User
DLively  Offline OP
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
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

Last edited by DevoN; 06/23/11 22:29.

A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: add an overlay to the toon shader [Re: DLively] #375178
06/23/11 23:12
06/23/11 23:12
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
No webpage yet.

Re: add an overlay to the toon shader [Re: Hummel] #375182
06/23/11 23:44
06/23/11 23:44
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline OP
Serious User
DLively  Offline OP
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Please let me know when you do wink


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: add an overlay to the toon shader [Re: DLively] #375256
06/24/11 16:05
06/24/11 16:05
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
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.

Re: add an overlay to the toon shader [Re: Hummel] #375354
06/25/11 00:58
06/25/11 00:58
Joined: Oct 2005
Posts: 4,771
Bay City, MI
lostclimate Offline
Expert
lostclimate  Offline
Expert

Joined: Oct 2005
Posts: 4,771
Bay City, MI
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.

Page 1 of 2 1 2

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1