BLOOM Effect Example
Hey All, just wanted to let you know that I am still working on porting the Deferred Shading library, had to spend my time on some other stuff for the past couple of weeks, but its still on the project list and mostly working, just ironing out some bugs with the masking and making sure that all the arrays are working properly.
Anyway, I remembered awhile bak someone was asking for an example of using Bloom, well I tracked a nice easy one DBPro one down, its part of the DarkSource examples, well, it was originally...
As usual, attachment contains the Source .cpp file, a compiled working EXE(GDK7.3) and it also contains the 3 .FX files to make bloom work, there is no other media, its all render targets
Here is a screeny, it shows just how simple the technique is :
Have Fun... I'll post some more as soon as I get the time to finish them off.. might be a little while though, man's gotta eat, and so does my 10yr old daughter lol Little busy with work atm is what I mean
EDIT : forgot the archive, sorry, here it is lol
Here is an alternative version of the code that demonstrates how to use OBJECT MASKING WITH SHADERS ... I basically replaced all of the show/hide object commands by masking the objects correctly.... doing it this way makes it ALOT easier to setup large shader scenes...
/////////////////////////////////////////////////////////////////////////////
// EVERYBODYLIKESBLOOM Example - Originally a DBPro snippet in DarkSource //
// //
// Ported to DarkGDK as a Shader Usage Example by Paul A Wilson 2009 //
/////////////////////////////////////////////////////////////////////////////
#include "DarkGDK.h"
// prototypes
void makecamera(int camid, int isquad, char* name, int w, int h, char* shader, int reverse);
void makeobject(int objid, char* name, int x, int y, int z, int w, int h, int d);
bool SetObjectMask(int ObjID, DWORD dwMask);
void DarkGDK ( void )
{
// local variables
int camid = 0;
int camfrom1 = 0;
float sw = 1024;
float sh = 768;
float verylosw = sw/4;
float verylosh = sh/4;
// setup display
dbSetDisplayMode(sw, sh, 32);
dbSetWindowPosition(0, 0);
dbSetWindowTitle(" -- DarkGDK FullScreen BLOOM Shader Example -- Ported from DBPro by Mista Wilson 2009 ");
// Setup render target cameras
camid = 0; makecamera(camid, 1, "backbuffer", sw, sh, "finalrender.fx", 0);
camid = 1; makecamera(camid, 0, "3d main scene", sw, sh, "", 0);
camid = 2; makecamera(camid, 1, "2d tone texture", verylosw, verylosh, "tone.fx", 0);
camid = 3; makecamera(camid, 1, "2d blur texture", verylosw, verylosh, "blur.fx", 0);
//Make sphere to test
int objid = 101; makeobject(objid, "sphere", 0, 0, 0, 50, 50, 50); // actually making a sphere lol
SetObjectMask(101, 1<<1);
//Apply render targets textures to quad objects
camid = 2; camfrom1 = 1; dbTextureObject(10 + camid, 0, camfrom1);
SetObjectMask(10 + camid, 1 << camid);
camid = 3; camfrom1 = 2; dbTextureObject(10 + camid, 0, camfrom1);
SetObjectMask(10 + camid, 1 << camid);
camid = 0; camfrom1 = 1; dbTextureObject(10 + camid, 0, camfrom1);
SetObjectMask(10 + camid, 1 << camid);
camid = 0; camfrom1 = 3; dbTextureObject(10 + camid, 1, camfrom1);
SetObjectMask(10 + camid, 1 << camid);
//Setup Lights and Main Render Camera
dbSyncOn();
dbSyncRate(0);
dbMakeLight(1);
dbSetPointLight(1, -100, -50, -75);
dbColorLight(1, dbRGB(64, 32, 0));
dbMakeLight(2);
dbSetPointLight(2, 100, -50, -75);
dbColorLight(2, dbRGB(0, 64, 0));
dbSetPointLight(0, 50, 200, -100);
dbPositionCamera(1, 0, 50, -100);
dbPointCamera(1, 0, 0, 0);
while ( LoopGDK ( ) )
{
//Render Main 3D scene
camid = 1;
dbSyncMask(1 << camid); // render only camera 1
dbRotateObject(101, dbObjectAngleX(101) + 0.2, dbObjectAngleY(101) + 1, 0);
// NOTE OBJECT 101 IS NOT BEING SHOWN AND HIDDEN HERE, ITS MASKING IS DOING IT FOR US
dbFastSync(); // render
//Tone Render
camid = 2;
dbSyncMask(1 << camid); // render only camera 2
dbFastSync();
//Actual "Bloom" Render
camid = 3;
dbSyncMask(1 << camid); // render only camera 3
dbFastSync();
//Final Render
camid = 0;
dbSyncMask(1 << camid); // render only camera 0
// here we make a call to update the contents of the screen
dbSync();
}
// and now everything is ready to return back to Windows
return;
}
// this function will make a camera, set it to be a render target on an image and make a quad
// object to texture with the image, and apply the effect to it... prety simple stuff really
void makecamera(int camid, int isquad, char* name, int w, int h, char* shader, int reverse)
{
if(camid > 0)
{
dbMakeCamera(camid);
dbSetCameraToImage(camid, camid, w, h);
}
else
{
dbBackdropOff(0);
}
if(isquad == 1)
{
dbMakeObjectPlain(10 + camid, 2, 2);
dbLoadEffect(shader, 10 + camid, 0);
dbSetObjectEffect(10 + camid, 10 + camid);
}
}
// this function just makes an object using the dimensions supplied, and then
// positions it at the x y z co-ords supplied.
// Note: This object is being scaled a little out of proportion to look like an egg
// to highlight the bloom a little better than a sphere would.
void makeobject(int objid, char* name, int x, int y, int z, int w, int h, int d)
{
dbMakeObjectSphere(objid, w, h, d);
dbScaleObject(objid, 200, 140, 100);
dbPositionObject(objid, x, y, z);
}
// object masking function - mask value is the camera/cameras that this object will show too.
bool SetObjectMask(int ObjID, DWORD dwMask)
{
if(::dbObjectExist(ObjID))
{
sObject* pObject = ::dbGetObject(ObjID);
pObject->dwCameraMaskBits = dwMask;
pObject = NULL;
return true;
}
return false;
};
If it ain't broke.... DONT FIX IT !!!