Topic: Need help with a texture scroll shader
Hi, i have this shader and i want texture to scroll x direction, but something is wrong and texture wont move. I'm new to shaders, please help
VERT:
attribute vec3 Vertex;
attribute vec2 TexCoord0;
varying vec2 TexCoord;
uniform mat4 TextureMatrix[8];
uniform mat4 ModelViewMatrix;
uniform mat4 ProjModelViewMatrix;
void main(void)
{
TexCoord = vec2(TextureMatrix[0] * vec4(TexCoord0, 1.0,1.0));
gl_Position = ProjModelViewMatrix * vec4(Vertex,1.0);
}
FRAG:
uniform sampler2D Texture[8];
uniform float Time;
varying vec2 TexCoord;
void main(void) {
vec4 texel = texture2D(Texture[0], vec2(TexCoord.x + 100.0, TexCoord.y));
//vec4 texel = texture(Texture[0], vec2(TexCoord.x + Time,0.0));
gl_FragColor = texel;
//gl_FragColor=vec4(1.0,1.0,1.0,1.0);
}
I have time implemented in behaviour dll and its set to <time+=0.1>. But for some reason it doesnt scroll the texture. Setting 0.5f instead of time scrolls the texture. This is my dll code:
.......
void MyBehavior::update(void)
{
MEngine * engine = MEngine::getInstance();
MRenderingContext *render = engine->getRenderingContext();
MGame * game = engine->getGame();
MLevel * level = engine->getLevel();
MScene * scene = level->getCurrentScene();
MOEntity* entity = scene->getEntityByName("Entity0");
MMesh * mesh = entity->getMesh();
// check if the game is running, removing thif test will enable In-Editor update (like for the lookAt behavior)
if(! game->isRunning())
return;
// get the associated parent object (who is using this behavior)
MObject3d * parent = getParentObject();
// lets rotate the parent object around the z axis, using our custom "rotationSpeed" variable
//parent->addAxisAngleRotation(MVector3(0, 0, 1), m_rotationSpeed);
if (time > 1.0)
{
time = 0.0;
}
else
{
time += 0.1;
}
MMaterial * material = mesh->getMaterial(0);
if (material)
{
MFXRef * FXRef = material->getFXRef();
if (FXRef)
{
unsigned int fxId = FXRef->getFXId();
render->bindFX(fxId);
// send uniform variable
render->sendUniformFloat(fxId, "Time", &time);
render->bindFX(0);
}
}
}
........
Last edited by Skywriter (2014-07-18 14:10:43)