'Swimmable' water in terrain

Advanced game related topics
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

'Swimmable' water in terrain

Post 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)
DarkDragon
Addict
Addict
Posts: 2347
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post 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.
bye,
Daniel
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

This could be done with the KODE ODE Wrapper - See Car Physics thread for links to the DEMO.
Paid up PB User !
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

Post 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
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

When underwater just change the ambient light to a blueish tone also add a few 2d bubbles going up ;)
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

Post 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...
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

Then why not use the fog() command ?
Paid up PB User !
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

Post 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()...
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post 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 ?
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post 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
Please correct my english
http://purebasic.developpez.com/
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post 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
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Want to take a swim underwater ???

Image
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Looks nice ;)
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

hey num3, show the real thing! can this be done in pb?!?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

Post 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...
Post Reply