From dad0a4d661eeee6ede3edb8a8becc3cd23690fa9 Mon Sep 17 00:00:00 2001 From: saschawillems Date: Mon, 15 Aug 2016 16:25:54 +0200 Subject: [PATCH] Use mip mapping sampler by default, rotate tunnel when not paused --- data/shaders/texturemipmapgen/texture.vert | 4 +-- .../shaders/texturemipmapgen/texture.vert.spv | Bin 1912 -> 2020 bytes texturemipmapgen/texturemipmapgen.cpp | 30 ++++++++++-------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/data/shaders/texturemipmapgen/texture.vert b/data/shaders/texturemipmapgen/texture.vert index bf6f9584..277dec0a 100644 --- a/data/shaders/texturemipmapgen/texture.vert +++ b/data/shaders/texturemipmapgen/texture.vert @@ -10,8 +10,8 @@ layout (location = 2) in vec3 inNormal; layout (binding = 0) uniform UBO { mat4 projection; + mat4 view; mat4 model; - vec4 viewPos; float lodBias; float samplerIndex; } ubo; @@ -31,5 +31,5 @@ void main() outUV.s *= 10.0; outLodBias = ubo.lodBias; outSamplerIndex = ubo.samplerIndex; - gl_Position = ubo.projection * ubo.model * vec4(inPos, 1.0); + gl_Position = ubo.projection * ubo.view * ubo.model * vec4(inPos, 1.0); } diff --git a/data/shaders/texturemipmapgen/texture.vert.spv b/data/shaders/texturemipmapgen/texture.vert.spv index e0e8a76e0e3748f94cbefdacd92df28f43edb55f..eb85901a4febede6a394917dd08d391b86ad89a8 100644 GIT binary patch delta 515 zcmYk2J4yp#6ov1+q9F0n7%`wiKm|dK&uEOJm6i#?N~|W)AP5?M3R3CS&`e-n}FSykY$9JPrAMZxBDa(`8jLz((OP>*R4R!OK6*&$QS0 z!#z!UPod~JFrVH>-j7p=8~%HHfxL*m1nOQOUnS;1ooC3`hz>}vX1Vs2rh0id!R$7a zzs5a>_)YxghH;fLITRL24WsSXIGpvjTF|fLI-f?SL)?@j(jz J0)1ow!~mA+D!>2$ diff --git a/texturemipmapgen/texturemipmapgen.cpp b/texturemipmapgen/texturemipmapgen.cpp index e2a7f6b4..7e8884be 100644 --- a/texturemipmapgen/texturemipmapgen.cpp +++ b/texturemipmapgen/texturemipmapgen.cpp @@ -28,13 +28,6 @@ #define VERTEX_BUFFER_BIND_ID 0 #define ENABLE_VALIDATION false -// Vertex layout for this example -struct Vertex { - float pos[3]; - float uv[2]; - float normal[3]; -}; - std::vector vertexLayout = { vkMeshLoader::VERTEX_LAYOUT_POSITION, @@ -72,9 +65,9 @@ public: struct uboVS { glm::mat4 projection; glm::mat4 view; - glm::vec4 viewPos; + glm::mat4 model; float lodBias = 0.0f; - float samplerIndex = 0.0f; + float samplerIndex = 1.0f; } uboVS; struct { @@ -95,6 +88,8 @@ public: camera.setTranslation(glm::vec3(10.0f, 0.0f, 0.0f)); camera.movementSpeed = 2.5f; camera.rotationSpeed = 0.5f; + timerSpeed *= 0.15f; + paused = true; } ~VulkanExample() @@ -439,7 +434,7 @@ public: vertices.bindingDescriptions[0] = vkTools::initializers::vertexInputBindingDescription( VERTEX_BUFFER_BIND_ID, - sizeof(Vertex), + vkMeshLoader::vertexSize(vertexLayout), VK_VERTEX_INPUT_RATE_VERTEX); // Attribute descriptions @@ -451,21 +446,21 @@ public: VERTEX_BUFFER_BIND_ID, 0, VK_FORMAT_R32G32B32_SFLOAT, - offsetof(Vertex, pos)); + 0); // Location 1 : Texture coordinates vertices.attributeDescriptions[1] = vkTools::initializers::vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 1, VK_FORMAT_R32G32_SFLOAT, - offsetof(Vertex, uv)); + 3 * sizeof(float)); // Location 1 : Vertex normal vertices.attributeDescriptions[2] = vkTools::initializers::vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 2, VK_FORMAT_R32G32B32_SFLOAT, - offsetof(Vertex, normal)); + 5 * sizeof(float)); vertices.inputState = vkTools::initializers::pipelineVertexInputStateCreateInfo(); vertices.inputState.vertexBindingDescriptionCount = static_cast(vertices.bindingDescriptions.size()); @@ -670,6 +665,11 @@ public: uboVS.projection = camera.matrices.perspective; uboVS.view = camera.matrices.view; + if (!paused) + { + uboVS.model = glm::rotate(glm::mat4(), glm::radians(timer * 360.0f), glm::vec3(1.0f, 0.0f, 0.0f)); + } + VK_CHECK_RESULT(uniformBufferVS.map()); memcpy(uniformBufferVS.mapped, &uboVS, sizeof(uboVS)); uniformBufferVS.unmap(); @@ -694,6 +694,10 @@ public: if (!prepared) return; draw(); + if (!paused) + { + updateUniformBuffers(); + } } virtual void viewChanged()