Enhanced Cel Shading

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
thebluefish
Gremlin
Posts: 170
Joined: Tue Apr 05, 2011 1:55 am

Enhanced Cel Shading

Post by thebluefish » Sun Apr 15, 2012 5:24 am

Alright, I've been pulling my hair out for 5 hours now regarding this one. I've been trying to implement the Enhanced Cel Shading example (http://www.ogre3d.org/tikiwiki/Enhanced ... e=Cookbook) to one of my many demos, however I haven't delved too far into shaders to really know why this is happening.

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;
}
The VertEdge.cg

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;
}
and the CelShading.material

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
         }
      }
   }   
}
and finally the material for my sample model

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 
			}
		}
	}
}
However, when I run my demo, no change:
Image

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)
Essentially, not thinking that the programs defined in the beginning of the file are even there. However I've had luck with doing this in the past, so I'm not sure why this would bring up an issue now?
0 x
During the code inspection, a couple of minor points were noticed: -

Function inlining was critical to performance.
For MSVC, at least, a "delete 0" caused execution of 11 assembly instructions, including a function call. So in cases where performance is at an absolute premium it can be worth inserting the extra manual test.

StrakeFengala
Kobold
Posts: 28
Joined: Wed Feb 10, 2010 11:18 pm
Location: USA

Re: Enhanced Cel Shading

Post by StrakeFengala » Sun Apr 15, 2012 5:07 pm

Greetings,

I took your shader and material files right off of the page here and it looks like 'CelShading.material' was tinkered with a little:

Code: Select all

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
   }
}
This fragment program is only for lights affecting the object and the shader program has no parameter called "diffuse" so I removed that and it compiles fine, it now looks like this:

Code: Select all

fragment_program CelShadingFP cg
{
   source CelShading.cg
   entry_point lighting_fp
   profiles ps_1_1 arbfp1 fp20
}
I am not getting these "reference to a non existing object" errors and my objects display their cel-shaded-ness, so it looks like the rest of what you have there is fine. Are you sure OGRE is configured (or compiled if built from source) properly? I am using OGRE v1.7.4 SDK Visual C++ build currently but I am not sure if the version matters that much.

I do admit, having put together those CG and material scripts myself to begin with, that the parts that I coded are not very good and desperately need a makeover, I was not too experienced then :oops:. The coding looks very confusing and has some inconsistent variable names, and is not very efficient because of so many passes, but it still works. So if you can provide any more info like the entire log file or a little code sample that might help a bit.

I hope you can get this sorted out.
0 x

User avatar
thebluefish
Gremlin
Posts: 170
Joined: Tue Apr 05, 2011 1:55 am

Re: Enhanced Cel Shading

Post by thebluefish » Thu Apr 19, 2012 11:45 pm

I put all of the programs into CelShading.program now, and I'm no longer getting those errors from before. It seems to have made some effect, I can now set the $diffuse properties properly and it seemed to be lit by quite a bit regardless of the fact that I have no ambient lighting. In fact, my scene's spotlight and point light aren't making any effect either =/ Weird.
0 x
During the code inspection, a couple of minor points were noticed: -

Function inlining was critical to performance.
For MSVC, at least, a "delete 0" caused execution of 11 assembly instructions, including a function call. So in cases where performance is at an absolute premium it can be worth inserting the extra manual test.

StrakeFengala
Kobold
Posts: 28
Joined: Wed Feb 10, 2010 11:18 pm
Location: USA

Re: Enhanced Cel Shading

Post by StrakeFengala » Fri Apr 20, 2012 4:56 am

I have updated the materials and programs dramatically, and cleaned up a lot of inconsistent code. Maybe starting fresh again will help sort out some of those problems. I think I know your at least one of your problems though. Firstly about the ambient lighting, the "cel_shading_diffuse.png" that comes with the OGRE package texture is grey-to-white rather than black-to-white like the specular texture, hence it comes with its own ambient lighting and it should be changed to black-to-white. Second, I don't believe I ever configured the shader to support directional lights (whoops) so spotlights and directional lights won't have any effect (or produce the wrong effect), I'm not sure what's going on with your point light though, maybe it has attenuation and it is not close enough?

[EDIT] Wiki page updated, uses better code than what I wrote down there so use the wiki code instead.[/EDIT]
  • --Main changes--
  • The materials are now single-pass with an optional "experimental outline" pass.
  • Took out the string variables called $diffuse, $specular and $shininess, and replaced those with their built-in pipeline counterparts with ambient and emissive enabled.
  • Renamed variables of the edge outline pass $modscale and $edgescale to $sinkScale and $edgeScale respectively. (I think those names better represent their purpose).
  • Specular texture mapping not re-implemented (yet), so don't try to add any specular mapping textures.
New CelShading.material, I create abstract passes to inherit from rather than complete materials, I feel it looks and works nicer that way:

Code: Select all

//
// Cel shading surface colors only.
abstract pass CelShading
{
	vertex_program_ref CelShadingVP {}
	fragment_program_ref CelShadingFP {}
	
	texture_unit diffRamp {
		texture cel_shading_diffuse.png 1d }
	texture_unit specRamp {
		texture cel_shading_specular.png 1d }
}

//
// Cel shading with a decal texture.
abstract pass CelShadingDecal
{	
	vertex_program_ref CelShadingVP {}
	fragment_program_ref CelShadingDecalFP {}
	
	texture_unit diffRamp {
		texture cel_shading_diffuse.png 1d }
	texture_unit specRamp {
		texture cel_shading_specular.png 1d }
	texture_unit decal {}
}

//
// Optional pass for experimental edge outlining.
abstract pass EdgeExperiment
{
	//
	// Diffuse tweaks outline color.
	diffuse 0 0 0
	
	//
	// Multiplier for how far the black mesh protrusion is, for edge size.
	set $edgeScale 1
	
	//
	// Multiplier for how far the black edge mesh should be pushed back to reduce Z fighting.
	//
	// Best value is greater for large meshes and smaller for small meshes. You may have to
	// tweak this variable dramatically.
	set $sinkScale 1

	vertex_program_ref EdgeExperimentVP
	{
		param_named edgeScale float $edgeScale
		param_named sinkScale float $sinkScale
	}
}
New CelShading.program:

