I was trying to get a Cel Shader running on iOS. However the Enhanced Cel Shader program (http://www.ogre3d.org/tikiwiki/tiki-ind ... CelShading) is not supported by my iPhone 4S and the one from the examples just makes my mesh black. I would be very grateful for tips on how to get a Cel Shader running on iOS.
My code currently looks like this but the color of my texture is not used. Instead the color of the cel_shading_diffuse.png is used for texture lookup.
cel_shader_vertex.glsles:
Code: Select all
#version 100
precision mediump int;
precision mediump float;
/* Cel shading vertex program for single-pass rendering
In this program, we want to calculate the diffuse and specular
ramp components, and the edge factor (for doing simple outlining)
For the outlining to look good, we need a pretty well curved model.
*/
// Parameters
attribute vec4 vertex;
attribute vec3 normal;
attribute vec4 uv0;
uniform vec3 lightPosition; // object space
uniform vec3 eyePosition; // object space
uniform vec4 shininess;
uniform mat4 worldViewProj;
varying float diffuseIn;
varying float specularIn;
varying float edge;
varying vec4 uvIn;
void main()
{
// calculate output position
gl_Position = worldViewProj * vertex;
// calculate light vector
vec3 N = normalize(normal);
vec3 L = normalize(lightPosition - vertex.xyz);
vec3 E = normalize(eyePosition - vertex.xyz);
// Calculate diffuse component
diffuseIn = max(dot(N, L) , 0.0);
// Mask off specular if diffuse is 0
if (diffuseIn == 0.0)
{
specularIn = 0.0;
}
else
{
// Calculate specular component
vec3 H = normalize(L + E);
specularIn = pow(max(dot(N, H), 0.0), shininess.x);
}
// Edge detection, dot eye and normal vectors
edge = max(dot(N, E), 0.0);
uvIn = uv0;
}
Code: Select all
#version 100
precision mediump int;
precision mediump float;
/* Cel shading fragment program for single-pass rendering */
uniform vec4 diffuse;
uniform vec4 specular;
uniform sampler2D diffuseRamp;
uniform sampler2D specularRamp;
uniform sampler2D edgeRamp;
uniform sampler2D texture;
varying float diffuseIn;
varying float specularIn;
varying float edge;
varying vec4 uvIn;
void main()
{
// Step functions from textures
vec4 diffuseStep = texture2D(diffuseRamp, vec2(diffuseIn));
vec4 specularStep = texture2D(specularRamp, vec2(specularIn));
vec4 edgeStep = texture2D(edgeRamp, vec2(edge));
gl_FragColor = edgeStep.x * ((texture2D(texture, uvIn.xy) * diffuseStep.x) +
(specular * specularStep.x));
}
Material File:
(dana_hair_clothes.png is a 8*8 pixel texture where simple colors are stored)
Code: Select all
material Clothes
{
receive_shadows on
technique
{
pass Clothes
{
vertex_program_ref cel_shaderVPGLSL
{
// map shininess from custom renderable param 1
param_named_auto shininess custom 1
}
fragment_program_ref cel_shaderFPGLSL
{
// shared_params_ref lighting
// map diffuse from custom renderable param 2
param_named_auto diffuse custom 2
// map specular from custom renderable param 3
param_named_auto specular custom 3
param_named_auto texture custom 4
}
texture_unit
{
texture cel_shading_diffuse.png 1d
tex_address_mode clamp
filtering none
}
texture_unit
{
texture cel_shading_specular.png 1d
tex_address_mode clamp
filtering none
}
texture_unit
{
texture cel_shading_edge.png 1d
tex_address_mode clamp
filtering none
}
texture_unit
{
texture dana_hair_clothes.png
tex_address_mode wrap
scale 1.0 1.0
colour_op modulate
}
}
}
}
Greetings Mike