Slow Cel Shading

Started by
8 comments, last by nife 18 years, 11 months ago
Alright So, I'm having fun with the Lesson 37: Cel Shading. And then I start creating more and more cel-shaded objects. After a while I started to notice a decrease in performance with the more cel-shaded objects that were being rendered. I narrowed it down to that performance is not affected as long as either the outline or the regular polygons are being rendered only (in other words having one without the other). I'm sure its just some c++ logic, but I was wondering if anyone had any insight on how to have multiple objects with both an outline and shaded polygons without as much loss of performance (I'm wondering if its the second for-loop for the outline code). Anyway, don't just take what I've said, check out the code in the Draw() function of lesson 37. Thanks a lot, Alex
Advertisement
Exactly how mutch preformance slowdown are we talking about.
Quote:Original post by Nerdco
So, I'm having fun with the Lesson 37: Cel Shading. And then I start creating more and more cel-shaded objects.


And how many objects?
Killers don't end up in jailThey end up on a high-score!
Obviously performance is going to vary greatly from computer to computer depending on hardware and some software variables. For me, I start noticing a decrease in performance at about 5 objects of 1250 triangles. I don't exactly have a lightspeed computer either. But it just seemed strange to have two loops (one for cel-shading and one for outlines). I could have twice as many objects with putting both the outline and the cel-shading code in the same loop. I just havn't been able to figure it, and I know I'll hate myself for looking past the obvious when someone gives me the solution.

Alex
I just had a brainstorm.

Alright, so the outline is a wireframe of the back facing triangles of the same mesh rendered again. Instead of going through the trouble of rending those back facing triangles that aren't going to be seen on the edges, perhaps it would be better to find out if a back facing triangle is connected/adjecent with a front facing one. That way only those back facing ones on the edge would be rendered.

I think its a good idea, I just have no clue how I would go about doing that...

If anybody knows how to deciefer a front or back facing triangle and/or determine if the two touch that would be great (or anything else that I might have missed)

Thanks,
Alex
In a stencil shadow algorithm, I needed to find objects' silhouettes, which is what you're doing here, but for a different use.

Anyways, I culled all the backfacing polygons by taking the vector from the polygon to the eye (E) and the polygon's normal (N).
Take the dot product of these NdL. If NdL is <0 then cull.

Then from the front facing polygons, cull away all duplicate edges. (All edges that are used by more than one polygon)

You should endup with the silhouette of the object.

There are probably faster ways than mine, which is a brute force approach.

Consider caching each meshs' silhouette and updating only when E differes significantly.

A while back I read a paper about a sampling an object from various viewpoints and storing those silhouettes for easy access later. Its probably pretty memory intensive for highpolygon meshs, but using indexed edges should eliminate the problem significantly.
Thats great!

You wouldn't happen to have the Ndl code or equation on you, would ya?

Thanks a lot
IICR float dot(v1, v2)=v1.x*v2.x + v1.y*v2.y + v1.z*v2.z

Dot products should be part of any vector/matrix math library and are used extensively. Sorry I can't give you any more information, I havn't takena vector math class at uni yet.
Quote:Original post by aaron_ds
IICR float dot(v1, v2)=v1.x*v2.x + v1.y*v2.y + v1.z*v2.z

Dot products should be part of any vector/matrix math library and are used extensively. Sorry I can't give you any more information, I havn't takena vector math class at uni yet.


Correct.

Should use something like:

double dot3( const vector3 &one, const vector3 &two)
{
return vector3(one.x + two.x, one.y + two.y, one.z + two.z);
}
Quote:Original post by foreignkid
Quote:Original post by aaron_ds
IICR float dot(v1, v2)=v1.x*v2.x + v1.y*v2.y + v1.z*v2.z

Dot products should be part of any vector/matrix math library and are used extensively. Sorry I can't give you any more information, I havn't takena vector math class at uni yet.


Correct.

Should use something like:

double dot3( const vector3 &one, const vector3 &two)
{
return vector3(one.x + two.x, one.y + two.y, one.z + two.z);
}


Well first of all that piece of code won't even compile :-P
Second of all the result of a dot product is a scalar, not a vector.

double dot3(const vector3 &one, const vector3 &two)
{
return one.x * two.x + one.y * two.y + one.z * two.z;
}

;-)
Killers don't end up in jailThey end up on a high-score!

This topic is closed to new replies.

Advertisement