glsl shaders not working??

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

glsl shaders not working??

Postby aburt11 » Sun Apr 29, 2012 6:49 am

hey there,

for some reason my SSAO shader example is not working on my game engine.
any ideas?


main.cpp
cpp Code: Select all
 
#include "main.h"
 
redNovember* SYS = new redNovember;
 
 
void redNovember::renderScene()
{
        int lastFPS = -1;
 
        while(device->run())
        {
                if (device->isWindowActive())
                {
                        driver->beginScene(true, true, video::SColor(255,200,200,200));
                        smgr->drawAll();
                        driver->endScene();
 
                        int fps = driver->getFPS();
 
                        if (lastFPS != fps)
                        {
                                core::stringw str = L"Irrlicht Engine - Quake 3 Map example [";
                                str += driver->getName();
                                str += "] FPS:";
                                str += fps;
 
                                device->setWindowCaption(str.c_str());
                                lastFPS = fps;
                        }
                }
                else
                        device->yield();
        }
       
}
 
 
int redNovember::shutdown()
{
        device->drop();
       
        return 0;
}
 
int main()
{
 
        SYS->initIrrlicht();
       
       
        SYS->initFPSCamera();
       
       
        SYS->initRain();
        SYS->initFog();
        SYS->initSSAO();
       
        ///put main poop in here
        //put gui loop here
       
        SYS->initSkydome("assets/skydome/storm1.jpg");
 
 
        /*
        SYS->initSkybox("assets/skybox/citystorm/up.jpg",
                        "assets/skybox/citystorm/down.jpg",
                        "assets/skybox/citystorm/left.jpg",
                        "assets/skybox/citystorm/right.jpg",
                        "assets/skybox/citystorm/back.jpg",
                        "assets/skybox/citystorm/front.jpg");*/

       
       
 
SYS->initScene();
 
 
 
 
        SYS->renderScene();
 
        SYS->shutdown();
 
}
 


main.h
cpp Code: Select all
#ifndef MAIN_H_
#define MAIN_H_
 
#include <irrlicht.h>
#include <iostream>
#include <string.h>
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
 
//globals
class redNovember
{
public:
        // always initialize class-members in the constructor - especially set pointers to 0!
        redNovember() : device(0), driver(0), smgr(0),guienv(0)
        {}
 
        ~redNovember();
 
        void initIrrlicht();
        void initFPSCamera();
        void renderScene();
        int shutdown();
 
        //for the game scenes
        void initScene();
        void initSkybox(const char* up,const char* down,const char* left, const char* right, const char* front, const char* back);
        void initSkydome(const char* skydomefile);
 
        //shader stuff
        void initShader(const char* vertexShader, const char* pixelShader);
       
 
 
        void initRain();
 
        void initFog();
        void initBloom();
        void initHDR();
        void initSSAO();
        void initBokehDOF();
       
 
 
        IrrlichtDevice *device;
        IVideoDriver* driver;
        ISceneManager* smgr;
        IGUIEnvironment* guienv;
        ICameraSceneNode * camera;
        IMetaTriangleSelector * meta;
        IGPUProgrammingServices* gpu;
 
        s32 newMaterialType1;
 
        //for shaders
       
        // You can put any other variables you want in here.
        // For example driver, scenemanger although you can also always get them from device
        // Note that the clean solution is making variables private and use public
        // get-functions to access them from other classes as you can see when looking at Irrlicht classes.
 
        // You can for example also create a function like that:
        //irr::scene::ISceneManager* getSceneManager() const { return device ? device->getSceneManager() : 0; }
};
 
       
        // every other global you would need can instead of being global just be put in here.
 
#endif


shaders.cpp
cpp Code: Select all
#include "main.h"
 
void redNovember::initShader(const char* vertexShader, const char* pixelShader)
{
        gpu = driver->getGPUProgrammingServices();
 
        newMaterialType1 = 0;
       
                s32 newMaterialType1 = gpu->addHighLevelShaderMaterialFromFiles(
                        vertexShader, "main", video::EVST_VS_1_1,
                        pixelShader, "main", video::EPST_PS_1_1,
                        0, video::EMT_SOLID);
 
}
 
