Hello,
i have a strange result when combining shaders. I loaded two shaders.
A perpixel lightning and a glow-shader. Seperatly both are working.
If I only perform the perpixel lightning it works, and if i only perform
the glow shader it works as well.
But when i try to combine those shaders something goes wrong.
I use the glutSolidTeapot in my example. Applying only one shader
(perpixel light, or glow) on the teapot i can rotate and move it.
Applying these two effects i cant rotate the teapot. I only see the
teapot pretty close on the top.
please have a look at the draw method
static GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT2_EXT};
RTT.BeginMRT(2, mrt); // render original teapot in target 0 and 2
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
shader2.SetParameterModelViewProjectionMatrix(CShaderObject::VERTEX,"modelViewProj");
shader2.SetParameterModelViewMatrixInv(CShaderObject::VERTEX,"modelViewInv");
shader2.SetParameterFloat3v(CShaderObject::VERTEX,"lightPosition",m_Camera.GetCameraPosition().Array());
shader2.SetParameterFloat3v(CShaderObject::VERTEX,"eyePosition",m_Camera.GetCameraPosition().Array());
shader2.Begin();
//glColor3f(0.95,0.57,0.25);
::glutSolidTeapot(1.0);
shader1.End();
RTT.End();
RTT.Begin(1);
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
cgfx.CgFxSetupSampler("SrcSampler",RTT.GetTextureID(0));
cgfx.CgFxBegin("pass0");
RTT.DrawFullscreenQuad();
cgfx.CgFxEnd();
RTT.End();
RTT.Begin(0);
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
cgfx.CgFxSetupSampler("SrcSampler",RTT.GetTextureID(1));
cgfx.CgFxBegin("pass1");
RTT.DrawFullscreenQuad();
cgfx.CgFxEnd();
RTT.End();
// draw teapot texture
RTT.EnableGLBlendColor();
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
cgfx.CgFxSetupSampler("SrcSampler",RTT.GetTextureID(2));
cgfx.CgFxBegin("pass3");
RTT.DrawFullscreenQuad();
cgfx.CgFxEnd();
// glow texture
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
cgfx.CgFxSetupSampler("TmpSampler",RTT.GetTextureID(0));
cgfx.CgFxBegin("pass2");
RTT.DrawFullscreenQuad();
cgfx.CgFxEnd();
RTT.DisableGLBlendColor();
RTT.Begin()
////////////////////////////////////////
// unbind texture
////////////////////////////////////////
glBindTexture(GL_TEXTURE_2D, 0);
////////////////////////////////////////
// bind framebuffer
////////////////////////////////////////
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_Framebuffer);
////////////////////////////////////////
// bind renderbuffer
////////////////////////////////////////
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_Framebuffer);
////////////////////////////////////////
// save current attribs
////////////////////////////////////////
glPushAttrib(SaveAttrib);
////////////////////////////////////////
// align viewport
////////////////////////////////////////
glViewport(0, 0, m_uiWidth, m_uiHeight);
////////////////////////////////////////
// set active attachment (target)
////////////////////////////////////////
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT+Target);
////////////////////////////////////////
// clear buffers
////////////////////////////////////////
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
////////////////////////////////////////
// fill cleared buffer with values
////////////////////////////////////////
glClearColor(0,0,0,0);
RTT.End()
////////////////////////////////////////
// unbind framebuffer
////////////////////////////////////////
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
////////////////////////////////////////
// pop attribs
////////////////////////////////////////
glPopAttrib();
I guess it has something to do with matrix transformation. But I dont understand how it could effect the other shader.
I also checked out if the glow shader is the reason for my problem, but it isnt. I wrote a simple passthrough shader.
And its the same result. Perpixel lightning + passthrough = wrong result. Teapot is not moving.
here are the links to pictures showing you what im talking about
http://rapidshare.com/files/222047298/glow.jpg
http://rapidshare.com/files/222047562/perpixel.jpg
http://rapidshare.com/files/222047694/perpixel_and_glow.jpg
Any ideas ?
thanks,
cmos