Update background shader
This commit is contained in:
@@ -3,39 +3,45 @@
|
||||
|
||||
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;
|
||||
|
||||
// Grid position are in clipped space
|
||||
vec4 gridPlane[4] = vec4[] (
|
||||
vec4(1, 1, 0, 1), vec4(-1, 1, 0, 1), vec4(1, -1, 0, 1), vec4(-1, -1, 0, 1)
|
||||
layout(location = 0) out vec2 textureCoordinates;
|
||||
|
||||
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)
|
||||
);
|
||||
|
||||
float realFov = 53;
|
||||
float realFov = 53; //TODO
|
||||
float realScale = tan(radians(realFov * 0.5)) * 2;
|
||||
float realAspect = 1.33333333;
|
||||
|
||||
void main() {
|
||||
float virtualAspect = cam.width / cam.height;
|
||||
vec4 position = gridPlane[gl_VertexIndex];
|
||||
vec4 position = PLANE[gl_VertexIndex];
|
||||
|
||||
// Calculate the scaling factors for width and height
|
||||
float scaleX = tan(radians(cam.fov * 0.5)) / tan(radians(realFov * 0.5));
|
||||
float scaleY = virtualAspect / realAspect * scaleX;
|
||||
// Calculate the scaling factors for width and height
|
||||
float scaleX = realScale / cam.scaleFactor;
|
||||
float scaleY = cam.aspect / realAspect * scaleX;
|
||||
|
||||
// Scale the quad's position
|
||||
position.xy *= vec2(scaleX, scaleY);
|
||||
// Scale the quad's position
|
||||
position.xy *= vec2(scaleX, scaleY);
|
||||
|
||||
// Pass the transformed position to the fragment shader
|
||||
gl_Position = position;
|
||||
gl_Position = position;
|
||||
textureCoordinates = TEX_COORDS[gl_VertexIndex];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user