Nvidia Nature Demo

This script is inspired by the Nvidia nature demo ( http://developer.nvidia.com/object/nature_scene.html ). It’s not a 1:1 copy, but very similar. All media have been taken from the original Nvidia demo. The main features are:

  • dynamic sky with tinting
  • static terrain with texture blending depending on terrain elevation
  • water reflection via planar mirror and projective texturing
  • water distortions
  • moving grass
  • fog on terrain and grass shaders

Performance is poor, but you can speed up by reducing GRASS_DISTANCE near the top of the script. Also try reducing fog density for brighter colors: “fog = Vec4( 0.16, 0.32, 0.36, 0.0001 ) # r, g, b, density” in line 118.

Screenshot:
http://www.dachau.net/users/pfrogner/nature.jpg

Download:
http://www.dachau.net/users/pfrogner/nature.zip

These have been my first steps with CG, and the shaders are far from perfect, and if someone knows ways to improve this demo please tell me.
enn0x

w00t w00t w00t :smiley:

This rocks;)

sweet. indeed.nice shaders =)

really nice…

Great work !

  1. Just a simple question : why do you use 800x600 buffer size for water reflection ? It breaks the reflection on my junkware here. So I use power of 2 size and everything is perfect.
  2. You use antialias for the grass, you must mean to use transparency AA, right ? You’ve done that using alpha mode (setting “True” == 1 == TransparencyAttrib.MAlpha). So,
self.grassNP.setAntialias( AntialiasAttrib.MMultisample, 1 )

doesn’t help at all, because it only fixes aliasing on points, lines, and polygons, not transparency AFAIK. Moreover, to use framebuffer AA, you have to enable it first (the default is disabled, try to print the config vars, and look for “framebuffer-multisample”).

Thank you very much for the many replies.

@ynjh_jo

(2) You are right, setting AntialiasAttrib.MMultisample on grassNP doesn’t help at all. I don’t see a difference on my PC if setting it to MAuto or even MPolygon. I had

framebuffer-multisample 1

in my config file, but moving it into the python code is probably better:

from pandac.PandaModules import loadPrcFileData
loadPrcFileData( '', 'framebuffer-multisample 1' )

Thanks for your help here, it helped me getting a better understanding of AA, but I am still far from having a firm grip on either transparency or AA.

(1) At first I wanted best quality, and since my card supports non-power-two textures I selected the same size for the framebuffer that the window has, to avoid ‘pixel’ effects. This is nonsense of course. The water gets distorted, and choosing a much smaller size gives no loss in quality.

One problem though. If I choose a different ratio than the window has (e.g. 256x256) then I get a strange effect. If I look to the right and left from the start position, and watch the reflections of the hills, then these reflections seem to ‘lean’ to the right and left. Do you have this effect too is you choose power 2 sizes?

enn0x

i dont see any sqeezed hills… but i can sometimes see the the terrain in the water reflection when looking at … dunno maybe 50degree angle onto the water. in this case the terrain in the reflection seems to be rendered in a side-perspective.

Oh, I didn’t notice it before… :open_mouth:
There is only 1 solution for this, set the water cam to use the same fov of the base.camera.

self.waterCameraNP.node( ).getLens( ).setFov(base.camLens.getFov())

That fixed it…perfectly.

If you’d like to see an example of transparency AA, goto http://www.humus.ca, jump to 3d section page 2 (if it’s not moved around), look for “alpha to coverage” example. It’s awesome, even when the camera-poly angle is very shallow.

Really nice!

Runs on my system, but I think the shaders aren’t working, because everything is a completely different colour from your screenshot and the water reflection looks wrong:

Try not to use arb profile on each shader, remove :

//Cg profile arbvp1 arbfp1

I bet it will work !

@Thomas : what you saw is the front face of the pond base, which is exposed to water cam at some points of view. Try to show the buffer and you’ll see it clearly.
Not sure it can be fixed if the terrain is just 1 piece.

I don’t find that string either in the python file or in the prc file?

@chombee: check the cg file;)

Don’t have one

Ok, then there is something wrong.
Did you really download the whole zip file?
There must be some cg (.sha) files inside there.

There are no cg files in that zip :slight_smile:

Trust me. There really is :wink:
Actually, there are four.

Okay, yes. .sha files, I was looking for .cg files. Sorry. Removed the lines though, no change :frowning:

…it sucks. I assume it failed silently, since you didn’t mention any error.
What is your graphics card ? Is it mobile card ? Perhaps the shaders are too heavy for yours.

@ynjh_jo
Thank you again for your help. Setting the camera FOV works like a charm.

@chombee
I get the same effect if I remove all ‘setShader’ lines from the demo. Can it be your card doesn’t support shaders? Or at least Panda3D can’t use shaders on your PC?

print base.win.getGsg( ).getSupportsBasicShaders( )

@ThomasEgi
I get some artifacts too if I look with flat angles over the water. I think they come from the underwater hills. I added to following lines to the demo (first two lines go into init, the rest somewhere else.

        self.accept( 'f4', self.toggleView )
        self.waterLevel = 36.0

    def toggleView( self ):
        base.camera.setZ( 2 * self.waterLevel - base.camera.getZ( ) )
        self.pitch = -self.pitch

Pressing F4 now moves the camera to the position where it should be when rendering the reflection. It seems the clip plane that should cut of everything below the water surface doesn’t work. So it is a bug in my code, and so far I don’t know a way to fix it.

enn0x

I just realized that you didn’t perform any filtering for the grass texture. No wonder the grass looks like that.

        tex.setMinfilter(Texture.FTLinearMipmapLinear)
        tex.setMagfilter(Texture.FTLinearMipmapLinear)

Now it’s so beautiful… :slight_smile: