Page 1 of 2

Water

Posted: Thu Aug 01, 2013 11:54 am
by NikitaOdnorob98
Is it possible to create water with a specific size? For example, I need to create a puddle of dimensions 2 m * 1 m * 30 cm

Re: Water

Posted: Fri Aug 02, 2013 7:45 am
by Bananenfreak
Nope, would be nice. Actual, water isn´t good to use.

Where the water is Floating is also missing (X,Y,Z) (SetWaterOrientation() or similar). Do the water react to Entities (Foam,...)?

An Expansion, that we can read out and set informations of the water (height at a specific Point,...). For effects like Battlefield 4, where the water is managed by the Server, so everyone has the "same" water, same waves,... ;)
This Point is important, because we Need to read the informations to set a ship or something else in the waves...

P.S.: A lib for waterfalls would be also nice :D

Re: Water

Posted: Fri Aug 02, 2013 11:00 am
by applePi
it is possible to make fake water to fill small lakes in a terrain, by inserting a thin disk under the terrain so it will penetrate some mountains and hills, the disk have cube mapping and made from stretched sphere, move with keys and mouse to the right eye, and if you go under the terrain you will see the disk.
Image

the code are extracted from one of the terrain examples in 3D section
for this example use this skull picture to make a terrain
http://s17.postimg.org/r678lwahr/skull.jpg
and this silver.jpg for the reflection surface (not absolute necessary)
Image
and this material save as cubemap.material

Code: Select all

material CubeMapMaterial
  {
    technique
    {
      pass
      {
        texture_unit
        {
          cubic_texture CubeMapTexture combinedUVW
          tex_address_mode clamp
          env_map cubic_reflection
        }
      }
    }
  }

Code: Select all

#CameraSpeed = 20
#TerrainMiniX = 0
#TerrainMiniY = 0
#TerrainMaxiX = 0
#TerrainMaxiY = 0
Define.f KeyX, KeyY, MouseX, MouseY


; OpenGL needs to have CG enabled to work (Linux and OS X have OpenGL by default)
;
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows Or Subsystem("OpenGL")
  Flags = #PB_Engine3D_EnableCG
CompilerEndIf

