opengl - 在 glsl 顶点着色器中使用额外的统一 mat4 转换灯光?
问题描述
我正在为我的场景使用场景图。它包含灯光和网格。网格具有局部变换,如果节点是网格节点的子节点,则其自身的局部变换与其父节点的变换组合在一起。
现在我正在尝试实现灯光。我将灯光的坐标(世界空间坐标)作为制服发送到我的着色器。
我必须转换这些光坐标吗?对我来说,必须使用特定于网格的变换来变换这些光坐标是没有意义的。
我是否需要向着色器发送另一个统一矩阵来以不同的方式变换灯光?
我的代码:
#version 330
const int numOfLights = 2;
// shader input
in vec2 vUV; // vertex uv coordinate
in vec3 vNormal; // untransformed vertex normal
in vec3 vPosition; // untransformed vertex position
uniform vec3 pointLights[numOfLights];
// shader output
out vec4 normal; // transformed vertex normal
out vec2 uv;
out vec4 position;
out vec3 lights[numOfLights];
uniform mat4 transform; //transform unique for this mesh containing the camera transformation
// vertex shader
void main()
{
position = transform * vec4(vPosition, 1.0);
// transform vertex using supplied matrix
gl_Position = position;
// forward normal and uv coordinate; will be interpolated over triangle
normal = transform * vec4( vNormal, 0.0f );
uv = vUV;
for (int i = 0; i < numOfLights; i++) {
//lights[i] = (transform * vec4(pointLights[i], 1.0)).xyz; //**Transform**?
lights[i] = pointLights[i];
}
}
解决方案
推荐阅读
- tensorflow - 致命例外:推理。无法从 Java 缓冲区复制到 TensorFlowLite 张量
- python - pip 未在 macOS 上使用 homebrew 安装
- javascript - 在 Safari 中禁用两指滚动
- python-3.x - 异常或其他块级范围中的变量范围
- c# - SSIS WinSCP C# 脚本任务正在运行但不执行任何操作
- c# - 有没有办法在 C# .net 中将时区格式(美国/芝加哥)转换为 UTC(-0500)?
- javascript - 为什么禁用缓存会使我的网页正常工作?
- jenkins - 如何从 jenkins 管道中的 JQL 查询中提取 TestCaseID
- ag-grid - 加载的行高与 ag-grid 中的实际行高不同
- 7zip - 如何在 Windows 上提取大文件