Code: Select all

//
// The maximum number of lights per-object.
//
// If you change this, then you must enter 'CelShading.cg' and change the 'NUM_LIGHTS'
// definition to match this variable.
//
//
set $numLights 16

vertex_program CelShadingVP cg
{
	source CelShading.cg
	entry_point main_vp
	profiles vs_1_1 arbvp1
	
	default_params
	{
		param_named_auto worldViewProj worldviewproj_matrix
	}
}
fragment_program CelShadingFP cg
{	
	source CelShading.cg
	entry_point main_fp
	profiles ps_1_1 arbfp1
	compile_arguments MaxLocalParams=128
	
	default_params
	{
		param_named_auto eyePosition camera_position_object_space
	
		param_named_auto ambientColor surface_ambient_colour
		param_named_auto diffuseColor surface_diffuse_colour
		param_named_auto specularColor surface_specular_colour
		param_named_auto emissiveColor surface_emissive_colour
		param_named_auto shininess surface_shininess
		
		param_named_auto ambientLight ambient_light_colour
		
		param_named_auto lightDiffuse light_diffuse_colour_array $numLights
		param_named_auto lightSpecular light_specular_colour_array $numLights
		param_named_auto lightPosition light_position_object_space_array $numLights
		param_named_auto lightAttenuation light_attenuation_array $numLights
	}
}
fragment_program CelShadingDecalFP cg
{
	source CelShading.cg
	entry_point mainDecal_fp
	profiles ps_1_1 arbfp1
	compile_arguments MaxLocalParams=128
	
	default_params
	{
		param_named_auto eyePosition camera_position_object_space
	
		param_named_auto ambientColor surface_ambient_colour
		param_named_auto diffuseColor surface_diffuse_colour
		param_named_auto specularColor surface_specular_colour
		param_named_auto emissiveColor surface_emissive_colour
		param_named_auto shininess surface_shininess
		
		param_named_auto ambientLight ambient_light_colour
		
		param_named_auto lightDiffuse light_diffuse_colour_array $numLights
		param_named_auto lightSpecular light_specular_colour_array $numLights
		param_named_auto lightPosition light_position_object_space_array $numLights
		param_named_auto lightAttenuation light_attenuation_array $numLights
	}
}

//
// A terrible edge outline "algorithm"...
vertex_program EdgeExperimentVP cg
{
	source VertEdge.cg
	entry_point EdgeVP
	profiles vs_1_1 arbvp1
	
	default_params
	{
		param_named_auto eyePosition camera_position_object_space
		param_named_auto worldViewProj worldViewProj_matrix
		
		//
		// Edge color based on diffuse surface color
		param_named_auto edgeColor surface_diffuse_colour
	}
}
New CelShading.cg (still no support for directional lights...yet):

Code: Select all

//
// The maximum number of lights per-object.
//
// If you change this, then you must enter 'CelShading.program' and change the '$numLights'
// variable to match this definition.
#define NUM_LIGHTS 16

float2 calculateSurfaceLighting(	float3 pos,
									float3 norm,
									
									float4 lightPos,
									float4 lightAtten,
									sampler1D diffuseRamp,
									
									float3 eyePos,
									float shininess,
									sampler1D specRamp )
{
	norm = normalize(norm);
	
	//
	// Calculate light vector and distance
	float3 lightVec = lightPos.xyz - pos;
	float lightDist = length(lightVec);
	lightVec = normalize(lightVec);

	//
	// Calculate specular component
	float3 eyeVec = normalize(eyePos - pos);
	float3 halfDir = normalize(lightVec + eyeVec);
	
	//
	// Calculate light attenuation
	float luminosity = 0;
	if( lightAtten.x > lightDist)
		luminosity = 1.0 / 
			( lightAtten.y + lightAtten.z*lightDist + 
			  lightAtten.w*(lightDist*lightDist) );
	
	float diffComponent = min(max(dot(norm, lightVec), 0.0625), 0.9375)*luminosity;
	float specComponent = min(max(pow(max(dot(norm, halfDir), 0), shininess), 0.0625), 0.9375)*luminosity;
	
	float diffuse = tex1D(diffuseRamp, diffComponent).r;
	float specular = tex1D(specRamp, specComponent).r;

	return float2(diffuse, specular);
}

//
// Single-pass vertex program
float4 main_vp(	float4 iPos			: POSITION,
				float3 iNorm		: NORMAL,
				float2 iUV			: TEXCOORD0,
				out float3 oPos		: TEXCOORD0,
				out float3 oNorm	: TEXCOORD1,
				out float2 oUV		: TEXCOORD3,
				uniform float4x4 worldViewProj ) : POSITION
{
	oPos = iPos.xyz;
	oNorm = iNorm;
	oUV = iUV;
	return mul(worldViewProj, iPos);
}

//
// Single-pass fragment program
float4 main_fp(	float3 iPos 	: TEXCOORD0,
				float3 iNorm	: TEXCOORD1,
				
				uniform float3 eyePosition,
				
				uniform float4 ambientColor,
				uniform float4 diffuseColor,
				uniform float4 specularColor,
				uniform float4 emissiveColor,
				uniform float shininess,
				
				uniform float3 ambientLight,

				// Light params
				uniform float4 lightDiffuse[NUM_LIGHTS],
				uniform float4 lightSpecular[NUM_LIGHTS],
				uniform float4 lightPosition[NUM_LIGHTS],
				uniform float4 lightAttenuation[NUM_LIGHTS],

				// Texture params
				uniform sampler1D diffuseRamp	: register(s0),
				uniform sampler1D specRamp		: register(s1) ) : COLOR
{
	float4 surfaceColor = float4(ambientLight,1)*ambientColor;
	
	for (char i = 0; i < NUM_LIGHTS; i++)
	{
		if (lightDiffuse[i].r > 0 || lightDiffuse[i].g > 0 || lightDiffuse[i].b > 0)
		{
			float2 surfaceLight = calculateSurfaceLighting(
					iPos, iNorm,
					lightPosition[i], lightAttenuation[i], diffuseRamp,
					eyePosition, shininess, specRamp);
					
			surfaceColor += surfaceLight.x*diffuseColor*lightDiffuse[i]
				+ surfaceLight.y*lightSpecular[i]*specularColor;
		}
	}
	
	return saturate(emissiveColor + surfaceColor);
}

