Page 1 of 1

Using Texture Matrix in shader

Posted: Wed Apr 22, 2020 6:01 pm
by Rusty Rooster
Hi guys,

What's the proper way to send a texture matrix to the vertex shader and access it? I have, say, a few nodes sharing a vertex buffer, ( with different indices, for LOD/tesselation), so I need to translate the texture so that it appears to cover multiple nodes.

I want to do something like this, no? I'm having trouble getting it to work, texture isn't modified at all.

Render:

Code: Select all

 
matrix4 tex;
tex.buildTextureTransform(0.0,vector2df(0,0),vector2df(X_Offset,Y_Offset),vector2df(2,2));
driver->setTransform(video::ETS_TEXTURE_0, tex );
 
OnSetConstants:

Code: Select all

 
core::matrix4 T = driver->getTransform(video::ETS_TEXTURE_0);
services->setVertexShaderConstant("T", T.pointer(), 16);
 
 
vertex shader:

Code: Select all

 
uniform mat4 T;
 
void main(void)
{
...
gl_TexCoord[0] = T * gl_MultiTexCoord0;
}
 

Re: Using Texture Matrix in shader

Posted: Thu Apr 23, 2020 10:01 am
by CuteAlien
ETS_TEXTURE_0 is set from the texture transformation in SMaterial (each texture layer can have a matrix). So usually you set it in there. If you call setTransform before setMaterial then it will be overwritten when the material is set.

I suppose your shader is correct, but in case it doesn't work, mine here uses T*vec4(gl_MultiTexCoord0.x,gl_MultiTexCoord0.y,1.0,1.0) for some reason, so you can try that as well (I don't know right now what .z and .w are by default).