Page 1 of 1

Black render result while enable bloom shader

Posted: Wed Jul 20, 2011 1:40 pm
by omg_fail
Hello guys.

After a short break , because of school , i work on a new project.But the i got my first problems with my 3d scene.

I add a Postprocess framework , some shader based water and a cold effect.

clear:

Code: Select all

   
 #include "RealisticWater.h"
#include "CloudSceneNode.h"
#include "PostProcessBloom.h"
 
also clear :

Code: Select all

 
     IrrlichtDevice *device = createDeviceEx(params); 
        //...
         video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices(); 
 
clear :

Code: Select all

 
 IPostProcessBloom *Bloom = new IPostProcessBloom(smgr->getRootSceneNode(), smgr, 666);
                        PPE_Bloom_Setup setup;
 
                        setup.sampleDist=0.008;
                        setup.strength=3;
                        setup.multiplier=5;
                        Bloom->initiate(1024,512,setup,smgr); 
 
 
      RealisticWaterSceneNode* water = new RealisticWaterSceneNode(smgr, 512, 512, driver->getTexture("data/waterbump.png"));
       smgr->getRootSceneNode()->addChild(water);
           
 
                cloudLayer1 = new scene::CCloudSceneNode(smgr->getRootSceneNode(), smgr);
        cloudLayer1->setTranslation(core::vector2d<f32>(0.008f, 0.0f));
        cloudLayer1->getMaterial(0).setTexture(0, driver->getTexture("cloud01.png"));
        cloudLayer1->setCloudHeight(0.5f, 0.1f, -0.05f);
 
        //...
 
Now :

Code: Select all

 
s32 lastFPS = -1;
 
           while(device->run())
                if (device->isWindowActive())
       {
          driver->beginScene(true, true, SColor(255,255,255,255));
         driver->setRenderTarget(Bloom->rt0, true, true, video::SColor(0,0,0,0));
 
          smgr->drawAll();
                  driver->setRenderTarget(0);    
                  Bloom->render();  
                  driver->setMaterial(driver->getMaterial2D());
                  env->drawAll();       
          driver->endScene();
           const s32 fps = driver->getFPS();
 
                if (lastFPS != fps)
                {
                        core::stringw str = L"Venom game";
                        str += driver->getName();
                        str += "FPS:";
                        str += fps;
 
                        device->setWindowCaption(str.c_str());
                        lastFPS = fps;
                }
        
                }
 
       smgr->getRootSceneNode()->removeChild(water);
      
 
       device->drop();
 
       return 0;
    }
 
By using

Code: Select all

 
         driver->setRenderTarget(Bloom->rt0, true, true, video::SColor(0,0,0,0));                 
 
//...
 
driver->setRenderTarget(0);    
                  Bloom->render();  
 
these lines i get a black screen.
Console says nothing about any big shader fails or code errors only 'Unsupported texture format' but this should not have a black screen as render result

Code: Select all

 
Using renderer: OpenGL 4.0.0
GeForce GTX 460/PCI/SSE2/3DNOW!: NVIDIA Corporation
OpenGL driver version is 1.2 or better.
GLSL version: 4.0
Loaded texture: d:/#venom/venom_game/venom_game/gamedata/skyboxes/calm_north.bmp
Loaded texture: d:/#venom/venom_game/venom_game/gamedata/skyboxes/calm_south.bmp
Loaded texture: d:/#venom/venom_game/venom_game/gamedata/skyboxes/calm_west.bmp
Loaded texture: d:/#venom/venom_game/venom_game/gamedata/skyboxes/calm_east.bmp
Loaded texture: d:/#venom/venom_game/venom_game/gamedata/skyboxes/calm_down.bmp
Loaded texture: d:/#venom/venom_game/venom_game/gamedata/skyboxes/calm_up.bmp
Unsupported texture format
Unsupported texture format
Loaded texture: d:/#venom/venom_game/venom_game/gamedata/data/waterbump.png
Unsupported texture format
Unsupported texture format
Unsupported texture format
Loaded texture: d:/#venom/venom_game/venom_game/gamedata/clouds/cloud01.png
Loaded texture: d:/#venom/venom_game/venom_game/gamedata/clouds/cloud02.png
Loaded texture: d:/#venom/venom_game/venom_game/gamedata/textures/cloud03.png
Resizing window (800 600)
 