//
// Single-pass fragment program
float4 mainDecal_fp(float3 iPos 	: TEXCOORD0,
					float3 iNorm	: TEXCOORD1,
					float3 iUV		: TEXCOORD3,
					
					uniform float3 eyePosition,
					
					uniform float4 ambientColor,
					uniform float4 diffuseColor,
					uniform float4 specularColor,
					uniform float4 emissiveColor,
					uniform float shininess,
					
					uniform float3 ambientLight,

					// Light params
					uniform float4 lightDiffuse[NUM_LIGHTS],
					uniform float4 lightSpecular[NUM_LIGHTS],
					uniform float4 lightPosition[NUM_LIGHTS],
					uniform float4 lightAttenuation[NUM_LIGHTS],

					// Texture params
					uniform sampler1D diffuseRamp	: register(s0),
					uniform sampler1D specRamp		: register(s1),
					uniform sampler2D decalTex		: register(s2) ) : COLOR
{
	float4 surfaceColor = float4(ambientLight,1)*ambientColor;
	float4 specularSurface = 0;
	
	for (char i = 0; i < NUM_LIGHTS; i++)
	{
		if (lightDiffuse[i].r > 0 || lightDiffuse[i].g > 0 || lightDiffuse[i].b > 0)
		{
			float2 surfaceLight = calculateSurfaceLighting(
					iPos, iNorm,
					lightPosition[i], lightAttenuation[i], diffuseRamp,
					eyePosition, shininess, specRamp);
					
			surfaceColor += surfaceLight.x*diffuseColor*lightDiffuse[i];
			specularSurface += surfaceLight.y*lightSpecular[i]*specularColor;
		}
	}
	
	return saturate(tex2D(decalTex, iUV)*saturate(emissiveColor + surfaceColor) + specularSurface);
}
Variable-tweaked VertEdge.cg

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 sinkScale,
			uniform float edgeScale,
			uniform float4x4 worldViewProj)
{
	float4 E = normalize(eyePosition);
	position = mul(worldViewProj, position - sinkScale*E);

	normal.w = 0;
	normal = normalize(mul(worldViewProj, normal));

	position += ((sinkScale/8.0f)+1.0) * edgeScale * float4(normal.xy, 0, 0);

	oPos=position;
	oColor=edgeColor;
}
Test Ogrehead.mesh material override (Ogre.material):

Code: Select all

//
// Ogrehead.mesh Samples
//
import * from "CelShading.material"

material Ogre/Skin
{
	technique
	{
		pass : CelShadingDecal
		{	
			specular 0.4 0.6 0.4 32
			
			texture_unit decal {
				texture GreenSkin.jpg }
		}
		pass : EdgeExperiment
		{
			set $sinkScale 4
		}
	}
}
material Ogre/Tusks
{
	technique
	{
		pass : CelShadingDecal
		{
			specular 0.5 0.5 0.5 8
			diffuse 0.75 0.75 0.75
			
			texture_unit decal {
				texture tusk.jpg }
		}
		pass : EdgeExperiment {}
	}
}
material Ogre/Earring
{
	technique
	{
		pass : CelShading
		{
			ambient 0.8 0.8 0
			diffuse 0.8 0.8 0
			specular 1 1 1 8
		}
		pass : EdgeExperiment {}
	}
}
material Ogre/Eyes
{
	technique
	{
		pass : CelShading
		{
			ambient 1 0.4 0.4
			diffuse 1 0.7 0
			emissive 0.3 0.1 0
		}
		pass : EdgeExperiment {}
	}
}
Try these out and let me know the outcome and post sreenshots if possible if you want to. Make sure you delete (or put in a separate folder that is not being grabbed by your resource groups) all old files associated with cel shading (except for the textures, just fix the diffuse one in the pain program or GIMP or whatever your favorite image editing program is). Directional lights as I have said earlier are still not supported, so try making just one point light and make sure you do not change attenuation and see how that works.

I plan on finishing the cel-shading part of the shader by adding direction light and specular mapping support, and possibly the horrible black edge texture shading, and updating the wiki page for it soon (*soon* as in not tonight, I am sleepy). I will not be updating the experimental edge outlining because I believe after much altering that I cannot get a better visual outcome, really the best way to do it would be to use compositors and a sobel outlining technique but I have not dug into those yet.
0 x

User avatar
thebluefish
Gremlin
Posts: 170
Joined: Tue Apr 05, 2011 1:55 am

Re: Enhanced Cel Shading

Post by thebluefish » Fri Apr 20, 2012 7:33 pm

D3D9:
Image

OgreLog.log:

Code: Select all

11:27:34: Parsing script CelShading.program
11:27:34: OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program CelShadingFP: CG ERROR : "The compile returned an error."
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(109) : error C3004: function "length" not supported in this profile
(109) : error C3004: function "length" not supported in this profile
(109) : error C3004: function "length" not supported in this profile
(109) : error C3004: function "length" not supported in this profile
(20) : error C3004: function "normalize" not supported in this profile
(30) : error C3004: function "length" not supported in this profile
(31) : error C3004: function "normalize" not supported in this profile
(35) : error C3004: function "normalize" not supported in this profile
(36) : error C3004: function "normalize" not supported in this profile
(49) : error C3004: function "max" not supported in this profile
(54) : error C3004: function "pow" not supported in this profile
(54) : error C3004: function "max" not supported in this profile
 in CgProgram::loadFromSource at ..\..\..\..\..\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
11:27:34: High-level program CelShadingFP encountered an error during loading and is thus not supported.
OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program CelShadingFP: CG ERROR : "The compile returned an error."
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(109) : error C3004: function "length" not supported in this profile
(109) : error C3004: function "length" not supported in this profile
(109) : error C3004: function "length" not supported in this profile
(109) : error C3004: function "length" not supported in this profile
(20) : error C3004: function "normalize" not supported in this profile
(30) : error C3004: function "length" not supported in this profile
(31) : error C3004: function "normalize" not supported in this profile
(35) : error C3004: function "normalize" not supported in this profile
(36) : error C3004: function "normalize" not supported in this profile
(49) : error C3004: function "max" not supported in this profile
(54) : error C3004: function "pow" not supported in this profile
(54) : error C3004: function "max" not supported in this profile
 in CgProgram::loadFromSource at ..\..\..\..\..\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(28): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(30): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(31): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(32): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(33): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(34): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(36): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(38): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(39): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(40): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(41): setting of constant failed
