feat: render 2 rotating cubes side by side
- Push constant changed from float angle (4B) to mat4 model (64B) - Two draw calls with different model matrices (x=-1.5 and x=+1.5) - Both cubes rotate around Y axis at 0.2 rad/s - 0 validation errors
This commit is contained in:
@@ -10,18 +10,11 @@ layout(row_major, set = 0, binding = 0) uniform CameraUBO {
|
||||
mat4 vp;
|
||||
};
|
||||
|
||||
layout(push_constant) uniform PC {
|
||||
float angle;
|
||||
layout(row_major, push_constant) uniform PC {
|
||||
mat4 model;
|
||||
} pc;
|
||||
|
||||
void main() {
|
||||
float c = cos(pc.angle);
|
||||
float s = sin(pc.angle);
|
||||
vec3 rotated = vec3(
|
||||
inPosition.x * c - inPosition.z * s,
|
||||
inPosition.y,
|
||||
inPosition.x * s + inPosition.z * c
|
||||
);
|
||||
gl_Position = vp * vec4(rotated, 1.0);
|
||||
gl_Position = vp * pc.model * vec4(inPosition, 1.0);
|
||||
fragColor = inColor;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -154,7 +154,7 @@ internal sealed unsafe class VulkanPipeline : IDisposable
|
||||
{
|
||||
stageFlags = VkShaderStageFlags.Vertex,
|
||||
offset = 0,
|
||||
size = 4,
|
||||
size = 64,
|
||||
};
|
||||
|
||||
var descLayout = DescriptorSetLayout;
|
||||
|
||||
@@ -188,9 +188,15 @@ internal sealed unsafe class VulkanRenderer : IRenderer, Engine.Graphics.IScreen
|
||||
|
||||
Vk.vkCmdBindIndexBuffer(cmd, _indexBuffer.Buffer, 0, 1);
|
||||
|
||||
float angle = _totalTime * 0.2f;
|
||||
Vk.vkCmdPushConstants(cmd, _pipeline.PipelineLayout, VkShaderStageFlags.Vertex, 0, 4, &angle);
|
||||
var angle = _totalTime * 0.2f;
|
||||
var rot = Matrix4x4.CreateRotationY(angle);
|
||||
|
||||
var model1 = Matrix4x4.CreateTranslation(-1.5f, 0, 0) * rot;
|
||||
Vk.vkCmdPushConstants(cmd, _pipeline.PipelineLayout, VkShaderStageFlags.Vertex, 0, 64, &model1);
|
||||
Vk.vkCmdDrawIndexed(cmd, _indexCount, 1, 0, 0, 0);
|
||||
|
||||
var model2 = Matrix4x4.CreateTranslation(1.5f, 0, 0) * rot;
|
||||
Vk.vkCmdPushConstants(cmd, _pipeline.PipelineLayout, VkShaderStageFlags.Vertex, 0, 64, &model2);
|
||||
Vk.vkCmdDrawIndexed(cmd, _indexCount, 1, 0, 0, 0);
|
||||
|
||||
Vk.vkCmdEndRendering(cmd);
|
||||
|
||||
Reference in New Issue
Block a user