1 registered members (Ayumi),
662
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Apply shader to model
#309082
02/07/10 01:35
02/07/10 01:35
|
Joined: Jan 2004
Posts: 439
Gamesaint762
OP
Senior Member
|
OP
Senior Member
Joined: Jan 2004
Posts: 439
|
I have done this before but cant seem to get this working. I am wanting to apply a toon shader to a model but the model comes into the game all black. So in MED to what skin is the .fx file applied to? Please help. here is the code.... /////////////////////////////// #include <acknex.h> #include <default.c> ///////////////////////////////
//Toonshading MATERIAL* mtlToonShader = { effect = "Toonshading.fx"; }
function ToonshadingValues(r,g,b) { mtlToonShader.skill1 = floatv(r); //4 looks okay mtlToonShader.skill2 = floatv(g); //same as above mtlToonShader.skill3 = floatv(b); //same as above }
VIEW* vToonView = { material = mtlToonShader; flags = CHILD | PROCESS_TARGET; }
float4 vecSkill1; //"Details" for the rgb values float4 vecViewPort;
Texture TargetMap; sampler2D smpSource = sampler_state { texture = <TargetMap>; };
float4 dirtyToonPS( float2 Tex : TEXCOORD0 ) : COLOR0 { half4 Color = tex2D(smpSource,Tex.xy); Color.r = round(Color.r*vecSkill1.x)/vecSkill1.x; Color.g = round(Color.g*vecSkill1.y)/vecSkill1.y; Color.b = round(Color.b*vecSkill1.z)/vecSkill1.z; return Color; }
technique postFX { pass p1 { PixelShader = compile ps_2_0 dirtyToonPS(); } }
technique fallback { pass one { } }
Last edited by Gamesaint762; 02/07/10 01:37.
|
|
|
Re: Apply shader to model
[Re: Gamesaint762]
#309223
02/08/10 01:20
02/08/10 01:20
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
hey if you're using the one from shaderTest.c, it's used in skill42, so use something like
ent.skill42 = floatv(50);
hope this helps
|
|
|
Re: Apply shader to model
[Re: MrGuest]
#309225
02/08/10 01:38
02/08/10 01:38
|
Joined: Jan 2004
Posts: 439
Gamesaint762
OP
Senior Member
|
OP
Senior Member
Joined: Jan 2004
Posts: 439
|
thanks MRGuest... Im not a much of a scripter but where do I place the code? In the shader itself or in player code? Thanks! heres the shader code... #include <define> #include <transform> #include <fog> #include <pos> #include <normal> #include <lights> #include <vecskill> #include <color>
texture entSkin1; // texture texture entSkin2; // lightmap sampler sBaseTex = sampler_state { Texture = <entSkin1>; MipFilter = Linear; }; sampler sSkin2 = sampler_state { Texture = <entSkin2>; MipFilter = Linear; };
struct toonOut { float4 Pos: POSITION; float Fog: FOG; float4 Ambient:COLOR1; float2 Tex: TEXCOORD0; float2 LM: TEXCOORD1; float4 Param: TEXCOORD3; };
toonOut toon_VS ( in float4 inPos: POSITION, in float3 inNormal: NORMAL, in float2 inTex: TEXCOORD0, in float2 inLM: TEXCOORD1 ) { toonOut Out; Out.Pos = DoTransform(inPos); Out.Tex = inTex; Out.LM = inLM; Out.Fog = DoFog(inPos); Out.Ambient = 2*DoAmbient();
float3 P = DoPos(inPos); // rotate and normalize the normal float3 N = DoNormal(inNormal);
float3 Color = 0; for (int i=0; i<iLights; i++) // Add dynamic lights Color += DoLight(P,N,i);
Out.Param.x = length(Color*vecDiffuse); Out.Param.y = DoDefault(vecSkill41.z*0.015,0.70); // shadow threshold Out.Param.z = DoDefault(vecSkill41.x*(0.3/50),0.3); // shadow brightness Out.Param.w = DoDefault(vecSkill41.w*(0.03/50),0.05); // shadow edge
return Out; }
float4 toon_PS(toonOut In): COLOR { float4 base = tex2D(sBaseTex,In.Tex); float light; if (In.Param.x > In.Param.y) light = 1.0; else if (In.Param.x > In.Param.y-In.Param.w) light = lerp(1.0,In.Param.z,(In.Param.y-In.Param.x)/(In.Param.w)); else light = In.Param.z; return base * light * In.Ambient; }
float4 toonLM_PS(toonOut In): COLOR { float4 base = tex2D(sBaseTex,In.Tex); float4 lightmap = tex2D(sSkin2,In.LM); In.Param.x += length(lightmap.xyz); float light; if (In.Param.x > In.Param.y) light = 1.0; else if (In.Param.x > In.Param.y-In.Param.w) light = lerp(1.0,In.Param.z,(In.Param.y-In.Param.x)/(In.Param.w)); else light = In.Param.z; return base * light * In.Ambient; }
technique toon { pass one { VertexShader = compile vs_2_0 toon_VS(); PixelShader = compile ps_2_0 toon_PS(); } pass two { CULLMODE=CW; vertexShaderConstant[0] = <matWorldViewProj>; vertexShaderConstant[16] = <vecSkill41.y*0.06>; 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 // Transform position to clip space mov oD0, c0 mov r0,c0 }; } }
technique toon_lm { pass one { VertexShader = compile vs_2_0 toon_VS(); PixelShader = compile ps_2_0 toonLM_PS(); } }
technique fallback { pass one { } }
Last edited by Gamesaint762; 02/08/10 01:42.
|
|
|
Re: Apply shader to model
[Re: Gamesaint762]
#309226
02/08/10 01:39
02/08/10 01:39
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
in the player code, outside of the while loop, also make sure you don't overwrite skill42 anywhere else later you'll probably need to change the ent.skill42 to my.skill42, depends on how you're handling your actions play around with it, you can't break it... i hope
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|