11:27:34: OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program CelShadingDecalFP: CG ERROR : "The compile returned an error."
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(159) : error C3004: function "length" not supported in this profile
(159) : error C3004: function "length" not supported in this profile
(159) : error C3004: function "length" not supported in this profile
(159) : error C3004: function "length" not supported in this profile
(159) : error C3004: function "length" not supported in this profile
(20) : error C3004: function "normalize" not supported in this profile
(30) : error C3004: function "length" not supported in this profile
(31) : error C3004: function "normalize" not supported in this profile
(35) : error C3004: function "normalize" not supported in this profile
(36) : error C3004: function "normalize" not supported in this profile
(49) : error C3004: function "max" not supported in this profile
(54) : error C3004: function "pow" not supported in this profile
(54) : error C3004: function "max" not supported in this profile
 in CgProgram::loadFromSource at ..\..\..\..\..\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
11:27:34: High-level program CelShadingDecalFP encountered an error during loading and is thus not supported.
OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program CelShadingDecalFP: CG ERROR : "The compile returned an error."
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(159) : error C3004: function "length" not supported in this profile
(159) : error C3004: function "length" not supported in this profile
(159) : error C3004: function "length" not supported in this profile
(159) : error C3004: function "length" not supported in this profile
(159) : error C3004: function "length" not supported in this profile
(20) : error C3004: function "normalize" not supported in this profile
(30) : error C3004: function "length" not supported in this profile
(31) : error C3004: function "normalize" not supported in this profile
(35) : error C3004: function "normalize" not supported in this profile
(36) : error C3004: function "normalize" not supported in this profile
(49) : error C3004: function "max" not supported in this profile
(54) : error C3004: function "pow" not supported in this profile
(54) : error C3004: function "max" not supported in this profile
 in CgProgram::loadFromSource at ..\..\..\..\..\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(53): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(55): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(56): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(57): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(58): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(59): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(61): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(63): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(64): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(65): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(66): setting of constant failed
11:27:34: OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program CelShadingDecalSpecFP: CG ERROR : "The compile returned an error."
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(212) : error C3004: function "length" not supported in this profile
(212) : error C3004: function "length" not supported in this profile
(212) : error C3004: function "length" not supported in this profile
(212) : error C3004: function "length" not supported in this profile
(212) : error C3004: function "length" not supported in this profile
(212) : error C3004: function "length" not supported in this profile
(20) : error C3004: function "normalize" not supported in this profile
(30) : error C3004: function "length" not supported in this profile
(31) : error C3004: function "normalize" not supported in this profile
(35) : error C3004: function "normalize" not supported in this profile
(36) : error C3004: function "normalize" not supported in this profile
(49) : error C3004: function "max" not supported in this profile
(54) : error C3004: function "pow" not supported in this profile
(54) : error C3004: function "max" not supported in this profile
 in CgProgram::loadFromSource at ..\..\..\..\..\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
11:27:34: High-level program CelShadingDecalSpecFP encountered an error during loading and is thus not supported.
OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program CelShadingDecalSpecFP: CG ERROR : "The compile returned an error."
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(212) : error C3004: function "length" not supported in this profile
(212) : error C3004: function "length" not supported in this profile
(212) : error C3004: function "length" not supported in this profile
(212) : error C3004: function "length" not supported in this profile
(212) : error C3004: function "length" not supported in this profile
(212) : error C3004: function "length" not supported in this profile
(20) : error C3004: function "normalize" not supported in this profile
(30) : error C3004: function "length" not supported in this profile
(31) : error C3004: function "normalize" not supported in this profile
(35) : error C3004: function "normalize" not supported in this profile
(36) : error C3004: function "normalize" not supported in this profile
(49) : error C3004: function "max" not supported in this profile
(54) : error C3004: function "pow" not supported in this profile
(54) : error C3004: function "max" not supported in this profile
 in CgProgram::loadFromSource at ..\..\..\..\..\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(78): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(80): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(81): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(82): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(83): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(84): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(86): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(88): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(89): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(90): setting of constant failed
11:27:34: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1423)
11:27:34: Compiler error: invalid parameters in CelShading.program(91): setting of constant failed
OpenGL (single point light):
Image

OgreLog.log:

Code: Select all

11:27:34: Compiler error: unknown error in CelShading.material(5): token "vertex_program_ref" is not recognized
11:27:34: Compiler error: unknown error in CelShading.material(6): token "fragment_program_ref" is not recognized
11:27:34: Compiler error: unknown error in CelShading.material(8): token "texture_unit" is not recognized
11:27:34: Compiler error: unknown error in CelShading.material(11): token "texture_unit" is not recognized
I made sure EVERYTHING was wiped clean from my resources before adding those in.

Edit: Just to make sure, I trashed my entire Ogre directory, re-downloaded 1.7.4 from the Downloads section, replaced all my binaries, and rebuilt the entire project with the same error messages coming up.
Last edited by thebluefish on Fri Apr 20, 2012 10:19 pm, edited 1 time in total.
0 x
During the code inspection, a couple of minor points were noticed: -

Function inlining was critical to performance.
For MSVC, at least, a "delete 0" caused execution of 11 assembly instructions, including a function call. So in cases where performance is at an absolute premium it can be worth inserting the extra manual test.

StrakeFengala
Kobold
Posts: 28
Joined: Wed Feb 10, 2010 11:18 pm
Location: USA

Re: Enhanced Cel Shading

Post by StrakeFengala » Fri Apr 20, 2012 9:51 pm

Those errors in your log files look very odd. Unfortunately I am not experienced enough in the development of OGRE to know exactly what's going on there. I'll try to help as much as I can from this point on but I'm afraid I may not be able to help much more. But anyway I'll show you what I have here because it works on my machine and it may be able to help if you tried to use this setup.

