如何从视图矩阵中删除旋转

问题描述 投票:1回答:1

我的问题是关于从视图矩阵中移除旋转。删除翻译很容易,但我找不到任何方法可以从矩阵中删除旋转。有什么方法可以消除视图矩阵的旋转。

[摄像机绕y轴旋转,因此视图矩阵也影响反射。

在顶点着色器中,我的代码是

#version 330 core
layout(location = 0) in vec3 ModelSpaceVertexPosition;
layout(location = 2) in vec3 ModelSpaceVertexNormal;

out vec3 reflectnormal;
out vec3 reflectposition;

uniform mat4 ModelMatrix;
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;

void main(){

reflectnormal =  ( ViewMatrix * ModelMatrix * vec4(ModelSpaceVertexNormal,0)).xyz;//mat3(transpose(inverse(ModelMatrix))) * ModelSpaceVertexNormal;
reflectposition =  vec3(0,0,0) - ( ViewMatrix * ModelMatrix * vec4(ModelSpaceVertexPosition,1)).xyz;//vec3(ModelMatrix * vec4(ModelSpaceVertexPosition, 1.0));
gl_Position =  ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(ModelSpaceVertexPosition,1);

}

在片段着色器中,我的代码是

#version 330 core

in vec3 reflectnormal;
in vec3 reflectposition;

uniform samplerCube skybox;

out vec3 color;

void main(){   
    vec3 Rtest = reflect(-reflectposition, reflectnormal);
    vec3 EnvironmentReflection = vec3(texture(skybox , Rtest));
    color = EnvironmentReflection;
}

这给了我enter image description here的漂亮视角

但是问题是旋转。当我旋转相机时,反射也会随着相机一起旋转。

enter image description here

enter image description here

如何去除反射的旋转?

Gif视频:https://imgur.com/a/rQh7A7H

opengl matrix glsl fragment-shader vertex-shader
1个回答
0
投票

skybox包含关于世界空间的立方体贴图。因此,您必须计算世界空间中的反射向量(Rtest)。

© www.soinside.com 2019 - 2024. All rights reserved.