Archived

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

cellShading color index?

This topic is 5379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, i am trying to figure out some code out of the cell shading article of http://www.gamedev.net/reference/programming/features/celshading/ everyting is working fine until i try to use the color instead of the 1d texture. i don''t understand how i can have the sharp lighting effect (the cel shading effect). Do i have to redefine the color index or something? because right now when i am mapping the light value from my array(0-31) that contain mainly 0.0 - 0.4 and 0.8 value the polygon only merge the color from one index to the other instead of having a clean separation. any solution? thanks siddim

Share this post


Link to post
Share on other sites
If you want to replace 1D texturing by OpenGL's standard colouring, I'm afraid you won't get the desired effect.

>> because right now when i am mapping the light value from
>> my array(0-31) that contain mainly 0.0 - 0.4 and 0.8 value
>> the polygon only merge the color from one index to the
>> other instead of having a clean separation.
I don't see very good the problem. Could you please post a screenshot ?

[Edit]
I've read the article again and now I think I see what you mean, if you're talking about cel-shading over a textured model.
The Sharp Lightmap is based on the fact that interpolating integers do not keep fractional parts of floating-point numbers. Unfortunately, there is no such control over OpenGL since interpolation is done regardless the color is an integer or not, and unless you post-multiply (multipass, thus slow and awful). Moreover I'm not sure that Direct3D could do it either.
In other words, this algorithm may not work.

The best you could do is multitexturing which is really straight-forward according to the fact that you already have a working cel-shading rendering for texture-less models.

[edited by - vincoof on March 25, 2003 8:41:44 AM]

Share this post


Link to post
Share on other sites
here''s a screen shot of the normal rendering without any shading:

http://www.thinbox.ca/_images/goliath/noShading.jpg

and here is the version with the cell shading tentative that is''n working:

http://www.thinbox.ca/_images/goliath/NotWorkingCelShading.jpg

the cell shading is working but only if we scale the model on the cell pass:
http://www.thinbox.ca/_images/goliath/scaleCelShading.jpg

but this cause the cell to display a little off the model and will produce bad display on concave model:

http://www.thinbox.ca/_images/goliath/scaleCelShadingMistake.jpg

so you think we better go with multitexturing?

siddim


Share this post


Link to post
Share on other sites
ok. if you scale the model, that means you are using a multipass technique and you are experiencing z-fighting issues.

If I get the idea right, you have 2 passes :
- the first pass renders the textured model,
- the second pass renders the cell-shaded model.

In that case, you need to setup a special depth test for the second pass, but you don''t need to scale :

renderTexturedModel();
glDepthFunc(GL_EQUAL); // set depth test to equality
renderCelShadedModel();
glDepthFunc(GL_LESS); // restore depth test

Yes it would be better with multitexturing. It would be faster and there would be no depth artefact. The only con is that the multitexture extension must be supported, which is not guaranteed on all OpenGL-compatible cards (although more than 95% graphics cards support multitexturing today).

Share this post


Link to post
Share on other sites
i just enable the depth call you tell me, and it work fine, but still i think i will try the multitexturing because the way we do it right now can can''t have darker color for the shader, or i have''n try enough

http://www.thinbox.ca/_images/goliath/CelShadingWithDepth.jpg

thanks alot.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
here''s the blending function, have''n play alot with it yet.

glBlendFunc(GL_ONE_MINUS_SRC_COLOR,GL_ONE);

Share this post


Link to post
Share on other sites
nice,

it work fine now, thanks

http://www.thinbox.ca/_images/goliath/CelShading.jpg

you beleive that multitexturing is better and faster then this method?

Share this post


Link to post
Share on other sites
Faster... no doubt multitexturing is.
Better ? That''s up to you to evaluate what "better" is !

Do you target a minium hardware ? If the program will only run on graphics cards that have (at least) two texture units, you should really use multitexturing.
Your application can speed up up to twice as fast (generally, 30-40% faster).

For the moment if the speed is good enough you can keep your rendering as is, but in the future if you want to optimize the gfx engine this will be one of the first things you will have to do.

Share this post


Link to post
Share on other sites
i just try to use the multitexturing stuff but (of course) i meet some problems:

http://www.thinbox.ca/_images/goliath/multiTex.jpg


the second texture, the 1d one, did''n seem to be used correctly, i change it and it still display the same way. Also the skybox is completly gone, i think it might be something i did''n disable correctly, but can''t find it. any idea?


glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D,ntexture[nTexID_]);
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_1D,ntexture[n1DTexID_]);

Share this post


Link to post
Share on other sites
You have to disable/enable texturing for each texture unit independently.
For instance this :

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_1D);
glEnable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE1_ARB);

is not the same as this :

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_1D);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);


For your code, you should enable texture 2D for texture unit 0 and texture 1D for texture unit 1, so :
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D,ntexture[nTexID_]);
glEnable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_1D,ntexture[n1DTexID_]);
glEnable(GL_TEXTURE_1D);

Also, I hope you send texture coordinates with glMultiTexCoord1fARB for the second texture unit.

If your skybox does not render correctly anymore, I bet this is because you either don''t disable texturing for second texture nuit, or because you don''t activate the first texture unit.
In other words, after rendering your cel-shaded model, you should call :
glActiveTextureARB(GL_TEXTURE0_ARB);
vglDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_1D);
glActiveTextureARB(GL_TEXTURE0_ARB);

The last line is extremely important because, if you don''t call it, all texture bindings will be done to TEXTURE1_ARB. For instance, your skybox (which is textured obviously) will setup textures for the second texture unit, but will send coordinates for the first texture unit (because glTexCoord(coord) is the same as calling glMultiTexCoord(GL_TEXTURE0_ARB, coord)).

Hope this helps.

Share this post


Link to post
Share on other sites
nice, it almost works, the model is rendered correctly and the sky box is well rendered also except that it seem that the multitexturing is still active when it displays the sky box. Therefore our second texture (shader) is displayed on top of the skybox.

How do we disable the second texture?

Share this post


Link to post
Share on other sites
If the second texture is 2D, call that :

glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);

If it is 1D, call that :
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_1D);

Either way, it is very important to call this line just after one of the two disable above, so that the first texture unit becomes the current one :
glActiveTextureARB(GL_TEXTURE0_ARB);

Share this post


Link to post
Share on other sites