I've managed to get the fresnal water shader and the bloom shader working perfectly together. Heres are screenshot:
Heres the code I've put together for this:
Rem Project: Water + Bloom
Rem Created: 09/12/2006 13:40:29
Rem ***** Main Source File *****
`Bloom effect variables
Global bloom_cam1 as integer
Global bloom_cam2 as integer
Global bloom_cam3 as integer
Global bloom_obj1 as integer
Global bloom_obj2 as integer
Global bloom_obj3 as integer
Global bloom_img1 as integer
Global bloom_img2 as integer
Global bloom_img3 as integer
Global Effect1 as integer
Global Effect2 as integer
Global Effect3 as integer
Global dis# as float
Global sh# as float
Global sw# as float
Global fov as integer
`Water Variables
global WaterObj as integer
global WaterHeight# as float
global water_fx as integer
global water_img1 as integer
global water_img2 as integer
global water_img3 as integer
global water_img4 as integer
Set Display Mode 1024,768,32
Sync On : Sync Rate 0
Autocam Off : Color Backdrop 0
Position Camera -100,90,-100
Rotate Camera 45,45,0
Load Object "Objects/test.dbo",1
Position Object 1,0,0,0
Load Object "Objectsplanet.dbo",2
Backdrop Off
Position Object 2,0,0,0
Scale Object 2,100*5,100*5,100*5
MakeWater(3,5,131069,512,-6.0,200,200)
Setup_Bloom(1,0.205,0.015)
Do
Text 0,0,"FPS: "+STR$(SCREEN FPS())
Text 0,20,"Polygons: "+STR$(Statistic(1))
`Rotate Sky
YRotate Object 2,WrapValue(Object Angle Y(2)+0.01)
`Camera Controls
Rotate Camera WrapValue(Camera Angle X(0)+MouseMoveY()),WrapValue(Camera Angle Y(0)+MouseMoveX()),0
If Upkey() then Move Camera 0,1
If Downkey() then Move Camera 0,-1
if Leftkey() then Position Camera Camera Position X(0)-1,Camera Position Y(0), Camera Position Z(0)
if Rightkey() then Position Camera Camera Position X(0)+1,Camera Position Y(0), Camera Position Z(0)
UpDateWater()
Update_Bloom()
Sync
Loop
Function Setup_Bloom(cam_1st as integer,B_brightness# as float,B_blurwidth# as float)
brightness# = B_brightness#
blurWidth# = B_blurwidth#
bloom_cam1 = cam_1st
bloom_cam2 = cam_1st+1
bloom_cam3 = cam_1st+2
effect1 = 1
effect2 = 2
effect3 = 3
fov = 70
sw# = screen width()
sh# = screen height()
dis# = (sh#/2)/tan(fov/2)
`set up main cams
set camera range 0.5,100000
set camera fov fov
make camera bloom_cam1
bloom_img1 = 10
set camera to image bloom_cam1,bloom_img1,256,256
set camera range bloom_cam1,3,100000
set camera fov bloom_cam1,fov
`Backdrop Off
`Render target for tone mapping
bloom_obj1 = 10
make object plain bloom_obj1,sw#/100,sh#/100
load effect "Shaders/Bloom.fx",effect1,0
texture object bloom_obj1,0,bloom_img1
set object effect bloom_obj1,effect1
position object bloom_obj1,0,-10000,dis#/100
`Backdrop Off bloom_cam1
`Render target for blur a
bloom_img2 = 11
make camera bloom_cam2
set camera to image bloom_cam2,bloom_img2,256,256
set camera range bloom_cam2,1,100
set camera fov bloom_cam2,fov
position camera bloom_cam2,0,-10000,0
bloom_obj2 = 11
make object plain bloom_obj2,sw#/100,sh#/100
load effect "Shaders/Bloom.fx",effect2,0
texture object bloom_obj2,bloom_img2
set object effect bloom_obj2,effect2
position object bloom_obj2,500,-10000,dis#/100
`Backdrop Off bloom_cam2
`Screen object
bloom_img3 = 12
make camera bloom_cam3
set camera to image bloom_cam3,bloom_img3,256,256
set camera range bloom_cam3,1,100
set camera fov bloom_cam3,fov
position camera bloom_cam3,500,-10000,0
bloom_obj3 = 12
make object plain bloom_obj3,-sw#/(400),sh#/(400)
load effect "Shaders/Bloom.fx",effect3,0
texture object bloom_obj3,0,bloom_img3
set object effect bloom_obj3,effect3
ghost object on bloom_obj3
`Set effect data
set effect technique effect1,"Tone"
set effect technique effect2,"blurpassX"
set effect technique effect3,"blurpassY"
set effect constant float effect2,"Brightness",brightness#
set effect constant float effect2,"blurWidth",blurWidth#
set effect constant float effect3,"Brightness",brightness#
set effect constant float effect3,"blurWidth",blurWidth#
Endfunction
Function Update_Bloom()
`Update bloom camera
`set camera fov 70
position camera bloom_cam1,camera position x(),camera position y(),camera position z()
rotate camera bloom_cam1,camera angle x(),camera angle y(),camera angle z()
`Update screen object
dis#=(sh#/2)/tan(fov/2)
position object bloom_obj3,camera position x(),camera position y(),camera position z()
rotate object bloom_obj3,camera angle x(),camera angle y(),camera angle z()
move object bloom_obj3,dis#/400
move object up bloom_obj3,0.01
move object left bloom_obj3,0.01
scale object bloom_obj3,101,101,0
Sync Mask 0x0000FFF
Endfunction
function MakeWater(Obj,Shader,Img,ImgSize,Height#,sizex as integer,sizez as integer)
WaterObj = Obj
WaterHeight# = Height#
water_fx = Shader
`Setup Cameras
Sw#=screen width():Sh#=screen height()
water_img1 = img
water_img2 = img+1
water_img3 = img+2
water_img4 = img+3
make camera 4
set camera range 4,1,15000
set camera aspect 4,Sw#/Sh#
backdrop off 4
set camera to image 4,water_img1,ImgSize,ImgSize
set camera fov 4,65
make camera 5
set camera range 5,1,15000
set camera aspect 5,Sw#/Sh#
backdrop off 5
set camera to image 5,water_img2,ImgSize,ImgSize
set camera fov 5,65
`Make Water plain
load image "Textures/Waves.dds",water_img3
load image "Textures/Fresnel.bmp",water_img4
If sizex > sizez
make object plain WaterObj,sizex,sizex
Else
make object plain WaterObj,sizez,sizez
Endif
texture object WaterObj,0,water_img1
texture object WaterObj,1,water_img2
texture object WaterObj,2,water_img3
texture object WaterObj,3,water_img4
xrotate object WaterObj,270
`Ghost Object On WaterObj,4
load effect "Shaders/Water.fx",water_fx,0
set object effect WaterObj,water_fx
Scale Object Texture WaterObj,0.46,0.46
endfunction
function UpDateWater()
`UpDate Water plain
position object WaterObj,object position x(WaterObj),WaterHeight#,object position z(WaterObj)
Hide object WaterObj
Hide Object bloom_obj3
`Upade Refract/Reflect cameras
set effect technique water_fx,"Refract"
UpDateRefraction()
if camera position y()>WaterHeight#
set effect technique water_fx,"ReflectRefract"
UpDateReflection()
endif
`Show Water
show object WaterObj
show object bloom_obj3
sync mask 0x00000001
endfunction
function UpDateRefraction()
position camera 4,camera position x(),camera position y(),camera position z()
rotate camera 4,camera angle x(),camera angle y(),camera angle z()
set camera clip 5,0,0,0,0,0,0,0
sync mask 0x0000001E
fastsync
fog off
endfunction
function UpDateReflection()
position camera 5,camera position x(),WaterHeight#-(camera position y()-WaterHeight#),camera position z()
rotate camera 5,-camera angle x(),camera angle y(),camera angle z()
set camera clip 5,1,0,WaterHeight#-5,0,0,1,0
sync mask 0x0000002E
fastsync
endfunction
I've attached the source files, media and the compiled EXE so you can take a look for yourselves.
The only problems I get is with the fresnal water shader. When I set the SYNC RATE to anything other than 0 it seems to kill the framerate. when I set it to zero, i seem to get around 215 frames, but when I set the sync rate to 60 (for example), it seems to drop down to 14 frames per second. Any ideas?
Anyway, I hope this code sort of helps a few people.
EDIT:
Forgot to mention the controls:
- Arrow keys to move camera
- Move mouse to rotate camera