Page 1 of 3

'Swimmable' water in terrain

Posted: Mon Feb 27, 2006 9:58 pm
by Roger
I'm still experimenting a bit with PureBasic's 3D functionality, and I've gotten the hang of creating terrains and displaying textures on them a bit. However, I can only create 'waterless' terrains as it is because I haven't got a clue about how to create 'swimmable' water.

Swimming animations and stuff is not at all necessary, but I can't even create something that 'covers' a part of my terrain in which i can 'submerge'. Hopefully you'll be able to provide me with some tips on this. I can't really give any relevant code yet, seeing as how I don't have a clue at the moment ;)

Edit:
For the underwater part I thought one could use the same mechanics that allows one to create fog-effects and have 'swimming physics' apply to the camera. That still leaves me with the upper layer of water that I need to be able to be 'breakable' by the camera (in other words, you must be able to go through it, even though from the outside it looks like a solid texture; a watery texture of course)

Posted: Tue Feb 28, 2006 7:10 am
by DarkDragon
Well I have done this just through a cube, but I don't know if it works in Ogre, too. You could use a second terrain and make it transparent. And Underwater you could draw a 2D Transparent Box to make your Screen looking a bit blue or use blue Fog.

Posted: Thu Mar 02, 2006 5:42 pm
by dontmailme
This could be done with the KODE ODE Wrapper - See Car Physics thread for links to the DEMO.

Posted: Thu Mar 02, 2006 7:32 pm
by Roger
Well, I managed to do it with the cube suggestion. With a scrolling texture you can even make the water 'move' (waves etc.).
I'm not yet sure about how to make an 'underwater' feeling, but I might do something with translucent sprites (I tried fog and a changed ambientcolor, but that's too heavy).

If you have any more suggestions or snippets, please don't hesitate to post them - I'm absorbing any knowledge on this like a sponge :P

Posted: Thu Mar 02, 2006 8:20 pm
by Num3
When underwater just change the ambient light to a blueish tone also add a few 2d bubbles going up ;)

Posted: Thu Mar 02, 2006 8:52 pm
by Roger
Changing the ambientcolor is easy enough. The thing is, when I'm underwater (not that I swim so often, but still :P) I always notice that anything above it is much more vague. Therefore I need some sort of fog effect, or maybe a blueish translucent sprite at the water-level so that it doesn't look as if I didn't just land in a slightly more blueish terrain...

Posted: Fri Mar 03, 2006 2:18 am
by dontmailme
Then why not use the fog() command ?

Posted: Fri Mar 03, 2006 8:28 am
by Roger
Well, the problem with the fog function is that it's not so useful on short distances (or so it seems). If I have a fog at a startdistance of 10 for example, the fog turns into a wall in the color I specified. There's nothing translucent about that...

If you look at this image:
http://www.luckypp.com/WoW_Screens/swim ... bigben.jpg
you'll see how it's done in World of Warcraft. They seem to have done something with the ambientcolor, and there is sòme fog, but not much. Furthermore, whilst you may not see it from this image, when it is just a smaller lake, there is still the underwater effect, even though the distance is too small to use a PB fog() effect....

I suppose doing *something* with translucent sprites creates that effect better than fog()...

Posted: Sat Mar 04, 2006 3:28 pm
by Num3
Roger wrote:Well, the problem with the fog function is that it's not so useful on short distances (or so it seems). If I have a fog at a startdistance of 10 for example, the fog turns into a wall in the color I specified. There's nothing translucent about that...
I've been fooling around with fog...
For it to be transparent you must specify a very large end distance...

For example 6000 units!

Btw, can someone post a cube manual mesh for me to test my water fx ?

Posted: Sat Mar 04, 2006 4:27 pm
by Comtois
Num3 wrote:Btw, can someone post a cube manual mesh for me to test my water fx ?
http://www.purebasic.fr/english/viewtopic.php?t=19904

or this one

Code: Select all

