Currently i'm working on a tech demo and i needed a special postprocessing approach and I think it's worth to share with you.
http://www.mediafire.com/?199pj1q9qpbsr4p
The single effects can be chained simply by calling them in the desired order
taking this scene
you can apply bloom, depth of field and vignette effect by taking these lines of code
Code: Select all
// begin the scene
driver->beginScene(true, true, video::SColor(255,200,200,200));
// prepare scene for post processing
// (render to rtt 'auxOut')
// call prepare(true) if depth or normal information is used (for example by the depth of field effect)
postProcessManager->prepare(true);
// render the scene as usual
smgr->drawAll();
// now render the post process effect
postProcessManager->render(EPPE_ADAPTIVE_BLOOM);
postProcessManager->render(EPPE_DEPTH_OF_FIELD);
postProcessManager->render(EPPE_VIGNETTE);
// finalize post processing
// (render to the framebuffer)
postProcessManager->update();
// end the scene
driver->endScene();
I collected some pp effects in the forum and elsewhere in the depth of the internet (please refer to the fx shader files)
for now the following effects are implemented (hlsl and glsl):
Code: Select all
// available effects
//
// if you want to create a new effect
// 1) add another EPPE_* constant
// 2) define its behaviour in the effect.xml configuration file
// 3) define additional render target textures in the rtt.xml configuration file
// 4) put the used shader programs into the media/shaders/hlsl and media/shaders/glsl subfolders
enum E_POSTPROCESS_EFFECT
{
EPPE_NO_EFFECT = 0,
EPPE_INVERT,
EPPE_SEPIA,
EPPE_GRAY_SCALE,
EPPE_SIMPLE_BLOOM,
EPPE_ADAPTIVE_BLOOM,
EPPE_MOTION_BLUR,
EPPE_NIGHT_VISION,
EPPE_DREAM_VISION,
EPPE_POSTERIZE,
EPPE_SHARPEN,
EPPE_EMBOSSED,
EPPE_TILING,
EPPE_DISPLACEMENT,
EPPE_SCRATCHED,
EPPE_PENCIL,
EPPE_BLUR,
EPPE_WATER,
EPPE_COLOR,
EPPE_PULSING,
EPPE_SHAKE,
EPPE_DESATURATE,
EPPE_RADIAL_BLUR,
EPPE_DEPTH_OF_FIELD,
EPPE_VIGNETTE,
EPPE_COUNT // just for counting the elements
};
Currently only shader postprocesses are supported but you can easily integrate fixed function pipeline postprocessing by deriving from the base class IPostProcess:
Code: Select all
#ifndef _IPOSTPROCESS_H
#define _IPOSTPROCESS_H
#include <irrlicht.h>
using namespace irr;
class IPostProcess : virtual public IReferenceCounted
{
public:
// constructor
IPostProcess(const core::stringw& name)
{
// create screen quad vertices
Vertices[0] = video::S3DVertex(-1.f, -1.f, 0.f, 0.f, 0.f, 1.f, video::SColor(255,255,255,255), 0.f, 1.f);
Vertices[1] = video::S3DVertex(-1.f, 1.f, 0.f, 0.f, 0.f, 1.f, video::SColor(255,255,255,255), 0.f, 0.f);
Vertices[2] = video::S3DVertex( 1.f, 1.f, 0.f, 0.f, 0.f, 1.f, video::SColor(255,255,255,255), 1.f, 0.f);
Vertices[3] = video::S3DVertex( 1.f, -1.f, 0.f, 0.f, 0.f, 1.f, video::SColor(255,255,255,255), 1.f, 1.f);
// set indices
Indices[0] = 0;
Indices[1] = 1;
Indices[2] = 2;
Indices[3] = 2;
Indices[4] = 3;
Indices[5] = 0;
// set name of the postprocess
Name = name;
}
protected:
// screend quad mesh
video::S3DVertex Vertices[4];
u16 Indices[6];
// name of the postprocess
core::stringw Name;
// input and output target for the postprocess
core::stringw RenderTarget;
core::stringw RenderSource;
public:
// set the rendertarget
virtual void setRenderTarget(const core::stringw& renderTarget) { RenderTarget = renderTarget; }
// returns the rendertarget
virtual const core::stringw& getRenderTarget() { return RenderTarget; }
// sets the rendersource (texturelayer 0 of the postprocess material)
virtual void setRenderSource(const core::stringw& renderSource) { RenderSource = renderSource; }
// returns the rendersource
virtual const core::stringw& getRenderSource() { return RenderSource; }
// returns the name of the postprocess
virtual const core::stringw& getName() { return Name; }
// returns the SMaterial struct of the postprocess
virtual video::SMaterial& getMaterial() = 0;
// renders the postprocess
virtual void render() = 0;
};
#endif
Code: Select all
<!-- EPPE_NIGHT_VISION = 7 -->
<Effect id="7" name="Night Vision">
<ShaderPostProcess name="Nightvison" vsFile="vertex.fx" vsType="0" psFile="nightvision.fx" psType="4" psUseRandom="1" >
<PixelShaderConstant name="LuminanceThreshold" value="0.01" />
<PixelShaderConstant name="ColorAmplification" value="0.4" />
<PixelShaderConstant name="NoiseStrength" value="1.2" />
<PixelShaderConstant name="VisionColorR" value="0.1" />
<PixelShaderConstant name="VisionColorG" value="0.99" />
<PixelShaderConstant name="VisionColorB" value="0.1" />
<Texture index="0" textureClamp="1" />
<Texture index="1" path="media/textures/postprocess/noise1.png" />
<Texture index="2" path="media/textures/postprocess/scope.png" textureClamp="1" />
<RenderSource path="auxIn" />
<RenderTarget path="auxOut" />
</ShaderPostProcess>
</Effect>
Code: Select all
<!-- additional render target textures adaptive bloom-->
<RenderTarget id="rtt0" colorFormat="10" scale="0.5"/>
<RenderTarget id="rtt1" colorFormat="10" scale="0.5"/>
<RenderTarget id="rtt2" colorFormat="10" scale="0.25"/>
<RenderTarget id="rtt3" colorFormat="10" scale="0.25"/>
<RenderTarget id="rtt4" colorFormat="10" scale="0.125"/>
<RenderTarget id="rtt5" colorFormat="10" scale="0.125"/>
<RenderTarget id="rtt6" colorFormat="10" scale="0.0625"/>
<RenderTarget id="rtt7" colorFormat="10" scale="0.0625"/>
<RenderTarget id="rtt_lg0" colorFormat="4" width="256" height="256" />
<RenderTarget id="rtt_lg1" colorFormat="4" width="64" height="64" />
<RenderTarget id="rtt_lg2" colorFormat="4" width="16" height="16" />
<RenderTarget id="rtt_lg3" colorFormat="4" width="4" height="4" />
<RenderTarget id="rtt_lg4" colorFormat="4" width="1" height="1" />
<RenderTarget id="prevLum" colorFormat="4" width="1" height="1" />
<RenderTarget id="finalLum" colorFormat="4" width="1" height="1" />
and the full source code in the link provided above
In the sample switch through the three implemented modes by pressing 'm'
mode 0: no pp effect
mode 1: sample effect, switch effect by pressing 'p'
mode 2: effect chain (adaptive bloom, depth of field, vignette)
I hope you find it usefull...
EDIT:
forgot to mention: license is zlib!