Hi all!
A friend of mine created this cgprogram for a toon shader, and I asked if i could use it within my project in unity, well he gave me the blessing and now here i am to ask help in how to do it.
First, here’s his code:
void ToonShading_VP
(
float4 position : POSITION,
float4 normal : NORMAL,
out float4 oPosition : POSITION,
out float4 oColor : COLOR0,
out float oLight : TEXCOORD0,
uniform float4 lightDir,
uniform float4 color,
uniform float4x4 worldIT,
uniform float4x4 worldViewProj
)
{
//posizione in world
oPosition = mul(worldViewProj, position );
oColor = color;
oLight = saturate(dot( normal.xyz, -lightDir.xyz ));
}
float4 ToonShading_FP
(
float4 color : COLOR0,
float light : TEXCOORD0,
uniform sampler1D toonLookupSample : register(s0)
)
: COLOR
{
light = tex1D( toonLookupSample, light ).r;
//scomponiamo luce colore mettendo uno in rgb e l'altro in a
return float4( color.r, color.g, color.b, 1-light );
}
void ToonShading_outline_VP
(
float4 position : POSITION,
float4 normal : NORMAL,
out float4 oPosition : POSITION,
out float4 oColor : COLOR0,
uniform float4 color,
uniform float4x4 world,
uniform float4x4 worldIT,
uniform float4x4 viewProj
)
{
//posizione in world
float4 wPos = mul( world, position );
//normal in world
normal.xyz = mul(worldIT, normal).xyz;
normal = normalize(normal);
//posizione con offset
wPos.xyz += normal.xyz;
//infine ottieni la posizione finale
oPosition = mul(viewProj, wPos);
oColor = color;
}
There are 2 passes, they need:
1st pass:
-a texture telling it how to use light tones, so black to white.
-base texture
-the World Inverse Traspose Matrix
-the WorldViewProjection Matrix
-direction of the light in the object space
2nd pass:
-outline color
-the World matrix
-the WorldIT matrix
-the View*Projection matrix
So, use the passes like this (i THINK maybe i can manage them with subshaders?)
pass1
ToonShading_VP
ToonShading_FP
pass2
ToonShading_outline_VP
ToonShading_FP
Then…can you kindly help me?
Thanks
Akabane!