
Texture combining
Posted Tuesday, 21 June, 2011 - 20:04 by ctartamella inSo I've been racking my brain on this all day and for the life of me I can't get it to work. What I have are a series of textures that need a "screen" blending effect done. This essentially means Inverse( Inverse(Image1)*Inverse(Image2) ) where inverse is just 1.0 minus each individual color value. That being said, I created the following texture combiner to start this process:
GL::ActiveTexture(TextureUnit::Texture0); GL::BindTexture(TextureTarget::Texture2D, m_glTextureList[0]); GL::TexEnv(TextureEnvTarget::TextureEnv, TextureEnvParameter::TextureEnvMode, (Int32)All::Replace); GL::ActiveTexture(TextureUnit::Texture1); GL::BindTexture(TextureTarget::Texture2D, m_glTextureList[1]); GL::TexEnv(TextureEnvTarget::TextureEnv, TextureEnvParameter::TextureEnvMode, (Int32)All::Decal); GL::ActiveTexture(TextureUnit::Texture2); GL::BindTexture(TextureTarget::Texture2D, m_blendedTexture); GL::TexEnv(TextureEnvTarget::TextureEnv, TextureEnvParameter::TextureEnvMode, (Int32)All::Combine); GL::TexEnv(TextureEnvTarget::TextureEnv, TextureEnvParameter::CombineRgb, (Int32) TextureEnvModeCombine::Modulate ); GL::TexEnv(TextureEnvTarget::TextureEnv, TextureEnvParameter::Source0Rgb, (Int32) TextureEnvModeSource::Texture1); GL::TexEnv(TextureEnvTarget::TextureEnv, TextureEnvParameter::Src1Rgb, (Int32) TextureEnvModeSource::Texture0); GL::TexEnv(TextureEnvTarget::TextureEnv, TextureEnvParameter::Operand0Rgb, (Int32) TextureEnvModeOperandRgb::OneMinusSrcColor); GL::TexEnv(TextureEnvTarget::TextureEnv, TextureEnvParameter::Operand1Rgb, (Int32) TextureEnvModeOperandRgb::OneMinusSrcColor);
I know this could be simplified... but I want to get it working first. Later on, when I go to draw my sphere which will have this texture I simply bind m_blendedTexture and draw my sphere. (Note I've also tried about 1000 other permutations of this trying to make it work. In some cases I set the active texture unit to two amongst other things.)
If anyone out there might be able to point out what I'm doing wrong I would be eternally grateful. My forehead will be even more so because I might be able to stop banging it against this desk here... :)


Comments
Re: Texture combining
Just think about writing a small Fragment Shader.
All you have to do is:
Passing two Textures to the Shader (by using Uniform Parameter and UniformLocation Calls)
Then you can do anything you like ( playing around with each Color component and alpha stencil and so on)
I have not tried your specific Idea but got good experience on working with two textures and combining them in a fragment shader
Regards