• Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

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

Sign in to follow this  


...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 X
CVector3 origin, X, Y, Z;

// now shoot the rays
unsigned 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);


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

// Store result
float f = 1.0f - float(hit) / float(total);
vertex colour = CColour4(f, f, f, 1.0f);
Sign in to follow this  


Recommended Comments

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

  • Advertisement