So far, I've defined the CelShading.cg
Code: Select all
//
//Basic lighting functions
//
void lighting_vp(float4 position : POSITION,
float3 normal : NORMAL,
// outputs
out float4 oPosition : POSITION,
out float diffuse : TEXCOORD0,
// parameters
uniform float3 lightPosition, // object space
uniform float4 lightAttenuation,
uniform float4x4 worldViewProj)
{
// calculate output position
oPosition = mul(worldViewProj, position);
// calculate light vector
float3 N = normalize(normal);
float3 L = normalize(lightPosition - position.xyz);
//Calculate distance from light to object.
float lightDist = length( lightPosition - position.xyz );
float luminosity = 0;
if( lightAttenuation.x > lightDist)
luminosity = 1.0 / ( lightAttenuation.y + lightAttenuation.z*lightDist + lightAttenuation.w*(lightDist*lightDist) );
// Calculate diffuse component
diffuse = max(dot(N, L) , 0)*luminosity;
}
void lighting_fp(float diffuseIn : TEXCOORD0,
out float4 colour : COLOR,
uniform sampler1D diffuseRamp : register(s0))
{
// Step functions from textures
diffuseIn = tex1D(diffuseRamp, diffuseIn).x;
colour = diffuseIn;
}
//
//Specular
//
void specular_vp(float4 position : POSITION,
float3 normal : NORMAL,
// outputs
out float4 oPosition : POSITION,
out float specular : TEXCOORD0,
float2 texCoord : TEXCOORD0,
out float2 uv : TEXCOORD1,
// parameters
uniform float3 lightPosition, // object space
uniform float4 lightAttenuation,
uniform float3 eyePosition, // object space
uniform float4 shininess,
uniform float4x4 worldViewProj)
{
// calculate output position
oPosition = mul(worldViewProj, position);
// calculate light vector
float3 N = normalize(normal);
float3 L = normalize(lightPosition - position.xyz);
// Calculate specular component
float3 E = normalize(eyePosition - position.xyz);
float3 H = normalize(L + E);
//Calculate distance from light to object.
float lightDist = length( lightPosition - position.xyz );
float luminosity = 0;
if( lightAttenuation.x > lightDist)
luminosity = 1.0 / ( lightAttenuation.y + lightAttenuation.z*lightDist + lightAttenuation.w*(lightDist*lightDist) );
specular = pow(max(dot(N, H), 0), shininess)*luminosity;
uv = texCoord;
}
void specular_fp(float specularIn : TEXCOORD0,
float2 uv : TEXCOORD1,
out float4 colour : COLOR,
uniform float4 specular,
uniform sampler1D specularRamp : register(s0))
{
// Step functions from textures
specularIn = tex1D(specularRamp, specularIn).x;
colour = specular * specularIn;
}
//
//Specular with specular mapping image
//
void specularTex_fp(float specularIn : TEXCOORD0,
float2 uv : TEXCOORD1,
out float4 colour : COLOR,
uniform float4 specular,
uniform sampler1D specularRamp : register(s0),
uniform sampler2D specMap : register(s1))
{
// Step functions from textures
specularIn = tex1D(specularRamp, specularIn).x;
float4 specValue = tex2D(specMap, uv);
colour = specular * specValue * specularIn;
}
//
//Basic ambent lighting
//
void ambientOneTexture_vp(float4 position : POSITION,
float2 uv : TEXCOORD0,
out float4 oPosition : POSITION,
out float2 oUv : TEXCOORD0,
out float4 colour : COLOR,
uniform float4x4 worldViewProj,
uniform float4 ambient,
uniform float4 diffuse)
{
oPosition = mul(worldViewProj, position);
oUv = uv;
colour = diffuse*ambient;
}
//
//Edge shading
//
void celEdge_vp(float4 position : POSITION,
float2 uv : TEXCOORD0,
float3 normal : NORMAL,
out float4 oPosition : POSITION,
out float edge : TEXCOORD0,
uniform float4x4 worldViewProj,
uniform float3 eyePosition )
{
oPosition = mul(worldViewProj, position);
float3 N = normalize(normal);
float3 E = normalize(eyePosition - position.xyz);
edge = max(dot(N, E), 0);
}
void celEdge_fp(float edge : TEXCOORD0,
out float4 colour : COLOR,
uniform float4 edgeColor,
uniform sampler1D edgeRamp : register(s0))
{
edge = tex1D(edgeRamp, edge).x;
colour = (1-edge)*edgeColor;
}
Code: Select all
void EdgeVP(float4 position : POSITION,
float4 normal : NORMAL0,
out float4 oPos : POSITION,
out float4 oColor : COLOR,
uniform float4 edgeColor,
uniform float4 eyePosition,
uniform float scale,
uniform float edgeScale,
uniform float4x4 worldViewProj)
{
float4 E = normalize(eyePosition);
position = mul(worldViewProj, position - scale*E);
normal.w = 0;
normal = normalize(mul(worldViewProj, normal));
//position -= float4(normal.xy*2, normal.zw);
position += ((scale/8.0f)+1.0) * edgeScale * float4(normal.xy, 0, 0);
oPos=position;
oColor=edgeColor;
}Code: Select all
// A really basic ambient pass program, support for one texture coodinate set
vertex_program AmbientOneTexture cg
{
source CelShading.cg
entry_point ambientOneTexture_vp
profiles vs_1_1 arbvp1
default_params
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto ambient ambient_light_colour
param_named diffuse float4 1 1 1 1
}
}
vertex_program CelEdgeVP cg
{
source CelShading.cg
entry_point celEdge_vp
profiles vs_1_1 arbvp1
default_params
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto eyePosition camera_position_object_space
}
}
fragment_program CelEdgeFP cg
{
source CelShading.cg
entry_point celEdge_fp
profiles ps_1_1 arbfp1 fp20
default_params
{
param_named edgeColor float4 0 0 0 1
}
}
vertex_program VertEdge cg
{
source VertEdge.cg
entry_point EdgeVP
profiles vs_1_1 arbvp1
default_params
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto eyePosition camera_position_object_space
param_named scale float 2
param_named edgeScale float 1 //<--EDIT: Added this parameter for changing the size of the edge, defaults at 1.
}
}
vertex_program CelShadingVP cg
{
source CelShading.cg
entry_point lighting_vp
profiles vs_1_1 arbvp1
default_params
{
param_named_auto lightPosition light_position_object_space 0
param_named_auto lightAttenuation light_attenuation 0
param_named_auto worldViewProj worldviewproj_matrix
}
}
fragment_program CelShadingFP cg
{
source CelShading.cg
entry_point lighting_fp
profiles ps_1_1 arbfp1 fp20
default_params
{
param_named diffuse float4 1 1 1 1
}
}
vertex_program CelSpecularVP cg
{
source CelShading.cg
entry_point specular_vp
profiles vs_1_1 arbvp1
default_params
{
param_named_auto lightPosition light_position_object_space 0
param_named_auto lightAttenuation light_attenuation 0
param_named_auto eyePosition camera_position_object_space
param_named_auto worldViewProj worldviewproj_matrix
param_named shininess float 10
}
}
fragment_program CelSpecularFP cg
{
source CelShading.cg
entry_point specular_fp
profiles ps_1_1 arbfp1 fp20
}
fragment_program CelSpecularTexFP cg
{
source CelShading.cg
entry_point specularTex_fp
profiles ps_1_1 arbfp1 fp20
}
material CelShading
{
technique
{
set $diffuse "1 1 1 1"
set $specular "1 1 1 1"
set $edge "0 0 0 1"
set $shininess "25"
set $modscale "2"
set $edgescale "1" //<--New variable to change the edge scale from other materials inheriting this one easily.
pass edge
{
vertex_program_ref VertEdge
{
param_named edgeColor float4 $edge
param_named scale float $modscale
param_named edgeScale float $edgescale
}
}
// Base ambient pass
pass ambient
{
// base colours, not needed for rendering, but as information
// to lighting pass categorisation routine
ambient 1 1 1
diffuse 0 0 0
specular 0 0 0 0
// Really basic vertex program
// NB we don't use fixed function here because GL does not like
// mixing fixed function and vertex programs, depth fighting can
// be an issue
vertex_program_ref AmbientOneTexture
{
}
}
pass perlight
{
ambient 0 0 0
iteration once_per_light
scene_blend add
vertex_program_ref CelShadingVP
{
}
fragment_program_ref CelShadingFP
{
}
texture_unit
{
texture cel_shading_diffuse.png 1d
tex_address_mode clamp
filtering trilinear
colour_op replace
}
}
pass decal
{
lighting off
vertex_program_ref AmbientOneTexture
{
param_named_auto worldViewProj worldviewproj_matrix
param_named ambient float4 1 1 1 1
param_named diffuse float4 $diffuse
}
scene_blend dest_colour zero
texture_unit decalmap
{
}
}
pass specular
{
ambient 0 0 0
iteration once_per_light
scene_blend add
vertex_program_ref CelSpecularVP
{
// map shininess from custom renderable param 1
param_named shininess float $shininess
}
fragment_program_ref CelSpecularFP
{
// map specular from custom renderable param 2
param_named specular float4 $specular
}
texture_unit
{
texture cel_shading_specular.png 1d
tex_address_mode clamp
filtering trilinear
colour_op replace
}
}
}
}
material CelShadingSpecular
{
technique
{
set $diffuse "1 1 1 1"
set $specular "1 1 1 1"
set $edge "0 0 0 1"
set $shininess "25"
set $modscale "2"
set $edgescale "1" //<--New variable to change the edge scale from other materials inheriting this one easily.
pass edge
{
vertex_program_ref VertEdge
{
param_named edgeColor float4 $edge
param_named scale float $modscale
param_named edgeScale float $edgescale
}
}
// Base ambient pass
pass ambient
{
// base colours, not needed for rendering, but as information
// to lighting pass categorisation routine
ambient 1 1 1
diffuse 0 0 0
specular 0 0 0 0
// Really basic vertex program
// NB we don't use fixed function here because GL does not like
// mixing fixed function and vertex programs, depth fighting can
// be an issue
vertex_program_ref AmbientOneTexture
{
}
}
pass perlight
{
ambient 0 0 0
iteration once_per_light
scene_blend add
vertex_program_ref CelShadingVP
{
}
fragment_program_ref CelShadingFP
{
}
texture_unit
{
texture cel_shading_diffuse.png 1d
tex_address_mode clamp
filtering trilinear
colour_op replace
}
}
pass decal
{
lighting off
vertex_program_ref AmbientOneTexture
{
param_named_auto worldViewProj worldviewproj_matrix
param_named ambient float4 1 1 1 1
param_named diffuse float4 $diffuse
}
scene_blend dest_colour zero
texture_unit decalmap
{
}
}
pass specular
{
ambient 0 0 0
iteration once_per_light
scene_blend add
vertex_program_ref CelSpecularVP
{
// map shininess from custom renderable param 1
param_named shininess float $shininess
}
fragment_program_ref CelSpecularTexFP
{
// map specular from custom renderable param 2
param_named specular float4 $specular
}
texture_unit
{
texture cel_shading_specular.png 1d
tex_address_mode clamp
filtering trilinear
colour_op replace
}
texture_unit specMap
{
texture white.png
}
}
}
}
Code: Select all
import * from "CelShading.material"
material 02-Default : CelShading
{
technique
{
set $specular "0.3 0.3 0.3 1"
set $modscale "4.0"
pass decal
{
texture_unit decalmap
{
texture GreenSkin.jpg
}
}
pass specular
{
texture_unit specMap
{
texture GreenSkin.jpg
}
}
}
}
material Material#23 : CelShading
{
technique
{
set $specular "0.3 0.3 0.3 1"
set $modscale "4.0"
pass decal
{
texture_unit decalmap
{
texture GreenSkin.jpg
}
}
pass specular
{
texture_unit specMap
{
texture GreenSkin.jpg
}
}
}
}
material 01-Default : CelShading
{
technique
{
set $specular "0.3 0.3 0.3 1"
set $modscale "4.0"
pass decal
{
texture_unit decalmap
{
texture GreenSkin.jpg
}
}
pass specular
{
texture_unit specMap
{
texture GreenSkin.jpg
}
}
}
}

Issue happens in both DX9 and GL. Now something interesting in the Ogre.log:
Code: Select all
21:19:26: Compiler error: reference to a non existing object in CelShading.material(119)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(138)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(148)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(151)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(166)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(183)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(188)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(119)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(138)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(148)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(151)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(166)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(183)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(188)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(119)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(138)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(148)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(151)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(166)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(183)
21:19:26: Compiler error: reference to a non existing object in CelShading.material(188)

