Initial commit

master
itycodes 7 months ago
commit 3e86e42076

@ -0,0 +1,26 @@
.PHONY: run clean
SHADERS = vert.spv frag.spv
CC = gcc
LIBS = -lvulkan -lglfw -lm
CFLAGS = $(LIBS)
OUT = main
SRC = main.c
all: $(SHADERS) $(OUT)
$(OUT): $(SRC)
$(CC) $(CFLAGS) $(SRC) -o $(OUT)
run: all
./$(OUT)
clean:
rm $(SHADERS)
rm $(OUT)
%.spv: %.vert
glslc $< -o $@
%.spv: %.frag
glslc $< -o $@

@ -0,0 +1,19 @@
#version 450
layout(location = 0) out vec4 outColor;
layout(location = 0) in vec4 normal;
layout(location = 1) in vec4 pos_pre;
layout(push_constant, std430) uniform pc {
layout(offset=80) vec4 data;
};
void main() {
outColor = vec4(data.rgb*(1.0+dot(normal.xyz, normalize(vec3(-0.7, -0.5, -0.1))))/2.0, 1.0);
//if(pos_post.z <= 0.0) {
// outColor = vec4(1.0);
//}
//outColor = normal.xyz;
//outColor = vec4(vec3(1.0-gl_FragCoord.z), 1.0);
}

1137
main.c

File diff suppressed because it is too large Load Diff

@ -0,0 +1,42 @@
#version 450
// This file contains the raw math performed by the matrices in vert.vert
// Matrices are still used for rotation, though.
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;
layout (location = 2) out vec4 pos_post;
const float PI = 3.14159;
const float TAU = PI*2.0;
void main() {
normal = pos.posnrm[gl_VertexIndex][1];
pos_pre = pos.posnrm[gl_VertexIndex][0];
float zFar = 100.0;
float zNear = 0.1;
gl_Position = pos.posnrm[gl_VertexIndex][0];
gl_Position.xyz += offst.xyz;
pos_post = gl_Position;
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);
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.x *= (1080.0/1920.0);
gl_Position.w = (gl_Position.z*sin(140.0/360.0*TAU));
gl_Position.z -= zNear;
gl_Position.z /= zFar;
}

@ -0,0 +1,109 @@
#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;
}
Loading…
Cancel
Save