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
1 registered members (Ayumi), 662 guests, and 3 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
Apply shader to model #309082
02/07/10 01:35
02/07/10 01:35
Joined: Jan 2004
Posts: 439
G
Gamesaint762 Offline OP
Senior Member
Gamesaint762  Offline OP
Senior Member
G

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

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 { } }





Last edited by Gamesaint762; 02/07/10 01:37.
Re: Apply shader to model [Re: Gamesaint762] #309216
02/07/10 23:57
02/07/10 23:57
Joined: Jan 2004
Posts: 439
G
Gamesaint762 Offline OP
Senior Member
Gamesaint762  Offline OP
Senior Member
G

Joined: Jan 2004
Posts: 439
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!

Re: Apply shader to model [Re: Gamesaint762] #309220
02/08/10 00:51
02/08/10 00:51
Joined: Jan 2004
Posts: 439
G
Gamesaint762 Offline OP
Senior Member
Gamesaint762  Offline OP
Senior Member
G

Joined: Jan 2004
Posts: 439
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!

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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

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

Code:
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
G
Gamesaint762 Offline OP
Senior Member
Gamesaint762  Offline OP
Senior Member
G

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

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 { } }


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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

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 tongue

Re: Apply shader to model [Re: MrGuest] #309227
02/08/10 01:43
02/08/10 01:43
Joined: Jan 2004
Posts: 439
G
Gamesaint762 Offline OP
Senior Member
Gamesaint762  Offline OP
Senior Member
G

Joined: Jan 2004
Posts: 439
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?

Re: Apply shader to model [Re: Gamesaint762] #309230
02/08/10 02:04
02/08/10 02:04
Joined: Jan 2004
Posts: 439
G
Gamesaint762 Offline OP
Senior Member
Gamesaint762  Offline OP
Senior Member
G

Joined: Jan 2004
Posts: 439
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)


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