Frage

Is it possible to have multiple modelview matrices in a single (vertex?) shader? I've gotten the following to sort of work, but I don't know if what I'm trying to do is recommended, or if there is an alternative approach to achieve something similar?

// inputs
attribute vec4 position;

// textures
attribute vec4 inputTextureCoordinate0;
attribute vec4 inputTextureCoordinate1;

// matrices
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix0;
uniform mat4 modelviewMatrix1;

// output
varying vec2 textureCoordinate0;
varying vec2 textureCoordinate1;

void main()
{
    gl_Position = position * projectionMatrix;
    textureCoordinate0 = vec2(inputTextureCoordinate0 * modelviewMatrix0);
    textureCoordinate1 = vec2(inputTextureCoordinate1 * modelviewMatrix1);
}
War es hilfreich?

Lösung

Modelview transformation usually is applied to the vertex position only. Texture coordinates normally are not transformed by the modelview, because it doesn't make a lot of sense in most situations.

Of course there are valid reasons to transform texture coordinates by a matrix, and you can of course pass as many matrix uniforms the OpenGL version you have permits.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top