You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.6 KiB
110 lines
2.6 KiB
#version 450
|
|
// vim: ft=c
|
|
|
|
layout(std430, set = 0, binding = 0) buffer positions_buffer {
|
|
mat2x4 posnrm[];
|
|
} pos;
|
|
|
|
layout(push_constant, std430) uniform pc {
|
|
layout(offset=0) mat4 data;
|
|
layout(offset=64) vec4 offst;
|
|
};
|
|
|
|
layout (location = 0) out vec4 normal;
|
|
layout (location = 1) out vec4 pos_pre;
|
|
|
|
const float PI = 3.14159;
|
|
// Forgive me for I have sinned
|
|
const float TAU = PI*2.0;
|
|
|
|
void main() {
|
|
// assign outs
|
|
normal = pos.posnrm[gl_VertexIndex][1];
|
|
pos_pre = pos.posnrm[gl_VertexIndex][0];
|
|
|
|
// define constants
|
|
const float zFar = 100.0;
|
|
const float zNear = 0.1;
|
|
|
|
// assign the transformee
|
|
gl_Position = pos.posnrm[gl_VertexIndex][0];
|
|
|
|
mat4 view_orig = mat4(
|
|
1.0, 0.0, 0.0, offst.x,
|
|
0.0, 1.0, 0.0, offst.y,
|
|
0.0, 0.0, 1.0, offst.z,
|
|
0.0, 0.0, 0.0, 1.0
|
|
);
|
|
mat4 view_rot_xz = mat4(
|
|
cos(offst.w), 0.0, sin(offst.w), 0.0,
|
|
0.0, 1.0, 0.0, 0.0,
|
|
-sin(offst.w), 0.0, cos(offst.w), 0.0,
|
|
0.0, 0.0, 0.0, 1.0
|
|
);
|
|
mat4 view_rot_yz = mat4(
|
|
1.0, 0.0, 0.0, 0.0,
|
|
0.0, cos(data[3].w), sin(data[3].w), 0.0,
|
|
0.0, -sin(data[3].w), cos(data[3].w), 0.0,
|
|
0.0, 0.0, 0.0, 1.0
|
|
);
|
|
mat4 project_aspect = mat4(
|
|
(1080.0/1920.0), 0.0, 0.0, 0.0,
|
|
0.0, 1.0, 0.0, 0.0,
|
|
0.0, 0.0, 1.0, 0.0,
|
|
0.0, 0.0, 0.0, 1.0
|
|
);
|
|
mat4 project_znear = mat4(
|
|
1.0, 0.0, 0.0, 0.0,
|
|
0.0, 1.0, 0.0, 0.0,
|
|
0.0, 0.0, 1.0, -zNear,
|
|
0.0, 0.0, 0.0, 1.0
|
|
);
|
|
mat4 project_div = mat4(
|
|
1.0, 0.0, 0.0, 0.0,
|
|
0.0, 1.0, 0.0, 0.0,
|
|
0.0, 0.0, 1.0, 0.0,
|
|
0.0, 0.0, tan((70.0/2.0)/360.0*TAU), 0.0
|
|
);
|
|
mat4 project_normal = mat4(
|
|
1.0, 0.0, 0.0, 0.0,
|
|
0.0, 1.0, 0.0, 0.0,
|
|
0.0, 0.0, 1.0/zFar, 0.0,
|
|
0.0, 0.0, 0.0, 1.0
|
|
);
|
|
|
|
// apply view's origin transformation
|
|
//gl_Position.xyz += offst.xyz;
|
|
gl_Position *= view_orig;
|
|
|
|
// apply view's xz rotation
|
|
//mat2 xz_rot;
|
|
//xz_rot[0] = vec2(cos(offst.w), -sin(offst.w));
|
|
//xz_rot[1] = vec2(sin(offst.w), cos(offst.w));
|
|
//gl_Position.xz *= inverse(xz_rot);
|
|
gl_Position *= view_rot_xz;
|
|
|
|
// apply view's yz rotation
|
|
//mat2 yz_rot;
|
|
//yz_rot[0] = vec2(cos(data[3].w), -sin(data[3].w));
|
|
//yz_rot[1] = vec2(sin(data[3].w), cos(data[3].w));
|
|
//gl_Position.yz *= inverse(yz_rot);
|
|
gl_Position *= view_rot_yz;
|
|
|
|
// aspect correction
|
|
//gl_Position.x *= (1080.0/1920.0);
|
|
gl_Position *= project_aspect;
|
|
|
|
// z near correction
|
|
//gl_Position.z -= zNear;
|
|
gl_Position *= project_znear;
|
|
|
|
// division by z
|
|
// has to be assigned by w so that the hardware performs the division AFTER clipping.
|
|
//gl_Position.w = (gl_Position.z*sin(140.0/360.0*TAU));
|
|
gl_Position *= project_div;
|
|
|
|
// z normalization
|
|
//gl_Position.z /= zFar;
|
|
gl_Position *= project_normal;
|
|
}
|