Thanks for your help

Luis

Re: Black render result while enable bloom shader

Posted: Thu Jul 21, 2011 12:36 pm
by omg_fail
Anyone knows the solution or find any mistake ?

Re: Black render result while enable bloom shader

Posted: Thu Jul 21, 2011 2:24 pm
by Xaryl
Although new IPostProcessBloom(...) looks funny, it is hard to tell without knowing what the class does.

You can try to narrow down the problem a little by first making the shader always returns for example red.

If the red shows up, then next try to make it return the input texture.

Re: Black render result while enable bloom shader

Posted: Thu Jul 21, 2011 2:41 pm
by omg_fail

Code: Select all

 
 
 
struct PPE_Bloom_Setup
{
    float sampleDist;
    float strength;
    float multiplier;
};
 
 
class PPE_Bloom_callback: public video::IShaderConstantSetCallBack
{
public:
    float sampleDist;
    float strength;
    float multiplier;
 
  virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
  {
    video::IVideoDriver* driver = services->getVideoDriver();
    services->setVertexShaderConstant("sampleDist", reinterpret_cast<f32*>(&sampleDist),1);
    services->setVertexShaderConstant("strength", reinterpret_cast<f32*>(&strength),1);
    services->setVertexShaderConstant("multiplier", reinterpret_cast<f32*>(&multiplier),1);
        }
};
 
 
 
 
class IPostProcessBloom : public scene::ISceneNode
{
 
public:
   core::aabbox3d<f32> Box;
   video::S3DVertex Vertices[6];//the vertices for the onscreenquad
   video::SMaterial Material;
   video::ITexture* rt0; //the rendertarget
   int mat;
   PPE_Bloom_callback* callback;
 
      IPostProcessBloom(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id): scene::ISceneNode(parent, mgr, id)
        {
      Vertices[0] = video::S3DVertex(-1.0f, -1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 0.0f, 1.0f);
      Vertices[1] = video::S3DVertex(-1.0f,  1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 0.0f, 0.0f);
      Vertices[2] = video::S3DVertex( 1.0f,  1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 1.0f, 0.0f);
      Vertices[3] = video::S3DVertex( 1.0f, -1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 1.0f, 1.0f);
      Vertices[4] = video::S3DVertex(-1.0f, -1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 0.0f, 1.0f);
      Vertices[5] = video::S3DVertex( 1.0f,  1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 1.0f, 0.0f);
        }
 
 
    void initiate(unsigned int sizeW,unsigned int sizeH,PPE_Bloom_Setup data,scene::ISceneManager* smgr)
   {
static stringc vertShader =
"varying float2 vTexCoord;"
"void main(void)"
"{"
  " float2 Position;"
  " Position.xy = sign(gl_Vertex.xy);"
  " gl_Position = vec4(Position.xy, 0.0, 1.0);"
   "vTexCoord =Position.xy *.5 + .5;"
"}";
 
static stringc fragShader =
"uniform sampler2D texture[2];"
"varying float2 vTexCoord;"
"uniform float sampleDist;"
"uniform float strength;"
"uniform float multiplier;"
"void main()"
"{"
"   float2 samples[12]; "
"   samples[0]  = vTexCoord + sampleDist * float2(-0.326212, -0.405805);"
"   samples[1]  = vTexCoord + sampleDist * float2(-0.840144, -0.073580);"
"   samples[2]  = vTexCoord + sampleDist * float2(-0.695914,  0.457137);"
"   samples[3]  = vTexCoord + sampleDist * float2(-0.203345,  0.620716);"
"   samples[4]  = vTexCoord + sampleDist * float2(0.962340, -0.194983);"
"   samples[5]  = vTexCoord + sampleDist * float2(0.473434, -0.480026);"
"   samples[6]  = vTexCoord + sampleDist * float2(0.519456,  0.767022);"
"   samples[7]  = vTexCoord + sampleDist * float2(0.185461, -0.893124);"
"   samples[8]  = vTexCoord + sampleDist * float2(0.507431,  0.064425);"
"   samples[9]  = vTexCoord + sampleDist * float2(0.896420,  0.412458);"
"   samples[10]  = vTexCoord + sampleDist * float2(-0.321940, -0.932615);"
"   samples[11]  = vTexCoord + sampleDist * float2(-0.791559, -0.597705);"
"   vec4 sample = texture2D(texture[0], vTexCoord);"
"   vec4 avg = sample;"
"   vec4 col;"
"   for (int i = 0; i < 12; i++)"
"   {"
"      float2 tC=min(float2(0.999,0.999),max(float2(0.001,0.001),samples[i]));"
"      avg +=texture2D(texture[0],tC);"
"   }"
"   avg /= 13.0;"
"   avg.r=pow(avg.r,strength);"
"   avg.g=pow(avg.g,strength);"
"   avg.b=pow(avg.b,strength);"
"   gl_FragColor = sample+avg*multiplier;"
"}";
 
video::IVideoDriver* driver = smgr->getVideoDriver();
video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
 
      callback= new PPE_Bloom_callback();
      callback->sampleDist=data.sampleDist;
      callback->strength=data.strength;
      callback->multiplier=data.multiplier;
 
      Material.MaterialType=(E_MATERIAL_TYPE)gpu->addHighLevelShaderMaterial
        (
               vertShader.c_str(), "main", video::EVST_VS_1_1,
               fragShader.c_str(), "main", video::EPST_PS_1_1,
               callback, (video::EMT_SOLID)
        );
      rt0 = driver->addRenderTargetTexture(core::dimension2d<u32>(sizeW,sizeH));
      Material.Wireframe = false;
      Material.Lighting = false;
      Material.setTexture(0, rt0);
    }
 
 
 
 
   virtual void OnPreRender(){}
 
