Advertisement

Toon lighting!

Started by May 19, 2002 09:38 AM
26 comments, last by finny26 22 years, 8 months ago
"The Nehe tutorial really needs an equation saying what he is doing!"


    TmpShade = DotProduct (TmpVector, lightAngle);if (TmpShade < 0.0f)	TmpShade = 0.0f;	// Clamp The Value to 0 If Negative    


Texture Coordinate = vertex normal (world space) dot Light Angle

Texture coordinate is clamped to 0, 1. it isnt that hard to work out.


finny26: fancy posting a screenshot?


Note: The original article for this code can be found at: http://www.gamedev.net/reference/programming/features/celshading.

that's located at the top of the tutorial. i didnt put it there for fun ya know . the article is a bit screwed up (it was only at alpha stage which is why there are so many errors in it) but dave put it up anyway for reasons best known to him.

This tutorial doesn't actually explain the theory, just the code. WHY it works can be found at the above link.

that might explain a bit too .

[edited by - MENTAL on May 22, 2002 2:35:16 PM]
quote:
Original post by MENTAL

finny26: fancy posting a screenshot?




Certainly do! In this screenshot the left half of the window is being ''toonified'', hey I invented a word!



Advertisement
finny, those pics look pretty good... but to me it looks like with ''toonified'' pictures the low-poly models would come out looking better, just because normal cartoons don''t put in so much detail.
damn, that looks pretty good .

what color depth are you using? 16 or 32?
"After drawing everything i want ''toon-style'', I''m drawing a rectangle (the same size as the window)"

what does "toon style" mean exactly? do you just mean with lighting disabled?

i think i''ll be adding this technique into the next version of the cel-article. full credit to you finny of course!!!
No sorry what I meant to say was, first I draw everything that I want to look like a cartoon (this is drawn as normal with OpenGL, 32 bit colour). THEN I draw the rectangles to apply the cartoon shading effect. And finally anything else I want to draw (but not cartoon style) is done last.

I''m using 32 bit colour ALL the time even though it looks like 8 bit, so you can mix the cartoon style with smooth shaded stuff and any special effects you want (like lens flares).

Hope that made sense this time, I don''t draw anything ''toon-style'', i just draw it normally with lighting on and then do the blending trick

You could also draw edge lines to get that nice cell shading effect

Glad you liked it

Oh and if you do credit me in that article (i would be most grateful), please email me first and i''ll give you contact details, my real name etc
Advertisement
Let me see if I understand you. You draw all the objects you want to appear as toons first, then you draw the rectangle. I assume this rectangle is drawn close to 0 on the z-axis. Then you say anything else drawn after that will appear smooth shaded. How is this possible? Surely some of the objects drawn later will still be drawn beyond the two rectangles (and therefore the color would be altered).

Perhaps you can post the full "cartoonizing" code so that I can get a better understanding of what you are doing.
Erunama: the 2 rectangles are probably done with depth buffer updates turned off.
I think so too. It''s not possible to draw a blended quad first and then draw a solid behind it and make it shine through anyway. It just gets clipped away. That is why you always have to draw solids first and then blended second (sorted from back to front).

It''s not a "window" you look through which makes everything Toonish, it''s a really really REALLY clever trick (hurray for finny I love your idea)

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

That''s right:

glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_DITHER);
glDisable(GL_TEXTURE_2D);

and most importantly:

glEnable(GL_BLEND);

Use glOrtho to draw the rectangles

Just tried it with my terrain engine and in a weird way it looks more realistic, i think maybe because you''re brain compensates for the lack of detail or something

Has any one else tried this yet?

And by the way I''m no expert (Just take a look at who started this thread!)

This topic is closed to new replies.

Advertisement