[Deprecated]SSAO with XEffects (Reloaded)

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

Code: Select all

#include <Irrlicht.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// XEffects Includes
#include "XEffects/CScreenQuad.h"
#include "XEffects/CShaderPre.h"
#include "XEffects/effectWrapper.h"
#include "XEffects/effectWrapperCB.h"

#ifdef _MSC_VER
#   pragma comment( lib, "Irrlicht.lib" )
#endif // _MSC_VER

#define USE_PUTS 1
#ifdef USE_PUTS
#   define debug_out( x ) puts( x )
#else
#   define debug_out( x ) fprintf( stderr, x )
#endif // USE_PUTS

using namespace irr;
using namespace irr::core;
using namespace irr::io;
using namespace irr::video;
using namespace irr::scene;

class EventReceiver : public IEventReceiver
{
public:
	// This is the one method that we have to implement
	virtual bool OnEvent(const SEvent& event)
	{
		// Remember whether each key is down or up
		if (event.EventType == irr::EET_KEY_INPUT_EVENT)
			KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;

		return false;
	}

	// This is used to check whether a key is being held down
	virtual bool IsKeyDown(EKEY_CODE keyCode) const
	{
		return KeyIsDown[keyCode];
	}

	EventReceiver()
	{
		for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
			KeyIsDown[i] = false;
	}

private:
	// We use this array to store the current state of each key
	bool KeyIsDown[KEY_KEY_CODES_COUNT];
};

int main( int argc, char **argv )
{
    // Create the device, and get the usual pointers
    IrrlichtDevice* device = createDevice( EDT_OPENGL, dimension2di( 800, 600 ), 32 );
    if( !device )
    {
        debug_out( "Device could not be created" );
        return( 0 );
    }

    IVideoDriver* videoDriver = device->getVideoDriver();
    ISceneManager* sceneMgr = device->getSceneManager();

    // Create the event receiver and add it to the device
    EventReceiver* events = new EventReceiver();
    device->setEventReceiver( events );

    // Seed the random number generator
    srand( time( NULL ) );

    // Create an FPS camera
    ICameraSceneNode* camera = sceneMgr->addCameraSceneNodeFPS(0,100,0.1f);
    camera->setPosition( vector3df( 20, 10, -10) );
    camera->setFarValue( 100 );
    camera->setNearValue( 0.1f );

    // Set the RTT size
    dimension2d< s32 > screenRTT = !videoDriver->getVendorInfo().equals_ignore_case( "NVIDIA Corporation" ) ?
        dimension2d< s32 >( 1204, 1024 ) : videoDriver->getScreenSize();

    // Create the effect handler
    effectHandler* effect = new effectHandler( device, dimension2di( 1024, 1024 ), "shaders", dimension2di( 0, 0 ) );

    // Set the clear color to black
    effect->setClearColour( SColor( 0x00FF0000 ) );

    effect->enableDepthPass( true );

    // Add a crap-load of cube nodes!
    for( s32 i = 0; i < 6; ++ i )
    {
        for( s32 j = 0; j < 6; ++ j )
        {
            for( s32 k = 0; k < 6; ++ k )
            {
                ISceneNode* cube = sceneMgr->addCubeSceneNode( 4.0 );
                cube->setPosition( vector3df( i * 4.0f + 2.0f , j * 5.0f + 1.0f, k * 6.0f + 3.0f ) );
                cube->setRotation( vector3df( rand() % 360, rand() % 360, rand() % 360 ) );
                cube->getMaterial( 0 ).setTexture( 0, videoDriver->getTexture( "media/wall.bmp" ) );
                cube->getMaterial( 0 ).setFlag( EMF_LIGHTING, false );

                effect->addNodeToDepthPass( cube );
            }
        }
    }

    // Create the post processing chain!!
    s32 ssao, blurv, blurh, lightmod;
    ssao = effect->addPostProcessingEffectFromFile( stringc( "shaders/SSAO.glsl" ) );
    //blurv = effect->addPostProcessingEffectFromFile( stringc( "shaders/BlurVP.glsl" ) );
    //blurh = effect->addPostProcessingEffectFromFile( stringc( "shaders/BlurHP.glsl" ) );
    //lightmod = effect->addPostProcessingEffectFromFile( stringc( "shaders/LightModulate.glsl" ) );

    // Retrieve the randomized vectors
    ITexture* randomVectors = videoDriver->getTexture( "media/SSAORandomVectors.bmp" );

    // Add it for the SSAO post-process
    effect->setPostProcessingUserTexture( randomVectors );

    bool on = true;
    while( device->run() )
    {
        if( device->isWindowActive() )
        {
            videoDriver->beginScene( true, true, SColor( 0x00FF0000 ) );
                effect->update();
                //videoDriver->draw2DImage( effect->getDepthMapTexture(), position2di( 0,0 ) );
            videoDriver->endScene();

            if( events->IsKeyDown( KEY_KEY_O ) && on == false )
            {
                on = true;
                ssao = effect->addPostProcessingEffectFromFile( stringc( "shaders/SSAO.glsl" ) );
                //blurv = effect->addPostProcessingEffectFromFile( stringc( "shaders/BlurVP.glsl" ) );
                //blurh = effect->addPostProcessingEffectFromFile( stringc( "shaders/BlurHP.glsl" ) );
                lightmod = effect->addPostProcessingEffectFromFile( stringc( "shaders/LightModulate.glsl" ) );
            }

            if( events->IsKeyDown( KEY_KEY_P ) && on == true )
            {
                on = false;
                effect->removePostProcessingEffect( ssao );
                effect->removePostProcessingEffect( blurv );
                effect->removePostProcessingEffect( blurh );
                effect->removePostProcessingEffect( lightmod );
            }

        }
    }

    delete effect;
    device->drop();
    return( 0 );

}

