fast cubemapped simple water

Community Forums/Graphic Chat/fast cubemapped simple water

D4NM4N(Posted 2005) [#1]


Ive put together a bit of code that may be useful to people.
It allows you to create massive areas of moving water with huge vertex counts, without the need for realtime pulling of the vertices (because as i recently discovered (to my big design horror)is slow). Based on a rendering idea by Rob Cummings. I cannot waste anymore time on it but anyone who makes it better, let me know as im at 'that' stage in my project.

Latest:----------------------------------------------------

While working on the TED demos, i decided to blow the cobwebs off this and have a new play around.

Ive changed the interface slightly to allow for things like fog and cameraranges.

Also, any object to be cubemapped (not only flat objects) by using an addreflection function.

Also i noticed if i turned on the zbuffer & background clearing it seemed to help with some(not all) of the underwater inverting. But i cannot remember if i did this on the original, as ive played with it so many times.

It seems to work fine now with terrains (there may be a little bit of disruprion here and there but is within tollerances.. well mine anyway :)

There is also a cubemapexclusion list function where you can put all entitys that need to be hidden when entering the water below a certain depth. It seems to be working ok in my own tests.

You can get the modified version from www.d-grafix.com/softwareted.html
and click on the downloads section > island demo


AdrianT(Posted 2005) [#2]
very nice :)


Picklesworth(Posted 2005) [#3]
Some of the best water I've seen Blitz do.


Red Ocktober(Posted 2005) [#4]
yeah... that looks really nice...

similar in technique to the cubed demo code that Rob Cummings put up a while back...


as far as moving vertices around, i've gotten a decent looking ocean (not as pretty as cubemapped, but i can't decide on which one to use seeing as the cubed stuff looks so mirror like, and the ocean just aint like that... well, maybe in the carribean, on a balmy summer evening) and i cap off the simulation rate and fps at 60... both seem to run equally as fast and smooth (although yours looks a lot prettier)...

also...

if i drop one of my subs into the water, it looks fine from ground level...


but if i move the viewpoint up a bit, this is what i see...


the subs shadow seems to stretch towards the horizon...


if the sub is suspended above the water, all looks fine though...


--Mike


morduun(Posted 2005) [#5]
Very sexy and a =very= usable interface. Many thanks for sharing :)


jfk EO-11110(Posted 2005) [#6]
Indeed, this is supersexy. I had to rename it to water_supersexy.zip to make sure I won't forget what it is (i mean, water.zip, what could this be). Very nice stuff, thanks a lot for sharing. This just gave me a inspirational kick.


Ross C(Posted 2005) [#7]
Dam... verrrrrrrrry nice!


Dirk Krause(Posted 2005) [#8]
Absolutely outstanding.


D4NM4N(Posted 2005) [#9]
to red ocktober:

no, its your subs leaky oil tank :)

i think the back of the waves are reflecting the back of the sub. try lowering the amplitude

I learned cubemapping from that technique! (didnt know who designed it). Oh well, thanx to rob for inspiring me. Cred where due!!

My poor PC is a Duron800 with a geforce4mx so vertex calls and updatenormal calls really kill my framerate. if you care to share, i would really like to look at your vertex system, mabe its better written than the one i tried.

anyway, enough waffle :)

to all:
Glad u like it, if anyone makes any breakthroughs with it let me know, and ill have a copy back.


ICECAP(Posted 2005) [#10]
Thats wicked!
I have been hunting around for some way to do what this does.
Damn if only i knew at the time it was that easy!
Thanks for sharing!


Red Ocktober(Posted 2005) [#11]
hahaha... sub leaking oil, good one...

ok, lets see... i tried playing with the amplitude, no luck... still get the oil slick...

... and since my chief engineer says the oil tanks are still full, it must be an underwater oil seepage of some sort...

i'll play around with the code and see if i can figure out what's happening.

again, this is verrry nice... suitable for lakes and ponds... but i really need ocean waves type water...

... something like this

http://home.att.net/~subbase2/MovingShadedWater.wmv

a lil test level i did in a6 using shaders and moving vertices...

i also got one in blitz... without the cubemapping effects... lemme see if i can find it...

[added] couldn't find it so i whipped up another one so you could see what i meant...

http://home.att.net/~subbase2/oceanwaves.wmv

this is running on a 733mhz gGeForce2 machine... but doesn't have the photorealistic cubemapping effects.

--Mike


IPete2(Posted 2005) [#12]
@ Mike,

Have you tried extracting the code from Fredbourgs' Roman Baths? It's a couple of functions and works really well.

It may only work for smaller areas though - I don't know.

The Roman Bath code is on the Gile[s] website and it updates in real-time (although it is a small area) - maybe there is a way to adapt it?

...Oh I just thought of a very stupid idea Mike, why don't you move the sub up to that height for the cubemapping update, generate the new cubemap and then put it back down to the place it should be for the renderworld? This way you'd maybe get the right effect even though its a completely crap way of doing it!


@ D - Grafix - very nice sir - thanks for sharing.
IPete2.


Red Ocktober(Posted 2005) [#13]
thx IPete... will take a look at that... the Roman baths...

and, ya see... why can't i ever come up with a fix like that!!!

that aint stoopid at all... it's inspired... thx again... lets try it and see..

--Mike


IPete2(Posted 2005) [#14]
Mike,

I just tried this with the following:


Global sub=CreateCube()
PositionEntity sub,0,1,0
ScaleEntity sub,23,13,13

www.smartscreenuk.com/Sub001.jpg

www.smartscreenuk.com/sub002.jpg

and I cant replicate what you are seeing...! Strange. The cube sub I create looks fantastic, the reflection is fine, just as you would expect from any angle, high or low.

I wonder if something else is not quite right here? Can't think what would affect the reflections like that...what are the settings you are using?

IPete2.


Red Ocktober(Posted 2005) [#15]
hhhhmmmmmm....

[added] i get the same thing with the cube...

hey, lemme try this on another machine... different video card...


--Mike


IPete2(Posted 2005) [#16]
Aha!

When I move the cube down into the water I get more of a reflection behind it! How strange! Maybe it is the vertical position of the cube camera? try moving it down or up the amount you moved the sub up to get a proper looking reflection.


In the function which updates the cube camera...

;position cubemap camera
camoffsety#=(EntityY(maincamera,True)-EntityY(entity,True))
PositionEntity camera,EntityX#(maincamera,True),EntityY#(entity,True)-camoffsety,EntityZ(maincamera,True)



...maybe?

IPete2.

ps it seemed to work better moving this camera up for me. Try half the distance as a compromise...seems to do it here.


Red Ocktober(Posted 2005) [#17]
well... lets give it a try...

in the meantime, i found that if i hide the sub and show it just before rendercubemaps() is called in the maion loop, that i get no reflection at all... sort of a fix :)

--Mike


IPete2(Posted 2005) [#18]
Heres the new setting which worked for my cube shaped sub...

camoffsety#=(EntityY(maincamera,True)+5)

As a guide...

BEFORE cube camera adjusted
www.smartscreenuk.com/sub004.jpg

AFTER cube camera adjusted
www.smartscreenuk.com/sub005.jpg


You get the reflection, and it is in the correct place, it may seem a little deeper than it should be though!

Mike, it's my snooze time - let me know how you get on!

Cheers!

IPete2.


Red Ocktober(Posted 2005) [#19]
thx IP... later

--Mike


Picklesworth(Posted 2005) [#20]
Those waves need a bit more curvy randomness...

Anyone thought of how to do this?


jhocking(Posted 2005) [#21]
Awesome water! Thanks for the gift.


Shambler(Posted 2005) [#22]
Very nice lateral thinking there =) ,although I can only see the environment map on this junk heap of a PC at work ^^

I'll look at replacing my vertex manipulated meshes using this method instead...I think the results will definitely look better and may just run faster on a wider range of PC's.

Cheers.


D4NM4N(Posted 2005) [#23]
The cubemapper in my code uses the same technique as the baths code, so you will probably get the same result. I think you need to place objects at water level as its reflecting back what it sees under the water and thats why you are getting the reflection. Technically its 'doing exactly what it says on the tin', but looks crap.


jfk EO-11110(Posted 2005) [#24]
Currently I can see only one solution fo this oil slick problem:
During Enviroment-Map Update
-Hide anything that is completely below the water level.
-Boolen Clip all meshes that are intersecting the water level, probably best use this code: http://www.blitzbasic.com/codearcs/codearcs.php?code=1143 , or think about to Pre-calc clipped hidden versions of the meshes with some slices raster. Whle the realtime clipping my be a bit slow (well, working on a copy of the originals anyway), the pre-calc solution may require a lot of ram.

I guess it can be implemented pretty easily when you have all meshes and their Min and Max (world)Y Vertex Location inside an array or type, then simply parse that list each frame and Hide/Clip as required.

EDIT: what I ask myself is: why isn't the green bottom texture of the skybox not mirrored the same bugous way then?


jfk EO-11110(Posted 2005) [#25]
uh realtime clipping may be too slow. I just tested it with a sphere with 100 Segments (that's about 40k tris) and my framerate drops to 150ms per frame on a Radeon 9200se.
Rendering with the same amount of polies, but using a precalculated clipped version for the EnvMap was done in 33ms/f on this machine (total 80kTris for the normal Renderworld, inclusive water quad and of course, the clipped quad in the 6*EnvMap Update).

BTW if you would use a relative small EnvMap resolution, it may be possible to use 6 cameras, each one with its own CameraViewport and angle, then create the Cubemap with a single renderworld.


TartanTangerine (was Indiepath)(Posted 2005) [#26]
I remember reading somewhere that you don't have to render all 6 faces of the cube map, only the ones facing you.

Anyway I just tried it and it works. I did not render the cube faces behind me or the cube face facing down and I only render 1 face per frame. I went from 200FPS to 280FPS :)


Damien Sturdy(Posted 2005) [#27]
Great work! Think about miplementing my cubemap functions to speed up cubemap rendernig though.. Most games even these days dont update the cubemaps each frame. :)


jhocking(Posted 2005) [#28]
Maybe ask this guy how he did it:
http://www.blitzbasic.com/gallery/view_pic.php?id=170&gallery=hr&page=12

It looks to me like the character is intersecting the water.


Red Ocktober(Posted 2005) [#29]
he probably did it something similar to this...



it's all done with mirrors...

see video... (880k small)
http://home.att.net/~subbase2/oceanwaves.WMV

with this method i at can get ocean waves... not ripples... but, i think i've gotta change the texture and lessen the wave action a bit... such a turbulent ocean wouldn't show a clear reflection, would it...

also, now i gotta make a mirror friendly half a skybox :)

[added] changed the pic and the lil video... got a half skybox working...

(*** boat model by Guillaume Darier and Matthew Sebring ***)

--Mike


jhocking(Posted 2005) [#30]
I don't know, the description specifically mentions cubemapping.


Red Ocktober(Posted 2005) [#31]
yeah... i was just being funny... looking at it a lil more seriously... it does look like its cubemapped...

i'm pursuing the mirrored approach... hey, take a quick look back at that lil video and the pic i just posted... i managed to get a half a skybox that works with a mirror...

still playing around with various things to get things looking 'right'


--Mike


jfk EO-11110(Posted 2005) [#32]
Well the Character on the Image who walks in the pool thing just obsures the relevant parts, so we don't know if he has the same problems or not.


Tracer(Posted 2005) [#33]
Man, this screws up royally on my system :)

I literally see one side of the cubemap cube in the top left corner.. the middle of the screen flickers (just a band).. and it's REALLY slow (this is a 3.6ghz with a Geforce 6800 Ultra SLI (two cards))

[EDIT] works in windowed mode, does the above in fullscreen.

Tracer


Kuron(Posted 2005) [#34]
the middle of the screen flickers (just a band)..
This sounds like the recent bugs being reported between B3D and somewhat newer video cards...


Naughty Alien(Posted 2005) [#35]
..on my machine everything working well and very very fast...P4, 2.4 GHz , 4 Gigs RAM,nVidia A310 256 MB Video RAM


Red Ocktober(Posted 2005) [#36]
SR i'm not sure if it's the video cards or the new monitors, or a combination of the two...

i experienced the samer thing... fixed it by adding this...


Update World
RenderWorld
...
...
VWait:Flip False


i'm using basically the timing algorithms on page 17 of the old written manual to limit my app speed...

--Mike


Ruz(Posted 2005) [#37]
looks really nice. had some weird z fighting issues at work,, but it worked fine at home with an older graphics card


D4NM4N(Posted 2005) [#38]
See original edited post for latest.


Damien Sturdy(Posted 2005) [#39]
Hey. looking good!

Funny- I recently pulled up my mirror code too. Progress is still slow- I'm yet to plop it in your code with the clipping of meshes at Y=n- which yould be darn excelent for this.

Would make it usable in a game for sure :D


Tom(Posted 2005) [#40]
Hi all,

http://www.tomspeed.com/b3d_rangefog/

Check the userlib & clipping example there. It does hardware 'user-defined' plane clipping @ rendertime, might be useful for what you're doing.

I'm revamping this userlib @ the request of Defoc8, update soon!
Tom


Robert Cummings(Posted 2005) [#41]
That Rob fellow keeps popping up everywhere like an egg of some sort. I wonder where I can find him?

Someone told me he was last seen skiing down everest for laughs naked. He then pulled his parachute cord at the last minute.

Apparently he was wearing a bright fuzzy ronald mcdonald wig at the time.


D4NM4N(Posted 2005) [#42]
@tom
for some weird reason i can see the files but not download them !?? i think its a problem with my setup As ive had this before. Any chance you can email them to me? also, whats that shadow thingy, it doesnt calculate static or dynamic shads by chance?


Damien Sturdy(Posted 2005) [#43]
Tom, my system's based on your files ;)


Ruz(Posted 2005) [#44]
looks superb


Damien Sturdy(Posted 2005) [#45]
Check your Email, D-Grafix. I finally got round to my promise :)


Happy Sammy(Posted 2007) [#46]
Is this zip still available somewhere?


D4NM4N(Posted 2007) [#47]
!!!!!ARGH! Attack of the UNDEAD THREAD!!!!!! :)

Lost the original, but i got a slightly later version with water fog etc here :
http://www.d-grafix.com?page=sourcecode

I took this page off being linked as it is not finished and has not been updated for a year or more, but youre welcome to it.


elcoo(Posted 2007) [#48]
For me, the water looks really weird! :(
Look at this:


What could this be? The textures there are totaly random!


D4NM4N(Posted 2007) [#49]
No idea. Looks like the video card is messing up the cubemap or something. There are probably loads better ways to do this these days like rendering to textures directly etc...

Not using some twobit intel GPU or anyting are you?


stayne(Posted 2007) [#50]
Could that be from a buffer? :)