   virtual void render()
   {
 
      u16 indices[] = {0,1,2,3,4,5};
      video::IVideoDriver* driver = SceneManager->getVideoDriver();
 
      driver->setMaterial(Material);
      driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
      driver->drawIndexedTriangleList(&Vertices[0], 6, &indices[0], 2);
   }
   //Renders the Post-Process Effect
 
  virtual u32 getMaterialCount(){return 1;}
  virtual video::SMaterial& getMaterial(s32 i){return (Material);}
  virtual const core::aabbox3d<f32>& getBoundingBox() const{return Box;}
};
 
 
#endif
 
 
 
there are the classes and rest of code

Re: Black render result while enable bloom shader

Posted: Thu Jul 21, 2011 3:14 pm
by Xaryl
My opengl version is older so I had to change something, but it seems to work.
Try this and see if you get a bloom-ed cube:

Code: Select all

 
#include "irrlicht.h"
using namespace irr;
using namespace core;
using namespace video;
using namespace scene;
using namespace gui;;
 
struct PPE_Bloom_Setup
{
    float sampleDist;
    float strength;
    float multiplier;
};
 
 
class PPE_Bloom_callback: public video::IShaderConstantSetCallBack
{
public:
    float sampleDist;
    float strength;
    float multiplier;
 
  virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
  {
    video::IVideoDriver* driver = services->getVideoDriver();
    services->setVertexShaderConstant("sampleDist", reinterpret_cast<f32*>(&sampleDist),1);
    services->setVertexShaderConstant("strength", reinterpret_cast<f32*>(&strength),1);
    services->setVertexShaderConstant("multiplier", reinterpret_cast<f32*>(&multiplier),1);
        }
};
 
 
 
 
class IPostProcessBloom : public scene::ISceneNode
{
 
public:
   core::aabbox3d<f32> Box;
   video::S3DVertex Vertices[6];//the vertices for the onscreenquad
   video::SMaterial Material;
   video::ITexture* rt0; //the rendertarget
   int mat;
   PPE_Bloom_callback* callback;
 
