Sign in to follow this  

some question about ambient occlusion

This topic is 3721 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey guys I am making a Demo of Ambient Occlusion, just following the chapter 17 of GPU Gems 1. And now i have the AO value array which contains every vertex's AO value. and i want to save it as a texture, what should i do? tell me something plz, thx a lot.

Share this post


Link to post
Share on other sites
i`m not familiar with that article, so i don`t know what is it about, but you could save ao value of some vertex to some texel on texture and then set that vertex tex coords to coords of that texel. and set point filtering.

but i`m afraid i can`t help you how to edit texture on cpu. i`ve got similar problem, see http://www.gamedev.net/community/forums/topic.asp?topic_id=466154

Share this post


Link to post
Share on other sites
Quote:
Original post by MassacrerAL
i`m not familiar with that article, so i don`t know what is it about, but you could save ao value of some vertex to some texel on texture and then set that vertex tex coords to coords of that texel. and set point filtering.



I did it like this:
Create a 512X512 bitmap, 24bit per pixel.
for (int i = 0; i < AOarray.size(); ++i)
{
pixel[i].r = AOarray[i] * 255;
pixel[i].g = AOarray[i] * 255;
pixel[i].b = AOarray[i] * 255;
texCoords[i].u = float(i % 512) / float(512); //u
texCoords[i].v = float(i / 512) / float(512); //v
}
the left pixels of bitmap I set them (0, 0, 0);
is that right?

Share this post


Link to post
Share on other sites
I dont see your point converting the per-vertex AO values into a texture? It takes three times more space (your short code, however you could take a single channel texture) If you want an AO-texture, you need to create it from the beginning and not try to put per-vertex values into this texture. The AO-texture won't give you any advantages.

About your code: The pixel colour calculations looks ok. The texture coordinate generation howver is completely wrong. You need to unwrap your model, these are links to texture unwrapping. There are several algorithms to do this, just do a quick search or look what modeling programs use.

Share this post


Link to post
Share on other sites
Quote:
Original post by Enrico
I dont see your point converting the per-vertex AO values into a texture? It takes three times more space (your short code, however you could take a single channel texture) If you want an AO-texture, you need to create it from the beginning and not try to put per-vertex values into this texture. The AO-texture won't give you any advantages.

About your code: The pixel colour calculations looks ok. The texture coordinate generation howver is completely wrong. You need to unwrap your model, these are links to texture unwrapping. There are several algorithms to do this, just do a quick search or look what modeling programs use.


thank U very much!"unwrap" is definitely what i need!
i really should make it a single-channel texture, but about this :"If you want an AO-texture, you need to create it from the beginning and not try to put per-vertex values into this texture", i couldn't understand it clearly, could you please explain it for me?

Share this post


Link to post
Share on other sites
Quote:
Original post by bbtt
about this :"If you want an AO-texture, you need to create it from the beginning and not try to put per-vertex values into this texture", i couldn't understand it clearly, could you please explain it for me?

Ok.
Imagine you have a triangle with three vertices and calculate AO values at these positions. When converting these three values to a texture, you will not take any advantage. What you want, is to calculate more than these three AO values for the triangle. And these values are then saved into a AO texture.

Share this post


Link to post
Share on other sites
We have 2 options - 1) sample at vertices (like you are doing) and pass the AO values to your vertex shader. Pass the AO values to your fragment shader as a 'varying' so that the interpolators do the work for you. 2) unwrap your model or find a model with unique UVs (not repeating) and sample per pixel. Apply AO map as a texture and modulate your lighting within your pixel shader.

Vertex sampling can work if your model is tesselated enough.

Manny

Share this post


Link to post
Share on other sites
Quote:
Original post by Enrico
Ok.
Imagine you have a triangle with three vertices and calculate AO values at these positions. When converting these three values to a texture, you will not take any advantage. What you want, is to calculate more than these three AO values for the triangle. And these values are then saved into a AO texture.


so, you mean per-vertex AO value is not accurate enough? yeah, it is. but how could i improve it?

Share this post


Link to post
Share on other sites
Quote:
Original post by MannyK
We have 2 options - 1) sample at vertices (like you are doing) and pass the AO values to your vertex shader. Pass the AO values to your fragment shader as a 'varying' so that the interpolators do the work for you. 2) unwrap your model or find a model with unique UVs (not repeating) and sample per pixel. Apply AO map as a texture and modulate your lighting within your pixel shader.

Vertex sampling can work if your model is tesselated enough.

Manny


actually, i want to try the second option first.i can find some models with unique UVs, sample per pixel and save it.
maybe this is a stupid question, but how to sample per pixel? i'm a bigenner, don't abandon me plz...

Share this post


Link to post
Share on other sites
Quote:
Original post by bbtt
actually, i want to try the second option first.i can find some models with unique UVs, sample per pixel and save it.
maybe this is a stupid question, but how to sample per pixel? i'm a bigenner, don't abandon me plz...

You need to transform the texture space position to world space and use this transformed position as sample position. I am not sure about the maths, I will need to check it at home (but I can not promise that I have anything which might help you!). So you might want to start for yourself. The transformation is not overly complex.

Share this post


Link to post
Share on other sites
Quote:
Original post by Enrico
You need to transform the texture space position to world space and use this transformed position as sample position. I am not sure about the maths, I will need to check it at home (but I can not promise that I have anything which might help you!). So you might want to start for yourself. The transformation is not overly complex.


i can google information of transformation maths or search in library.

“transform the texture space position to world space and use this transformed position as sample position”, this means that i should transform the coords per pixel to the world space or something else? after i transform every pixel's coordsto world space, what should i do to do the interpolation?
for each triangle, i get the pixels of sides by interpolating vertices, then get pixels in triangle by interpolating pixels of sides, is that right?

[Edited by - bbtt on October 6, 2007 7:00:43 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by bbtt
i can google information of transformation maths or search in library.

Try Crystal Space or the Q3map(2) map compiler. Both can calculate lightmaps with texture coordinates in different quality settings for an arbitrary mesh.

Quote:
“transform the texture space position to world space and use this transformed position as sample position”, this means that i should transform the coords per pixel to the world space or something else?

Yes, you need to find out, which world space position a pixel in the lightmap actually has. And then use this pixel world space position to calculate AO values.


Quote:
after i transform every pixel's coordsto world space, what should i do to do the interpolation? for each triangle, i get the pixels of sides by interpolating vertices, then get pixels in triangle by interpolating pixels of sides, is that right?

I am not sure what you mean with these questions...



Share this post


Link to post
Share on other sites

This topic is 3721 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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