Jump to content
  • Advertisement
Sign in to follow this  
bbtt

some question about ambient occlusion

This topic is 4027 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
Advertisement
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.r = AOarray * 255;
pixel.g = AOarray * 255;
pixel.b = AOarray * 255;
texCoords.u = float(i % 512) / float(512); //u
texCoords.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
Sign in to follow this  

  • 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!