      IPostProcessBloom(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id): scene::ISceneNode(parent, mgr, id)
        {
      Vertices[0] = video::S3DVertex(-1.0f, -1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 0.0f, 1.0f);
      Vertices[1] = video::S3DVertex(-1.0f,  1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 0.0f, 0.0f);
      Vertices[2] = video::S3DVertex( 1.0f,  1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 1.0f, 0.0f);
      Vertices[3] = video::S3DVertex( 1.0f, -1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 1.0f, 1.0f);
      Vertices[4] = video::S3DVertex(-1.0f, -1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 0.0f, 1.0f);
      Vertices[5] = video::S3DVertex( 1.0f,  1.0f, 0.0f,1,1,0, video::SColor(255,0,255,255), 1.0f, 0.0f);
        }
 
 
    void initiate(unsigned int sizeW,unsigned int sizeH,PPE_Bloom_Setup data,scene::ISceneManager* smgr)
   {
static stringc vertShader =
"varying vec2 vTexCoord;\n"
"void main(void)"
"{"
  " vec2 Position;\n"
  " Position.xy = sign(gl_Vertex.xy);\n"
  " gl_Position = vec4(Position.xy, 0.0, 1.0);\n"
   "vTexCoord =Position.xy *.5 + .5;\n"
"}";
 
static stringc fragShader =
"#version 120\n"
"uniform sampler2D texture[2];\n"
"varying vec2 vTexCoord;\n"
"uniform float sampleDist;\n"
"uniform float strength;\n"
"uniform float multiplier;\n"
"void main()\n"
"{"
"   vec2 samples[12];\n"
"   samples[0]  = vTexCoord + sampleDist * vec2(-0.326212, -0.405805);\n"
"   samples[1]  = vTexCoord + sampleDist * vec2(-0.840144, -0.073580);\n"
"   samples[2]  = vTexCoord + sampleDist * vec2(-0.695914,  0.457137);\n"
"   samples[3]  = vTexCoord + sampleDist * vec2(-0.203345,  0.620716);\n"
"   samples[4]  = vTexCoord + sampleDist * vec2(0.962340, -0.194983);\n"
"   samples[5]  = vTexCoord + sampleDist * vec2(0.473434, -0.480026);\n"
"   samples[6]  = vTexCoord + sampleDist * vec2(0.519456,  0.767022);\n"
"   samples[7]  = vTexCoord + sampleDist * vec2(0.185461, -0.893124);\n"
"   samples[8]  = vTexCoord + sampleDist * vec2(0.507431,  0.064425);\n"
"   samples[9]  = vTexCoord + sampleDist * vec2(0.896420,  0.412458);\n"
"   samples[10]  = vTexCoord + sampleDist * vec2(-0.321940, -0.932615);\n"
"   samples[11]  = vTexCoord + sampleDist * vec2(-0.791559, -0.597705);\n"
"   vec4 sample = texture2D(texture[0], vTexCoord);\n"
"   vec4 avg = sample;\n"
"   vec4 col;\n"
"   for (int i = 0; i < 12; i++)"
"   {"
"      vec2 tC=min(vec2(0.999,0.999),max(vec2(0.001,0.001),samples[i]));\n"
"      avg +=texture2D(texture[0],tC);\n"
"   }"
"   avg /= 13.0;\n"
"   avg.r=pow(avg.r,strength);\n"
"   avg.g=pow(avg.g,strength);\n"
"   avg.b=pow(avg.b,strength);\n"
"   gl_FragColor = sample+avg*multiplier;\n"
"   //gl_FragColor=vec4(1.0,0.0,0.0,0.0);\n"
"}\n";
 
video::IVideoDriver* driver = smgr->getVideoDriver();
video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
 
      callback= new PPE_Bloom_callback();
      callback->sampleDist=data.sampleDist;
      callback->strength=data.strength;
      callback->multiplier=data.multiplier;
 
      Material.MaterialType=(E_MATERIAL_TYPE)gpu->addHighLevelShaderMaterial
        (
               vertShader.c_str(), "main", video::EVST_VS_1_1,
               fragShader.c_str(), "main", video::EPST_PS_1_1,
               callback, (video::EMT_SOLID)
        );
      rt0 = driver->addRenderTargetTexture(core::dimension2d<u32>(sizeW,sizeH));
      Material.Wireframe = false;
      Material.Lighting = false;
      Material.setTexture(0, rt0);
    }
   virtual void OnPreRender(){}
 
