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