Apply shader to model

Posted By: Gamesaint762

Apply shader to model - 02/07/10 01:35

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....

Quote:
///////////////////////////////
#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 { } }




Posted By: Gamesaint762

Re: Apply shader to model - 02/07/10 23:57

How can apply the Toon shader thats in shader.c to my levels? I have got the one from the wiki working but its pretty horrible and no black outlines. Please help!
Posted By: Gamesaint762

Re: Apply shader to model - 02/08/10 00:51

Ok I figured it out. It was pretty simple and I feel a bit dumb. Ok now for the line thickness, I have adjusted the vecSkill41.y value but nothing seems to change. How can I add thickness to the black outline?? Please help!
Posted By: MrGuest

Re: Apply shader to model - 02/08/10 01:20

hey

if you're using the one from shaderTest.c, it's used in skill42,
so use something like

Code:
ent.skill42 = floatv(50);




hope this helps
Posted By: Gamesaint762

Re: Apply shader to model - 02/08/10 01:38

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...

Quote:
#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 { } }

Posted By: MrGuest

Re: Apply shader to model - 02/08/10 01:39

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 tongue
Posted By: Gamesaint762

Re: Apply shader to model - 02/08/10 01:43

Ok thanks! Works Great... Took me 2 days to figure all that out! Ok on to more art related things cause scripting SUCKS! However for other objects that are not "the player" then I need to use the ent.skill42 instead of my.skill42?
Posted By: Gamesaint762

Re: Apply shader to model - 02/08/10 02:04

Ok I just created an Action for a building. This way I can control line thickness on each model in the game. Thanks again MRGuest, your the best! Muhahahahaha! GS out! (this one solved moderator)
© 2024 lite-C Forums