Merge pull request 'Enhancements & Fixes' (#78) from enhancements into master

Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/78
This commit is contained in:
Georg Hagen
2024-07-24 16:06:01 +02:00
45 changed files with 442 additions and 110 deletions

View File

@@ -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
{
@@ -21,8 +22,14 @@ layout(set = 1, binding = 0) uniform CameraData
void main()
{
vec2 rm = (texCoords - 0.5) * 2;
float intensity = rm.x * rm.x + rm.y * rm.y;
intensity = (intensity / 1.4) * scale / 2;
fragColor = texture(camTexture, texCoords);
fragColor.rgb = fragColor.rgb - intensity;
#ifdef ENABLE_DEPTH_WRITE
gl_FragDepth = (texture(depthMap, texCoords).r - cam.near) / (cam.far - cam.near);
#endif
}
}

View File

@@ -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];
}