looking for a water effect

Blitz3D Forums/Blitz3D Programming/looking for a water effect

Pinete(Posted 2004) [#1]
Hi All,
Please someone could tell me where I can find a good
water effect for a huge extension of water (sea)??

Thanks in advance!


jfk EO-11110(Posted 2004) [#2]
water effect sounds a bit vague. Maybe try robs cubic enviroment maping demo. It has some water with enviroment reflection. Just search for "redflame" :)


bradford6(Posted 2004) [#3]
Graphics3D 1024,768
cam = CreateCamera()
light = CreateLight()
MoveEntity cam,0,45,-15
TurnEntity cam,15,0,0
;WireFrame enable

Global WATER_GRID_SIZE = 32
Global WATER_HEIGHT# = 16
Dim WaterY(WATER_GRID_SIZE+1,WATER_GRID_SIZE+1)
Global wz,wx
Global hite#
Global waterlevel#
Global waterangle#
Global water
Global watert
Global curdetail


		For q = 0 To WATER_GRID_SIZE
							For j = 0 To WATER_GRID_SIZE
									WaterY(q,j) = Rnd(0,360)
								Next 
							Next
					; Create some terrain and load the water texture onto it
					water = CreateTerrain(WATER_GRID_SIZE)
					;watert = LoadTexture("wswirl.jpg")
					watert = CreateTexture(256,256)
					
					SetBuffer TextureBuffer(watert)
						Color  0,0,255 
						Rect 0,0,256,256
						Color 255,255,255
						For i = 1 To 75
							circle = Rnd(2,25)
							Oval Rnd(0,225),Rnd(0,225),circle,circle,0
						Next
					;waterg = LoadTexture("wswirl.jpg")
					waterg = CreateTexture(256,256)

						SetBuffer TextureBuffer(waterg)
						Color  0,200,0 
						Rect 0,0,256,256
						
						For i = 1 To 10000
						    Color 0,Rnd(5,135),0
							Plot Rnd(0,255),Rnd(0,255)
							;Oval Rnd(0,225),Rnd(0,225),circle,circle,0
							
						
						Next
					SetBuffer BackBuffer()
					TextureBlend watert,3
					ScaleTexture watert,.2,.2
					ScaleTexture waterg,.5,.5

					EntityTexture water,watert,0,1
					EntityTexture water,waterg,0,0
					EntityAlpha water,.9
					
					; Resize and position the water
					PositionEntity water,-1000,8,-1000
					;MoveEntity water,0,5,0
					ScaleEntity water,WATER_GRID_SIZE*4,WATER_HEIGHT#,WATER_GRID_SIZE*4
					
					; Modify the detail of the terrain
					TerrainShading water,False
					curdetail = 500
					TerrainDetail water,curdetail,False


Repeat
water_wave()

	
	RenderWorld
	Flip
	

Until KeyHit(1) = 1


Function water_wave()
; Here we itterate through all the cells on the terrain grid (switch wireframe on to
	; see them) and then make them simply bounce up and down.
	For wz = 0 To WATER_GRID_SIZE-1
		For wx = 0 To WATER_GRID_SIZE-1
			hite# = Sin(WaterY(wz,wx))
			ModifyTerrain water,wx,wz,(hite#/4)+.5,False
			WaterY(wz,wx) = WaterY(wz,wx) + 2
			If watery(wz,wx)>3439 Then watery(wz,wx) = 1
		Next
	Next
	
waterangle# = waterangle# +.2
If waterangle#>360 Then waterangle#=.2
RotateTexture watert,Sin(waterangle#)
 ;;RotateTexture cloudmask,waterangle#
End Function




Pinete(Posted 2004) [#4]
god bless to you!
I will try to implement waves and will make
different trials with the extures..
I'll keep you informed!

Thanks a lot!!!!


AbbaRue(Posted 2004) [#5]
Wow bradford6:
That is quite awsome, and simple too.
Thanks. Good source for the Archives.


bradford6(Posted 2004) [#6]
most of the interesting code was from another source. Rob H maybe? it was a long time ago...


bradford6(Posted 2004) [#7]
This one is a little more interesting.

use WASD to 'fly'

[SPACEBAR] toggles wireframe

Graphics3D 1024,768
Global campiv = CreatePivot()			; camera pivot entity
Global camera = CreateCamera(campiv)	; camera (campiv is the parent)
Global light = CreateLight(2)
MoveEntity light,-40,20,-40

PositionEntity campiv,0,30,0
RotateEntity camera,15,0,0
CameraClsColor camera,230,230,255

cube = CreateCube()
EntityColor cube,20,20,20
ScaleEntity cube,15,25,15

Global midw = GraphicsWidth()/2  	; 	 middle of
Global midh = GraphicsHeight()/2 	;  the screen
	HidePointer 						; hide the mouse pointer
	WireFrame False						; don't do wireframe


Global WATER_GRID_SIZE = 32
Global sizer = 3
Global WATER_HEIGHT# = 16
Dim WaterY(WATER_GRID_SIZE+1,WATER_GRID_SIZE+1)
Global wz,wx
Global hite#
Global waterlevel#
Global waterangle#
Global water
Global watert
Global curdetail
	

Const ENTS = 50							; TOTAL NUMBER OF TOKAMAKPHYSICS Rigid Bodies
Const ANIMS = 10						; TOTAL NUMBER OF TOKAMAKPHYSICS Animated bodies

Const FPS=50							
Const w=17, s=31, a=30, d=32, space=57	; movement keys
shot_delay = 120						; delay between shots
Global pickmarker = CreateSphere(4)		; visual for campick
EntityAlpha pickmarker,.75				; slightly transparent
Global pictentity,pnx#,pny#,pnz#,pcx#,pcy#,pcz#	; pick stuff (pick normals and pick coordinates)
Global latspeed#,speed#,MX#,MY#			; camera speed



		For q = 0 To WATER_GRID_SIZE
							For j = 0 To WATER_GRID_SIZE
									WaterY(q,j) = Rnd(0,360)
								Next 
							Next
					; Create some terrain and load the water texture onto it
					water = CreateTerrain(WATER_GRID_SIZE)
					;watert = LoadTexture("wswirl.jpg")
					watert = CreateTexture(256,256)
					
					SetBuffer TextureBuffer(watert)
						Color  0,0,255 
						Rect 0,0,256,256
						Color 255,255,255
						For i = 1 To 75
							circle = Rnd(2,25)
							Oval Rnd(0,225),Rnd(0,225),circle,circle,0
						Next
					;waterg = LoadTexture("wswirl.jpg")
					waterg = CreateTexture(256,256)

						SetBuffer TextureBuffer(waterg)
						Color  0,200,0 
						Rect 0,0,256,256
						
						For i = 1 To 10000
						    Color 0,Rnd(5,135),0
							Plot Rnd(0,255),Rnd(0,255)
							;Oval Rnd(0,225),Rnd(0,225),circle,circle,0
							
						
						Next
					SetBuffer BackBuffer()
					TextureBlend watert,3
					ScaleTexture watert,.2,.2
					ScaleTexture waterg,.5,.5

					EntityTexture water,watert,0,1
					EntityTexture water,waterg,0,0
					EntityAlpha water,.9
					
					; Resize and position the water
					PositionEntity water,-1000,8,-1000
					;MoveEntity water,0,5,0
					ScaleEntity water,WATER_GRID_SIZE*sizer,WATER_HEIGHT#,WATER_GRID_SIZE*sizer
					
					; Modify the detail of the terrain
					TerrainShading water,False
					curdetail = 500
					TerrainDetail water,curdetail,False

; #################################################################
Repeat

	water_wave()
	
If KeyHit( 57 )=True Then enable=1-enable 
WireFrame enable
move_camera()

	
	RenderWorld
			Color 255,0,0
			Rect midw-4,midh-4,8,8,0

	Flip
	

Until KeyHit(1) = 1
ShowPointer 


Function water_wave()
; Here we itterate through all the cells on the terrain grid (switch wireframe on to
	; see them) and then make them simply bounce up and down.
	For wz = 0 To WATER_GRID_SIZE-1
		For wx = 0 To WATER_GRID_SIZE-1
			hite# = Sin(WaterY(wz,wx))
			ModifyTerrain water,wx,wz,(hite#/4)+.5,False
			WaterY(wz,wx) = WaterY(wz,wx) + 2
			If watery(wz,wx)>3439 Then watery(wz,wx) = 1
		Next
	Next
	
waterangle# = waterangle# +.2
If waterangle#>360 Then waterangle#=.2
RotateTexture watert,Sin(waterangle#)
 ;;RotateTexture cloudmask,waterangle#
End Function

Function curvevalue#(newvalue#,oldvalue#,increments# )
	If increments>1 Then oldvalue#=oldvalue#-(oldvalue#-newvalue#)/increments
	If increments<=1 Then oldvalue=newvalue
	Return oldvalue#
End Function
;==================================================================================
Function move_camera()
	; Movement controls
	If KeyDown(w)=1 Then speed# = speed#+.03
	If KeyDown(a)=1 Then latspeed# = latspeed# - .02
	If KeyDown(s)=1 Then speed# = speed# -.03
	If KeyDown(d)=1 Then latspeed# = latspeed# + .02

latspeed#=latspeed#*.98
speed#=speed#*.98

MY#=curvevalue#(MouseYSpeed(),MY#,3 )
MX#=curvevalue#(MouseXSpeed(),MX#,3 )
TurnEntity campiv,MY#,-MX#,0 ; turn camera up and down
;TurnEntity campiv,0,-MX#,0 ;  turn nnn left --right
RotateEntity campiv,EntityPitch(campiv),EntityYaw(campiv),0
If EntityPitch(campiv)>88 Then RotateEntity campiv,88,EntityYaw(campiv),EntityRoll(campiv)
If EntityPitch(campiv)<-88 Then RotateEntity campiv,-88,EntityYaw(campiv),EntityRoll(campiv)

MoveMouse 100,100

MoveEntity campiv,latspeed#,0,speed#
	


End Function






semar(Posted 2004) [#8]
@Bill,
very nice, expecially the first one. I like how the water moves - sometime I experience some unreal stutter, but I think it's due to sin and cos approx ?

Anyway, nice effects. Do you know also an effect for under water diving ? I think it can be easily achieved with cameracolor command, or put a big blue-ish sprite in front of the camera... how would you do that ?

Sergio.


Genexi2(Posted 2004) [#9]
Hmm....your example uses Blitz terrains though Brad, wouldnt using a mesh be faster instead?
(also for the sake of compatibility of some Radeon card drivers which dislike Blitz terrains)


jfk EO-11110(Posted 2004) [#10]
I think those Radeon Cards need a driver update. At least this fixed my terrain issues on a 9200se. It seems like it was a true bug in some radeon drivers. So it wasn't Blitz's fault at all.

Using a terrain for water is a good idea IMHO cause you can lower the level of details a lot and it won't suck when the terrain pops in and out. So the LOF can be used pretty consequently.


bradford6(Posted 2004) [#11]
BLitz uses ROAM for it's LOD calculations. If you want a slightly faster sim on a smaller scale VERTEXCOORDS will do fine.