A simple, robust and extendible postprocessing class

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
DavidJE13
Posts: 165
Joined: Tue Jan 09, 2007 7:17 pm

Post by DavidJE13 »

nice effect! the glowing eyes are a little creepy though :D
remember to change that first render call to a preRender() to make it safer.
Your effect is fairly efficient, although you could probably get away with PP_BLUR instead of bloom, i.e.

Code: Select all

CEffectPostProc* ppBloom = new CEffectPostProc( ppRenderer, dimension2di( 1024, 512 ),PP_BLUR,0.005f);
(it's a little less glowy, but simplifies the effect somewhat)


I made an example for depth of field. It uses PP_BLURDOF (maybe I should give it a better name?), and you need to remember to use special shaders on all your objects (shaders which set the alpha channel to the z-position * a constant). These can either be your own, or one of the basic ones I made;

setup code:

Code: Select all

	u32 matid;
	IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices( );
	switch( driver->getDriverType( ) ) {
		case EDT_OPENGL:
			matid = gpu->addHighLevelShaderMaterial( GL_V_MAT, "main", EVST_VS_1_1, GL_PLAIN, "main", EPST_PS_1_1, new CTexturesShaderCallback( ), EMT_SOLID, 1 );
			break;
		case EDT_DIRECT3D8:
		case EDT_DIRECT3D9:
		default:
			matid = gpu->addHighLevelShaderMaterial( DX_V_MAT, "main", EVST_VS_1_1, DX_PLAIN, "main", EPST_PS_1_1, NULL, EMT_SOLID, 0 );
	}
then for each object,

Code: Select all

myNode->setMaterialType( (E_MATERIAL_TYPE) matid );
I'd like this to be more compact, but for now it's the only way. This setup will let you use the objects with PP_BLURDOF (etc), PP_DEPTH and PP_OCCLUSION
sp00n
Posts: 114
Joined: Wed Sep 13, 2006 9:39 am

Post by sp00n »

More better and better :)))
It looks awesome.
One more shader you can include to -- lens flare :)
Good luck

p.s. you wrote at the first post - heat haze included now, will try ;)

Edit:

1) at the sources isn't defined recti that is rect<s32>
2) how can i change the speed of the haze effect?
3) how can i set a new texture for the haze? (i mean - second texture, it needs me to use for camera and other dynamic features for example :) )
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

I'm compiling this on my project with no luck. It was compiled and builded with warnings:

Code: Select all

In member function `virtual void CSplitPostProc::renderEffect(irr::video::ITexture*)': 

[Warning] passing `irr::f32' for converting 1 of `irr::core::rect<T>::rect(T, T, T, T) [with T = irr::s32]' 

[Warning] passing `irr::f32' for converting 2 of `irr::core::rect<T>::rect(T, T, T, T) [with T = irr::s32]' 

[Warning] passing `irr::f32' for converting 3 of `irr::core::rect<T>::rect(T, T, T, T) [with T = irr::s32]' 

[Warning] passing `irr::f32' for converting 4 of `irr::core::rect<T>::rect(T, T, T, T) [with T = irr::s32]' 
Changed all recti to rect<s32>.

I have black stripes on screen. Tried preRender() but black screen appeared.
DavidJE13
Posts: 165
Joined: Tue Jan 09, 2007 7:17 pm

Post by DavidJE13 »

oops, made the same mistake again then (using recti instead of rect<s32>).. it's a habit I need to get out of I guess. fixed :)

m_krzywy:
Can you be more specific? does the example run ok?
Things which come to mind:
* Are you still calling smgr->drawAll() ? this line should be removed when using PostProc (beginScene & endScene are still needed)
* Maybe you're not clearing the ZBuffer when you need to.
preRender should only be called if render(NULL) will be called later

