Horde3D

Next-Generation Graphics Engine
It is currently 25.11.2024, 07:14

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: More terrain shading
PostPosted: 13.04.2009, 06:51 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
I'm working on a terrain shader for a graphics tech-demo.
It uses the techniques already written up on the wiki (tri-planar texturing + packing 4 detail textures into 1 map) and adds soft-edged water with animated normals:
Image

The ripples in the water are rendered/animated using Horde's 2d renderer. The ripple normal map is added with scrolling normal maps to get the final water normal.

I'm still working on it, but I'll be sure to detail the shader in the wiki once it's done.


Top
 Profile  
Reply with quote  
 Post subject: Re: More terrain shading
PostPosted: 13.04.2009, 13:46 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Looks very good so far! :)

Are you already using a highpass-filtered detail maps? The detail maps could also have an additional normal map and even use parallax mapping. This looks extremely cool for small stones or grooves on the ground.

In general, I see two appropriate approaches for terrain texturing:

- Texture splatting where several tiled albedo textures are blended together (often based on slope, height, or custom blend map). The problem here is getting high-frequency details without having a too repetitive look from the tiled textures and variation in colors.
- Extensive use of bump-mapped detail textures that can be painted on the terrain (e.g. detail map index stored in a texture map stretched accross the terrain). Since all the high frequency details come from the detail maps, it is ok to have a relatively low-resolution unique (non-tiled) surface texture for the terrain that just gives the color for the detailmaps.


Top
 Profile  
Reply with quote  
 Post subject: Re: More terrain shading
PostPosted: 14.04.2009, 01:25 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Thanks.

Yeah I'm using detail textures pretty much the same as the ones described in that link. I'm also texturing the terrain the way you first describe.
I do like that idea of a detail-index map though... :D

Here's a short video of the lightning effect I'm adding: http://www.youtube.com/watch?v=wZI8PiYD42I


Currently the terrain shader is very hungry for texture samplers, so I would be cautious adding normals to the detail textures:
3 samples of the detail map (tri-planar)
1 sample of the grass diffuse map
1 sample of the dirt diffuse map
3 samples of the rock diffuse map (tri-planar)
1 sample of the water diffuse map
4 samples of the water normal map
1 sample of the animated ripple normal map
1 sample of the reflection cube map
== 15 texture samples per pixel


Top
 Profile  
Reply with quote  
 Post subject: Re: More terrain shading
PostPosted: 14.04.2009, 08:03 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Thanks for the video, the water looks already very impressive. That will become a nice demo :D

Yeah, the number of texture samples required for complex terrain texturing is always quite high. You could try a few things though. The triplanar maping is only required at steep slopes so you could try out dynamic branching based on the normal. Rendering the terrain geometry is quite efficient so it could also be worth to think about a multi-pass approach where a second/third quality pass is only done when required. The third thing is level of detail: Terrain sectors that are far away could disable some shader flags and use a cheaper shader combination (without bump mapping for example).

Here is a quite inspiring link covering terrain rendering in BF3:
http://ati.amd.com/developer/gdc/2007/Andersson-TerrainRendering(Siggraph07).pdf


Top
 Profile  
Reply with quote  
 Post subject: Re: More terrain shading
PostPosted: 19.04.2009, 10:14 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Wow, that PDF is very inspiring!

I've got a "finished" demo now (I will try some more dynamic branching, material LOD, etc later).
Also, this is still running Horde Beta2 - some things would've been easier to do on Beta3, but I haven't had time to do the upgrade yet :oops:

I got 25-60fps on my 2yr old laptop, but it's aimed at high-end cards.

Download demo (8MB)
Microsoft Visual C++ 2008 Redistributable (required to run the demo on a computer that does not have Visual C++ 2008 installed.)
YouTube video
Older YouTube video


Top
 Profile  
Reply with quote  
 Post subject: Re: More terrain shading
PostPosted: 19.04.2009, 11:26 
Offline

Joined: 22.01.2009, 19:49
Posts: 14
Location: Germany
Very impressive!

I get between 30 and 45 fps in 1280x1024 with AA enabled on a GF8800GT in Vista x64.


Top
 Profile  
Reply with quote  
 Post subject: Re: More terrain shading
PostPosted: 19.04.2009, 15:29 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
Like always 10/10 :wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: More terrain shading
PostPosted: 20.04.2009, 09:02 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Great work!

The camera movement through the world is impressive und the rain effects look good. I think some simple sound effects (ambient noise of the rain and loud thunder) would help to make the demo even more impressive.
What I noticed though is that you are using a high fov when the camera is in manual mode so there is some distortion. Is this intended? The other thing is that the terrain appears really dark on my screen.


Top
 Profile  
Reply with quote  
 Post subject: Re: More terrain shading
PostPosted: 20.04.2009, 10:29 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
The camera movement is based on "Cardinal splines". The code is at the bottom of this post if you're interested.

I would've loved to add sound to it as well, but I didn't have time (I was trying to get this finished in time for a job interview today :wink: )

The camera has a 90ยบ FOV -- it's probably too much, but I wanted you to be able to see as much on screen as possible.

Dark scenes are always hard to get right. It looks really dark on one of my LCD screens as well, but everything is easily distinguishable on my main LCD. I'm not sure what kind of calibration I should use for testing...


I got the camera movement algorithm from:
http://www.cubic.org/docs/hermite.htm
http://en.wikipedia.org/wiki/Hermite_curve
I just collected a series of points in the world and store them in an array, then I use this code to interpolate between them:
Code:
   CVector3f HermiteCurveInterpolation( float fraction, const CVector3f& p1, const CVector3f& p2,
                                        const CVector3f& t1, const CVector3f& t2 )
   {
      float s2 = fraction*fraction;
      float s3 = s2*fraction;
      float h1 =  2*s3 - 3*s2 + 1;
      float h2 = -2*s3 + 3*s2;
      float h3 =    s3 - 2*s2 + fraction;
      float h4 =    s3 -   s2;
      return CVector3f( h1*p1 + h2*p2 + h3*t1 + h4*t2 );
   }
   CVector3f CardinalSplineInterpolation( float fraction, const CVector3f& p0, const CVector3f& p1,
                                          const CVector3f& p2, const CVector3f& p3, float c )//interpolates between p1 and p2
   {
      CVector3f t1( (1-c)*0.5f*(p2-p0) );
      CVector3f t2( (1-c)*0.5f*(p3-p1) );
      return HermiteCurveInterpolation( fraction, p1, p2, t1, t2 );
   }


Top
 Profile  
Reply with quote  
 Post subject: Re: More terrain shading
PostPosted: 20.04.2009, 11:09 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Yes, a fov of 90 degree would explain the distortion that I noticed. I usually use 45 degrees.

Thanks for the spline code and good luck with your interview (if it is not yet done) :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group