Here is my 'resources.cfg' for my test application:

Code: Select all

[General]
FileSystem=./media
plugins.cfg:

Code: Select all

PluginFolder=.
 Plugin=RenderSystem_Direct3D9_d
 Plugin=RenderSystem_GL_d
 Plugin=Plugin_CgProgramManager_d
And list of files in the './media' directory, most of them are taken straight from the wiki page:
-cel_shading_diffuse.png
-cel_shading_specular.png (copied from 'cel_shading_diffuse.png')
-CelShading.cg
-CelShading.material
-CelShading.program
-GreenSkin.jpg (from the OGRE media)
-Ogre.material (from the Edge Outline Vertex Shader Experiment section in the wiki)
-ogrehead.mesh (from the OGRE media)
-Outline.material
-Outline.program
-tusk.jpg (from the OGRE media)
-VertEdge.cg
So try just loading JUST the Ogrehead.mesh with this configuration and one point light and do not edit any of the materials or programs and post a screenshot of the result. It may help to post the entire log file, only use the

Code: Select all

 mark to post it so that we get it in a scrollable text window. :wink:

[b]EDIT: Come to think of it those errors seem unrelated to the things I suggested tying so they might not work, unless of course you modified the files and they should just be replaced with the original. It might just be that your GPU does not support this fragment shader but I couldn't say because I don't know the details behind it. Posting the ENTIRE log file just might help with this.[/b]
0 x

User avatar
thebluefish
Gremlin
Posts: 170
Joined: Tue Apr 05, 2011 1:55 am

Re: Enhanced Cel Shading

Post by thebluefish » Fri Apr 20, 2012 10:37 pm

Sure thing! Created a new test unit, pointed my directories to a test resource directory with all of the correct files. Works PERFECT in OpenGL, but I'm getting the same errors with DirectX, even when I upped the profiles. My GPU is a GTX 9800+ and can handle most shaders (except of course, I can't get GPU geometry going).
0 x
During the code inspection, a couple of minor points were noticed: -

Function inlining was critical to performance.
For MSVC, at least, a "delete 0" caused execution of 11 assembly instructions, including a function call. So in cases where performance is at an absolute premium it can be worth inserting the extra manual test.

StrakeFengala
Kobold
Posts: 28
Joined: Wed Feb 10, 2010 11:18 pm
Location: USA

Re: Enhanced Cel Shading

Post by StrakeFengala » Fri Apr 20, 2012 10:43 pm

That's great that it works on OpenGL, glad you got that working!

Upping the profiles shouldn't have much to do with it though, I use D3D9 and it works perfectly. Look at the edit of my previous post and try putting up the entire log file, it contains some info on how the RenderSystem is set up and some of its capabilities.

EDIT: Yeah your GPU is fine --unless it has malfunctioned somewhere in the hardware-- because I use 9700M GT. You can try updating your graphics driver and see if that helps.
0 x

User avatar
thebluefish
Gremlin
Posts: 170
Joined: Tue Apr 05, 2011 1:55 am

Re: Enhanced Cel Shading

Post by thebluefish » Fri Apr 20, 2012 10:57 pm

Here is the log file:

Code: Select all

