O'Reilly logo

Irrlicht 1.7 Realtime 3D Engine by Aung Sithu Kyaw, Johannes Stein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - using a toon shader

Let's copy the Toon.frag and Toon.vert files from the GLSL demo to your Irrlicht project folder and here's our vertex shader:

varying vec3 Normal;
void main(void)
{
Normal = normalize(gl_NormalMatrix * gl_Normal);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

And this is our little fragment shader:

uniform vec3 DiffuseColor;
uniform vec3 PhongColor;
uniform float Edge;
uniform float Phong;
varying vec3 Normal;
void main (void)
{
vec3 color = DiffuseColor;
float f = dot(vec3(0,0,1),Normal);
if (abs(f) < Edge)
color = vec3(0);
if (f > Phong)
color = PhongColor;
gl_FragColor = vec4(color, 1);
}

To feed the constant uniform values to our shader from the Irrlicht program we need to implement the IShaderConstantSetCallBack ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required