[cel shading]how is mapped the 1d texture ?

Started by
2 comments, last by airseb 20 years, 3 months ago
previous question answered by the first post: [cel shading]why the lighting is managed by software and not by hardware ? why don't they use open gl functions for lighting ? new question : how is mapped the 1d texture ? is it mapped on all the surface of the polygon ? if yes how ? because the height is of 1, isn't it ? [edited by - airseb on January 15, 2004 1:39:26 PM]
Advertisement
Because standard OpenGL lighting (with the fixed function pipeline) doesn''t allow enough control to produce good cell shaded lighting. It will always produce a continuous gradient, when you need non-linear shading. And when you need non-linear shading the answer is almost always to switch to texture based methods.
up for the new question !
I'm not an expert on cel-shading, but as far as I know, you "map" the lighting value you get (which will be from 0 to 1.0) into a 1D texture. Generally, the 1D texture is composed of chunks of different colors in a row, so as the lighting intensities change on the polygon, they skip to different colors rather than grading through various shades like real-life lighting would appear. You map it using glTexCoord1f(). Something like the following:

glBindTexture(GL_TEXTURE_1D, celtexture);glBegin(GL_TRIANGLES);float intensity = dot3(light_direction, poly.normal);if (intensity < 0.0f) intensity = 0.0f;glTexCoord2f(intensity);glVertex3f(poly.vertex[0], poly.vertex[1], poly.vertex[2]);glEnd();    


You could accomplish this in a far more efficient manner with a vertex shader, but whatever

edit: the way I originally wrote it would interpolate texture values between the vertices, where each vertex had a separate calculation -- woops. You want the whole polygon one color... that's one way of doing it at least.

edit2: duh, don't need the for loop either, I'm stupid.
[edited by - chawk on January 15, 2004 6:46:13 PM]

[edited by - chawk on January 15, 2004 6:51:19 PM]

This topic is closed to new replies.

Advertisement