graphics - Vulkan 漫反射着色不随对象变换而改变
问题描述
系统:GPU:Intel(R) UHD Graphics
这是我的着色器代码:
顶点着色器:
#version 450
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 color;
layout(location = 2) in vec3 normal;
layout(location = 3) in vec2 uv;
layout(location = 0) out vec3 fragCol;
layout(push_constant) uniform Push {
mat4 transform; // projection * view * model
mat4 modelMatrix;
} push;
vec3 DIRECTION_TO_LIGHT = normalize(vec3(1.0, -10.0, -1.0));
void main() {
gl_Position = push.transform * vec4(position, 1.0);
vec3 normalWorldSpace = normalize(mat3(push.modelMatrix) * normal);
float lightIntensity = max(dot(normalWorldSpace, DIRECTION_TO_LIGHT), 0);
fragCol = lightIntensity * vec3(1.0);
}
片段着色器:
#version 450 core
layout(location = 0) in vec3 fragCol;
layout(location = 0) out vec4 outColor;
layout(push_constant) uniform Push{
mat4 transform;
mat4 modelMatrix;
}push;
void main(){
outColor = vec4(fragCol, 1.0);
}
即使在 z 轴上旋转时,模型的黑暗部分仍然保持黑暗。就像颜色被烘焙到模型中一样,事实并非如此。
我尝试在片段着色器上计算颜色,但这也不起作用。
计算变换矩阵的代码:
auto projectionMatrix = camera.getProjection() * camera.getView();
for (auto& obj : gameObjects) {
//rotating doesn't change the dark pixels.
obj.transform.rotation.y += glm::radians(45.0f) * deltaTime;
SimplePushConstantData push{};
auto modelMatrix = obj.transform.mat4();
push.transform = projectionMatrix * modelMatrix;
push.modelMatrix = modelMatrix;
vkCmdPushConstants(commandBuffer, pipelineLayout,
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
0, sizeof(SimplePushConstantData), &push);
obj.model->bind(commandBuffer);
obj.model->draw(commandBuffer);
}
解决方案
推荐阅读
- ubuntu - Apache2 总是将默认站点加载为我的 PrestaShop 首页
- javascript - Typescript - 如何推断非调用函数中的泛型?
- r - 如何将格式化的表格输出保存为 .png?
- javascript - 如何检查值是否已包含在数组javascript中
- reactjs - Redux 设计问题:可以/应该将经常更改的状态(光标索引)保留在存储之外吗?如果是这样,替代方案?
- python - 我是 python 新手,第一个 if 语句出现错误
- html - Z-index 不适用于伪元素 ::after
- arrays - Powershell将范围作为数组传递?
- c# - 在服务错误 C# 上回滚 MVC 中的更改
- r - R:如何使用函数生成部分函数参数