Code-Cleanup: All samples now use the camera class and it's matrices
Cleaned up base class
This commit is contained in:
parent
27d5abc038
commit
ab38f8b150
42 changed files with 234 additions and 396 deletions
|
|
@ -42,6 +42,8 @@ private:
|
|||
matrices.view = transM * rotM;
|
||||
}
|
||||
|
||||
viewPos = glm::vec4(position, 0.0f) * glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f);
|
||||
|
||||
updated = true;
|
||||
};
|
||||
public:
|
||||
|
|
@ -50,6 +52,7 @@ public:
|
|||
|
||||
glm::vec3 rotation = glm::vec3();
|
||||
glm::vec3 position = glm::vec3();
|
||||
glm::vec4 viewPos = glm::vec4();
|
||||
|
||||
float rotationSpeed = 1.0f;
|
||||
float movementSpeed = 1.0f;
|
||||
|
|
@ -113,7 +116,7 @@ public:
|
|||
{
|
||||
this->rotation = rotation;
|
||||
updateViewMatrix();
|
||||
};
|
||||
}
|
||||
|
||||
void rotate(glm::vec3 delta)
|
||||
{
|
||||
|
|
@ -133,6 +136,16 @@ public:
|
|||
updateViewMatrix();
|
||||
}
|
||||
|
||||
void setRotationSpeed(float rotationSpeed)
|
||||
{
|
||||
this->rotationSpeed = rotationSpeed;
|
||||
}
|
||||
|
||||
void setMovementSpeed(float movementSpeed)
|
||||
{
|
||||
this->movementSpeed = movementSpeed;
|
||||
}
|
||||
|
||||
void update(float deltaTime)
|
||||
{
|
||||
updated = false;
|
||||
|
|
|
|||
|
|
@ -336,20 +336,18 @@ void VulkanExampleBase::renderLoop()
|
|||
// Rotate
|
||||
if (std::abs(gamePadState.axisLeft.x) > deadZone)
|
||||
{
|
||||
rotation.y += gamePadState.axisLeft.x * 0.5f * rotationSpeed;
|
||||
camera.rotate(glm::vec3(0.0f, gamePadState.axisLeft.x * 0.5f, 0.0f));
|
||||
updateView = true;
|
||||
}
|
||||
if (std::abs(gamePadState.axisLeft.y) > deadZone)
|
||||
{
|
||||
rotation.x -= gamePadState.axisLeft.y * 0.5f * rotationSpeed;
|
||||
camera.rotate(glm::vec3(gamePadState.axisLeft.y * 0.5f, 0.0f, 0.0f));
|
||||
updateView = true;
|
||||
}
|
||||
// Zoom
|
||||
if (std::abs(gamePadState.axisRight.y) > deadZone)
|
||||
{
|
||||
zoom -= gamePadState.axisRight.y * 0.01f * zoomSpeed;
|
||||
camera.translate(glm::vec3(0.0f, 0.0f, gamePadState.axisRight.y * 0.01f));
|
||||
updateView = true;
|
||||
}
|
||||
if (updateView)
|
||||
|
|
@ -1180,8 +1178,7 @@ void VulkanExampleBase::handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
|
|||
case WM_MOUSEWHEEL:
|
||||
{
|
||||
short wheelDelta = GET_WHEEL_DELTA_WPARAM(wParam);
|
||||
zoom += (float)wheelDelta * 0.005f * zoomSpeed;
|
||||
camera.translate(glm::vec3(0.0f, 0.0f, (float)wheelDelta * 0.005f * zoomSpeed));
|
||||
camera.translate(glm::vec3(0.0f, 0.0f, (float)wheelDelta * 0.005f));
|
||||
viewUpdated = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1292,15 +1289,12 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
|
|||
int32_t eventX = AMotionEvent_getX(event, 0);
|
||||
int32_t eventY = AMotionEvent_getY(event, 0);
|
||||
|
||||
float deltaX = (float)(vulkanExample->touchPos.y - eventY) * vulkanExample->rotationSpeed * 0.5f;
|
||||
float deltaY = (float)(vulkanExample->touchPos.x - eventX) * vulkanExample->rotationSpeed * 0.5f;
|
||||
float deltaX = (float)(vulkanExample->touchPos.y - eventY) * vulkanExample->camera.rotationSpeed * 0.5f;
|
||||
float deltaY = (float)(vulkanExample->touchPos.x - eventX) * vulkanExample->camera.rotationSpeed * 0.5f;
|
||||
|
||||
vulkanExample->camera.rotate(glm::vec3(deltaX, 0.0f, 0.0f));
|
||||
vulkanExample->camera.rotate(glm::vec3(0.0f, -deltaY, 0.0f));
|
||||
|
||||
vulkanExample->rotation.x += deltaX;
|
||||
vulkanExample->rotation.y -= deltaY;
|
||||
|
||||
vulkanExample->viewChanged();
|
||||
|
||||
vulkanExample->touchPos.x = eventX;
|
||||
|
|
@ -1494,8 +1488,7 @@ void VulkanExampleBase::pointerAxis(wl_pointer *pointer, uint32_t time,
|
|||
switch (axis)
|
||||
{
|
||||
case REL_X:
|
||||
zoom += d * 0.005f * zoomSpeed;
|
||||
camera.translate(glm::vec3(0.0f, 0.0f, d * 0.005f * zoomSpeed));
|
||||
camera.translate(glm::vec3(0.0f, 0.0f, d * 0.005f));
|
||||
viewUpdated = true;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -2184,19 +2177,14 @@ void VulkanExampleBase::handleMouseMove(int32_t x, int32_t y)
|
|||
}
|
||||
|
||||
if (mouseButtons.left) {
|
||||
rotation.x += dy * 1.25f * rotationSpeed;
|
||||
rotation.y -= dx * 1.25f * rotationSpeed;
|
||||
camera.rotate(glm::vec3(dy * camera.rotationSpeed, -dx * camera.rotationSpeed, 0.0f));
|
||||
viewUpdated = true;
|
||||
}
|
||||
if (mouseButtons.right) {
|
||||
zoom += dy * .005f * zoomSpeed;
|
||||
camera.translate(glm::vec3(-0.0f, 0.0f, dy * .005f * zoomSpeed));
|
||||
camera.translate(glm::vec3(-0.0f, 0.0f, dy * .005f));
|
||||
viewUpdated = true;
|
||||
}
|
||||
if (mouseButtons.middle) {
|
||||
cameraPos.x -= dx * 0.01f;
|
||||
cameraPos.y -= dy * 0.01f;
|
||||
camera.translate(glm::vec3(-dx * 0.01f, -dy * 0.01f, 0.0f));
|
||||
viewUpdated = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,8 +160,6 @@ public:
|
|||
|
||||
VkClearColorValue defaultClearColor = { { 0.025f, 0.025f, 0.025f, 1.0f } };
|
||||
|
||||
float zoom = 0;
|
||||
|
||||
static std::vector<const char*> args;
|
||||
|
||||
// Defines a frame rate independent timer value clamped from -1.0...1.0
|
||||
|
|
@ -169,18 +167,9 @@ public:
|
|||
float timer = 0.0f;
|
||||
// Multiplier for speeding up (or slowing down) the global timer
|
||||
float timerSpeed = 0.25f;
|
||||
|
||||
bool paused = false;
|
||||
|
||||
// Use to adjust mouse rotation speed
|
||||
float rotationSpeed = 1.0f;
|
||||
// Use to adjust mouse zoom speed
|
||||
float zoomSpeed = 1.0f;
|
||||
|
||||
Camera camera;
|
||||
|
||||
glm::vec3 rotation = glm::vec3();
|
||||
glm::vec3 cameraPos = glm::vec3();
|
||||
glm::vec2 mousePos;
|
||||
|
||||
std::string title = "Vulkan Example";
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -6,6 +6,7 @@ layout (location = 1) in vec2 inUV;
|
|||
layout (binding = 0) uniform UBO
|
||||
{
|
||||
mat4 projection;
|
||||
mat4 view;
|
||||
mat4 model;
|
||||
} ubo;
|
||||
|
||||
|
|
@ -15,6 +16,6 @@ layout (location = 1) out vec4 outPos;
|
|||
void main()
|
||||
{
|
||||
outUV = inUV;
|
||||
outPos = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
|
||||
outPos = ubo.projection * ubo.view * ubo.model * vec4(inPos.xyz, 1.0);
|
||||
gl_Position = outPos;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -7,6 +7,7 @@ layout (location = 3) in vec3 inNormal;
|
|||
layout (binding = 0) uniform UBO
|
||||
{
|
||||
mat4 projection;
|
||||
mat4 view;
|
||||
mat4 model;
|
||||
vec4 lightPos;
|
||||
} ubo;
|
||||
|
|
@ -20,8 +21,8 @@ void main()
|
|||
{
|
||||
outNormal = inNormal;
|
||||
outColor = inColor;
|
||||
gl_Position = ubo.projection * ubo.model * inPos;
|
||||
outEyePos = vec3(ubo.model * inPos);
|
||||
gl_Position = ubo.projection * ubo.view * ubo.model * inPos;
|
||||
outEyePos = vec3(ubo.view * ubo.model * inPos);
|
||||
outLightVec = normalize(ubo.lightPos.xyz - outEyePos);
|
||||
|
||||
// Clip against reflection plane
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -721,7 +721,7 @@ public:
|
|||
ubos.scene.projection = camera.matrices.perspective;
|
||||
ubos.scene.view = camera.matrices.view;
|
||||
|
||||
ubos.scene.model = glm::translate(glm::mat4(1.0f), glm::vec3(sin(glm::radians(timer * 360.0f)) * 0.25f, -1.0f, cos(glm::radians(timer * 360.0f)) * 0.25f) + cameraPos);
|
||||
ubos.scene.model = glm::translate(glm::mat4(1.0f), glm::vec3(sin(glm::radians(timer * 360.0f)) * 0.25f, -1.0f, cos(glm::radians(timer * 360.0f)) * 0.25f));
|
||||
ubos.scene.model = glm::rotate(ubos.scene.model, -sinf(glm::radians(timer * 360.0f)) * 0.15f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
ubos.scene.model = glm::rotate(ubos.scene.model, glm::radians(timer * 360.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public:
|
|||
|
||||
struct {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
} uboVS;
|
||||
|
||||
int vertexBufferSize;
|
||||
|
|
@ -83,8 +83,11 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -2.0f;
|
||||
title = "Compute shader image load/store";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -2.0f));
|
||||
camera.setRotation(glm::vec3(0.0f));
|
||||
camera.setPerspective(60.0f, (float)width * 0.5f / (float)height, 1.0f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -613,15 +616,8 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
// Vertex shader uniform buffer block
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width*0.5f / (float)height, 0.1f, 256.0f);
|
||||
glm::mat4 viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
uboVS.model = viewMatrix * glm::translate(glm::mat4(1.0f), cameraPos);
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
memcpy(uniformBufferVS.mapped, &uboVS, sizeof(uboVS));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public:
|
|||
|
||||
struct UBOTessEval {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
glm::vec4 lightPos = glm::vec4(0.0f, -1.0f, 0.0f, 0.0f);
|
||||
float tessAlpha = 1.0f;
|
||||
float tessStrength = 0.1f;
|
||||
|
|
@ -80,9 +80,11 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -1.25f;
|
||||
rotation = glm::vec3(-20.0f, 45.0f, 0.0f);
|
||||
title = "Tessellation shader displacement";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -1.25f));
|
||||
camera.setRotation(glm::vec3(-20.0f, 45.0f, 0.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -445,19 +447,9 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
// Tessellation eval
|
||||
glm::mat4 viewMatrix = glm::mat4(1.0f);
|
||||
uboTessEval.projection = glm::perspective(glm::radians(45.0f), (float)(width) / (float)height, 0.1f, 256.0f);
|
||||
viewMatrix = glm::translate(viewMatrix, glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
uboTessEval.model = glm::mat4(1.0f);
|
||||
uboTessEval.model = viewMatrix * glm::translate(uboTessEval.model, glm::vec3(0, 0, 0));
|
||||
uboTessEval.model = glm::rotate(uboTessEval.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboTessEval.model = glm::rotate(uboTessEval.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboTessEval.model = glm::rotate(uboTessEval.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboTessEval.projection = camera.matrices.perspective;
|
||||
uboTessEval.modelView = camera.matrices.view;
|
||||
uboTessEval.lightPos.y = -0.5f - uboTessEval.tessStrength;
|
||||
|
||||
memcpy(uniformBuffers.tessEval.mapped, &uboTessEval, sizeof(uboTessEval));
|
||||
|
||||
// Tessellation control
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public:
|
|||
|
||||
struct UBOVS {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
} uboVS;
|
||||
|
||||
struct UBOFS {
|
||||
|
|
@ -111,8 +111,11 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -2.0f;
|
||||
title = "Distance field font rendering";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -2.0f));
|
||||
camera.setRotation(glm::vec3(0.0f));
|
||||
camera.setPerspective(splitScreen ? 30.0f : 45.0f, (float)width / (float)(height * ((splitScreen) ? 0.5f : 1.0f)), 1.0f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -606,17 +609,8 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
// Vertex shader
|
||||
glm::mat4 viewMatrix = glm::mat4(1.0f);
|
||||
uboVS.projection = glm::perspective(glm::radians(splitScreen ? 30.0f : 45.0f), (float)width / (float)(height * ((splitScreen) ? 0.5f : 1.0f)), 0.001f, 256.0f);
|
||||
viewMatrix = glm::translate(viewMatrix, glm::vec3(0.0f, 0.0f, splitScreen ? zoom : zoom - 2.0f));
|
||||
|
||||
uboVS.model = glm::mat4(1.0f);
|
||||
uboVS.model = viewMatrix * glm::translate(uboVS.model, cameraPos);
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
memcpy(uniformBuffers.vs.mapped, &uboVS, sizeof(uboVS));
|
||||
}
|
||||
|
||||
|
|
@ -677,6 +671,7 @@ public:
|
|||
updateFontSettings();
|
||||
}
|
||||
if (overlay->checkBox("Splitscreen", &splitScreen)) {
|
||||
camera.setPerspective(splitScreen ? 30.0f : 45.0f, (float)width / (float)(height * ((splitScreen) ? 0.5f : 1.0f)), 1.0f, 256.0f);
|
||||
buildCommandBuffers();
|
||||
updateUniformBuffers();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,10 +44,12 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -16.0f;
|
||||
rotation = glm::vec3(-23.75f, 41.25f, 21.0f);
|
||||
title = "Vulkan gears";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 2.5f, -16.0f));
|
||||
camera.setRotation(glm::vec3(-23.75f, 41.25f, 21.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.001f, 256.0f);
|
||||
timerSpeed *= 0.25f;
|
||||
title = "Rotating gears";
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -321,10 +323,9 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
glm::mat4 perspective = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.001f, 256.0f);
|
||||
for (auto& gear : gears)
|
||||
{
|
||||
gear->updateUniformBuffer(perspective, rotation, zoom, timer * 360.0f);
|
||||
gear->updateUniformBuffer(camera.matrices.perspective, camera.matrices.view, timer * 360.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -265,29 +265,17 @@ void VulkanGear::draw(VkCommandBuffer cmdbuffer, VkPipelineLayout pipelineLayout
|
|||
vkCmdDrawIndexed(cmdbuffer, indexCount, 1, 0, 0, 1);
|
||||
}
|
||||
|
||||
void VulkanGear::updateUniformBuffer(glm::mat4 perspective, glm::vec3 rotation, float zoom, float timer)
|
||||
void VulkanGear::updateUniformBuffer(glm::mat4 perspective, glm::mat4 view, float timer)
|
||||
{
|
||||
ubo.projection = perspective;
|
||||
|
||||
ubo.view = glm::lookAt(
|
||||
glm::vec3(0, 0, -zoom),
|
||||
glm::vec3(-1.0, -1.5, 0),
|
||||
glm::vec3(0, 1, 0)
|
||||
);
|
||||
ubo.view = glm::rotate(ubo.view, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
ubo.view = glm::rotate(ubo.view, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
ubo.view = view;
|
||||
ubo.model = glm::mat4(1.0f);
|
||||
ubo.model = glm::translate(ubo.model, pos);
|
||||
rotation.z = (rotSpeed * timer) + rotOffset;
|
||||
ubo.model = glm::rotate(ubo.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
ubo.model = glm::rotate(ubo.model, glm::radians((rotSpeed * timer) + rotOffset), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
ubo.normal = glm::inverseTranspose(ubo.view * ubo.model);
|
||||
|
||||
ubo.lightPos = glm::vec3(0.0f, 0.0f, 2.5f);
|
||||
ubo.lightPos.x = sin(glm::radians(timer)) * 8.0f;
|
||||
ubo.lightPos.z = cos(glm::radians(timer)) * 8.0f;
|
||||
|
||||
memcpy(uniformBuffer.mapped, &ubo, sizeof(ubo));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
#include <glm/gtc/matrix_inverse.hpp>
|
||||
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
#include "VulkanTools.h"
|
||||
#include "VulkanDevice.hpp"
|
||||
#include "VulkanBuffer.hpp"
|
||||
|
|
@ -92,7 +91,7 @@ public:
|
|||
VkDescriptorSet descriptorSet;
|
||||
|
||||
void draw(VkCommandBuffer cmdbuffer, VkPipelineLayout pipelineLayout);
|
||||
void updateUniformBuffer(glm::mat4 perspective, glm::vec3 rotation, float zoom, float timer);
|
||||
void updateUniformBuffer(glm::mat4 perspective, glm::mat4 view, float timer);
|
||||
|
||||
void setupDescriptorSet(VkDescriptorPool pool, VkDescriptorSetLayout descriptorSetLayout);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,12 +48,12 @@ public:
|
|||
|
||||
struct {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
} uboVS;
|
||||
|
||||
struct {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
glm::vec2 viewportDim;
|
||||
} uboGS;
|
||||
|
||||
|
|
@ -73,9 +73,11 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -8.0f;
|
||||
rotation = glm::vec3(0.0f, -25.0f, 0.0f);
|
||||
title = "Geometry shader normal debugging";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -8.0f));
|
||||
camera.setRotation(glm::vec3(0.0f, -25.0f, 0.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 1.0f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -409,17 +411,12 @@ public:
|
|||
void updateUniformBuffers()
|
||||
{
|
||||
// Vertex shader
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.001f, 256.0f);
|
||||
glm::mat4 viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
uboVS.model = viewMatrix * glm::translate(glm::mat4(1.0f), cameraPos);
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
memcpy(uniformBuffers.VS.mapped, &uboVS, sizeof(uboVS));
|
||||
|
||||
// Geometry shader
|
||||
uboGS.model = uboVS.model;
|
||||
uboGS.projection = uboVS.projection;
|
||||
uboGS.projection = camera.matrices.perspective;
|
||||
uboGS.modelView = camera.matrices.view;
|
||||
uboGS.viewportDim = glm::vec2(width, height);
|
||||
memcpy(uniformBuffers.GS.mapped, &uboGS, sizeof(uboGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,10 +98,10 @@ public:
|
|||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
title = "Instanced mesh rendering";
|
||||
zoom = -18.5f;
|
||||
rotation = { -17.2f, -4.7f, 0.0f };
|
||||
cameraPos = { 5.5f, -1.85f, 0.0f };
|
||||
rotationSpeed = 0.25f;
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(5.5f, -1.85f, -18.5f));
|
||||
camera.setRotation(glm::vec3(-17.2f, -4.7f, 0.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 1.0f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -544,11 +544,8 @@ public:
|
|||
{
|
||||
if (viewChanged)
|
||||
{
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.1f, 256.0f);
|
||||
uboVS.view = glm::translate(glm::mat4(1.0f), cameraPos + glm::vec3(0.0f, 0.0f, zoom));
|
||||
uboVS.view = glm::rotate(uboVS.view, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.view = glm::rotate(uboVS.view, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.view = glm::rotate(uboVS.view, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.view = camera.matrices.view;
|
||||
}
|
||||
|
||||
if (!paused)
|
||||
|
|
|
|||
|
|
@ -122,11 +122,12 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -32.5f;
|
||||
zoomSpeed = 2.5f;
|
||||
rotationSpeed = 0.5f;
|
||||
rotation = { 0.0f, 37.5f, 0.0f };
|
||||
title = "Multi threaded command buffer";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, -0.0f, -32.5f));
|
||||
camera.setRotation(glm::vec3(0.0f));
|
||||
camera.setRotationSpeed(0.5f);
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||
settings.overlay = true;
|
||||
// Get number of max. concurrrent threads
|
||||
numThreads = std::thread::hardware_concurrency();
|
||||
|
|
@ -319,12 +320,8 @@ public:
|
|||
|
||||
vkCmdBindPipeline(secondaryCommandBuffers.background, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.starsphere);
|
||||
|
||||
glm::mat4 view = glm::mat4(1.0f);
|
||||
view = glm::rotate(view, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
view = glm::rotate(view, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
view = glm::rotate(view, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
glm::mat4 mvp = matrices.projection * view;
|
||||
glm::mat4 mvp = matrices.projection * matrices.view;
|
||||
mvp[3] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
vkCmdPushConstants(
|
||||
secondaryCommandBuffers.background,
|
||||
|
|
@ -564,12 +561,8 @@ public:
|
|||
|
||||
void updateMatrices()
|
||||
{
|
||||
matrices.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.1f, 256.0f);
|
||||
matrices.view = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
matrices.view = glm::rotate(matrices.view, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
matrices.view = glm::rotate(matrices.view, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
matrices.view = glm::rotate(matrices.view, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
matrices.projection = camera.matrices.perspective;
|
||||
matrices.view = camera.matrices.view;
|
||||
frustum.update(matrices.projection * matrices.view);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -634,9 +634,9 @@ public:
|
|||
float bottom = -wd2;
|
||||
|
||||
glm::vec3 camFront;
|
||||
camFront.x = -cos(glm::radians(rotation.x)) * sin(glm::radians(rotation.y));
|
||||
camFront.y = sin(glm::radians(rotation.x));
|
||||
camFront.z = cos(glm::radians(rotation.x)) * cos(glm::radians(rotation.y));
|
||||
camFront.x = -cos(glm::radians(camera.rotation.x)) * sin(glm::radians(camera.rotation.y));
|
||||
camFront.y = sin(glm::radians(camera.rotation.x));
|
||||
camFront.z = cos(glm::radians(camera.rotation.x)) * cos(glm::radians(camera.rotation.y));
|
||||
camFront = glm::normalize(camFront);
|
||||
glm::vec3 camRight = glm::normalize(glm::cross(camFront, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public:
|
|||
|
||||
struct UBOVS {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
glm::vec4 lightPos = glm::vec4(10.0f, 10.0f, 10.0f, 1.0f);
|
||||
float visible;
|
||||
} uboVS;
|
||||
|
|
@ -84,11 +84,12 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -35.0f;
|
||||
zoomSpeed = 2.5f;
|
||||
rotationSpeed = 0.5f;
|
||||
rotation = { 0.0, -123.75, 0.0 };
|
||||
title = "Occlusion queries";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -35.0f));
|
||||
camera.setRotation(glm::vec3(0.0f, -123.75f, 0.0f));
|
||||
camera.setRotationSpeed(0.5f);
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 1.0f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -543,19 +544,10 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
// Vertex shader
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.1f, 256.0f);
|
||||
glm::mat4 viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
glm::mat4 rotMatrix = glm::mat4(1.0f);
|
||||
rotMatrix = glm::rotate(rotMatrix, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
rotMatrix = glm::rotate(rotMatrix, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
rotMatrix = glm::rotate(rotMatrix, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVS.model = viewMatrix * rotMatrix;
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
|
||||
uint8_t *pData;
|
||||
|
||||
// Occluder
|
||||
uboVS.visible = 1.0f;
|
||||
memcpy(uniformBuffers.occluder.mapped, &uboVS, sizeof(uboVS));
|
||||
|
|
@ -563,13 +555,13 @@ public:
|
|||
// Teapot
|
||||
// Toggle color depending on visibility
|
||||
uboVS.visible = (passedSamples[0] > 0) ? 1.0f : 0.0f;
|
||||
uboVS.model = viewMatrix * rotMatrix * glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -10.0f));
|
||||
uboVS.modelView = camera.matrices.view * glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -10.0f));
|
||||
memcpy(uniformBuffers.teapot.mapped, &uboVS, sizeof(uboVS));
|
||||
|
||||
// Sphere
|
||||
// Toggle color depending on visibility
|
||||
uboVS.visible = (passedSamples[1] > 0) ? 1.0f : 0.0f;
|
||||
uboVS.model = viewMatrix * rotMatrix * glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 10.0f));
|
||||
uboVS.modelView = camera.matrices.view * glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 10.0f));
|
||||
memcpy(uniformBuffers.sphere.mapped, &uboVS, sizeof(uboVS));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ public:
|
|||
|
||||
struct UBO {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 view;
|
||||
glm::mat4 model;
|
||||
glm::vec4 lightPos = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
} uboShared;
|
||||
|
|
@ -99,16 +100,18 @@ public:
|
|||
VkDescriptorImageInfo descriptor;
|
||||
} offscreenPass;
|
||||
|
||||
glm::vec3 meshPos = glm::vec3(0.0f, -1.5f, 0.0f);
|
||||
glm::vec3 meshRot = glm::vec3(0.0f);
|
||||
glm::vec3 modelPosition = glm::vec3(0.0f, -1.5f, 0.0f);
|
||||
glm::vec3 modelRotation = glm::vec3(0.0f);
|
||||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -6.0f;
|
||||
rotation = { -2.5f, 0.0f, 0.0f };
|
||||
cameraPos = { 0.0f, 1.0f, 0.0f };
|
||||
timerSpeed *= 0.25f;
|
||||
title = "Offscreen rendering";
|
||||
timerSpeed *= 0.25f;
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 1.0f, -6.0f));
|
||||
camera.setRotation(glm::vec3(-2.5f, 0.0f, 0.0f));
|
||||
camera.setRotationSpeed(0.5f);
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||
settings.overlay = true;
|
||||
// The scene shader uses a clipping plane, so this feature has to be enabled
|
||||
enabledFeatures.shaderClipDistance = VK_TRUE;
|
||||
|
|
@ -777,47 +780,34 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
// Mesh
|
||||
uboShared.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.1f, 256.0f);
|
||||
glm::mat4 viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
uboShared.model = viewMatrix * glm::translate(glm::mat4(1.0f), cameraPos);
|
||||
uboShared.model = glm::rotate(uboShared.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboShared.model = glm::rotate(uboShared.model, glm::radians(rotation.y + meshRot.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboShared.model = glm::rotate(uboShared.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboShared.model = glm::translate(uboShared.model, meshPos);
|
||||
uboShared.projection = camera.matrices.perspective;
|
||||
uboShared.view = camera.matrices.view;
|
||||
|
||||
// Model
|
||||
uboShared.model = glm::mat4(1.0f);
|
||||
uboShared.model = glm::rotate(uboShared.model, glm::radians(modelRotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboShared.model = glm::translate(uboShared.model, modelPosition);
|
||||
memcpy(uniformBuffers.vsShared.mapped, &uboShared, sizeof(uboShared));
|
||||
|
||||
// Mirror
|
||||
uboShared.model = viewMatrix * glm::translate(glm::mat4(1.0f), cameraPos);
|
||||
uboShared.model = glm::rotate(uboShared.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboShared.model = glm::rotate(uboShared.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboShared.model = glm::rotate(uboShared.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboShared.model = glm::mat4(1.0f);
|
||||
memcpy(uniformBuffers.vsMirror.mapped, &uboShared, sizeof(uboShared));
|
||||
|
||||
// Debug quad
|
||||
// @todo: Full screen triangle in VS
|
||||
uboShared.projection = glm::ortho(4.0f, 0.0f, 0.0f, 4.0f*(float)height / (float)width, -1.0f, 1.0f);
|
||||
uboShared.model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
|
||||
memcpy(uniformBuffers.vsDebugQuad.mapped, &uboShared, sizeof(uboShared));
|
||||
}
|
||||
|
||||
void updateUniformBufferOffscreen()
|
||||
{
|
||||
uboShared.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.1f, 256.0f);
|
||||
glm::mat4 viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
uboShared.model = viewMatrix * glm::translate(glm::mat4(1.0f), cameraPos);
|
||||
uboShared.model = glm::rotate(uboShared.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboShared.model = glm::rotate(uboShared.model, glm::radians(rotation.y + meshRot.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboShared.model = glm::rotate(uboShared.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboShared.projection = camera.matrices.perspective;
|
||||
uboShared.view = camera.matrices.view;
|
||||
uboShared.model = glm::mat4(1.0f);
|
||||
uboShared.model = glm::rotate(uboShared.model, glm::radians(modelRotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboShared.model = glm::scale(uboShared.model, glm::vec3(1.0f, -1.0f, 1.0f));
|
||||
uboShared.model = glm::translate(uboShared.model, meshPos);
|
||||
|
||||
uboShared.model = glm::translate(uboShared.model, modelPosition);
|
||||
memcpy(uniformBuffers.vsOffScreen.mapped, &uboShared, sizeof(uboShared));
|
||||
}
|
||||
|
||||
|
|
@ -857,7 +847,7 @@ public:
|
|||
draw();
|
||||
if (!paused)
|
||||
{
|
||||
meshRot.y += frameTimer * 10.0f;
|
||||
modelRotation.y += frameTimer * 10.0f;
|
||||
updateUniformBuffers();
|
||||
updateUniformBufferOffscreen();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,14 +96,14 @@ public:
|
|||
|
||||
struct UBOVS {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
glm::vec2 viewportDim;
|
||||
float pointSize = PARTICLE_SIZE;
|
||||
} uboVS;
|
||||
|
||||
struct UBOEnv {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
glm::mat4 normal;
|
||||
glm::vec4 lightPos = glm::vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
} uboEnv;
|
||||
|
|
@ -127,11 +127,12 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -75.0f;
|
||||
rotation = { -15.0f, 45.0f, 0.0f };
|
||||
title = "CPU based particle system";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -75.0f));
|
||||
camera.setRotation(glm::vec3(-15.0f, 45.0f, 0.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 1.0f, 256.0f);
|
||||
settings.overlay = true;
|
||||
zoomSpeed *= 1.5f;
|
||||
timerSpeed *= 8.0f;
|
||||
rndEngine.seed(benchmark.active ? 0 : (unsigned)time(nullptr));
|
||||
}
|
||||
|
|
@ -697,24 +698,16 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
// Vertex shader
|
||||
glm::mat4 viewMatrix = glm::mat4(1.0f);
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.001f, 256.0f);
|
||||
viewMatrix = glm::translate(viewMatrix, glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
uboVS.model = glm::mat4(1.0f);
|
||||
uboVS.model = viewMatrix * glm::translate(uboVS.model, glm::vec3(0.0f, 15.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
// Particle system fire
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
uboVS.viewportDim = glm::vec2((float)width, (float)height);
|
||||
memcpy(uniformBuffers.fire.mapped, &uboVS, sizeof(uboVS));
|
||||
|
||||
// Environment
|
||||
uboEnv.projection = uboVS.projection;
|
||||
uboEnv.model = uboVS.model;
|
||||
uboEnv.normal = glm::inverseTranspose(uboEnv.model);
|
||||
uboEnv.projection = camera.matrices.perspective;
|
||||
uboEnv.modelView = camera.matrices.view;
|
||||
uboEnv.normal = glm::inverseTranspose(uboEnv.modelView);
|
||||
memcpy(uniformBuffers.environment.mapped, &uboEnv, sizeof(uboEnv));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,9 +61,12 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -10.5f;
|
||||
rotation = glm::vec3(-25.0f, 15.0f, 0.0f);
|
||||
title = "Pipeline state objects";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -10.5f));
|
||||
camera.setRotation(glm::vec3(-25.0f, 15.0f, 0.0f));
|
||||
camera.setRotationSpeed(0.5f);
|
||||
camera.setPerspective(60.0f, (float)(width / 3.0f) / (float)height, 0.1f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -379,15 +382,8 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)(width / 3.0f) / (float)height, 0.1f, 256.0f);
|
||||
|
||||
glm::mat4 viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
uboVS.modelView = viewMatrix * glm::translate(glm::mat4(1.0f), cameraPos);
|
||||
uboVS.modelView = glm::rotate(uboVS.modelView, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.modelView = glm::rotate(uboVS.modelView, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.modelView = glm::rotate(uboVS.modelView, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
memcpy(uniformBuffer.mapped, &uboVS, sizeof(uboVS));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
struct UBOVS {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
glm::vec4 lightPos = glm::vec4(0.0, 0.0, -2.0, 1.0);
|
||||
} uboVS;
|
||||
|
||||
|
|
@ -68,12 +68,13 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -30.0;
|
||||
zoomSpeed = 2.5f;
|
||||
rotationSpeed = 0.5f;
|
||||
timerSpeed *= 0.5f;
|
||||
rotation = { -32.5, 45.0, 0.0 };
|
||||
title = "Push constants";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -30.0f));
|
||||
camera.setRotation(glm::vec3(-32.5f, 45.0f, 0.0f));
|
||||
camera.setRotationSpeed(0.5f);
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 1.0f, 256.0f);
|
||||
timerSpeed *= 0.5f;
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -394,16 +395,8 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
// Vertex shader
|
||||
glm::mat4 viewMatrix = glm::mat4(1.0f);
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.001f, 256.0f);
|
||||
viewMatrix = glm::translate(viewMatrix, glm::vec3(0.0f, 2.0f, zoom));
|
||||
|
||||
uboVS.model = viewMatrix * glm::translate(glm::mat4(1.0f), glm::vec3(0, 0, 0));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
memcpy(uniformBuffer.mapped, &uboVS, sizeof(uboVS));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public:
|
|||
|
||||
struct UboVS {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
float gradientPos = 0.0f;
|
||||
} uboScene;
|
||||
|
||||
|
|
@ -107,10 +107,12 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -10.0f;
|
||||
rotation = { -16.25f, -28.75f, 0.0f };
|
||||
timerSpeed *= 0.5f;
|
||||
title = "Full screen radial blur effect";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -10.0f));
|
||||
camera.setRotation(glm::vec3(-16.25f, -28.75f, 0.0f));
|
||||
camera.setPerspective(45.0f, (float)width / (float)height, 1.0f, 256.0f);
|
||||
timerSpeed *= 0.5f;
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -615,15 +617,10 @@ public:
|
|||
void updateUniformBuffersScene()
|
||||
{
|
||||
uboScene.projection = glm::perspective(glm::radians(45.0f), (float)width / (float)height, 1.0f, 256.0f);
|
||||
glm::mat4 viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
uboScene.model = glm::mat4(1.0f);
|
||||
uboScene.model = viewMatrix * glm::translate(uboScene.model, cameraPos);
|
||||
uboScene.model = glm::rotate(uboScene.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboScene.model = glm::rotate(uboScene.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboScene.model = glm::rotate(uboScene.model, glm::radians(timer * 360.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboScene.model = glm::rotate(uboScene.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
camera.setRotation(camera.rotation + glm::vec3(0.0f, frameTimer * 10.0f, 0.0f));
|
||||
uboScene.projection = camera.matrices.perspective;
|
||||
uboScene.modelView = camera.matrices.view;
|
||||
// split into model view for separating rotation
|
||||
if (!paused)
|
||||
{
|
||||
uboScene.gradientPos += frameTimer * 0.1f;
|
||||
|
|
|
|||
|
|
@ -131,9 +131,11 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -20.0f;
|
||||
rotation = { -15.0f, -390.0f, 0.0f };
|
||||
title = "Projected shadow mapping";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, -0.0f, -20.0f));
|
||||
camera.setRotation(glm::vec3(-15.0f, -390.0f, 0.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 1.0f, 256.0f);
|
||||
timerSpeed *= 0.5f;
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
|
@ -689,26 +691,16 @@ public:
|
|||
{
|
||||
// Shadow map debug quad
|
||||
float AR = (float)height / (float)width;
|
||||
|
||||
uboVSquad.projection = glm::ortho(2.5f / AR, 0.0f, 0.0f, 2.5f, -1.0f, 1.0f);
|
||||
uboVSquad.model = glm::mat4(1.0f);
|
||||
|
||||
memcpy(uniformBuffers.debug.mapped, &uboVSquad, sizeof(uboVSquad));
|
||||
|
||||
// 3D scene
|
||||
uboVSscene.projection = glm::perspective(glm::radians(45.0f), (float)width / (float)height, zNear, zFar);
|
||||
|
||||
uboVSscene.view = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
uboVSscene.view = glm::rotate(uboVSscene.view, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVSscene.view = glm::rotate(uboVSscene.view, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVSscene.view = glm::rotate(uboVSscene.view, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVSscene.projection = camera.matrices.perspective;
|
||||
uboVSscene.view = camera.matrices.view;
|
||||
uboVSscene.model = glm::mat4(1.0f);
|
||||
|
||||
uboVSscene.lightPos = lightPos;
|
||||
|
||||
uboVSscene.depthBiasMVP = uboOffscreenVS.depthMVP;
|
||||
|
||||
memcpy(uniformBuffers.scene.mapped, &uboVSscene, sizeof(uboVSscene));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,11 +73,12 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -0.9f;
|
||||
rotationSpeed = 0.75f;
|
||||
zoomSpeed = 0.25f;
|
||||
rotation = glm::vec3(-25.0f, 23.75f, 0.0f);
|
||||
title = "Spherical Environment Mapping";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -0.9f));
|
||||
camera.setRotation(glm::vec3(-25.0f, 23.75f, 0.0f));
|
||||
camera.setRotationSpeed(0.75f);
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -371,21 +372,10 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
uboVS.projection = glm::perspective(glm::radians(45.0f), (float)width / (float)height, 0.1f, 256.0f);
|
||||
|
||||
uboVS.view = glm::lookAt(
|
||||
glm::vec3(0, 0, -zoom),
|
||||
glm::vec3(0, 0, 0),
|
||||
glm::vec3(0, 1, 0)
|
||||
);
|
||||
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.view = camera.matrices.view;
|
||||
uboVS.model = glm::mat4(1.0f);
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVS.normal = glm::inverseTranspose(uboVS.view * uboVS.model);
|
||||
|
||||
memcpy(uniformBuffer.mapped, &uboVS, sizeof(uboVS));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public:
|
|||
|
||||
struct UBOTessEval {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
float tessAlpha = 1.0f;
|
||||
} uboTessEval;
|
||||
|
||||
|
|
@ -83,10 +83,11 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -6.5f;
|
||||
rotation = glm::vec3(-350.0f, 60.0f, 0.0f);
|
||||
cameraPos = glm::vec3(-3.0f, 2.3f, 0.0f);
|
||||
title = "Tessellation shader (PN Triangles)";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(-3.0f, 2.3f, -6.5f));
|
||||
camera.setRotation(glm::vec3(-350.0f, 60.0f, 0.0f));
|
||||
camera.setPerspective(45.0f, (float)(width * ((splitScreen) ? 0.5f : 1.0f)) / (float)height, 0.1f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -453,20 +454,10 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
// Tessellation eval
|
||||
glm::mat4 viewMatrix = glm::mat4(1.0f);
|
||||
uboTessEval.projection = glm::perspective(glm::radians(45.0f), (float)(width* ((splitScreen) ? 0.5f : 1.0f)) / (float)height, 0.1f, 256.0f);
|
||||
viewMatrix = glm::translate(viewMatrix, glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
uboTessEval.model = glm::mat4(1.0f);
|
||||
uboTessEval.model = viewMatrix * glm::translate(uboTessEval.model, cameraPos);
|
||||
uboTessEval.model = glm::rotate(uboTessEval.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboTessEval.model = glm::rotate(uboTessEval.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboTessEval.model = glm::rotate(uboTessEval.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboTessEval.projection = camera.matrices.perspective;
|
||||
uboTessEval.modelView = camera.matrices.view;
|
||||
// Tessellation evaulation uniform block
|
||||
memcpy(uniformBuffers.tessEval.mapped, &uboTessEval, sizeof(uboTessEval));
|
||||
|
||||
// Tessellation control uniform block
|
||||
memcpy(uniformBuffers.tessControl.mapped, &uboTessControl, sizeof(uboTessControl));
|
||||
}
|
||||
|
|
@ -522,6 +513,7 @@ public:
|
|||
buildCommandBuffers();
|
||||
}
|
||||
if (overlay->checkBox("Splitscreen", &splitScreen)) {
|
||||
camera.setPerspective(45.0f, (float)(width * ((splitScreen) ? 0.5f : 1.0f)) / (float)height, 0.1f, 256.0f);
|
||||
updateUniformBuffers();
|
||||
buildCommandBuffers();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -649,7 +649,7 @@ public:
|
|||
|
||||
struct UBOVS {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
glm::vec4 lightPos = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
} uboVS;
|
||||
|
||||
|
|
@ -662,11 +662,11 @@ public:
|
|||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
title = "Vulkan Example - Text overlay";
|
||||
settings.overlay = false;
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -4.5f));
|
||||
camera.setRotation(glm::vec3(-25.0f, -0.0f, 0.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||
settings.overlay = false;
|
||||
}
|
||||
|
||||
~VulkanExample()
|
||||
|
|
@ -749,7 +749,7 @@ public:
|
|||
{
|
||||
std::stringstream vpos;
|
||||
vpos << std::showpos << x << "/" << y << "/" << z;
|
||||
glm::vec3 projected = glm::project(glm::vec3((float)x, (float)y, (float)z), uboVS.model, uboVS.projection, glm::vec4(0, 0, (float)width, (float)height));
|
||||
glm::vec3 projected = glm::project(glm::vec3((float)x, (float)y, (float)z), uboVS.modelView, uboVS.projection, glm::vec4(0, 0, (float)width, (float)height));
|
||||
textOverlay->addText(vpos.str(), projected.x, projected.y + (y > -1 ? 5.0f : -20.0f), TextOverlay::alignCenter);
|
||||
}
|
||||
}
|
||||
|
|
@ -762,11 +762,11 @@ public:
|
|||
{
|
||||
ss.str("");
|
||||
ss << std::fixed << std::setprecision(2) << std::showpos;
|
||||
ss << uboVS.model[0][i] << " " << uboVS.model[1][i] << " " << uboVS.model[2][i] << " " << uboVS.model[3][i];
|
||||
ss << uboVS.modelView[0][i] << " " << uboVS.modelView[1][i] << " " << uboVS.modelView[2][i] << " " << uboVS.modelView[3][i];
|
||||
textOverlay->addText(ss.str(), (float)width, 25.0f + (float)i * 20.0f, TextOverlay::alignRight);
|
||||
}
|
||||
|
||||
glm::vec3 projected = glm::project(glm::vec3(0.0f), uboVS.model, uboVS.projection, glm::vec4(0, 0, (float)width, (float)height));
|
||||
glm::vec3 projected = glm::project(glm::vec3(0.0f), uboVS.modelView, uboVS.projection, glm::vec4(0, 0, (float)width, (float)height));
|
||||
textOverlay->addText("Uniform cube", projected.x, projected.y, TextOverlay::alignCenter);
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
|
|
@ -888,10 +888,7 @@ public:
|
|||
void updateUniformBuffers()
|
||||
{
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.model = glm::rotate(glm::mat4(1.0f), glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
uboVS.model = camera.matrices.view * uboVS.model;
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
memcpy(uniformBuffer.mapped, &uboVS, sizeof(uboVS));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public:
|
|||
|
||||
struct {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
glm::vec4 viewPos;
|
||||
float lodBias = 0.0f;
|
||||
} uboVS;
|
||||
|
|
@ -77,9 +77,11 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -2.5f;
|
||||
rotation = { 0.0f, 15.0f, 0.0f };
|
||||
title = "Texture loading";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -2.5f));
|
||||
camera.setRotation(glm::vec3(0.0f, 15.0f, 0.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -772,26 +774,17 @@ public:
|
|||
&uniformBufferVS,
|
||||
sizeof(uboVS),
|
||||
&uboVS));
|
||||
VK_CHECK_RESULT(uniformBufferVS.map());
|
||||
|
||||
updateUniformBuffers();
|
||||
}
|
||||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
// Vertex shader
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.001f, 256.0f);
|
||||
glm::mat4 viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
uboVS.model = viewMatrix * glm::translate(glm::mat4(1.0f), cameraPos);
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVS.viewPos = glm::vec4(0.0f, 0.0f, -zoom, 0.0f);
|
||||
|
||||
VK_CHECK_RESULT(uniformBufferVS.map());
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
uboVS.viewPos = camera.viewPos;
|
||||
memcpy(uniformBufferVS.mapped, &uboVS, sizeof(uboVS));
|
||||
uniformBufferVS.unmap();
|
||||
}
|
||||
|
||||
void prepare()
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ public:
|
|||
|
||||
struct UboVS {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
glm::vec4 viewPos;
|
||||
float depth = 0.0f;
|
||||
} uboVS;
|
||||
|
|
@ -192,9 +192,11 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -2.5f;
|
||||
rotation = { 0.0f, 15.0f, 0.0f };
|
||||
title = "3D textures";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -2.5f));
|
||||
camera.setRotation(glm::vec3(0.0f, 15.0f, 0.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||
settings.overlay = true;
|
||||
srand((unsigned int)time(NULL));
|
||||
}
|
||||
|
|
@ -749,7 +751,7 @@ public:
|
|||
&uniformBufferVS,
|
||||
sizeof(uboVS),
|
||||
&uboVS));
|
||||
|
||||
VK_CHECK_RESULT(uniformBufferVS.map());
|
||||
updateUniformBuffers();
|
||||
}
|
||||
|
||||
|
|
@ -757,15 +759,9 @@ public:
|
|||
{
|
||||
if (viewchanged)
|
||||
{
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.001f, 256.0f);
|
||||
glm::mat4 viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
uboVS.model = viewMatrix * glm::translate(glm::mat4(1.0f), cameraPos);
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVS.viewPos = glm::vec4(0.0f, 0.0f, -zoom, 0.0f);
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
uboVS.viewPos = camera.viewPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -773,10 +769,7 @@ public:
|
|||
if (uboVS.depth > 1.0f)
|
||||
uboVS.depth = uboVS.depth - 1.0f;
|
||||
}
|
||||
|
||||
VK_CHECK_RESULT(uniformBufferVS.map());
|
||||
memcpy(uniformBufferVS.mapped, &uboVS, sizeof(uboVS));
|
||||
uniformBufferVS.unmap();
|
||||
}
|
||||
|
||||
void prepare()
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public:
|
|||
|
||||
struct UBOVS {
|
||||
glm::mat4 projection;
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelView;
|
||||
float lodBias = 0.0f;
|
||||
} uboVS;
|
||||
|
||||
|
|
@ -75,10 +75,12 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -4.0f;
|
||||
rotationSpeed = 0.25f;
|
||||
rotation = { -7.25f, -120.0f, 0.0f };
|
||||
title = "Cube map textures";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -4.0f));
|
||||
camera.setRotation(glm::vec3(-7.25f, -120.0f, 0.0f));
|
||||
camera.setRotationSpeed(0.25f);
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -642,39 +644,22 @@ public:
|
|||
void updateUniformBuffers()
|
||||
{
|
||||
// 3D object
|
||||
glm::mat4 viewMatrix = glm::mat4(1.0f);
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.001f, 256.0f);
|
||||
viewMatrix = glm::translate(viewMatrix, glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
uboVS.model = glm::mat4(1.0f);
|
||||
uboVS.model = viewMatrix * glm::translate(uboVS.model, cameraPos);
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
memcpy(uniformBuffers.object.mapped, &uboVS, sizeof(uboVS));
|
||||
|
||||
// Skybox
|
||||
viewMatrix = glm::mat4(1.0f);
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.001f, 256.0f);
|
||||
|
||||
uboVS.model = glm::mat4(1.0f);
|
||||
uboVS.model = viewMatrix * glm::translate(uboVS.model, glm::vec3(0, 0, 0));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVS.modelView = camera.matrices.view;
|
||||
// Cancel out translation
|
||||
uboVS.modelView[3] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
memcpy(uniformBuffers.skybox.mapped, &uboVS, sizeof(uboVS));
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
VulkanExampleBase::prepareFrame();
|
||||
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
||||
|
||||
VulkanExampleBase::submitFrame();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -113,8 +113,12 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -2.5f;
|
||||
title = "Vulkan Example - Basic indexed triangle";
|
||||
// Setup a default look-at camera
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -2.5f));
|
||||
camera.setRotation(glm::vec3(0.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 1.0f, 256.0f);
|
||||
// Values not set here are initialized in the base class constructor
|
||||
}
|
||||
|
||||
|
|
@ -1048,15 +1052,10 @@ public:
|
|||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
// Update matrices
|
||||
uboVS.projectionMatrix = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.1f, 256.0f);
|
||||
|
||||
uboVS.viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
|
||||
|
||||
// Pass matrices to the shaders
|
||||
uboVS.projectionMatrix = camera.matrices.perspective;
|
||||
uboVS.viewMatrix = camera.matrices.view;
|
||||
uboVS.modelMatrix = glm::mat4(1.0f);
|
||||
uboVS.modelMatrix = glm::rotate(uboVS.modelMatrix, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.modelMatrix = glm::rotate(uboVS.modelMatrix, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.modelMatrix = glm::rotate(uboVS.modelMatrix, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
// Map uniform buffer and update it
|
||||
uint8_t *pData;
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public:
|
|||
camera.type = Camera::CameraType::firstperson;
|
||||
camera.setRotation(glm::vec3(0.0f, 90.0f, 0.0f));
|
||||
camera.setTranslation(glm::vec3(7.0f, 3.2f, 0.0f));
|
||||
camera.movementSpeed = 5.0f;
|
||||
camera.setMovementSpeed(5.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -312,9 +312,9 @@ public:
|
|||
float bottom = -wd2;
|
||||
|
||||
glm::vec3 camFront;
|
||||
camFront.x = -cos(glm::radians(rotation.x)) * sin(glm::radians(rotation.y));
|
||||
camFront.y = sin(glm::radians(rotation.x));
|
||||
camFront.z = cos(glm::radians(rotation.x)) * cos(glm::radians(rotation.y));
|
||||
camFront.x = -cos(glm::radians(camera.rotation.x)) * sin(glm::radians(camera.rotation.y));
|
||||
camFront.y = sin(glm::radians(camera.rotation.x));
|
||||
camFront.z = cos(glm::radians(camera.rotation.x)) * cos(glm::radians(camera.rotation.y));
|
||||
camFront = glm::normalize(camFront);
|
||||
glm::vec3 camRight = glm::normalize(glm::cross(camFront, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
|
||||
|
|
|
|||
|
|
@ -90,10 +90,12 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
zoom = -3.75f;
|
||||
rotationSpeed = 0.5f;
|
||||
rotation = glm::vec3(15.0f, 0.f, 0.0f);
|
||||
title = "Vulkan Demo Scene - (c) 2016 by Sascha Willems";
|
||||
title = "Vulkan Demo Scene - (c) by Sascha Willems";
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -3.75f));
|
||||
camera.setRotation(glm::vec3(15.0f, 0.0f, 0.0f));
|
||||
camera.setRotationSpeed(0.5f);
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||
settings.overlay = true;
|
||||
}
|
||||
|
||||
|
|
@ -381,42 +383,26 @@ public:
|
|||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||
&uniformData.meshVS,
|
||||
sizeof(uboVS));
|
||||
|
||||
VK_CHECK_RESULT(uniformData.meshVS.map());
|
||||
updateUniformBuffers();
|
||||
}
|
||||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.1f, 256.0f);
|
||||
|
||||
uboVS.view = glm::lookAt(
|
||||
glm::vec3(0, 0, -zoom),
|
||||
cameraPos,
|
||||
glm::vec3(0, 1, 0)
|
||||
);
|
||||
|
||||
uboVS.projection = camera.matrices.perspective;
|
||||
uboVS.view = camera.matrices.view;
|
||||
uboVS.model = glm::mat4(1.0f);
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
uboVS.normal = glm::inverseTranspose(uboVS.view * uboVS.model);
|
||||
|
||||
uboVS.lightPos = lightPos;
|
||||
|
||||
VK_CHECK_RESULT(uniformData.meshVS.map());
|
||||
memcpy(uniformData.meshVS.mapped, &uboVS, sizeof(uboVS));
|
||||
uniformData.meshVS.unmap();
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
VulkanExampleBase::prepareFrame();
|
||||
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
||||
|
||||
VulkanExampleBase::submitFrame();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue