与视图矩阵相乘不会影响 OpenGL ES 2.0/3.0 中的结果值 [英] Multiplication by a view matrix does not affect the resulting value in OpenGL ES 2.0/3.0

查看:64
本文介绍了与视图矩阵相乘不会影响 OpenGL ES 2.0/3.0 中的结果值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了获得恒定的方向光,我将视图矩阵乘以光方向向量:

#version 300 es统一 mat4 u_mvMatrix;//模型视图矩阵统一 mat4 u_vMatrix;//查看矩阵在 vec4 a_position;在 vec3 a_normal 中;const vec3 lightDirection = vec3(-1.9, 0.0, -5.0);...无效主(){vec3 modelViewNormal = vec3(u_mvMatrix * vec4(a_normal, 0.0));vec3 lightVector = -(mat3(u_vMatrix) * lightDirection);浮动diffuseFactor = max(dot(modelViewNormal, lightVector), 0.0);...}

但是diffuseFactor的值和使用时一样:

vec3 lightVector = -lightDirection;

换句话说,结果同样糟糕.

问题:谁能建议为什么乘以视图矩阵不会影响结果值diffuseFactor?

注意:使用以下方法创建视图矩阵:

Matrix.setLookAtM(viewMatrix, rmOffset:0, eyeX:0f, eyeY:0f, eyeZ:0f,centerX:0f, centerY:0f, centerZ:-4f, upX:0f, upY:1f, upZ:0f)有趣的 getVMatrixAsFloatBuffer(): FloatBuffer = Buffers.floatBuffer(viewMatrix)GLES20.glUniformMatrix4fv(vMatrixLink, 1, false, view.getVMatrixAsFloatBuffer());

我还使用以下方法检查了视图矩阵的正确性:

gl_Position = u_pMatrix * u_vMatrix * u_mMatrix * a_position;

这工作正常.

提前致谢!

解决方案

视图矩阵

<块引用>

Matrix.setLookAtM(viewMatrix, 0, 0f, 0f, 4f, 0.0f, 0f, 0f, 0f, 1.0f, 0.0f)

不影响观看方向,因为视图矩阵的左上角3x3是身份矩阵.

因此操作

<块引用>

vec3 lightVector = -(mat3(u_vMatrix) * lightDirection);

将向量 lightDirection 乘以单位矩阵,并且根本不改变向量.

使用不同的视角,来看到视角矩阵的效果.例如:

Matrix.setLookAtM(viewMatrix, 0f, 0f, 2.8f, 2.8f, 0.0f, 0f, 0f, 0f, 1.0f, 0.0f)

To obtain constant directional light, I multiplied the view matrix by the light direction vector:

#version 300 es
uniform mat4 u_mvMatrix; // model-view matrix
uniform mat4 u_vMatrix; // view matrix
in vec4 a_position;
in vec3 a_normal;
const vec3 lightDirection = vec3(-1.9, 0.0, -5.0);
...
void main() {
    vec3 modelViewNormal = vec3(u_mvMatrix * vec4(a_normal, 0.0));
    vec3 lightVector = -(mat3(u_vMatrix) * lightDirection);
    float diffuseFactor = max(dot(modelViewNormal, lightVector), 0.0);
    ...
}

But the diffuseFactor value is the same as when use:

vec3 lightVector = -lightDirection;

In other words, it turns out the same worst picture.

Question: Can anyone please suggest why multiplication by a view matrix does not affect the resulting value diffuseFactor?

Note: The view matrix is created using:

Matrix.setLookAtM(viewMatrix, rmOffset:0, eyeX:0f, eyeY:0f, eyeZ:0f,
        centerX:0f, centerY:0f, centerZ:-4f, upX:0f, upY:1f, upZ:0f)
fun getVMatrixAsFloatBuffer(): FloatBuffer = Buffers.floatBuffer(viewMatrix)
GLES20.glUniformMatrix4fv(vMatrixLink, 1, false, view.getVMatrixAsFloatBuffer());

I also checked the correctness of the view matrix using:

gl_Position = u_pMatrix * u_vMatrix * u_mMatrix * a_position;

This is working fine.

Thanks in advance!

解决方案

The view matrix

Matrix.setLookAtM(viewMatrix, 0, 0f, 0f, 4f, 0.0f, 0f, 0f, 0f, 1.0f, 0.0f)

does not affect the viewing directing, because the upper left 3x3 of the view matrix is the Identity matrix.

Hence the operation

vec3 lightVector = -(mat3(u_vMatrix) * lightDirection);

multiplies the vector lightDirection by the identity matrix and doesn't change the vector at all.

Use different a point of view, to see the effect of the view matrix. For Instance:

Matrix.setLookAtM(viewMatrix, 0f, 0f, 2.8f, 2.8f, 0.0f, 0f, 0f, 0f, 1.0f, 0.0f)

这篇关于与视图矩阵相乘不会影响 OpenGL ES 2.0/3.0 中的结果值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