I want to modify a material found on this forum to make a toon effect.
I would like to apply shader (cel shading) to texture.
To begin, I apply this material to ogre head on example scene. I have been using 2 pass because the Earring's material not done a good result.
If I use a 1 pass material, effect works but with this 2 pass material, a unstable black texture show up.
I am a beginner with shader and I don't understand why I have this result.
cg file :
Code: Select all
void main_vp(float4 position : POSITION,
float3 normal : NORMAL,
// outputs
out float4 oPosition : POSITION,
float2 texCoord3 : TEXCOORD0,
out float specular : TEXCOORD1,
out float edge : TEXCOORD2,
out float2 uv3 : TEXCOORD3,
// parameters
uniform float3 lightPosition, // object space
uniform float3 eyePosition, // object space
uniform float4 shininess,
uniform float4x4 worldViewProj)
{
uv3 = texCoord3;
// calculate output position
oPosition = mul(worldViewProj, position);
// calculate light vector
float3 N = normalize(normal);
float3 L = normalize(lightPosition - position.xyz);
// Calculate diffuse component
//diffuse = max(dot(N, L) , 0);
// Calculate specular component
float3 E = normalize(eyePosition - position.xyz);
float3 H = normalize(L + E);
specular = pow(max(dot(N, H), 0), shininess);
// Mask off specular if diffuse is 0
//if (diffuse == 0) specular = 0;
// Edge detection, dot eye and normal vectors
edge = max(dot(N, E), 0);
}
void main_fp(float diffuseIn : TEXCOORD0,
float specularIn : TEXCOORD1,
float edge : TEXCOORD2,
float2 uv3: TEXCOORD3,
out float4 colour : COLOR,
uniform float4 diffuse,
uniform float4 specular,
uniform sampler1D diffuseRamp,
uniform sampler1D specularRamp,
uniform sampler1D edgeRamp,
uniform sampler2D texture)
{
// Step functions from textures
diffuseIn = tex1D(diffuseRamp, diffuseIn).x;
specularIn = tex1D(specularRamp, specularIn).x;
edge = tex1D(edgeRamp, edge).x;
float4 texture_color = tex2D(texture, uv3);
colour = edge * ((texture_color * diffuseIn) + (texture_color * specularIn));
}
Code: Select all
// -------------------------------
// Cel Shading Section
// -------------------------------
vertex_program Ogre/CelShadingVP cg
{
source Example_CelShading.cg
entry_point main_vp
profiles vs_1_1 arbvp1
default_params
{
param_named_auto lightPosition light_position_object_space 0
param_named_auto eyePosition camera_position_object_space
param_named_auto worldViewProj worldviewproj_matrix
param_named shininess float 10
}
}
fragment_program Ogre/CelShadingFP cg
{
source Example_CelShading.cg
entry_point main_fp
profiles ps_1_1 arbfp1 fp20
}
material Ogre/Skin
{
technique
{
pass
{
vertex_program_ref Ogre/CelShadingVP
{
// map shininess from custom renderable param 1
param_named_auto shininess custom 1
}
ambient 0.3 0.8 0.3
texture_unit
{
texture GreenSkin.jpg
tex_address_mode mirror
}
}
pass
{
fragment_program_ref Ogre/CelShadingFP
{
// map diffuse from custom renderable param 2
param_named_auto diffuse custom 2
// map specular from custom renderable param 2
param_named_auto specular custom 3
}
texture_unit
{
texture cel_shading_diffuse.png 1d
tex_address_mode clamp
filtering none
}
texture_unit
{
texture cel_shading_specular.png 1d
tex_address_mode clamp
filtering none
}
texture_unit
{
texture cel_shading_edge.png 1d
tex_address_mode clamp
filtering none
}
texture_unit
{
colour_op_ex source2 src_texture src_texture
}
}
}
}
Does anyone have a solution to offer me ?
Thanks