14:48:23: Creating resource group General
14:48:23: Creating resource group Internal
14:48:23: Creating resource group Autodetect
14:48:23: SceneManagerFactory for type 'DefaultSceneManager' registered.
14:48:23: Registering ResourceManager for type Material
14:48:23: Registering ResourceManager for type Mesh
14:48:23: Registering ResourceManager for type Skeleton
14:48:23: MovableObjectFactory for type 'ParticleSystem' registered.
14:48:23: OverlayElementFactory for type Panel registered.
14:48:23: OverlayElementFactory for type BorderPanel registered.
14:48:23: OverlayElementFactory for type TextArea registered.
14:48:23: Registering ResourceManager for type Font
14:48:23: ArchiveFactory for archive type FileSystem registered.
14:48:23: ArchiveFactory for archive type Zip registered.
14:48:23: DDS codec registering
14:48:23: FreeImage version: 3.15.1
14:48:23: This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
14:48:23: Supported formats: bmp,ico,jpg,jif,jpeg,jpe,jng,koa,iff,lbm,mng,pbm,pbm,pcd,pcx,pgm,pgm,png,ppm,ppm,ras,tga,targa,tif,tiff,wap,wbmp,wbm,psd,cut,xbm,xpm,gif,hdr,g3,sgi,exr,j2k,j2c,jp2,pfm,pct,pict,pic,3fr,arw,bay,bmq,cap,cine,cr2,crw,cs1,dc2,dcr,drf,dsc,dng,erf,fff,ia,iiq,k25,kc2,kdc,mdc,mef,mos,mrw,nef,nrw,orf,pef,ptx,pxn,qtk,raf,raw,rdc,rw2,rwl,rwz,sr2,srf,sti
14:48:23: Registering ResourceManager for type HighLevelGpuProgram
14:48:23: Registering ResourceManager for type Compositor
14:48:23: MovableObjectFactory for type 'Entity' registered.
14:48:23: MovableObjectFactory for type 'Light' registered.
14:48:23: MovableObjectFactory for type 'BillboardSet' registered.
14:48:23: MovableObjectFactory for type 'ManualObject' registered.
14:48:23: MovableObjectFactory for type 'BillboardChain' registered.
14:48:23: MovableObjectFactory for type 'RibbonTrail' registered.
14:48:23: Loading library ./plugins/RenderSystem_Direct3D9_d
14:48:23: Installing plugin: D3D9 RenderSystem
14:48:23: D3D9 : Direct3D9 Rendering Subsystem created.
14:48:23: D3D9: Driver Detection Starts
14:48:23: D3D9: Driver Detection Ends
14:48:23: Plugin successfully installed
14:48:23: Loading library ./plugins/RenderSystem_GL_d
14:48:23: Installing plugin: GL RenderSystem
14:48:23: OpenGL Rendering Subsystem created.
14:48:23: Plugin successfully installed
14:48:23: Loading library ./plugins/Plugin_CgProgramManager_d
14:48:23: Installing plugin: Cg Program Manager
14:48:23: Plugin successfully installed
14:48:23: *-*-* OGRE Initialising
14:48:23: *-*-* Version 1.7.4 (Cthugha)
14:48:23: D3D9 : RenderSystem Option: Allow NVPerfHUD = No
14:48:23: D3D9 : RenderSystem Option: FSAA = 0
14:48:23: D3D9 : RenderSystem Option: Floating-point mode = Fastest
14:48:23: D3D9 : RenderSystem Option: Full Screen = No
14:48:23: D3D9 : RenderSystem Option: Rendering Device = Monitor-1-NVIDIA GeForce 9800 GTX/9800 GTX+
14:48:23: D3D9 : RenderSystem Option: Resource Creation Policy = Create on all devices
14:48:23: D3D9 : RenderSystem Option: VSync = No
14:48:23: D3D9 : RenderSystem Option: VSync Interval = 1
14:48:23: D3D9 : RenderSystem Option: Video Mode = 1024 x 768 @ 32-bit colour
14:48:23: D3D9 : RenderSystem Option: sRGB Gamma Conversion = No
14:48:24: CPU Identifier & Features
14:48:24: -------------------------
14:48:24:  *   CPU ID: GenuineIntel: Intel(R) Core(TM)2 Duo CPU     E8500  @ 3.16GHz
14:48:24:  *      SSE: yes
14:48:24:  *     SSE2: yes
14:48:24:  *     SSE3: yes
14:48:24:  *      MMX: yes
14:48:24:  *   MMXEXT: yes
14:48:24:  *    3DNOW: no
14:48:24:  * 3DNOWEXT: no
14:48:24:  *     CMOV: yes
14:48:24:  *      TSC: yes
14:48:24:  *      FPU: yes
14:48:24:  *      PRO: yes
14:48:24:  *       HT: no
14:48:24: -------------------------
14:48:24: D3D9 : Subsystem Initialising
14:48:24: Registering ResourceManager for type Texture
14:48:24: Registering ResourceManager for type GpuProgram
14:48:24: D3D9RenderSystem::_createRenderWindow "Derived", 1024x768 windowed  miscParams: FSAA=0 FSAAHint= colourDepth=32 gamma=false monitorIndex=0 useNVPerfHUD=false vsync=false vsyncInterval=1 
14:48:24: D3D9 : Created D3D9 Rendering Window 'Derived' : 1024x768, 32bpp
14:48:24: D3D9 : WARNING - disabling VSync in windowed mode can cause timing issues at lower frame rates, turn VSync on if you observe this problem.
14:48:24: D3D9: Vertex texture format supported - PF_FLOAT16_RGB
14:48:24: D3D9: Vertex texture format supported - PF_FLOAT16_RGBA
14:48:24: D3D9: Vertex texture format supported - PF_FLOAT32_RGB
14:48:24: D3D9: Vertex texture format supported - PF_FLOAT32_RGBA
14:48:24: D3D9: Vertex texture format supported - PF_FLOAT16_R
14:48:24: D3D9: Vertex texture format supported - PF_FLOAT32_R
14:48:24: D3D9: Vertex texture format supported - PF_FLOAT16_GR
14:48:24: D3D9: Vertex texture format supported - PF_FLOAT32_GR
14:48:24: RenderSystem capabilities
14:48:24: -------------------------
14:48:24: RenderSystem Name: Direct3D9 Rendering Subsystem
14:48:24: GPU Vendor: nvidia
14:48:24: Device Name: Monitor-1-NVIDIA GeForce 9800 GTX/9800 GTX+
14:48:24: Driver Version: 8.17.12.9573
14:48:24:  * Fixed function pipeline: yes
14:48:24:  * Hardware generation of mipmaps: yes
14:48:24:  * Texture blending: yes
14:48:24:  * Anisotropic texture filtering: yes
14:48:24:  * Dot product texture operation: yes
14:48:24:  * Cube mapping: yes
14:48:24:  * Hardware stencil buffer: yes
14:48:24:    - Stencil depth: 8
14:48:24:    - Two sided stencil support: yes
14:48:24:    - Wrap stencil values: yes
14:48:24:  * Hardware vertex / index buffers: yes
14:48:24:  * Vertex programs: yes
14:48:24:  * Number of floating-point constants for vertex programs: 256
14:48:24:  * Number of integer constants for vertex programs: 16
14:48:24:  * Number of boolean constants for vertex programs: 16
14:48:24:  * Fragment programs: yes
14:48:24:  * Number of floating-point constants for fragment programs: 224
14:48:24:  * Number of integer constants for fragment programs: 16
14:48:24:  * Number of boolean constants for fragment programs: 16
14:48:24:  * Geometry programs: no
14:48:24:  * Number of floating-point constants for geometry programs: 0
14:48:24:  * Number of integer constants for geometry programs: 8
14:48:24:  * Number of boolean constants for geometry programs: 0
14:48:24:  * Supported Shader Profiles: hlsl ps_1_1 ps_1_2 ps_1_3 ps_1_4 ps_2_0 ps_2_a ps_2_b ps_2_x ps_3_0 vs_1_1 vs_2_0 vs_2_a vs_2_x vs_3_0
14:48:24:  * Texture Compression: yes
14:48:24:    - DXT: yes
14:48:24:    - VTC: no
14:48:24:    - PVRTC: no
14:48:24:  * Scissor Rectangle: yes
14:48:24:  * Hardware Occlusion Query: yes
14:48:24:  * User clip planes: yes
14:48:24:  * VET_UBYTE4 vertex element type: yes
14:48:24:  * Infinite far plane projection: yes
14:48:24:  * Hardware render-to-texture: yes
14:48:24:  * Floating point textures: yes
14:48:24:  * Non-power-of-two textures: yes
14:48:24:  * Volume textures: yes
14:48:24:  * Multiple Render Targets: 4
14:48:24:    - With different bit depths: yes
14:48:24:  * Point Sprites: yes
14:48:24:  * Extended point parameters: yes
14:48:24:  * Max Point Size: 10
14:48:24:  * Vertex texture fetch: yes
14:48:24:  * Number of world matrices: 0
14:48:24:  * Number of texture units: 8
14:48:24:  * Stencil buffer depth: 8
14:48:24:  * Number of vertex blend matrices: 0
14:48:24:    - Max vertex textures: 4
14:48:24:    - Vertex textures shared: no
14:48:24:  * Render to Vertex Buffer : no
14:48:24:  * DirectX per stage constants: yes
14:48:24: ***************************************
14:48:24: *** D3D9 : Subsystem Initialised OK ***
14:48:24: ***************************************
14:48:24: DefaultWorkQueue('Root') initialising on thread 0038FEF0.
14:48:24: DefaultWorkQueue('Root')::WorkerFunc - thread 0411E118 starting.
14:48:24: DefaultWorkQueue('Root')::WorkerFunc - thread 0411E148 starting.
14:48:24: Particle Renderer Type 'billboard' registered
14:48:24: Added resource location 'wanchu/test' of type 'FileSystem' to resource group 'General'
14:48:24: Parsing scripts for resource group Autodetect
14:48:24: Finished parsing scripts for resource group Autodetect
14:48:24: Parsing scripts for resource group General
14:48:24: Parsing script CelShading.program
14:48:24: OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program CelShadingFP: The compile returned an error.
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(19) : error C3004: function "float3 normalize(float3);" not supported in this profile
(24) : error C3004: function "float length(float3);" not supported in this profile
(25) : error C3004: function "float3 normalize(float3);" not supported in this profile
(29) : error C3004: function "float3 normalize(float3);" not supported in this profile
(30) : error C3004: function "float3 normalize(float3);" not supported in this profile
(40) : error C3004: function "float min(float, float);" not supported in this profile
(40) : error C3004: function "float max(float, float);" not supported in this profile
(41) : error C3004: function "float min(float, float);" not supported in this profile
(41) : error C3004: function "float max(float, float);" not supported in this profile
(41) : error C3004: function "float pow(float, float);" not supported in this profile
(41) : error C3004: function "float max(float, float);" not supported in this profile
 in CgProgram::loadFromSource at ..\..\..\..\..\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
