Sign in to follow this  
Nerdco

Slow Cel Shading

Recommended Posts

Nerdco    122
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

Share this post


Link to post
Share on other sites
nife    235
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?

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
foreignkid    142
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);
}

Share this post


Link to post
Share on other sites
nife    235
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;
}

;-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this