Water
Posted: Thu Aug 01, 2013 11:54 am
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
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
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).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
Compiler options: Library Subsystem: openglBananenfreak wrote:How to set Subsystem to OpenGL? I don´t got it...
Code: Select all
CompilerIf Subsystem("opengl")
Debug "Subsystem OpenGL"
CompilerEndIf
Oh my!! Lovely! The water looks amazing.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.
Code: Select all
#PB_World_WaterSmooth