From 693c4a8be53010d451826fb3eca83907045e0847 Mon Sep 17 00:00:00 2001 From: "disus.dev" Date: Tue, 3 Jan 2023 00:16:39 +0100 Subject: [PATCH] Fix InfinitePlane shaders after changes in gridColor function --- data/shaders/chapter07/VK03_InfinitePlane.frag | 3 ++- data/shaders/chapter07/VK03_InfinitePlane.vert | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/data/shaders/chapter07/VK03_InfinitePlane.frag b/data/shaders/chapter07/VK03_InfinitePlane.frag index ea56ca0..55fce2b 100644 --- a/data/shaders/chapter07/VK03_InfinitePlane.frag +++ b/data/shaders/chapter07/VK03_InfinitePlane.frag @@ -5,9 +5,10 @@ #include layout (location=0) in vec2 uv; +layout (location=1) in vec2 cameraPos; layout (location=0) out vec4 out_FragColor; void main() { - out_FragColor = gridColor(uv); + out_FragColor = gridColor(uv, cameraPos); } diff --git a/data/shaders/chapter07/VK03_InfinitePlane.vert b/data/shaders/chapter07/VK03_InfinitePlane.vert index 342ce3a..0c0b3bd 100644 --- a/data/shaders/chapter07/VK03_InfinitePlane.vert +++ b/data/shaders/chapter07/VK03_InfinitePlane.vert @@ -4,6 +4,7 @@ #include layout (location=0) out vec2 uv; +layout (location=1) out vec2 cameraPos; layout(binding = 0) uniform UniformBuffer { @@ -20,6 +21,12 @@ void main() int idx = indices[gl_VertexIndex]; vec3 position = pos[idx] * gridSize; + mat4 iview = inverse(ubo.view); + cameraPos = vec2(iview[3][0], iview[3][2]); + + position.x += cameraPos.x; + position.z += cameraPos.y; + gl_Position = MVP * vec4(position, 1.0); uv = position.xz; }