Add some shaders
This commit is contained in:
39
openVulkanoCpp/Shader/background.vert
Normal file
39
openVulkanoCpp/Shader/background.vert
Normal file
@@ -0,0 +1,39 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(std140, push_constant) uniform CameraData
|
||||
{
|
||||
mat4 viewProjection;
|
||||
mat4 view;
|
||||
mat4 projection;
|
||||
vec4 camPos;
|
||||
float nearPlane;
|
||||
float farPlane;
|
||||
float width;
|
||||
float height;
|
||||
float fov;
|
||||
float aspect;
|
||||
} 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)
|
||||
);
|
||||
|
||||
float realFov = 53;
|
||||
float realAspect = 1.33333333;
|
||||
|
||||
void main() {
|
||||
float virtualAspect = cam.width / cam.height;
|
||||
vec4 position = gridPlane[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;
|
||||
|
||||
// Scale the quad's position
|
||||
position.xy *= vec2(scaleX, scaleY);
|
||||
|
||||
// Pass the transformed position to the fragment shader
|
||||
gl_Position = position;
|
||||
}
|
||||
Reference in New Issue
Block a user