Don't work with shader code posted 3-4 posts above. Gives me black screen. Tryed without randomized vectors. It's only difference from demo code is camera range.

That's the error i get loading .vert and .frag files as you say:
Image
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Those errors looks like you are trying to load a vertex shader as a pixel shader.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
9YkKsvXM
Posts: 64
Joined: Tue Mar 11, 2008 11:45 pm

Post by 9YkKsvXM »

-
Last edited by 9YkKsvXM on Mon Jun 08, 2020 1:24 am, edited 1 time in total.
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

GeForce 8600M GT i think it's because of wrong understandment of the topic.

I have just copied shader from some posts above and applied it as a postprocess like in the Halifax's demo. (modified shader file only)
Black screen appeared.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

No thats not the problem, he is trying to use vertex shader variables/functions in a pixel shader. Maybe he accidentally typed "VS" instead of "PS" in the filename parameter?
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
9YkKsvXM
Posts: 64
Joined: Tue Mar 11, 2008 11:45 pm

Post by 9YkKsvXM »

-
Last edited by 9YkKsvXM on Mon Jun 08, 2020 1:24 am, edited 1 time in total.
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

Wish to have a working code with leadwerk's ssao shader. It's not real SSAO but looks great. Feel the depth xD

As I learned to implement some shaders to project I must create texture as big as screen is and put postprocess on it and make it actual render. Is that correct?
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Ok you can check out my new SSAO algorithm included with the new release of XEffects.

Here are some screenshots using Halfax' scene:

Image

Image

Image

I worked on it for a bit, and then I realised that it's quite similar to Halifax' algorithm except I take the looong way around and do everything in world space. Oh well I suppose you could do deferred shading or something while you're at it. :lol:

In the end however there were a few crucial differences that make this one stand out a little. For one mine works in the traditional monte-carlo boolean operation fashion (Except for the long range damping tweak) and normalizes the offset kernal. Also I've taken into consideration that nearby things don't necessarily occlude far away things that are behind them, that should be handled fairly adequately by this algorithm, but you may need to do some tweaking in the shader settings (At the top of SSAO.hlsl/.glsl).
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

BlindSide wrote:I've taken into consideration that nearby things don't necessarily occlude far away things that are behind them, that should be handled fairly adequately by this algorithm
Yeah, that's one key thing my algorithm forgot. But anyways, you did it exactly the way I was about to do it after reading the Blizzard paper on how they did SSAO.

As I said in your thread, great job!

And this SSAO shader is now deprecated. :lol:
TheQuestion = 2B || !2B
Steel Style
Posts: 168
Joined: Sun Feb 04, 2007 3:30 pm
Location: France

Post by Steel Style »

Oh :[ this Leadwerks SSAO seemed fine.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Steel Style wrote:Oh :[ this Leadwerks SSAO seemed fine.
I could always PM you the shader. You'll have to wait for me to get home though and get on my development computer, which might take a day or two. :?
TheQuestion = 2B || !2B
Post Reply