;Comtois le 04/03/06
;PB4 beta 5

;- Initialisation
If InitEngine3D() = 0
 MessageRequester( "Erreur" , "Impossible d'initialiser la 3D , vérifiez la présence de engine3D.dll" , 0 )
 End
ElseIf InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse()=0
 MessageRequester( "Erreur" , "Impossible d'initialiser DirectX 7 Ou plus" , 0 )
 End
ElseIf OpenScreen( 800 , 600 , 32 , "M3D_Matrix3D" ) = 0
 MessageRequester( "Erreur" , "Impossible d'ouvrir l'écran " , 0 )
 End
EndIf

Structure Vertex
px.f
py.f
pz.f
nx.f
ny.f
nz.f
co.l
tu.f
tv.f
EndStructure

Structure Face
  p1.w
  p2.w
  p3.w
  p4.w
  p5.w
  p6.w
EndStructure
Structure s_Cube
  No.l
EndStructure
Structure s_Angle
  AngleX.f
  AngleY.f
  AngleZ.f
EndStructure
Macro MaCouleur(Rouge,Vert,Bleu)
  Rouge << 16 + Vert << 8 + Bleu
EndMacro

;-Texture
CreateTexture(0,64,64)
StartDrawing(TextureOutput(0))
Box(0,0,64,64,$111111)
Box(1,1,62,62,$FFFFFF)
StopDrawing()

;-Material
CreateMaterial(0,TextureID(0))
MaterialAmbientColor(0,-1)

;-Entity
Global Taille=200
Global Angle.f

*Ptr.Vertex=AllocateMemory(SizeOf(Vertex)*24)
CopyMemory(?Vertices,*Ptr,SizeOf(Vertex)*24)
;Couleur dessus
*Mem.Vertex = *Ptr
For i = 0 To 3
  *Mem\co=MaCouleur(0,0,255)
  *Mem + SizeOf(Vertex)
Next i
;Couleur dessous
*Mem.Vertex = *Ptr + 4 * SizeOf(Vertex)
For i = 0 To 3
  *Mem\co=MaCouleur(255,255,255)
  *Mem + SizeOf(Vertex)
Next i
;Couleur devant
*Mem.Vertex = *Ptr + 8 * SizeOf(Vertex)
For i = 0 To 3
  *Mem\co=MaCouleur(255,255,0)
  *Mem + SizeOf(Vertex)
Next i
;Couleur derriere
*Mem.Vertex = *Ptr + 12 * SizeOf(Vertex)
For i = 0 To 3
  *Mem\co=MaCouleur(255,128,0)
  *Mem + SizeOf(Vertex)
Next i
;Couleur gauche
*Mem.Vertex = *Ptr + 16 * SizeOf(Vertex)
For i = 0 To 3
  *Mem\co=MaCouleur(0,255,0)
  *Mem + SizeOf(Vertex)
Next i
;Couleur droit
*Mem.Vertex = *Ptr + 20 * SizeOf(Vertex)
For i = 0 To 3
  *Mem\co=MaCouleur(255,0,0)
  *Mem + SizeOf(Vertex)
Next i
CreateMesh(0,10)
SetMeshData(0, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate , *Ptr,24)
SetMeshData(0,#PB_Mesh_Face,?Triangles,12)

;Entity
CreateEntity(0,MeshID(0),MaterialID(0))
ScaleEntity(0,Taille,Taille,Taille)
EntityLocate(0, 0 , 0 , 0)


;-Camera
CreateCamera(0,0,0,100,100)
CameraBackColor(0,RGB(0,0,255))
AmbientColor(RGB(200,200,200))
CameraLocate(0,EntityX(0) + 250 ,EntityY(0)+ 250,EntityZ(0))
MoveCamera(0,0,40,350)
CameraLookAt(0,EntityX(0),EntityY(0),EntityZ(0))

Repeat
  ExamineKeyboard()
  Angle + 0.5
  RotateEntity(0,Angle,Angle,Angle)
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)