   virtual void render(){
      u16 indices[] = {0,1,2,3,4,5};
      video::IVideoDriver* driver = SceneManager->getVideoDriver();
      driver->setMaterial(Material);
      driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
      driver->drawIndexedTriangleList(&Vertices[0], 6, &indices[0], 2);
   }
   //Renders the Post-Process Effect
 
  virtual u32 getMaterialCount(){return 1;}
  virtual video::SMaterial& getMaterial(s32 i){return (Material);}
  virtual const core::aabbox3d<f32>& getBoundingBox() const{return Box;}
};
 
 
int main(){
    IrrlichtDevice* device = createDevice(video::EDT_OPENGL, core::dimension2d<irr::u32>(800,600), 32, false, false, false, 0);
    //device->getFileSystem()->addFileArchive("data/",false,false);
    //IGUIEnvironment* env = device->getGUIEnvironment();
    IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
    ISceneNode* light = smgr->addLightSceneNode();
    light->setPosition(vector3df(0,10,0));
    ICameraSceneNode* camera = smgr->addCameraSceneNode();
    camera->setPosition(vector3df(0,50,3));
    camera->setTarget(vector3df(10,10,0));
    ISceneNode* cube = smgr->addCubeSceneNode();
    cube->setPosition(vector3df(10,10,0));
    cube->setMaterialFlag(EMF_LIGHTING,false);
 
    IPostProcessBloom *Bloom = new IPostProcessBloom(smgr->getRootSceneNode(), smgr, 666);
                            PPE_Bloom_Setup setup;
 
                            setup.sampleDist=0.008;
                            setup.strength=3;
                            setup.multiplier=5;
                            Bloom->initiate(1024,512,setup,smgr);
 
    while(device->run()){
        driver->beginScene(true, true);
        driver->setRenderTarget(Bloom->rt0, true, true, video::SColor(0,0,0,0));
        smgr->drawAll();
        driver->setRenderTarget(0);
        Bloom->render();
        driver->endScene();
    }
}
 

Re: Black render result while enable bloom shader

Posted: Thu Jul 21, 2011 3:36 pm
by omg_fail
Yes man i get a bloomed cube

Re: Black render result while enable bloom shader

Posted: Thu Jul 21, 2011 3:45 pm
by omg_fail
Ok.
I tested around a bit with your code and added one for one all nodes and pther stuff i had in my normal code.It worked fine until i added the water

Code: Select all

 
      RealisticWaterSceneNode* water = new RealisticWaterSceneNode(smgr, 10512, 10512, driver->getTexture("data/waterbump.png"));
       smgr->getRootSceneNode()->addChild(water);
 
After this the screen turned black.

Any ideas ?

Luis

Re: Black render result while enable bloom shader

Posted: Sat Jul 23, 2011 5:36 pm
by omg_fail
So now I know that if I use both shaders in the code , there's anywhere a point where they get errors because of the other shader.

Could it be that it is because the one is in GLSL and the other in HLSL.(i am not sure if this is right , just an idea)

Anyone have some know-how about this stuff ?
Would be very interessting for me.

Thanks

Luis.

Re: Black render result while enable bloom shader

Posted: Sun Jul 24, 2011 9:27 pm
by serengeor
omg_fail wrote: Could it be that it is because the one is in GLSL and the other in HLSL.(i am not sure if this is right , just an idea)
That might be a problem, since I don't think that you are running opengl and directx at the same time. You should convert either the hlsl shader to glsl and run in opengl driver or convert the glsl shader to hlsl and run the directx driver.

Re: Black render result while enable bloom shader

Posted: Mon Jul 25, 2011 2:45 am
by mongoose7
Surely it is not possible to use HLSL shaders and GLSL shaders at the same time?

Re: Black render result while enable bloom shader

Posted: Mon Jul 25, 2011 5:43 am
by omg_fail
since I don't think that you are running opengl and directx at the same time
Sure this would be very strange :lol:

ok I will try to convert it.