14:48:24: High-level program CelShadingFP encountered an error during loading and is thus not supported.
OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program CelShadingFP: The compile returned an error.
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(19) : error C3004: function "float3 normalize(float3);" not supported in this profile
(24) : error C3004: function "float length(float3);" not supported in this profile
(25) : error C3004: function "float3 normalize(float3);" not supported in this profile
(29) : error C3004: function "float3 normalize(float3);" not supported in this profile
(30) : error C3004: function "float3 normalize(float3);" not supported in this profile
(40) : error C3004: function "float min(float, float);" not supported in this profile
(40) : error C3004: function "float max(float, float);" not supported in this profile
(41) : error C3004: function "float min(float, float);" not supported in this profile
(41) : error C3004: function "float max(float, float);" not supported in this profile
(41) : error C3004: function "float pow(float, float);" not supported in this profile
(41) : error C3004: function "float max(float, float);" not supported in this profile
 in CgProgram::loadFromSource at ..\..\..\..\..\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(30): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(32): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(33): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(34): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(35): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(36): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(38): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(40): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(41): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(42): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(43): setting of constant failed
14:48:24: OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program CelShadingDecalFP: The compile returned an error.
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(19) : error C3004: function "float3 normalize(float3);" not supported in this profile
(24) : error C3004: function "float length(float3);" not supported in this profile
(25) : error C3004: function "float3 normalize(float3);" not supported in this profile
(29) : error C3004: function "float3 normalize(float3);" not supported in this profile
(30) : error C3004: function "float3 normalize(float3);" not supported in this profile
(40) : error C3004: function "float min(float, float);" not supported in this profile
(40) : error C3004: function "float max(float, float);" not supported in this profile
(41) : error C3004: function "float min(float, float);" not supported in this profile
(41) : error C3004: function "float max(float, float);" not supported in this profile
(41) : error C3004: function "float pow(float, float);" not supported in this profile
(41) : error C3004: function "float max(float, float);" not supported in this profile
 in CgProgram::loadFromSource at ..\..\..\..\..\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
14:48:24: High-level program CelShadingDecalFP encountered an error during loading and is thus not supported.
OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program CelShadingDecalFP: The compile returned an error.
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(0) : warning C6504: Unknown profile option 'MaxLocalParams' ignored
(19) : error C3004: function "float3 normalize(float3);" not supported in this profile
(24) : error C3004: function "float length(float3);" not supported in this profile
(25) : error C3004: function "float3 normalize(float3);" not supported in this profile
(29) : error C3004: function "float3 normalize(float3);" not supported in this profile
(30) : error C3004: function "float3 normalize(float3);" not supported in this profile
(40) : error C3004: function "float min(float, float);" not supported in this profile
(40) : error C3004: function "float max(float, float);" not supported in this profile
(41) : error C3004: function "float min(float, float);" not supported in this profile
(41) : error C3004: function "float max(float, float);" not supported in this profile
(41) : error C3004: function "float pow(float, float);" not supported in this profile
(41) : error C3004: function "float max(float, float);" not supported in this profile
 in CgProgram::loadFromSource at ..\..\..\..\..\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(55): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(57): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(58): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(59): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(60): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(61): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(63): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(65): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(66): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(67): setting of constant failed
14:48:24: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\..\..\OgreMain\src\OgreGpuProgramParams.cpp (line 1425)
14:48:24: Compiler error: invalid parameters in CelShading.program(68): setting of constant failed
14:48:24: Parsing script CelShading.material
14:48:24: Parsing script ogrehead.material
14:48:24: Finished parsing scripts for resource group General
14:48:24: Parsing scripts for resource group Internal
14:48:24: Finished parsing scripts for resource group Internal
14:48:24: Demo initialized!
14:48:24: Entering MenuState...
14:48:24: Mesh: Loading ogrehead.mesh.
14:48:24: WARNING: material Ogre/Eyes has no supportable Techniques and will be blank. Explanation: 
Pass 0: Fragment program CelShadingFP cannot be used - compile error.

14:48:24: WARNING: material Ogre/Skin has no supportable Techniques and will be blank. Explanation: 
Pass 0: Fragment program CelShadingDecalFP cannot be used - compile error.

