We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I have a toon shader which works well, but, as you can see in the fragment shader code below, allways output 'greenish' colors to the drawn geometry.
To test the shader, I use a glut teapot, with an OpenGL material defined (ambient, diffuse, specular, shininess).
What I would like is to modify the fragment shader in order for it to output a color based on the current material diffuse term.
**Toon vertex Shader code : **
String[] toonShaderVertexCode =
{
"varying vec3 eyeSpaceNormal;",
"void main()",
"{",
" eyeSpaceNormal = gl_NormalMatrix * gl_Normal;",
" gl_Position = ftransform();",
"}"
};
Toon fragment shader code :
String[] toonShaderFragmentCode =
{
"varying vec3 eyeSpaceNormal;",
"vec4 toonify(in float intensity)",
"{",
" if (intensity > 0.95)",
" return vec4(0.5, 1.0, 0.5, 1.0);",
" else if (intensity > 0.5)",
" return vec4(0.3, 0.6, 0.3, 1.0);",
" else if (intensity > 0.25)",
" return vec4(0.2, 0.4, 0.2, 1.0);",
" else",
" return vec4(0.1, 0.2, 0.1, 1.0);",
" }",
" void main() ",
" {",
" vec3 normal = normalize(eyeSpaceNormal);",
" float intensity = dot(normalize(gl_LightSource[0].position.xyz), normal);",
" gl_FragColor = toonify(intensity);",
" }",
};
I have tried replacing the last line of the fragment shader with this line :
gl_FragColor = toonify(intensity) + gl_FrontMaterial.diffuse ;"
But I don't quite get the wanted results..
Maybe it would be a good idea to completely take out the 'green coloring' in the fragment shader, and replace it by some code that "toonify" the same way, but based on the current material diffuse color..
But I don't have any clue on how to do this..
Any idea, you hardcore GLSL jedis ?