Ambient occlusion for terrain

Return to Panda Features in Development

Ambient occlusion for terrain

Postby rdb » Sat Oct 08, 2011 1:08 pm

I just committed some simple but effective ambient occlusion support to GeoMipTerrain. It's simple to enable, isn't very heavy on the GPU (it bakes the AO into the vertex colours) and requires a simple function call (terrain.calcAmbientOcclusion()) before you generate the terrain. It doesn't use shaders.

A screenshot:
Image
rdb
 
Posts: 9742
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby preusser » Sat Oct 08, 2011 1:47 pm

Looks nice :)
May I ask why only GeoMipterrains though? If it works on vertex colors, I would guess it could be used on any NodePath, like egg terrains.
preusser
 
Posts: 520
Joined: Sun Mar 27, 2011 10:07 am

Postby rdb » Sat Oct 08, 2011 2:30 pm

It's a cheap technique that uses the heightmap image to calculate the ambient occlusion. It wouldn't work for non-heightfield geometry. For that, you'd have to use SSAO, which is a bit similar in principle (but much more complex).
rdb
 
Posts: 9742
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby preusser » Sun Oct 09, 2011 1:04 am

Oh OK.
I've had problems with SSAO before. It seems it's only useful for indoor scenes as the effects "bleeds" to the skydome. Or maybe I just set it up wrong.
preusser
 
Posts: 520
Joined: Sun Mar 27, 2011 10:07 am

Postby rdb » Sun Oct 09, 2011 4:20 am

You can probably fix that by making sure the skybox doesn't write to the depth buffer.
rdb
 
Posts: 9742
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby preusser » Sun Oct 09, 2011 8:13 am

Not really, the sky consists of few layers, like the cloud layer is separate from the gradient.
preusser
 
Posts: 520
Joined: Sun Mar 27, 2011 10:07 am

Postby AnimateDream » Thu Dec 01, 2011 3:23 am

It's lovely! I have been putting off working on this for my terrain and i get to enjoy it anyways. :D Is there a way to grab the ambient occlusion as a texture or PNMImage with python so I can combine it easily with my shader?
AnimateDream
 
Posts: 89
Joined: Tue Feb 16, 2010 2:36 am

Postby rdb » Thu Dec 01, 2011 8:49 am

After calculating the ambient occlusion, use terrain.colorMap() to get a reference to the computed lightmap, as a PNMImage. Note that if you want to use the ambient occlusion in your shader, you can also just read out vtx_color in the shader, as the AO map is baked into the vertex colours.
rdb
 
Posts: 9742
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby AnimateDream » Tue Dec 13, 2011 9:37 am

Thanks! I'm not sure I can use this feature with my current shader though. My shader actually includes lighting calculations in order to add normal mapping. Actually if the engine is calculating lighting for the terrain even if it has a shader, that means my program is doing the same work twice?
AnimateDream
 
Posts: 89
Joined: Tue Feb 16, 2010 2:36 am

Postby rdb » Tue Dec 13, 2011 12:05 pm

I'm not sure what you mean. Ambient occlusion is only computed once, not every frame.

You can combine the vertex colour (which will just be a grayscale colour between black and white) with your existing lighting calculations to combine the ambient occlusion with your lighting model.
rdb
 
Posts: 9742
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby AnimateDream » Mon Dec 19, 2011 3:49 pm

Ohhh. Ok. Good. That's what I originally assumed when you said it was baked in. Sorry, I just second guessed myself out of paranoia about where and how it was getting these vertex colors outside of my shader. I guess my understanding of the renderer is still rather flimsy after all this time. :roll:
AnimateDream
 
Posts: 89
Joined: Tue Feb 16, 2010 2:36 am

Re: Ambient occlusion for terrain

Postby aaagul45 » Thu Dec 18, 2014 5:02 am

I have been putting off working on this for my terrain and i get to enjoy it anyways. :D Is there a way to grab the ambient occlusion as a texture or PNMImage with python so I can combine it easily with my shader???
GuL
aaagul45
 
Posts: 1
Joined: Thu Dec 18, 2014 3:46 am


Return to Panda Features in Development

Who is online

Users browsing this forum: No registered users and 0 guests