|
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
OP
Serious User
|
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?
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.
|
|
|
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
OP
Serious User
|
OP
Serious User
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
|
oh? Thank you very much I hadn't realized that it was "that" old I do use c-script still, so i dont know if that makes a difference to you.
|
|
|
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
Expert
|
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:
//==========================================//
#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. shader file content only, for demo follow the download link at the beginning of the post.
//==========================================//
//#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
OP
Serious User
|
OP
Serious User
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
|
Yikes my eyes! ^^Thank you very much^^ It works like a charm!! XD I never would have been able to do this myself.. However, I do see (somewhat) how you did it... and wow.. Genius 1 small step for man.. well this man incase anyone else is interested, I implemented the black outline into it. Hope you dont mind at the end of the .fx file you will see:
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 Greatest Regards, Devon
Last edited by DevoN; 06/23/11 22:29.
|
|
|
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
Expert
|
Expert
Joined: Mar 2006
Posts: 2,252
|
|
|
|
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
Expert
|
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.
|
|
|
|