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

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 on other sites
im not familiar with that article, so i dont 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 im afraid i cant help you how to edit texture on cpu. ive got similar problem, see http://www.gamedev.net/community/forums/topic.asp?topic_id=466154

Share on other sites
Quote:
 Original post by MassacrerALim 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 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 on other sites
Quote:
 Original post by EnricoI 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 on other sites
Quote:
 Original post by bbttabout 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 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 on other sites
Quote:
 Original post by EnricoOk.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 on other sites
Quote:
 Original post by MannyKWe 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 on other sites
Quote:
 Original post by bbttactually, 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.

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 36
• 23
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631703
• Total Posts
3001816
×