ATI's ambient occlusion thingy was too slow...

Published July 09, 2005
Advertisement
...so I made a per-vertex one to play with. It works out looking just as nice for a detailed model, and means one less texture - the data can just be stuffed into the vertex colour. Interestingly, this approach would work just fine on a card that doesn't even support multitexturing. Lighting is a whole lot easier at runtime when you precalculate as much as possible.


Ruby was too slow so I chopped her head off... the rest is in the closet over there.

The basic approach:
// first build a coordinate system with Z as the normal// make X anything perpendicular to Z, then Y = Z cross XCVector3 origin, X, Y, Z;...// now shoot the raysunsigned hit, total;for (unsigned u = 0; u < samples; u++){	float phi = u * pi / samples;	float c = cos(phi);	for (unsigned v = 0; v < samples; v++)	{		float theta = 2.0f * pi * v / samples;		float x = c * cos(theta);		float y = c * sin(theta);		float z = sin(phi);		total++;		const CVector3 dir = x * X + y * Y + z * Z;		// Test ray against mesh		// Note highly scientific fudge factor		if (test mesh against ray(origin + dir * 0.001f, dir))			hit++;	}}// Store resultfloat f = 1.0f - float(hit) / float(total);vertex colour = CColour4(f, f, f, 1.0f);
Previous Entry Blurry reflections
0 likes 2 comments

Comments

NickGeorgia
Sweetness!
July 09, 2005 09:40 PM
Daerax
hmmm... Yet Another one of those viewtiful journals.
July 10, 2005 02:34 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement