• entries
14
17
• views
5456

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

90 views

...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);

Sweetness!

hmmm... Yet Another one of those viewtiful journals.

## Create an account

Register a new account