Here is the code for a material using blender's own cel shading cg program while also using your very own texture, instead of manually coloring it in material by material as the example program does.
Code: Select all
// -------------------------------
// Cel Shading Section, so we can use Ogre's CelShading tools. You probably have to delete the original ones in the materials/programs
// folder or you will have the same thing defined twice. Or just rename them(?)
// -------------------------------
vertex_program Ogre/CelShadingVP cg
{
source Example_CelShading.cg
entry_point main_vp
profiles vs_1_1 arbvp1
default_params
{
param_named_auto lightPosition light_position_object_space 0
param_named_auto eyePosition camera_position_object_space
param_named_auto worldViewProj worldviewproj_matrix
param_named shininess float 10
}
}
fragment_program Ogre/CelShadingFP cg
{
source Example_CelShading.cg
entry_point main_fp
profiles ps_1_1 arbfp1 fp20
}
// Here we go
material my_material
{
technique
{
// This pass draws your texture on with absolutely no shading, so that its just the texture, plain and simple.
pass
{
lighting off
shading flat
texture_unit
{
texture chord_texture.tga
tex_coord_set 0
filtering trilinear
}
}
// This pass does the magic: it draws cel shading on TOP of the texture
pass
{
// This will keep things looking nice.
depth_bias 16
// Everything below is from the example
vertex_program_ref Ogre/CelShadingVP
{
// map shininess from custom renderable param 1
param_named_auto shininess custom 1
}
fragment_program_ref Ogre/CelShadingFP
{
// map diffuse from custom renderable param 2
param_named_auto diffuse custom 2
// map specular from custom renderable param 2
param_named_auto specular custom 3
}
texture_unit
{
texture cel_shading_diffuse.png 1d
tex_address_mode clamp
filtering none
}
texture_unit
{
texture cel_shading_specular.png 1d
tex_address_mode clamp
filtering none
}
texture_unit
{
texture cel_shading_edge.png 1d
tex_address_mode clamp
filtering none
}
// Dont forget to modulate so the two passes will blend!
scene_blend modulate
}
}
}
Code: Select all
void TutorialApplication::createScene(void)
{
Ogre::Light* light = mSceneMgr->createLight();
light->setPosition(20, 40, -50);
Ogre::Entity* ent = mSceneMgr->createEntity("Mesh", "Mesh.mesh");
ent->getSubEntity(1)->setMaterialName("chord_body_mat"); // subentity of 1 is the material i want, is mesh specific.
mSceneMgr->getRootSceneNode()->attachObject(ent);
Ogre::SubEntity* sub = ent->getSubEntity(1);
sub->setCustomParameter(1, Ogre::Vector4(35, 0, 0, 0)); // Shininess
sub->setCustomParameter(2, Ogre::Vector4(1, 1, 1, 1)); // Diffuse
sub->setCustomParameter(3, Ogre::Vector4(1, 1, 1, 1)); // Specular
}