This topic is now archived and is closed to further replies.


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

Recommended Posts

airseb    100
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]

Share this post

Link to post
Share on other sites
OrangyTang    1298
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.

Share this post

Link to post
Share on other sites
chawk    122
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);

float intensity = dot3(light_direction, poly.normal);
if (intensity < 0.0f) intensity = 0.0f;
glVertex3f(poly.vertex[0], poly.vertex[1], poly.vertex[2]);


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]

Share this post

Link to post
Share on other sites