Hi guys,
sorry just a simple question,
I am trying to do some image processing on the entire buffer from the camera view.
How do I apply shader based on the view (image buffer) from the camera view directly?
Image processing on the entire camera view?
Re: Image processing on the entire camera view?
Render to a texture and then use that texture on a quad (2 triangles) that fills the whole screen. I think XEffects might already have some support for that (search the forum for that).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Image processing on the entire camera view?
Thanks CuteAlien for the help as always, appreciated it.
I am looking into RTT for few hours now and still couldn't make it work.
My scenario is this :
I have two shaders A & B, I attached it to my model ( a scene node ), but find it always only render the latest shader B, and shader A is never drawn.
I tried various ways but still couldn't see any effect, I had gone thru the tutorial 13 but still no luck with 2 shaders.
My Sample code below :
Setting up RTT
Rendering
I am looking into RTT for few hours now and still couldn't make it work.
My scenario is this :
I have two shaders A & B, I attached it to my model ( a scene node ), but find it always only render the latest shader B, and shader A is never drawn.
I tried various ways but still couldn't see any effect, I had gone thru the tutorial 13 but still no luck with 2 shaders.
My Sample code below :
Setting up RTT
Code: Select all
ITexture * rtt0 = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(256,256), "RTT0");
body->getMaterial(0).setTexture(0, rtt0);
ITexture * rtt1 = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(256,256), "RTT1");
body->getMaterial(0).setTexture(1, rtt1);
Rendering
Code: Select all
// set render target texture
node->setVisible(false);
videoDriver->setRenderTarget(rtt0, true, true, video::SColor(0,0,0,0));
node->getMaterial(0).MaterialType = (E_MATERIAL_TYPE) gShaderA;
node->render();
videoDriver->setRenderTarget(rtt1, false, false, video::SColor(0,0,0,0));
node->getMaterial(0).MaterialType = (E_MATERIAL_TYPE) gShaderB;
node->render();
// draw whole scene into render buffer
sceneManager->drawAll();
// set back old render target
// The buffer might have been distorted, so clear it
videoDriver->setRenderTarget(0, true, true, video::SColor(0, 0, 0, 0));
node->setVisible(true);
sceneManager->drawAll();
Re: Image processing on the entire camera view?
Probably you need to set a blend mode.
Re: Image processing on the entire camera view?
Thanks mongoose7,
but my shader A is applying an offset of vertices (somesort like layering effect),
gl_Position = offset + worldviewProj * gl_Vertex;
so basically I think that there's no need for blending,
it should show me two layers of model with one at original position, another at the offset one.
but my shader A is applying an offset of vertices (somesort like layering effect),
gl_Position = offset + worldviewProj * gl_Vertex;
so basically I think that there's no need for blending,
it should show me two layers of model with one at original position, another at the offset one.
-
- Posts: 21
- Joined: Thu Feb 20, 2014 7:39 pm
Re: Image processing on the entire camera view?
Never needed blending. Use the ScreenQuadScene node to render to the screen. Works great for me.
Code: Select all
//! This is a helper class that is used to render a whole screen rectangle
class CScreenQuadSceneNode : public scene::ISceneNode{
core::aabbox3df aabb; //An axis aligned bounding box. Actually not needed.
video::SMaterial material; //The material used to render the Scene Node
video::S3DVertex2TCoords vertices[4]; //The vertices of the Scene Node.
//Normally we wouldn't need more
//than one set of UV coordinates.
//But if we are to use the builtin materials, this is necesary
public:
CScreenQuadSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
:ISceneNode(parent,mgr,id)
{
f32 shiftX,shiftY;
core::dimension2d<u32> currentResolution;
/**Here we initialize the vertices of the screen Aligned quad*/
currentResolution = mgr->getVideoDriver()->getScreenSize();
aabb.reset(0,0,0);
shiftX = 0.5/currentResolution.Width; //This small shift is necesary to compensate the texture sampling bias
shiftY = 0.5/currentResolution.Height; //It avoids that our effect becomes too blurry.
vertices[0] = video::S3DVertex2TCoords(
-1.0f,-1.0f,0.0f,
0.0f,0.0f,-1.0f,
video::SColor(255,255,255,255),
shiftX,shiftY,
shiftX,shiftY);
vertices[1] = video::S3DVertex2TCoords(
1.0f,-1.0,0.0f,
0.0f,0.0f,-1.0f,
video::SColor(255,255,255,255),
1.0f+shiftX,shiftY,
1.0f+shiftX,shiftY);
vertices[2] = video::S3DVertex2TCoords(
-1.0f,1.0,0.0f,
0.0f,0.0f,-1.0f,
video::SColor(255,255,255,255),
shiftX,1+shiftY,
shiftX,1+shiftY);
vertices[3] = video::S3DVertex2TCoords(
1.0f,1.0f,0.0f,
0.0f,0.0f,-1.0f,
video::SColor(255,255,255,255),
1.0f+shiftX,1+shiftY,
1.0f+shiftX,1+shiftY);
/**Now we proceed to initialize the appropriate settings for the material we are going to use
We can alter these later, but for the time being, initializing then here will do no harm*/
material.Lighting = false; //No need for lighting.
material.MaterialType = video::EMT_LIGHTMAP_ADD; //This will add both first and second textures :)
material.BackfaceCulling=false; //not needed, but simplifies things
setAutomaticCulling(scene::EAC_OFF); //We don't need this scene
material.setFlag(video::EMF_TRILINEAR_FILTER, false);
material.setFlag(video::EMF_ANISOTROPIC_FILTER, false);
material.setFlag(video::EMF_FOG_ENABLE, false);
material.setFlag(video::EMF_LIGHTING, false);
}
~CScreenQuadSceneNode()
{
}
const core::aabbox3df& getBoundingBox() const
{
return aabb;
}
void OnRegisterSceneNode()
{
//This method is empty because it is best for us to render this scene node manually.
//So, it is never really rendered on its own, if we don't tell it to do so.
}
void render()
{
video::IVideoDriver* drv = getSceneManager()->getVideoDriver();
core::matrix4 proj;
u16 indices[] = {0,1,2,3,1,2};
//A triangle list
drv->setMaterial(material);
drv->setTransform(video::ETS_PROJECTION, core::IdentityMatrix);
drv->setTransform(video::ETS_VIEW, core::IdentityMatrix);
drv->setTransform(video::ETS_WORLD, core::IdentityMatrix);
drv->drawIndexedTriangleList(&vertices[0],4,&indices[0],2);
}
u32 getMaterialCount()
{
return 1; //There is only one material
}
video::SMaterial& getMaterial(irr::u32 i)
{
return material;//We always return the same material, so there is no need for more.
}
};
-
- Posts: 21
- Joined: Thu Feb 20, 2014 7:39 pm
Re: Image processing on the entire camera view?
I would *guess* that your problem might be because you have not set matrix to identity before rendering to the screen.
Re: Image processing on the entire camera view?
Thanks motorfreak, I have tried resetting the matrix to identity but still no helps.
Regarding the QuadNode, is there any different from my code because I couldn't figure out why my code doesn't work.
Thanks =)
Regarding the QuadNode, is there any different from my code because I couldn't figure out why my code doesn't work.
Thanks =)
-
- Posts: 21
- Joined: Thu Feb 20, 2014 7:39 pm
Re: Image processing on the entire camera view?
Try debugging your shaders. Try rendering to screen, then switch to render to texture and try to render that texture using draw2DImage. You can always render the offscreen ITexture that you use for render to texture into the screen directly. Then if that all works then go to 3d render (you can't use shaders with draw2dimage). Then try setting your gl_FragColor to like red. If that works, expand from there. Start with what works and gradually transform it while making sure that it continues to work.