From 23df2966104f58d76b68c9fd52b8dbe83270f238 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 21 Jul 2024 17:34:43 +0200 Subject: [PATCH] Update formatting --- openVulkanoCpp/Shader/background.frag | 9 ++-- openVulkanoCpp/Shader/background.vert | 74 ++++++++++++++------------- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/openVulkanoCpp/Shader/background.frag b/openVulkanoCpp/Shader/background.frag index a1025c7..c05c432 100644 --- a/openVulkanoCpp/Shader/background.frag +++ b/openVulkanoCpp/Shader/background.frag @@ -1,13 +1,14 @@ #version 450 -layout (set = 3, binding = 0) uniform sampler2D camTexture; +layout(set = 3, binding = 0) uniform sampler2D camTexture; #ifdef ENABLE_DEPTH_WRITE -layout (set = 2, binding = 1) uniform sampler2D depthMap; +layout(set = 2, binding = 1) uniform sampler2D depthMap; #endif -layout (location = 0) in vec2 texCoords; -layout (location = 0) out vec4 fragColor; +layout(location = 0) in vec2 texCoords; +layout(location = 1) in float scale; +layout(location = 0) out vec4 fragColor; layout(set = 1, binding = 0) uniform CameraData { diff --git a/openVulkanoCpp/Shader/background.vert b/openVulkanoCpp/Shader/background.vert index 7d5b677..f6a52ae 100644 --- a/openVulkanoCpp/Shader/background.vert +++ b/openVulkanoCpp/Shader/background.vert @@ -3,56 +3,58 @@ layout(set = 1, binding = 0) uniform CameraData { - mat4 viewProjection; - mat4 view; - mat4 projection; - vec4 camPos; - float nearPlane; - float farPlane; - float width; - float height; - float fov; - float aspect; - float scaleFactor; - float pixelScaleFactor; + mat4 viewProjection; + mat4 view; + mat4 projection; + vec4 camPos; + float nearPlane; + float farPlane; + float width; + float height; + float fov; + float aspect; + float scaleFactor; + float pixelScaleFactor; } cam; layout(set = 2, binding = 0) uniform RealCameraData { - mat3 intrinsic; - int width; - int height; + mat3 intrinsic; + int width; + int height; } realCam; layout(location = 0) out vec2 textureCoordinates; +layout(location = 1) out float scaleOut; const float FLOAT_MAX_LESS_THAN_1 = 0.999999940395355224609; // Background plane positions are in clipped space -const vec4 PLANE[4] = vec4[] ( - vec4(1, -1, FLOAT_MAX_LESS_THAN_1, 1), vec4(-1, -1, FLOAT_MAX_LESS_THAN_1, 1), vec4(1, 1, FLOAT_MAX_LESS_THAN_1, 1), vec4(-1, 1, FLOAT_MAX_LESS_THAN_1, 1) -); -const vec2 TEX_COORDS[4] = vec2[] ( - vec2(1, 0), vec2(0, 0), vec2(1, 1), vec2(0, 1) -); +const vec4 PLANE[4] = vec4[]( + vec4(1, -1, FLOAT_MAX_LESS_THAN_1, 1), vec4(-1, -1, FLOAT_MAX_LESS_THAN_1, 1), vec4(1, 1, FLOAT_MAX_LESS_THAN_1, 1), vec4(-1, 1, FLOAT_MAX_LESS_THAN_1, 1) + ); +const vec2 TEX_COORDS[4] = vec2[]( + vec2(1, 0), vec2(0, 0), vec2(1, 1), vec2(0, 1) + ); void main() { - vec4 position = PLANE[gl_VertexIndex]; + vec4 position = PLANE[gl_VertexIndex]; - // Calculate the scaling factors for width and height - float height = realCam.height; - float realScale = realCam.intrinsic[1][1] / height; - float realAspect = height / realCam.width; - float scaleY = realScale / cam.scaleFactor; - float scaleX = scaleY / (cam.aspect * realAspect); + // Calculate the scaling factors for width and height + float height = realCam.height; + float realScale = realCam.intrinsic[1][1] / height; + float realAspect = height / realCam.width; + float scaleY = realScale / cam.scaleFactor; + float scaleX = scaleY / (cam.aspect * realAspect); - // Scale the quad's position - position.xy *= vec2(scaleX, scaleY); + // Handle center + vec2 centerOffset = realCam.intrinsic[2].xy / vec2(realCam.width, realCam.height); + centerOffset -= 0.5; + position.xy -= centerOffset * vec2(2, 2); - // Handle center - vec2 centerOffset = realCam.intrinsic[2].xy / vec2(realCam.width, realCam.height); - centerOffset -= 0.5; - position.xy -= centerOffset; + // Scale the quad's position + position.xy *= vec2(scaleX, scaleY); - gl_Position = position; - textureCoordinates = TEX_COORDS[gl_VertexIndex]; + scaleOut = 1 / scaleY; + gl_Position = position; + textureCoordinates = TEX_COORDS[gl_VertexIndex]; }