Cubemapped Water...

Blitz3D Forums/Blitz3D Programming/Cubemapped Water...

OrcSlayer(Posted 2006) [#1]
I just tried out adding cube mapped water to my game, by copying the example code in the gile[s] b3d parser example and changing it to fit my engine. After a long bit of trial and error (this kind of thing isn't my specialization), I got it to run, but with a few problems.

First off, at times it would be fast enough to not impact my frame rate (set at 60 FPS), but other times (especially if something is actually happening on screen, shooting a gun, particle effects, etc) it would slow down the whole thing horribly (sometimes down to 20 FPS or less).

The other problem is that it also rendered things that it shouldn't...like stuff that's already penetrated the surface and is laying on the bottom of the pit. This I understand, and I know the way to fix it would be to hide entities that are in the liquid body when it renders the cube map images for it...but I don't know how to go about doing that.

As for the speed issue, is the example in the gile[s] parser just not a "fast" way to do it? I'm not up on cubemapping methods, so I may be missing something here. I think that demo is fairly old, perhaps someone has found a faster way to do it?

Any tips on how to fix my problems would be greatly appreciated.


jfk EO-11110(Posted 2006) [#2]
make sure to read the code archives on cube mapping. one example explains how to render 6 sides with one renderworld.

Other solutions do not update every side for every frame, but frequently update a side of the cube texture, using a turnus order.

Most important is to use the right texture flags to make sure Copyrect will work fast enough (not sure if the flag 256 is set by default when you use cubemapping, you better set it to be on the save side)

Hiding those things that are lower than the cubemap surface (eg floor) is a bit tricky, especially when they intersect with the surface. This is only an idea, maybe it works: position a black box on the surface level, width and depth pseudo infinite, top side right on the surface y level, FX fullbright. Now when you render the scene, in theory things inside the box/cube will be hidden under the black zones, as well as intersection parts etc. All you have to do now is Drawimage to draw everything but the black pixels to a buffer that has a neutral pattern.


Red Ocktober(Posted 2006) [#3]
and take a look at the water contest we just had not too long ago... some of the code examples there are very good... and pretty fast as well...

for example, i'm using a modification of the code that Fredborg so generously gave out... and it is pretty fast, especially considering that i have scaled up the water quite a bit, and i have all sorts of particles stuff running around in the scenes as well (look at the graphics showcase for my lil sub video thingees to get an idea)

good luck...


--Mike


OrcSlayer(Posted 2006) [#4]
Thanks for the info guys, I'll go check it out!


OrcSlayer(Posted 2006) [#5]
I have the code for Fredborgs cubemapped water...it is impressive but it's just not wanting to work for me...

Does anyone have an old copy of the cubed demo with source code? The one by Rob Cummings? I had it but I think I lost it...all I can find now is the one without source.


Damien Sturdy(Posted 2006) [#6]
*Points at sig* This might also help. :)


Red Ocktober(Posted 2006) [#7]
Orc... if i remember, Rob's water is based on 2 files... ocean reflect and ocean... ocean sets up a few things and makes the calls to the actual work functions in ocean reflect...

what's not working?

--Mike


Damien Sturdy(Posted 2006) [#8]
Hey Red, whatever happened to my technique? Were there any problems?


OrcSlayer(Posted 2006) [#9]
Red Ocktober: It works fine, but I only have the demo with no source code. All the links I found to the copy WITH source code are dead.

Cygnus: Looks good, but I think I've pretty much decided NOT to use real time cubemapping, but rather single render cubemapping with dynamic surface animation. It's the only way I think I can pull off the effect I want, without the problems.

Namely, stuff like everything that goes into the water making seriously weird reflections...which is caused by the very way it all works. Of course, I also want to save speed, since there's a lot that goes on in my game at any given time.


Damien Sturdy(Posted 2006) [#10]

Namely, stuff like everything that goes into the water making seriously weird reflections...



Something Toms DX7 dll can be used to fix- using a method I gave to Red :)


OrcSlayer(Posted 2006) [#11]
Well, I'm a bit worried about using DLL's...mostly because I'm working on project that is going to be a commercial game (indie though)...and I'm leary of restrictions and such (except for Tokamak I'm currently using pure Blitz for everything).

Where can I find this DLL, and does it have any restrictions on it, or possible incompatibility issues?


Damien Sturdy(Posted 2006) [#12]
Well, the clip planes work, full stop, theyre just a DX7 feature that blitz didn't implement (which IMO it should.)

there are parts of the DLL that arent compatible with everything (DirectX texture compression stuff) but the clip plane you will need works fine.

Youre more likely to run into errors due to lack of cubemap support :)

As for where to get it from, fraid I don't have a direct link, but I can put the demo I did for red online in a few hours :)


OrcSlayer(Posted 2006) [#13]
I see, well I'll be sure to check back and see about this demo of yours!

I finally got cubemaps sort of working...but they look horrible unless I constantly update them, and to do that I have to render everything...including objects that can pass through them (unless I wrote a function to hide all non-static entities when rendering a cube map...now that would be horrible, but is one possible solution).

Hopefully your demo will help me sort this out...


Damien Sturdy(Posted 2006) [#14]
The demo will show you an example, it may be too slow depending on how complex your scene is though!

It uses the DX7 dll to clip rendering above/below a certain point. It doesn't simply hide an entity, but only renders the part of the entity thats above the clip range.

BTW, to get the above effect requires hiding/showing certain entities and rendering the scene twice. The result is *worth it* providing you dont have a bazillion bullets flying around :)


OrcSlayer(Posted 2006) [#15]
I'll be sure to check it out then...but, things can get pretty hectic in the game. Not quite a bazillion bullets...but lots of bullets/particles/decals and a fair amount of characters/scenery can all be in scene at once...

If it works, I'll be very happy. If not, I'll fake it.


jfk EO-11110(Posted 2006) [#16]
Cygnus - could you help me too with this clip plane thing? I guess it would be useful also for CreateMirror()?


Red Ocktober(Posted 2006) [#17]
uuhhh, now don't get mad at me Cyg... but i still haven't put in your clipping code yet... i'm still using my old method (just too lazy to add it in)...

i did look at it, and it looks like it'll go in smoothly enough... and the demo works great...

--Mike


Damien Sturdy(Posted 2006) [#18]
Ok, i'll shove it up now.


Damien Sturdy(Posted 2006) [#19]
http://www.blitzbasic.com/Community/posts.php?topic=60331


jfk EO-11110(Posted 2006) [#20]
Thanks a lot!