Set a shader material to a fllscreen quad?

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.
Post Reply
JunkerKun
Posts: 97
Joined: Mon Jan 28, 2013 12:52 am

Set a shader material to a fllscreen quad?

Post by JunkerKun »

I try to do it like this but all I see is a black screen.

Code: Select all

 
colorBufferMaterial.Wireframe = false;
colorBufferMaterial.Lighting = false;
colorBufferMaterial.ZWriteEnable = false;
colorBufferMaterial.AntiAliasing = 0;
colorBufferMaterial.MaterialType = coreManager->GetShadersManager()->GetShaderMaterial(8);
colorBufferMaterial.TextureLayer[0].BilinearFilter=(settings->renderQuality!=1);
colorBufferMaterial.TextureLayer[0].TrilinearFilter=false;
colorBufferMaterial.TextureLayer[0].AnisotropicFilter=false;
colorBufferMaterial.setTexture(0, colorBuffer);
 
vertices[0] = video::S3DVertex2TCoords(-1,-1,0,0,0,1,video::SColor(255,255,255,255),0,1);
vertices[1] = video::S3DVertex2TCoords(1,-1,0,0,0,1,video::SColor(255,255,255,255),1,1);
vertices[2] = video::S3DVertex2TCoords(1,1,0,0,0,1,video::SColor(255,255,255,255),1,0);
vertices[3] = video::S3DVertex2TCoords(-1,1,0,0,0,1,video::SColor(255,255,255,255),0,0);
 
indices[0] = 0; indices[1] = 3; indices[2] = 2; indices[3] = 0; indices[4] = 2; indices[5] = 1;
 

Code: Select all

 
driver->setMaterial(colorBufferMaterial);
driver->setTransform(video::ETS_PROJECTION, core::IdentityMatrix);
driver->setTransform(video::ETS_VIEW, core::IdentityMatrix);
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
driver->drawIndexedTriangleList(vertices, 4, indices, 2);
 
This is the shader:

Code: Select all

 
void main()
{  
    gl_Position = ftransform();
    gl_TexCoord[0]=gl_MultiTexCoord0;
} 
 

Code: Select all

 
uniform sampler2D Texture0;
 
void main()
{
    gl_FragColor = texture2D(Texture0,gl_TexCoord[0].st);
}
 
Is it even possible to set a shader material to such quad?
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Set a shader material to a fllscreen quad?

Post by mongoose7 »

In the texture read you use 'st' but I think you have set only 'uv'.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Set a shader material to a fllscreen quad?

Post by CuteAlien »

Maybe check-out XEffects in this thread: http://irrlicht.sourceforge.net/forum/v ... =6&t=30631
It does have a ScreenQuad class I think.
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
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Set a shader material to a fllscreen quad?

Post by hendu »

Indeed, copy a working screenQuad from code snippets first.
JunkerKun
Posts: 97
Joined: Mon Jan 28, 2013 12:52 am

Re: Set a shader material to a fllscreen quad?

Post by JunkerKun »

I actually already looked there and it's almost the same.
In the texture read you use 'st' but I think you have set only 'uv'.
It doesn't matter. Even if I set the frag color to white it gives me black.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Set a shader material to a fllscreen quad?

Post by mongoose7 »

Yes, you call ftransform(), which is normally not done. I don't want to try to imagine what a projection matrix that is the identity would do, but I guess your quad has been culled. But you can set the transformed position manually like, for example,

Code: Select all

    gl_Position = vec4(gl_Vertex.x, gl_Vertex.y, 0.0, 1.0);
And try leaving the projection matrix alone. Or copy the code from XEffects.
JunkerKun
Posts: 97
Joined: Mon Jan 28, 2013 12:52 am

Re: Set a shader material to a fllscreen quad?

Post by JunkerKun »

mongoose7 wrote:Yes, you call ftransform(), which is normally not done. I don't want to try to imagine what a projection matrix that is the identity would do, but I guess your quad has been culled. But you can set the transformed position manually like, for example,

Code: Select all

    gl_Position = vec4(gl_Vertex.x, gl_Vertex.y, 0.0, 1.0);
And try leaving the projection matrix alone. Or copy the code from XEffects.
I use GLSL 120, this IS how transformation done there. And besides, I begin to think it's not the transformation issue but something else since when I use XEffects code it gives me the same result.
Post Reply