PDA

View Full Version : Water/terrain rendering



NecroDOME
02-12-2008, 01:29 PM
Hi guys,

I'm still busy with my 3D engine, so far so good. But now I have stumbled upon some questions regarding water/terrain rendering (basicly the same).

I want to have a grid that is transformed by a heightmap in real time.

What I want to know is what is the best approach.
- I can calculate everyting on the CPU, what would be kinda slow.
- I can do texture lookup in a vertex shader 3.0. However there are some restrictions and limitations on this one, and it is not supported on ATI cards I think.

Anyone any idea how to render a grid with real-time animated waves?

Thanks in advance!

User137
02-12-2008, 01:42 PM
At least in OpenGL you can use vertex array. May not be fastest but it's 1 way. You can create a single trianglestrip to cover the entire visible rectangular ocean grid. You only need to define texture coordinates once, maybe even X and Z coordinates for vertices too and only change Vertex Y when animating, or is it just texture coordinates that change. Depending ofc how do you animate it. I would imagine normals are not needed with water, and they slow rendering down a bit.

NecroDOME
02-12-2008, 07:33 PM
You can do similar stuff with DirectX, but I want a way to do it on the video card. In my rendering I want to do it screen-space, so every coordinate changes as I move the camera.

chronozphere
03-12-2008, 08:01 AM
Are you sure about Texture-lookup not being supported by ATI cards? :shock: (We are talking about Tex2d() right?). Tex2d() is AFAIK a very basic and populair HLSL function. I can't imagine it not being supported by ATI. :?

You should start looking of info about Tex2D() on ATI-cards. If you have an URL with some more info about whether it works or not, i would like to see it.

And i also would like to know about those restrictions and limitations. I think reading some more docs would be a good idea in this case. :)

P.S: According to MSDN, Tex2d() is supported by all shadermodels:
http://msdn.microsoft.com/en-us/library/bb509677(VS.85).aspx
I assume this is also the case on ATI cards.

NecroDOME
03-12-2008, 02:05 PM
tex2D is only supported in pixel shaders, not in vertex shaders. I can use tex2Dlod, that is supported in vertex shader 3.0. In vertex shaders this only works with 32 bit floating point textures (R32F and A32R32G32B32F (on nVidia cards that is at least)).
Also texture lookups in vertex shaders do not use any filtering or mip mapping. It's just point plane filtering.

Anyway here's an nice article about it: http://www.ziggyware.com/readarticle.php?article_id=127

edit:
AFAIK
- nVidia supports texture loopups in vertex shader
- ATI supports rendering to a vertex buffer via pixels shader

chronozphere
03-12-2008, 02:15 PM
Okay... lol :oops: I totally forgot about the difference between vertex- and pixelshaders. In this case, you need your texture-lookup in the vertexshader, which is a problem.

Maybe you can do something with parameterized terrain, but that would require an awefull lot of math, and it's only good for total random terrain generation.

And that article looks very interesting. ;)

NecroDOME
03-12-2008, 03:34 PM
im still looking for a solution. Maybe I can use 2 vertex buffers? 1 for terrain and one for height offset? In this case I have a static buffer and a second dynamic buffer. However I have to dive into this to see if I can get it to work and if it's even possible...

Galfar
03-12-2008, 07:13 PM
All DirectX 10 GPUs can do vertex texture fetch (just tried running NVidias Direct3D9 VTF demo on ATI Radeon 4850). They can also use all available texture formats, not just FP32 (but this may work only in D3D10?).

I had similar problem once (it was OpenGL program and vertex texture lookup doesn't work there even for new ATI cards). I used 2 buffers as you wrote earlier. I had a static triangulated 2D grid which was reused for every terrain block. Scalar height values were in separate buffers (one for each terrain block).

NecroDOME
04-12-2008, 12:15 PM
I know, but I'm not gonna use DX 10 atm. Just looking for some proof of concept that works on both nVidia and ATI cards, preferably on shader model 2, but shader model 3 is also no problem.