14:48:24: WARNING: material Ogre/Earring has no supportable Techniques and will be blank. Explanation: 
Pass 0: Fragment program CelShadingFP cannot be used - compile error.

14:48:24: WARNING: material Ogre/Tusks has no supportable Techniques and will be blank. Explanation: 
Pass 0: Fragment program CelShadingDecalFP cannot be used - compile error.

14:48:27: Main loop quit
14:48:27: Leaving MenuState...
14:48:27: Shutdown OGRE...
14:48:27: DefaultWorkQueue('Root') shutting down on thread 0038FEF0.
14:48:27: DefaultWorkQueue('Root')::WorkerFunc - thread 0411E148 stopped.
14:48:27: DefaultWorkQueue('Root')::WorkerFunc - thread 0411E118 stopped.
14:48:27: *-*-* OGRE Shutdown
14:48:27: Unregistering ResourceManager for type Compositor
14:48:27: Unregistering ResourceManager for type Font
14:48:27: Unregistering ResourceManager for type Skeleton
14:48:27: Unregistering ResourceManager for type Mesh
14:48:27: Unregistering ResourceManager for type HighLevelGpuProgram
14:48:27: Uninstalling plugin: Cg Program Manager
14:48:27: Plugin successfully uninstalled
14:48:27: Unloading library ./plugins/Plugin_CgProgramManager_d
14:48:27: Uninstalling plugin: GL RenderSystem
14:48:27: *** Stopping Win32GL Subsystem ***
14:48:27: Plugin successfully uninstalled
14:48:27: Unloading library ./plugins/RenderSystem_GL_d
14:48:27: Uninstalling plugin: D3D9 RenderSystem
14:48:27: D3D9 : Shutting down cleanly.
14:48:27: Unregistering ResourceManager for type Texture
14:48:27: Unregistering ResourceManager for type GpuProgram
14:48:27: D3D9 : Direct3D9 Rendering Subsystem destroyed.
14:48:27: Plugin successfully uninstalled
14:48:27: Unloading library ./plugins/RenderSystem_Direct3D9_d
14:48:27: Unregistering ResourceManager for type Material

0 x
During the code inspection, a couple of minor points were noticed: -

Function inlining was critical to performance.
For MSVC, at least, a "delete 0" caused execution of 11 assembly instructions, including a function call. So in cases where performance is at an absolute premium it can be worth inserting the extra manual test.

StrakeFengala
Kobold
Posts: 28
Joined: Wed Feb 10, 2010 11:18 pm
Location: USA

Re: Enhanced Cel Shading

Post by StrakeFengala » Fri Apr 20, 2012 11:28 pm

Wow...I just looked at the source for my own test code and it turns out that the render system was forced to OpenGL regardless of what 'Ogre.cfg' said :shock:. I tried switching to D3D9 and it doesn't work, it gives me the same errors you are getting.

You can blame me for this... :oops:

I'll fiddle around with the code a bit and see if I can get something working. I have a feeling it's in the compiler arguments that I passed in the program. :roll:
0 x

User avatar
thebluefish
Gremlin
Posts: 170
Joined: Tue Apr 05, 2011 1:55 am

Re: Enhanced Cel Shading

Post by thebluefish » Fri Apr 20, 2012 11:38 pm

Phew, glad to hear my gfx card wasn't dying or something xD I have no knowledge of shaders (for now), so I didn't even know where to begin :cry:
0 x
During the code inspection, a couple of minor points were noticed: -

Function inlining was critical to performance.
For MSVC, at least, a "delete 0" caused execution of 11 assembly instructions, including a function call. So in cases where performance is at an absolute premium it can be worth inserting the extra manual test.

StrakeFengala
Kobold
Posts: 28
Joined: Wed Feb 10, 2010 11:18 pm
Location: USA

Re: Enhanced Cel Shading

Post by StrakeFengala » Sat Apr 21, 2012 2:04 am

Seems like I was fooled by the program with OpenGL telling me that I could put in 16+ lights with diffuse specular and attenuation and decal and specular maps and cram those into a single pass fragment program with 'ps_1_1' as the shader version. Funny thing was that I still got good performance.

Anyway it looks like this is getting more complicated. I posted the shader on the wiki too soon, I hope I have not caused any problems there. The shader version has to be moved all the way up to 'ps_2_x' in order to have multiple lights with per-pixel calculations and all the other stuff. I will try to put something together and possibly make down-toned versions of the shader for older GPU compatibility, but don't expect to see anything more posted today. I apologize for the inconvenience, you can try just using OpenGL for now if it suits you.

EDIT:

Main problem now is that passing the compiler argument "MaxLocalParams" will not work in D3D9 for some reason, but does work in OpenGL.

So right now the max lights is 6 because I keep getting
(0) : error C6007: Constant register limit exceeded; more than 32 constant registers needed to compiled program
in my log file, EVEN though my GPU supports 224. I'm not sure why it's capped at 32. I suppose 6 lights per object is a reasonable number to deal with for now, nothing I can do about that.
0 x

User avatar
thebluefish
Gremlin
Posts: 170
Joined: Tue Apr 05, 2011 1:55 am

Re: Enhanced Cel Shading

Post by thebluefish » Sat Apr 21, 2012 2:29 am

Honestly, any game that wants to utilize cell shading shouldn't be taking more than 6 lights to begin with :lol:
0 x
During the code inspection, a couple of minor points were noticed: -

Function inlining was critical to performance.
For MSVC, at least, a "delete 0" caused execution of 11 assembly instructions, including a function call. So in cases where performance is at an absolute premium it can be worth inserting the extra manual test.

StrakeFengala
Kobold
Posts: 28
Joined: Wed Feb 10, 2010 11:18 pm
Location: USA

Re: Enhanced Cel Shading

Post by StrakeFengala » Sat Apr 21, 2012 2:46 am

Well that's good to know, I haven't had much experience there so I didn't know that :lol:, but it looks like we're good now 8). I updated the wiki page again with D3D9 support. Still no spotlights yet, I need to work on that eventually. I had to make some major tweaks to the shader code because D3D9 didn't like some of my functions, but the outcome should be the same. :wink:
0 x

Post Reply