Using Texture Matrix in shader

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Rusty Rooster
Posts: 11
Joined: Thu May 24, 2018 6:43 pm
Location: USA

Using Texture Matrix in shader

Post 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;
}
 
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Using Texture Matrix in shader

Post 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).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply