Water / Terrain - Use the stencil buffer?

Started by
14 comments, last by ajoling 17 years, 10 months ago
Sure jamesw!

Here are two screenshots for you. The terrain might look 'small' but it's an RTS game and will be quite zoomed in. :) I'd like to have the specular highlight which you have as well and some more wavey effect.

I think I have reflections currently disabled, trying to find out how to squeeze more FPs juice out of everything. My card ain't the best videocard, but I still think it should do better. Rendering water really kills the fps.

Distant view:



Closer (excuse the texture choice):



Geometry (simple return float4(0.0f,1.0f,0.0f,1.0f) in shader)




Hope this is useful to you :)
www.persistentrealities.com for Inline ASM for VB, VB Fibre, and other nice code samples in C++, PHP, ASP, etc.<br/>Play Yet Another Laser Game!<br/>
Advertisement
Hm, I spent a while on the shader. It's nearly similar now, and because of a few specifics, does not fit into PS1.4 :(, but still it's 20-30fps faster for me:



Although maybe I will use one pow() (or something) to make the water blend faster on the sides. Now one side is less shorelined than the other.

Original:
approximately 26 instruction slots used (3 texture, 23 arithmetic)

New:
approximately 10 instruction slots used (3 texture, 7 arithmetic)
www.persistentrealities.com for Inline ASM for VB, VB Fibre, and other nice code samples in C++, PHP, ASP, etc.<br/>Play Yet Another Laser Game!<br/>
Quote:Original post by ajoling


I'd say your problem is that you're using a heightmap of quads instead of a heightmap of triangles. Try instead making the heightmap with patches like this:

H***********H*---------*-**-------*---**-----*-----**---*-------**-*---------*H***********H


...instead of like this:
**************-----------**-----------**-----H-----**-----------**-----------**************(H means a height sample in your heightmap image or 2d array)


Then your edges will be smooth without any need to turn off z-buffering. That would solve a lot of your problems I think...

Btw nice with a western game, way too few are made. I wish you good luck and hope it'll be available to buy or as freeware soon :)
Thanks :). I will have a look at it. I'm probably going to alter my terrain generator a bit anyway, I have way too much quadtree nodes in my terrain. Rendering those seperately takes more time than rendering a bigger chunk.

About the western games: Yeah, my favorite 'game' is a mod called "Badlands" for Unreal tournament 1. Nothing beats walking around with a Sharps plains rifle. Truly one of the best mods made for the game.

And because of the time I spent in this game, I'm afraid it won't be freeware :). But, it won't be expensive either.. :). If I finish it ofcourse.
www.persistentrealities.com for Inline ASM for VB, VB Fibre, and other nice code samples in C++, PHP, ASP, etc.<br/>Play Yet Another Laser Game!<br/>
Quote:Wow, jamesw, would you be willing to point me in the right direction on how to make an effect like that? I'm pretty clueless on pixel shaders, I'd love to know how that's actually done.


The best place to start is right here on gamedev, Yann's water article. And once you have that stuff down take a look at the 'Generic refraction simulation' article in GPU Gems 2 as well as the one about animation water in ShaderX3. Both of these articles have a wealth of knowledge on water effects and the GPU Gems 2 one has a full working sample. Just don't copy it like so many do, figure out how it works and make your own.

Quote:Here are two screenshots for you.


Thanks! You really have the edge fadeout down, I can't see any sharp edges at all. How come you don't have any banding? Or is it just too far away for that. When I scale the depth values into a good range to be a blend factor they band like crazy.

Quote:approximately 10 instruction slots used (3 texture, 7 arithmetic)


I'm using 67 arithmetic =( It currently rapes cards with low pixel power. I have to find a way to fit it in ps2.0.
Quote:Original post by jamesw
Quote:Wow, jamesw, would you be willing to point me in the right direction on how to make an effect like that? I'm pretty clueless on pixel shaders, I'd love to know how that's actually done.


The best place to start is right here on gamedev, Yann's water article. And once you have that stuff down take a look at the 'Generic refraction simulation' article in GPU Gems 2 as well as the one about animation water in ShaderX3. Both of these articles have a wealth of knowledge on water effects and the GPU Gems 2 one has a full working sample. Just don't copy it like so many do, figure out how it works and make your own.

Quote:Here are two screenshots for you.


Thanks! You really have the edge fadeout down, I can't see any sharp edges at all. How come you don't have any banding? Or is it just too far away for that. When I scale the depth values into a good range to be a blend factor they band like crazy.

Quote:approximately 10 instruction slots used (3 texture, 7 arithmetic)


I'm using 67 arithmetic =( It currently rapes cards with low pixel power. I have to find a way to fit it in ps2.0.



Yeah, my reflection is based on Yann's water article. I guess I should look for some refraction articles myself. Most of them are plain ASM though, which I have started to dislike ever since I started on DX9. :).

I've used two techniques for my water james.

Method 1 (old):

The heightmap is sampled on the appropriate coordinate. Since I know what my min/max terrain values are, I can multiply the .r * maxterreinheight. This gives me the (near) perfect height. I also knew the water level (I first had a fixed water height).

So, I did something like:

float fTerrainHeight = tex2D(HeightMap, vPos).r * fTerrainMaxHeight;
float fWaterCalc = fWaterLevel-(fTerrainHeight);
float fAlpha = ((fWaterCalc+0.25f) / fWaterLevel);

This is old HLSL code, I might have modified it in a version so that it doesn't work.

It produces a similar effect as my new version.

Method 2:

Now I have multi level water (just not for reflections, a whole different challenge with clipping planes..). And I cheated on the water height.

I removed the "river" in my original heightmap, and created a watermap. This watermap is like a heightmap, but it tells me where to "dig" rivers/lakes. I have limited the range of depth: 0 = 0, 255 = 4. This depends on your unit system.

When generting the terrain, the watermap and heightmap will be 'merged'. so rivers/lakes will automatically be shown in the vertexdata. And, as bonus, I still have this "water map". Submitting this to the pixelshader gives me exact knowledge where to start blending. I can actually immediatly cull any pixels which are black too!

Ofcourse, you can generate this map from a fixed (known) waterlevel - height. And submit this texture to the shader.

Hope this works out for you. I thought my idea was pretty cool, and the water looks almost commercial quality :-).
www.persistentrealities.com for Inline ASM for VB, VB Fibre, and other nice code samples in C++, PHP, ASP, etc.<br/>Play Yet Another Laser Game!<br/>

This topic is closed to new replies.

Advertisement