water effect by Acolyte Entertainment2nd Jan 2005 1:08
|
---|
Summary water effect using shader for realistic look Description `darkwater v1.0 Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `darkwater v1.0 `Start Date: 12-4-04 `Last Modified: 12-14-04 `color backdrop 0 `set ambient light 25 ` Set up the main camera set camera range 0,1,20000 position camera 0,0,0,0 point camera 0,0,0,100 set current camera 0 set current bitmap 0 sync set ambient light 75 `draw to front backdrop on sync ` load base and detail texture load image "color2.bmp", 1 load image "detail.tga", 2 make object terrain 1 ` create the terrain object set terrain heightmap 1, "dist3.bmp" ` set the heightmap set terrain scale 1, 5, 2.0, 5 ` set the scale set terrain split 1, 32 ` split value by 16 * 16 set terrain tiling 1, 4 ` detail map tiling set terrain light 1, 1, -0.25, 0, 1, 1, 0.78, 0.5 ` light - xdir, ydir, zdir, red, green, blue, intensity set terrain texture 1, 1, 2 ` base and detail texture build terrain 1 ` finally build the terrain set image colorkey 255,0,255 load object "skybox.x",100 `set object transparency 100,1 set object light 100, 0 set object texture 100, 3, 1 position object 100, 1000,0,1000 scale object 100, 8500, 8000, 8500 rem Setup main soft light set point light 0,400,0,600 position light 0,400,0,600 set light range 0,10000 `lower layer of clouds load object "cloudsky.x",2200 clone object 2201,2200 ghost object on 2201 set object collision off 2201 position object 2200,0,600,0 position object 2201,0,601,0 scale object 2200,150,150,150 scale object 2201,150,150,150 rotate object 2201,0,180,0 ghost object on 2200,1 set object collision off 2200 `skysphere of clouds load object "bsky.x",101 set object light 101,0 set object collision off 101 position object 101, 0, -1000, 0 scale object 101, 2000, 2000, 2000 `fx file to add cubemapped water with slight ripple load effect "darkwater.fx",2,1 #constant matInverse 4 r = make matrix4(matInverse) view matrix4 matInverse r = inverse matrix4(matInverse,matInverse) set effect constant matrix 2,"viewIT",matInverse set effect constant float 2,"refractStrength",0.10 `bumpHeight sets how much of the waves2.dds transposes through set effect constant float 2,"bumpHeight",0.10 set effect constant float 2,"fresnelBias",0.10 set effect constant float 2,"fresnelPower",4.0 set effect constant float 2,"hdrMultiplier",10.77 set effect constant float 2,"reflectionAmount",0.1 set effect constant float 2,"waterAmount",1.1 :`Value Between 0-1 0 = Lots of Water, 1 = Little water. Baiscally sets color set effect constant float 2,"waveAmp",0.02 :`sets the height of the surge for ocean effect set effect constant float 2,"waveFreq",0.108 : `Determines the frequency at which the sun glistens #constant deepColor 20 #constant shallowColor 21 `#constant reflectionColor 22 `#constant textureScale 23 #constant bumpSpeed 24 `Water Color null=make vector4(deepColor) set vector4 deepColor,0,0,0,0 set effect constant vector 2,"deepColor",deepColor null=make vector4(shallowColor) set vector4 shallowColor,0.2352941,0.2352941,0.2352941,0 set effect constant vector 2,"shallowColor",shallowColor `null=make vector4(reflectionColor) `set vector4 reflectionColor,.1,.1,.1,1 `set effect constant vector 2,"reflectionColor",reflectionColor `couldn't really get this to work right `null=make vector4(textureScale) `set vector4 textureScale,8.0,4.0,8.0,4.0 `set effect constant vector 2,"textureScale",textureScale `remend `this controlls how fast the ripples move null=make vector4(bumpSpeed) set vector4 bumpSpeed,-0.002,0.0,0,0 set effect constant vector 2,"bumpSpeed",bumpSpeed load object "ripple.x",7 `loop object 6 `set object speed 6, 5 scale object 7,1960,1000,1960 `set alpha mapping on 7,50 ghost object on 7 `set cube mapping on 7,5,6,3,4,2,1 `set reflection shading on 7 set object effect 7,2 set object cull 7,1 position object 7,1020,4 + get terrain ground height( 1, 1020, 1700 ),1700 `add a subsurface transparent plain to make the water look dark `ripple.x is a simple plain, with UVW map applied before export set image colorkey 1,0,1 load image "dark.jpg",20 load object "ripple.x",6 scale object 6,5960,5960,5960 texture object 6,20 set object transparency 6,1 set alpha mapping on 6,77 set object cull 6,1 position object 6,1020,0.5 + get terrain ground height( 1, 1020, 1700 ),1700 sync on sync rate 60 posxb = 1575 + rnd(75) wait 50 randomize timer() poszb = 1850 + rnd(250) ` get the height of the terrain at the current position posyb = get terrain ground height( 1, posxb, poszb ) wait 50 posx = 450 + rnd(150) wait 50 randomize timer() posz = 750 + rnd(300) ` get the height of the terrain at the current position posy = get terrain ground height( 1, posx, posz ) wait 50 randomize timer() random = rnd(80) rotation = random position camera 1086,posy+20,1763 yrotate camera random + 180 `code to explore the terrain sync on backdrop on autocam off hide all sprites hide mouse position camera camera position x(),camera position y(),camera position z() + 20 ` main program loop ` movement g_fSpeed# = 2 g_fTurn# = 0.5 do if spacekey() = 1 set current camera 5 endif scroll object texture 101,0.00002,0.00002 ` handle user input and show some stats gosub userInput gosub information ` get the height of the terrain at the current camera position a# = get terrain ground height( 1, camera position x( ), camera position z( ) ) ` now position the camera slightly above the terrain position camera camera position x( ), a# + 13, camera position z() ` let the terrain handle some internal work update terrain ` final screen update sync loop userInput: ` simple mouse and keyboard movement ` move around with arrow keys control camera using arrowkeys 0, g_fSpeed#, g_fTurn# ` store old camera angle OldCamAngleY# = CameraAngleY# OldCamAngleX# = CameraAngleX# ` store new camera angle CameraAngleY# = wrapvalue ( CameraAngleY# + mousemovex ( ) * 0.4 ) CameraAngleX# = wrapvalue ( CameraAngleX# + mousemovey ( ) * 0.4 ) ` rotate camera yrotate camera curveangle ( CameraAngleY#, OldCamAngleY#, 24 ) xrotate camera curveangle ( CameraAngleX#, OldCamAngleX#, 24 ) ` speed up movement if inkey$ ( ) = "+" if g_fSpeed# < 1000 g_fSpeed# = g_fSpeed# + 0.01 endif endif ` slow down movement if inkey$ ( ) = "-" if g_fSpeed# > 0.002 g_fSpeed# = g_fSpeed# - 0.001 endif endif return information: ` show some information if hit > 1 then print " hit = " + str$(hit) ` start printing at top of screen set cursor 0, 0 ` show frame rate print "fps = " + str$ ( screen fps ( ) ) print "" ` current camera position print "" print "x = " + str$ ( camera position x ( ) ) print "y = " + str$ ( camera position y ( ) ) print "z = " + str$ ( camera position z ( ) ) print "" ` finally the polygon count print "polygon count = " + str$ ( statistic ( 1 ) ) print "" return |