• Advertisement
Sign in to follow this  

Cel Shading Questions...

This topic is 4555 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'm writing some code to display a model cel shaded (using the code from the tutorial on cel shading found on NeHe's site). Anyways, I have it all working like the code, but have a few questions: 1. This is obviously a slow way to do all of this (ie. doing a dot product for each and every vertex). However, since things change everyframe, we DO need to do this calculation on a per vertex basis. Is there maybe a faster way to do this? Maybe a way to include this calculation in a display list? 2. When I draw the outline around the model, we are basically drawing the model again but simply in wireframe mode with a different culling mode to only get the lines that we want drawn. However, since we are using the LEQUAL cull mode, we get the lines drawn on top of the polygons already in the frame buffer. Well, this seems to be causing z-buffer fighting along these lines which results in nasty sorting issues. Anyone know of a better way to do this? I mean this for both not drawing the entire model over again, plus fixing the sorting issues with the lines? Any help would be great! Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Polygon offset (in OpenGL) and z-bias (in D3D) might help, but I don't think there is a way to get perfect results.

Share this post


Link to post
Share on other sites
1. You can easily do this in a vertex shader which is much more efficient.

2. The best way IMHO is to re-draw the entire model but solid colour (usually black). Flip the culling from back to front faces and move all the vertices along their normals (again, this can be done trivially in a vertex shader). This avoid poping as models rotate, eliminates z fighting and lets you have arbitrary thickness lines without the dodgy joints.

Share this post


Link to post
Share on other sites
OrangyTang is right - redrawing the model with only a solid color is the best way that I have found. Also, if you are having a bunch of z-fighting on the outline, try switching to a 24 or 32 bit z-buffer. This GREATLY improved my gooch shader which uses the same outline method.

Also, a multi-sampled back buffer helps alot too. Even only 2x makes a big difference for smoothing it out.

Share this post


Link to post
Share on other sites
Awesome, thanks. I like the idea of rendering the entire model in polygon mode instead of wireframe.

Can you use a vertex shader in OpenGL? I thought these were a DirectX only feature.

- Thanks

Share this post


Link to post
Share on other sites
Take a look into the ARB_vertex_program and ARB_vertex_shader extensions. The former is for the ARB ASM vertex programming, and the latter is for GL's version of HLSL: GLSL. ARB_vertex_program is supported on card models back to the GeForce 2 TI, in case hardware is an issue.

Share this post


Link to post
Share on other sites
Quote:
Original post by Julian Spillane
GLSL. ARB_vertex_program is supported on card models back to the GeForce 2 TI, in case hardware is an issue.

ARB_vertex_program should be available all the way back to TNT cards (but emulated on the CPU, obviously). GF3 and up should have hardware support though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement