Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Realtime water, using the vertex shader!

Author
Message
dark coder
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 5th Oct 2008 23:37 Edited at: 5th Oct 2008 23:44
So I made this small tech demo showcasing displacement maps for use in water simulation using the vertex shader. The demo was merely for fun as I'd never used vertex textures before and... writing shaders is fun of course.

The shader itself is very vertex shader intensive, the water is comprised of 3 octaves(layers), and 3 displacement maps(Waves.dds, rgb channels), you can adjust the settings for all 3 of these layers independently. In total 3 heights are sampled so I can find the surface normal for any given vertex, I use this to calculate the reflection and refraction vectors which are used to sample from two cubemaps in the pixel shader, I also attenuate between these via a simple Fresnel term so it's easier to see waves at a shallower angle. Finally there is a light direction that I use to give the dark side of the waves a slight dimness in colour so you can see them from above.

Make sure you have a GPU capable of using VS3.0, if you get 0.1FPS then I suggest changing the water mesh that's loaded, the default is Water3.dbo, Water1.dbo is a far smaller scale version. Also I'm not sure if this works on ATI cards, I've only had one person test it with one and they couldn't see anything.

Also remember that this isn't exactly practical for most games, for instance getting the height of any given point on the water's surface on the CPU isn't that easy, you'll need to emulate the shader code, and I'm not even sure if you can load 128bit(ARGB32F) images like I used into a memblock.

Pic:

Demo + source: http://www.mediafire.com/?ymdmmyktzxj or https://forumfiles.thegamecreators.com/download/1604383

AndrewT
19
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 6th Oct 2008 00:33
That's awesome! I get 350FPS on an 8800GTS, so performance is pretty good.

RedFlames
18
Years of Service
User Offline
Joined: 25th Aug 2007
Location: Germania
Posted: 6th Oct 2008 01:59
Yep cant see anything on my HD3850
But on the other hand i get 3600 FPS but only with your EXE, if i compile it its just 3000 FPS ...

James H
19
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 6th Oct 2008 02:14
Nice. I get 290-300 fps on an 8800GT.
jasonhtml
22
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 6th Oct 2008 02:39 Edited at: 24th Dec 2009 19:14
Amazing! this is by far the best water i have ever seen used in DBP. Terrific job!

Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 6th Oct 2008 04:11
vertex texture fetch is not supported with ATI cards. And that is a bummer. I built a whole other pc with an nvidea card a while back to explore VTF. I think VTF is supported way back to 6000 series nvidea cards.
Irradic
19
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 6th Oct 2008 10:47
The water looks amazing ! Great job !

Jeff Miller
21
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 6th Oct 2008 13:48
With an 8500GT at 1920x1200, I got 78FPS with Water3 at default resolution. At full screen I got 35FPS with Water3, and 78FPS with Water1. Looks very good.
Morcilla
23
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 6th Oct 2008 14:24
Great contribution again

Quote: "this isn't exactly practical for most games"

Nevertheless it is a very good sample code. Many things can be learnt from it. Always discovering new things with your code

I got it working here with an ATI HD4870, but I had to change last line in 'Shading.fx' to:



That is, change the 1.4 ps compiling version to 3.0 ps (2.0 was not working).

I'm getting 980 fps with the default 'Main.exe' & 'Water3.dbo'.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Oct 2008 15:06
I'll be making good use of this demo when I finally upgrade to a PS3 (PS4?) capable machine.

The screenshot and feedback from others are very encouraging.

Thanks and well done.
Marvey
23
Years of Service
User Offline
Joined: 15th Oct 2002
Location:
Posted: 6th Oct 2008 15:15 Edited at: 6th Oct 2008 15:16
running your exe i got 446 fps with 9600GT TOP
nice work
RedFlames
18
Years of Service
User Offline
Joined: 25th Aug 2007
Location: Germania
Posted: 6th Oct 2008 16:36
Quote: "
I got it working here with an ATI HD4870, but I had to change last line in 'Shading.fx' to:

That is, change the 1.4 ps compiling version to 3.0 ps (2.0 was not working).
"

Yeah that works, now i get ~280 FPS on my HD3850

Lucy
19
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Roanoke, VA USA
Posted: 6th Oct 2008 16:45
My ATI x1600 isn't able to run it. On the first try, I got a flat plane that didn't move. Then, I did what Morcilla did and got nothing but the solid color sky.

bob_marley
18
Years of Service
User Offline
Joined: 19th Sep 2007
Location:
Posted: 6th Oct 2008 17:31
Looks amazing in screeny, i doubt it will work on this tho - integrated intel card.

I miss my old computer
Sid Sinister
20
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 6th Oct 2008 19:01
Nice! I got 42 FPS on a 8600M GT on my laptop.

"If I have seen a little further it is by standing on the shoulders of Giants" - Isaac Newton
-Computer Animation Major @Baker.edu-
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 6th Oct 2008 21:24
It went really dodgy on mine, as though it was using integers for the heights. The waves are really jagged instead of being smooth. When I used the largest one, I got 9 FPS, but certain parts were smooth, and the rest was jagged. I have a GeForce 6200.