DataSection
Vertices:
;Dessus 0 à 3
Data.f -0.5,0.5,-0.5
Data.f 0,1,0
Data.l 0
Data.f 0,0

Data.f 0.5,0.5,-0.5
Data.f 0,1,0
Data.l 0
Data.f 0,1

Data.f 0.5,0.5,0.5
Data.f 0,1,0
Data.l 0
Data.f 1,1

Data.f -0.5,0.5,0.5
Data.f 0,1,0
Data.l 0
Data.f 1,0

;Dessous 4 à 7
Data.f -0.5,-0.5,0.5
Data.f 0,-1,0
Data.l 0
Data.f 0,0

Data.f 0.5,-0.5,0.5
Data.f 0,-1,0
Data.l 0
Data.f 0,1

Data.f 0.5,-0.5,-0.5
Data.f 0,-1,0
Data.l 0
Data.f 1,1

Data.f -0.5,-0.5,-0.5
Data.f 0,-1,0
Data.l 0
Data.f 1,0

;Devant 8 à 11
Data.f -0.5,0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 0,0

Data.f 0.5,0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 0,1

Data.f 0.5,-0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 1,1

Data.f -0.5,-0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 1,0

;Derrière 12 à 15
Data.f 0.5,0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 0,0

Data.f -0.5,0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 0,1

Data.f -0.5,-0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 1,1

Data.f 0.5,-0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 1,0

;Cote gauche 16 à 19
Data.f -0.5,0.5,-0.5
Data.f -1,0,0
Data.l 0
Data.f 0,0

Data.f -0.5,0.5,0.5
Data.f -1,0,0
Data.l 0
Data.f 0,1

Data.f -0.5,-0.5,0.5
Data.f -1,0,0
Data.l 0
Data.f 1,1

Data.f -0.5,-0.5,-0.5
Data.f -1,0,0
Data.l 0
Data.f 1,0

;Cote droit 20 à 23
Data.f 0.5,0.5,0.5
Data.f 1,0,0
Data.l 0
Data.f 0,0

Data.f 0.5,0.5,-0.5
Data.f 1,0,0
Data.l 0
Data.f 0,1

Data.f 0.5,-0.5,-0.5
Data.f 1,0,0
Data.l 0
Data.f 1,1

Data.f 0.5,-0.5,0.5
Data.f 1,0,0
Data.l 0
Data.f 1,0

Triangles:
;0 à 3
Data.w 2,1,0
Data.w 0,3,2
;4 à 7
Data.w 6,5,4
Data.w 4,7,6
;8 à 11
Data.w 10,9,8
Data.w 8,11,10
;12 à 15
Data.w 14,13,12
Data.w 12,15,14
;16 à 19
Data.w 18,17,16
Data.w 16,19,18
;20 à 23
Data.w 22,21,20
Data.w 20,23,22
EndDataSection

Posted: Mon Mar 06, 2006 8:51 pm
by Num3
Here's my water...

It's animated and fully transparent!
(This is a Jpeg, so details are blured)

Image

Notice the fringe on the shore, i know this is because of the intersection between the terrain and the water cube, anyone knows how to reduce it ?

(This is a croped PNG, with low color (for size sake))
Image

Posted: Mon Mar 06, 2006 10:03 pm
by Num3
Want to take a swim underwater ???

Image

Posted: Mon Mar 06, 2006 10:28 pm
by Fred
Looks nice ;)

Posted: Mon Mar 06, 2006 10:28 pm
by blueznl
hey num3, show the real thing! can this be done in pb?!?

Posted: Tue Mar 07, 2006 12:50 am
by Roger
Hmm yes, that definately looks nice. If I'm permitted... Would you please post the code to create that? :twisted:

And, I managed to create an effect a little like it, not as good though, and indeed, the place where the water cube crosses the terrain gets quite ugly. I hope someone's got ideas on how to make that smoother...