Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    14
  • comments
    17
  • views
    5641

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

Sign in to follow this  
uavfun

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

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 result
float f = 1.0f - float(hit) / float(total);
vertex colour = CColour4(f, f, f, 1.0f);
Sign in to follow this  


2 Comments


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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!