void redNovember::initFog()
{
 
        driver->setFog(video::SColor(0,128,128,128), video::EFT_FOG_EXP, 250, 1000, .0001f, true, false);
}
 
void redNovember::initRain()
{
       
 
 
        scene::IParticleSystemSceneNode* ps = 0;
        ps = smgr->addParticleSystemSceneNode(false);
        ps->setParent(smgr->getActiveCamera());
        scene::IParticleEmitter* em = ps->createBoxEmitter(
                core::aabbox3d<f32>(-10,-10,-10,20,20,20),
                core::vector3df(0.00f,0.00f,0.0f),
                700,1000,
                video::SColor(0,255,255,255), video::SColor(0,255,255,255),
                500,2000);
 
        ps->setEmitter(em);
        em->drop();
        scene::IParticleAffector* paf =
                ps->createGravityAffector(core::vector3df(0.00f,-0.25f, 0.0f), 1000);
 
        ps->addAffector(paf);
        paf->drop();
 
        ps->setMaterialFlag(video::EMF_LIGHTING, false);
        ps->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
        ps->setMaterialTexture(0, driver->getTexture("assets/shaders/rain.png"));
       
       
 
        core::vector3df camDir=smgr->getActiveCamera()->getTarget()-smgr->getActiveCamera()->getAbsolutePosition();
        camDir=camDir.normalize();
        f32 camPitch = camDir.dotProduct(core::vector3df(0,1,0));
        if(camPitch<0.0)
                camPitch = camDir.dotProduct(core::vector3df(0,-1,0));
        camPitch=(1.0f-camPitch)+0.01;
        ps->setParticleSize(core::dimension2d<f32>(0.05f, 1.5f*camPitch));
       
       
}
 
void redNovember::initSSAO() // not working here :(
{
        initShader("assets/shaders/ssao/ssao.vert","assets/shaders/ssao/ssao.frag");
}
aburt11
 
Posts: 66
Joined: Sun Jan 15, 2012 10:27 am

Re: glsl shaders not working??

Postby hendu » Sun Apr 29, 2012 8:21 am

You are not using the shader anywhere?
hendu
 
Posts: 1552
Joined: Sat Dec 18, 2010 12:53 pm

Re: glsl shaders not working??

Postby aburt11 » Tue May 01, 2012 6:14 am

sorry i forgot to add this, a little slice from initScene

cpp Code: Select all
void redNovember::initScene()
{
 
        /*
switch(selectedScene)
        case 'level1':
                sceneLoad = "assets/levels/level1.irr";
                        break;*/

 
 
        //smgr->loadScene("assets/levels/dropzone.irr"); //load scene like this until debug is finished
 
        //3ds level
        IAnimatedMesh* model = smgr->getMesh("assets/placeholder.3ds");
        IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( model );
 
        if (node)
        {
                //node->setMaterialFlag(EMF_LIGHTING, false);
                node->setMaterialTexture( 0, driver->getTexture("assets/test.jpg") );
                node->setPosition(core::vector3df(100,-30,100));
        }
 
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMaterialFlag(EMF_FOG_ENABLE,true);
 
       
        //attach shader to object
       
       
        node->setMaterialType((E_MATERIAL_TYPE)newMaterialType1);
aburt11
 
Posts: 66
Joined: Sun Jan 15, 2012 10:27 am

Re: glsl shaders not working??

Postby hendu » Tue May 01, 2012 4:44 pm

That's not going to do what you want, usually SSAO is applied on the whole screen and not just one mesh. Then you need the depth, which you don't have at the time you render the mesh for the first time.

Hint: see the many post-processing examples.
hendu
 
Posts: 1552
Joined: Sat Dec 18, 2010 12:53 pm

Re: glsl shaders not working??

Postby aburt11 » Thu May 03, 2012 9:49 am

okay, how would i be able to apply shaders to the whole screen
(some code snippets would be great)
aburt11
 
Posts: 66
Joined: Sun Jan 15, 2012 10:27 am


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest