@paroj sorry for bother but I need help with C++ material.
Code: Select all
Ogre::MaterialPtr mat =
Ogre::MaterialManager::getSingleton()
.getByName("Water/Above",
"Water");
if (!mat) {
mat = Ogre::MaterialManager::getSingleton()
.create("Water/Above",
"Water");
Ogre::Technique *tech =
mat->getTechnique(0);
Ogre::Pass *pass = tech->getPass(0);
pass->setLightingEnabled(true);
pass->setAmbient(
Ogre::ColourValue(1, 1, 1, 1));
pass->setDiffuse(Ogre::ColourValue(
0.0f, 0.2f, 0.5f, 1.0f));
pass->setCullingMode(Ogre::CULL_NONE);
pass->setManualCullingMode(
Ogre::MANUAL_CULL_NONE);
pass->setVertexProgram(
"Water/water_vp");
pass->setFragmentProgram(
"Water/water_fp");
/* this one works well*/
Ogre::TextureUnitState *texture_unit =
pass->createTextureUnitState();
texture_unit->setTextureName(
"ReflectionRefractionTexture");
Ogre::Sampler::UVWAddressingMode uvw;
uvw.u = Ogre::TextureUnitState::TAM_MIRROR;
uvw.v = Ogre::TextureUnitState::TAM_MIRROR;
uvw.w = Ogre::TextureUnitState::TAM_MIRROR;
texture_unit->setTextureAddressingMode(
uvw);
texture_unit->setTextureFiltering(
Ogre::FT_MIN, Ogre::FO_LINEAR);
texture_unit->setTextureFiltering(
Ogre::FT_MAG, Ogre::FO_LINEAR);
texture_unit->setTextureFiltering(
Ogre::FT_MIP, Ogre::FO_LINEAR);
/* this one doesn't work */
Ogre::TextureUnitState *texture_unit2 =
pass->createTextureUnitState();
texture_unit2->setTextureName(
"waves2.png");
texture_unit2->setTextureAddressingMode(
uvw);
texture_unit2->setTextureFiltering(
Ogre::FT_MIN, Ogre::FO_LINEAR);
texture_unit2->setTextureFiltering(
Ogre::FT_MAG, Ogre::FO_LINEAR);
texture_unit2->setTextureFiltering(
Ogre::FT_MIP, Ogre::FO_NONE);
}
The problem is that texture_unit2 behaves exactly like texture_unit sampling the same image in fragment shader as if it is duplicate,
no shader errors are produced. However waves2.png loads successfully. "ReflectionRefractionTexture" is RTT created beforehand.
Fragment shader code:
Code: Select all
OGRE_NATIVE_GLSL_VERSION_DIRECTIVE
#include <OgreUnifiedShader.h>
SAMPLER2D(reflectMap, 0);
SAMPLER2D(noiseMap, 1);
MAIN_PARAMETERS
IN(vec4 clipSpace, TEXCOORD0)
IN(vec2 textureCoords, TEXCOORD1)
MAIN_DECLARATION
{
vec2 ndc = clipSpace.xy / clipSpace.w / 2.0 + vec2(0.5, 0.5);
vec2 reflectionUV = vec2(ndc.x, 1.0 - ndc.y) * 0.5;
vec2 refractionUV = vec2(ndc.x, 1.0 - ndc.y) * 0.5 + vec2(0.5, 0.0);
vec4 distortion_color = texture2D(noiseMap, textureCoords);
vec4 reflectionColour = texture2D(reflectMap, reflectionUV);
vec4 refractionColour = texture2D(reflectMap, refractionUV);
gl_FragColor = distortion_color;
// gl_FragColor = mix(reflectionColour, refractionColour, 0.5);
}
}
It looks like I miss something basic. Any ideas?