[b]Yuor signutare was aresed by a deslyxic mud...
BOX2D V2 HAS HELP FILES! AND A WIKI!
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 6th Oct 2008 21:47
I get the same results as Diggsey, on my GeForce 7500 LE.

Hoozer
19
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bremerhaven (Germany)
Posted: 6th Oct 2008 21:49
@ dark coder:
Once again a really extreme good looking demo from you.

It seems like GeFo-6X00-series got a problem in some way to render it correctly! It is like Diggsey said, I get a edged square in the middle of the plain and the rest seems to be more or less smooth (but flickering)!

I attached a screen-shot to clarify what I mean.


Hoozer

AMD64X24800+(939);2GB;GF6800LE (@12PS, 6VS; 380 MHz, RAM: 434 MHz)
DP-Sw-Mode-Comp-Entry (updated to V. 1.4):
http://forum.thegamecreators.com/?m=forum_view&t=109846&b=5&p=0
Lukas W
22
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 6th Oct 2008 21:57
Very cool effect.

Will you try to make it possible to see through the water next?
Maybe add some dimming so it's harder to see the bottom depending on depth. (Kind of like how valve did it in hl2).

Anyway, It's totally awesome as it is. But with real-time water, I thought you meant if you dropped a cube in the water, it would cause waves.

ps. I got an estimated average fps of 420 on my 8800gt.

dark coder
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 6th Oct 2008 22:29
The issue some people are getting is that earlier generation(Nvidia only?) cards don't support linear interpolation of vertex textures, I've read some info about it online as well as a way to get around it, but the fix is a bit annoying to implement, it involves manually calculating the blending which is annoying to implement in my demo, so good luck .

Quote: "Will you try to make it possible to see through the water next?"


You can do this yourself you know, shaders are just text files! Not 128 bit encrypted lists of asm instructions that need to be viewed through special glasses to read. Look at line 126, the 1.0f at the end is 100% alpha, you can change this to 0.5f or something for very basic transparency, just make sure in DBPro you set the object's transparency to mode 2 or something.

Quote: "Maybe add some dimming so it's harder to see the bottom depending on depth."


If you mean make it so objects in the water get darker the deeper they are then that's not so straight forward, in Source all the reflective/refractive(or expensive as they call it, I think) water is on a flat surface so shading objects based on depth is very easy, you just sample the depth and dim it by whatever scale you want. But because this water isn't flat you can't do such a linear approach, the easiest(though not always accurate) way would be to first do a depth pass of the scene without the water, then in the pixel shader you sample the distance between the water's pixel and the depth of that pixel from the depth map and set the alpha accordingly. But this is a bit beyond the scope of what I intended to make :p.

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 7th Oct 2008 01:28 Edited at: 7th Oct 2008 03:58
Sid Sinister posted for the 8600mGT already...

But I get

53-62 FPS (depending on zoom): Maxamized_Window
and a solid
60 FPS (regardless of zoom): Normal_Window

draknir_
19
Years of Service
User Offline
Joined: 19th Oct 2006
Location: Netherlands
Posted: 7th Oct 2008 03:13
Looks fantastic dark coder, I'm getting 27 FPS with an 8400M.
Doz
18
Years of Service
User Offline
Joined: 16th Apr 2008
Location:
Posted: 7th Oct 2008 05:53
This is just amazing...great work, and for reference getting ~650fps on a gtx 260.
Bad Monkey
19
Years of Service
User Offline
Joined: 1st Jan 2007
Location:
Posted: 7th Oct 2008 07:31 Edited at: 7th Oct 2008 07:31
I got the same problem with rendering a cube in the center of the water. I have nvidia 6000 series. But still neat effect.


Visit my website:
http://www.artistsareus.com
trogdor
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: Portsmouth, VA, USA
Posted: 10th Oct 2008 23:11
Sweet shader
I get 31fps on Radeon HD 2400 Pro at 1920x1200

If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.
coolgames
20
Years of Service
User Offline
Joined: 26th Sep 2005
Location: Oregon, USA
Posted: 11th Oct 2008 21:21 Edited at: 11th Oct 2008 21:26
Nice! I'm getting ~300 fps on an HD3850 AGP.

Edit:
@GG: if you're looking to upgrade your AGP card, then I would recommend the Powercolor hd3850 agp card. It is directx 10 and runs great on my agp system. I upgraded from an fx5200. Just make sure you have a 450w power supply or better.
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 11th Oct 2008 22:28 Edited at: 11th Oct 2008 22:39
Quote: "this isn't exactly practical for most games, for instance getting the height of any given point on the water's surface on the CPU isn't that easy"


If I used this I would shorten the wave heights and just use the height of the original plane for any water calculations.

Also can this be modified so that the reverse of the water isn't invisible?

Edit:
"Set Object 1 , 1, 0, 0" Yep add this and the water is visible on both sides.

"Set Effect Constant Float 1, "oct1Power", 1.0" Change this line and the effect looks way more real. Woot.

Login to post a reply

Server time is: 2026-06-05 22:09:33
Your offset time is: 2026-06-05 22:09:33