sp00n:
thanks :)
the haze effect's speed can't be changed (oops missed that out - I'll add a speed multiplier option as the 3rd parameter and update in a min) and it's currently framerate-dependent, which I seriously need to fix. When making it the speed wasn't so important to me

set a second texture with:
ppMyPP->setInput(1,ppMyOtherPP);
this can be another renderer to show a different scene, and you can use preRender as discussed above to make it show the view from a different camera, etc.
however, if you want to use an actual texture as the input, this doesn't support it... yet. I'll add the feature and update in a min.

lens flare? sure I'll give it a go :D
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

Main Loop

Code: Select all

while(device->run())
	{
		if(oldFps != driver->getFPS())
		{
			stringw windowCaption = L"Krzywy's demo 01 ( FPS: ";
			windowCaption += driver->getFPS();
			windowCaption += " )";
			device->setWindowCaption(windowCaption.c_str());
			oldFps = driver->getFPS();
		}
        rot-= 0.01f;

        clouds->setRotation(vector3df(0,rot,0));
        
		driver->beginScene( false, false );
		ppBloom->render(NULL);
       
        driver->endScene();
        
        if (camera->getPosition().Y < -300.0f)
            camera->setPosition(core::vector3df(1000,500,1000));

	}


	device->drop();
main:

Code: Select all

int main(int argc, char *argv[])
{
    
    
    //driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
    kamera();
    terrain();
    skybox();
    chmurki();
    
       IPostProc* ppRenderer = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor(255,100,101,140) );
   CEffectPostProc* ppBloom = new CEffectPostProc( ppRenderer, dimension2di( 1024, 512 ), PP_BLOOM /* Parameters here if needed */ );
I am loading irr scene node in terrain(), skydome in skybox(), chmurki is CCloudSceneNode.

Tried only with terrain. Same problem, black stripes flickering. Using Irrlicht 1.5
DavidJE13
Posts: 165
Joined: Tue Jan 09, 2007 7:17 pm

Post by DavidJE13 »

Sorry for the delay - the new version's up. (had some trouble with allowing textures)
It has the changes mentioned above, namely:
* recti is now rect<s32>
* Haze now has time and scale multipliers
* Haze is no longer framerate-dependent, but I'm not entirely happy with the solution - you need to call ppMyPP->setTimer( device->getTimer( ) ); - but you only need to do this for 1 node, it will spread the timer across all nodes itself.
* setInput can now take an ITexture as well as an IPostProc, but the constructor must still have an IPostProc. If you need the first input to be a texture, change it after creation.

m_krzwyw:
Looks ok to me, I'll see if I can find the bug - it's likely in my code.
DavidJE13
Posts: 165
Joined: Tue Jan 09, 2007 7:17 pm

Post by DavidJE13 »

just updated it with a small change to possibly fix m_krzywy's problem;

I removed beginScene and endScene from the CRendererPostProc class, which might fix your problem, m_krzywy.
(I'm not sure if those are needed here, I guess not but I don't really understand them)

can't remember changing anything else, but there's possibly some bug fixing in there too.
sp00n
Posts: 114
Joined: Wed Sep 13, 2006 9:39 am

Post by sp00n »

Big thanks, David.
I'll try a new version, when'll have some time :)
But i have one question more: why are we use a shaders from the .h file? Would be better use it from .glsl files or similar? Because if we wan to use it in future we need to recompil this "postprocess" part of the imaginary engine/renderer if we need to change any shader, i think easy would be if we'll use it independent of the main render part compiling, isn't? :)
And again - big thanks.
p.s. may be i'll teach some HLSL and add a DX shaders too to your project :) But it will not quick, because time lack, may be anybody else?

Good luck
DavidJE13
Posts: 165
Joined: Tue Jan 09, 2007 7:17 pm

Post by DavidJE13 »

shaders are in the .h file mainly for convenience (1 file instead of about 40-odd, and no dependence on external files. edit: ah, of course I was forgetting about entryPoint, which would let all the shaders fit in 2 files...) but you raise a good point. Custom shaders can go wherever you like (well, actually they can't because .glsl file support is yet another feature I forgot to wrap! adding it now!)

DirectX shaders would be very much appreciated :)
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

Not using it yet, planning on using it soon however and even if I don't, lots of good karma for some awesome work!
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

DavidJE13 wrote:just updated it with a small change to possibly fix m_krzywy's problem;

I removed beginScene and endScene from the CRendererPostProc class, which might fix your problem, m_krzywy.
(I'm not sure if those are needed here, I guess not but I don't really understand them)

can't remember changing anything else, but there's possibly some bug fixing in there too.
Thank you so much. It's working perfectly! <3
Problem solved. Waiting for future releases.
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

i'm using a crappy computer here which doesnt support shader. anyone mind to show some screenshots/videos about the effects? i'm very curious about it. thanks.
DavidJE13
Posts: 165
Joined: Tue Jan 09, 2007 7:17 pm

Post by DavidJE13 »

sure, here's some screenshots. Can't do videos (haven't been able to work that out yet :oops:) so I can't really show you haze.

Most effects are pretty simple, here are some of the more interesting ones:

Depth of field (currently has poor blurring around edges of near objects)
Image

Depth (not a complicated one, but I just like how this one makes things look :))
Image

One scene rendered twice with different textures, then one output blurred and overlayed on the other (from freetimecoder, but I used a more boring texture)
Image

Occlusion, on a white texture (no lights) and exaggerated 10x. The "wood" effect can be fixed (it was fixed in the example I used, I removed that for speed) but I've found it's near-invisible when used properly.
Image

Old Monitor (not for actual use)
Image

that's all the noteworthy ones. All the others look exactly as you would expect!

m_krzywy: great! glad it's sorted now.
dorth: thanks :)
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

those shaders look cool :D
DavidJE13
Posts: 165
Joined: Tue Jan 09, 2007 7:17 pm

Post by DavidJE13 »

Updated to add a really simple lens flare effect. Give it an object to follow and a flare texture (a simple one is provided) and it'll render it.
These can be stacked to have more than one flare, and you can specify a multiply colour to tint / fade it.
Currently doesn't check if the light source is obscured, but will fade out towards screen edges.

Image
Post Reply