根据此页面: https://matthewwellings.com/blog/the-new-vulkan-coefficient-system/
Vulkan 坐标系具有:
在我自己的测试中,我可以确认X轴和Y轴。然而,对我来说,-Z 指向屏幕,而不是+Z。我的意思是:
我相信链接页面胜过我自己的学习代码,所以我不确定为什么会出现这种效果。
我的场景由一个纹理四边形组成。这是我正在使用的代码:
C++
// No rotation
auto identMat = glm::mat4(1.0f);
auto rotAmount = 0.0f;
auto rotAxis = glm::vec3(0.0f, 0.0f, 1.0f);
mUBO.mModel = glm::rotate(identMat, rotAmount, rotAxis);
float eyeXPos = 0.0f;
float eyeYPos = 0.0f;
float eyeZPos = time * 1.0f;
auto eyePosition = glm::vec3(eyeXPos, eyeYPos, eyeZPos);
auto centerPosition = glm::vec3(0.0f, 0.0f, 0.0f);
auto upAxis = glm::vec3(0.0f, 1.0f, 0.0f);
mUBO.mView = glm::lookAt(eyePosition, centerPosition, upAxis);
const float kWindowWidth = 800;
const float kWindowHeight = 600;
auto verticalFOV = glm::radians(45.0f);
auto aspectRatio = kWindowWidth / kWindowHeight;
auto nearPlane = 0.1f;
auto farPlane = 100.0f;
mUBO.mProj = glm::perspective(verticalFOV, aspectRatio, nearPlane, farPlane);
Run Code Online (Sandbox Code Playgroud)
顶点着色器
layout(location = 0) in vec2 inPosition;
// ...
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0);
Run Code Online (Sandbox Code Playgroud)
- - - - - - - - - - - - 编辑 - - - - - - - - - - - - - ---------
我不会因为这个或类似的事情而失眠。但是,由于我决定给自己买一件 Vulkan T 恤,所以我继续为这个问题创建了一个测试用例,以防有人有足够的好奇心来运行它。更新UBO的函数名称称为UpdateUniformBuffer()。该代码是独立的,只是它需要 GLFW 库。另外,它需要最新的 C++ 编译器(我使用 VS2017)。
T恤:https://teespring.com/vulkan#pid=2&cid=2397&sid=front
main.cpp https://pastebin.com/RWpNDfjc
TestRenderer.hpp https://pastebin.com/09TTF1e3
TestRenderer.cpp https://pastebin.com/wCDV0CEk
着色器.vert https://pastebin.com/fb5f4hvF
着色器.frag https://pastebin.com/CCVpnmwj
| 归档时间: |
|
| 查看次数: |
5677 次 |
| 最近记录: |