If InitEngine3D(Flags)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
ExamineDesktops()
win = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "fake water", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(win),0,0,DesktopWidth(0), DesktopHeight(0))
    Add3DArchive("/", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures/"       , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures/nvidia" , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts"         , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/GUI"           , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
    Parse3DScripts()
    
    WorldShadows(#PB_Shadow_Modulative, -1, RGB(105, 105, 105))
    
    ;- Light 
    ;
    light.l = CreateLight(#PB_Any ,RGB(255, 255, 255), 4000, 1200, 1000,#PB_Light_Directional)
    SetLightColor(light, #PB_Light_SpecularColor, RGB(255*0.4, 255*0.4,255*0.4)) 
    LightDirection(light ,0.55, -0.3, -0.75) 
    AmbientColor(RGB(255*0.2, 255*0.2,255*0.2))
        
    ;- Camera 
    ;
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0,  100, 500, 1500, #PB_Absolute)
    RotateCamera(0, -15, 0, 0 ,#PB_Absolute)
    CameraBackColor(0, RGB(5, 5, 10))
    
    
    ;----------------------------------
    ; terrain definition
    SetupTerrains(LightID(Light), 200, #PB_Terrain_NormalMapping)
    ; initialize terrain 
    ;CreateTerrain(#Terrain, Size, WorldSize, Scale, NbLayers, Filename$, Extension$)
    CreateTerrain(0, 129, 1500, 100, 1, "terrain02", "Dat")
    ;set all texture will be use when terrrain will be constructed 
    ;AddTerrainTexture(#Terrain, Layer, WorldSize, DiffuseSpecular$, NormalHeight$)
    AddTerrainTexture(0,  0, 100, "dirt_grayrocky_diffusespecular.dds",  "dirt_grayrocky_normalheight.dds")
        
    ;construct terrains
    DefineTerrainTile(0, 0, 0, "skull.jpg", 0, 0)  
    
    BuildTerrain(0)  
    
    ; enable shadow terrain
    TerrainRenderMode(0, #PB_Terrain_CastShadows)
        
    
    CreateSphere(1, 70)
    Global Ball = CreateEntity(#PB_Any, MeshID(1), #Null)
    MoveEntity(Ball, -200,520,0, #PB_Absolute)
    EntityRenderMode(Ball, #PB_Entity_CastShadow)
    
    ; SkyBox
    ;
    SkyBox("desert07.jpg")
    ;SkyDome("clouds.jpg", 3)
    
    ShowGUI(128, 1) ; Display the GUI, semi-transparent and display the mouse cursor
    EnableWorldPhysics(1)
    TerrainPhysicBody(0, 0.2,2.0)
    
    EntityPhysicBody(Ball,#PB_Entity_SphereBody,6,3,5)
    
    WorldGravity(-220)
    MyCubeMap = CreateCubeMapTexture(#PB_Any, 256, 256, "CubeMapTexture")
  GetScriptMaterial(2,"CubeMapMaterial")
  SetMaterialColor(2, #PB_Material_SelfIlluminationColor, $FFFFFF)
  
  Mirror = CreateSphere(#PB_Any, 80)
  Entity = CreateEntity(#PB_Any,MeshID(Mirror),MaterialID(2))
  
  EntityCubeMapTexture(MyCubeMap, Entity)
  MoveEntity(Entity, 200,20,-120)
  ScaleEntity(Entity, 4,0.2,4)
  
    CreateMaterial(4, LoadTexture(4, "silver.jpg"))
    AddMaterialLayer(2, TextureID(4) , #PB_Material_Modulate)
    Repeat
      ;Screen3DEvents()
      
      If ExamineKeyboard()       
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf
        
      EndIf
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
        
        ;InputEvent3D(MouseX(), MouseY(), MouseButton(#PB_MouseButton_Left))
        
        ;If MouseButton(#PB_MouseButton_Left)
          ;TerrainMousePick(0,  CameraID(0), MouseX(),  MouseY())
          ;MoveEntity(ball, PickX(), PickY()+20, PickZ(), #PB_Absolute)
        ;EndIf
        
      EndIf
      ;CameraLocate(0, CameraX(0), PBO_GetTerrainHeight(0, CameraX(0), CameraZ(0)) + 20, CameraZ(0))
      MoveCamera  (0, KeyX, 0, KeyY)
      RotateCamera(0,  MouseY, MouseX, 0, #PB_Relative) 
      y.f+0.6
      z.f+0.2
      RotateEntity(Ball, -90, y, z ,#PB_Absolute)

      RenderWorld()
      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape)   
    
    End 
    
  
Else
  MessageRequester("Error","Can't initialize engine3D")
EndIf

Re: Water

Posted: Fri Aug 02, 2013 2:52 pm
by Olby
Bananenfreak wrote:Nope, would be nice. Actual, water isn´t good to use.

Where the water is Floating is also missing (X,Y,Z) (SetWaterOrientation() or similar). Do the water react to Entities (Foam,...)?

An Expansion, that we can read out and set informations of the water (height at a specific Point,...). For effects like Battlefield 4, where the water is managed by the Server, so everyone has the "same" water, same waves,... ;)
This Point is important, because we Need to read the informations to set a ship or something else in the waves...

P.S.: A lib for waterfalls would be also nice :D
You can already code it manually using the existing command set and a bit of OpenGl shader knowledge. As I see it, current water commands are fine for general use. If you need advanced simulation you will have to resort to a third party lib or do it manually (manual mesh deformation, shaders + buoyancy physics).

Re: Water

Posted: Sun Aug 04, 2013 9:32 am
by Bananenfreak
@applePi:
This "water" isn´t moving, Looks like a mirror and not really real. But if Nikita is searching for this, ok ;)

@Olby:
I think Fred uses Hydrax for the water so look this:
http://modclub.rigsofrods.com/xavi/05AP ... tions.html
In my mind, These Options allow users to set the height of waves and the dimensions of the water (X,Z in world space).
What is the MeshVertexType?

See this URL: http://modclub.rigsofrods.com/xavi/05AP ... _grid.html
Look at: float Hydrax::Module::RadialGrid::getHeigth ( const Ogre::Vector2 & Position)

Why do I Need Shader knowledge, it´s all in the waterlib...
I think rest of my Points are also in Hydrax (Expect waterfalls ;) ).

In my mind, water is nothing than fluid Terrain (http://modclub.rigsofrods.com/xavi/05AP ... _mesh.html) and should be handled like this. This means the functions, too.

Re: Water

Posted: Sun Aug 04, 2013 9:37 am
by Fred

Re: Water

Posted: Sun Aug 04, 2013 10:26 am
by Bananenfreak
How to set Subsystem to OpenGL? I don´t got it...

Re: Water

Posted: Sun Aug 04, 2013 10:31 am
by Danilo
Bananenfreak wrote:How to set Subsystem to OpenGL? I don´t got it...
Compiler options: Library Subsystem: opengl

Test code:

Code: Select all

CompilerIf Subsystem("opengl")
    Debug "Subsystem OpenGL"
CompilerEndIf
You can see available subsystems in PB directory/subsystems/

OpenGL is default on Linux and Mac OS X, so there is no subsystem for it.

Re: Water

Posted: Sun Aug 04, 2013 10:56 am
by Bananenfreak
Thanks, Danilo.


Nice water, but Hydrax is still better (no offense :) ).

Re: Water

Posted: Sun Aug 04, 2013 1:13 pm
by Olby
Yep, judging by the screenshots it looks like they are using Hydrax. I wish we can get some more of it exposed in PB, for example commands to set wave amp and speed. Currently it's just a nice looking prop without any actual in-game benefit.

Re: Water

Posted: Sun Aug 04, 2013 2:31 pm
by applePi
i have downloaded the demo Hydrax-v0.5.1_Demo1.rar from
http://modclub.rigsofrods.com/xavi/
it has exe file
it display an island with a wavy water and a waving palms, we can walk in the island, it is great.
Image

Re: Water

Posted: Sun Aug 04, 2013 3:11 pm
by DK_PETER
applePi wrote:i have downloaded the demo Hydrax-v0.5.1_Demo1.rar from
http://modclub.rigsofrods.com/xavi/
it has exe file
it display an island with a wavy water and a waving palms, we can walk in the island, it is great.
Image
Oh my!! Lovely! The water looks amazing.

Re: Water

Posted: Sun Aug 04, 2013 4:42 pm
by Bananenfreak
Read this Topic:
http://www.purebasic.fr/english/viewtop ... =3&t=49412

Olby, it not only look like PB uses Hydrax, Pb uses Hydrax :D

Ehm, i played a bit with the Water.pb Demo. I enabled and disabled

Code: Select all

#PB_World_WaterSmooth
and I see no difference... Someone else see a difference? ^^

Re: Water

Posted: Sun Aug 04, 2013 5:50 pm
by applePi
i think the quality depends on the graphics card and subsys used , as an example for me geforce 210 the water are better in the default dx but very bad in opengl subsystem. even in other 3D examples it is better in opengl subsys.
for me it is only the #PB_World_WaterFoam witch makes a difference.
i think what is important is to be able to do something like that in the picture above.

Re: Water

Posted: Mon Aug 05, 2013 11:05 am
by Bananenfreak
Hmm, why the graphics Card modify the graphic result? In comparison of a new and a very old graphics Card, ok, but i can´t believe, that the graphic should be different with different "newer" graphics Cards...

We are able to do program a world like in the Picture above. You have to create a Terrain with a hill, then create water a Little bit under the top of the hill. Now, you have an Island :)
The only Thing, I wanna know is how to write such a shader program for "shaking trees"...