diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..68c5952 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +data/ filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore index 6aa1a6b..dba8568 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ build/* bin/* -data/* tags Session.vim diff --git a/data/Color Palette 140.png b/data/Color Palette 140.png new file mode 100644 index 0000000..32f3bbb Binary files /dev/null and b/data/Color Palette 140.png differ diff --git a/data/colored_vertices.frag b/data/colored_vertices.frag new file mode 100644 index 0000000..363c8ce --- /dev/null +++ b/data/colored_vertices.frag @@ -0,0 +1,11 @@ +#version 330 core + +in vec3 frag_color; + +out vec4 color; + + +void main() +{ + color = vec4(frag_color, 1); +} diff --git a/data/colored_vertices.vert b/data/colored_vertices.vert new file mode 100644 index 0000000..464a63f --- /dev/null +++ b/data/colored_vertices.vert @@ -0,0 +1,22 @@ +#version 330 core + +layout (location = 0) in vec3 position; +layout (location = 1) in vec3 color; + +out vec3 frag_color; + +layout (std140) uniform matrices +{ + mat4 view_xform; + mat4 proj_xform; + mat4 normal_xform; +}; + +uniform mat4 node_xform; + + +void main() +{ + frag_color = color; + gl_Position = proj_xform * view_xform * node_xform * vec4(position, 1); +} diff --git a/data/debug.frag b/data/debug.frag new file mode 100644 index 0000000..32af9c9 --- /dev/null +++ b/data/debug.frag @@ -0,0 +1,11 @@ +#version 330 core + +in vec3 frag_normal; + +out vec4 color; + + +void main() +{ + color = vec4(frag_normal, 1); +} diff --git a/data/debug.vert b/data/debug.vert new file mode 100644 index 0000000..aa39fa4 --- /dev/null +++ b/data/debug.vert @@ -0,0 +1,26 @@ +#version 330 core + +layout (location = 0) in vec3 position; +layout (location = 1) in vec3 normal; + +out vec3 frag_normal; + +layout (std140) uniform matrices +{ + mat4 view_xform; + mat4 proj_xform; + mat4 normal_xform; +}; + +uniform mat4 node_xform; + + +void main() +{ + // TODO: probably better to do this once in a separate uniform than once + // for every vertex + mat4 xform = node_xform; + xform[3] = vec4(0, 0, 0, 1); // NOTE: undo translation + frag_normal = vec4(xform * vec4(normal, 1)).xyz; + gl_Position = proj_xform * view_xform * node_xform * vec4(position, 1); +} diff --git a/data/full_lighting.frag b/data/full_lighting.frag new file mode 100644 index 0000000..f157004 --- /dev/null +++ b/data/full_lighting.frag @@ -0,0 +1,67 @@ +#version 330 core + +in vec3 frag_pos; +in vec3 frag_normal; +in vec2 frag_uv; + +out vec4 color; + +uniform sampler2D sampler; + +const uint NUM_LIGHTS = 32u; + +layout (std140) uniform lights +{ + uint max_p_lights; + uint active_p_lights; + uint max_d_lights; + uint active_d_lights; + uint padding; + + vec4 ambient_color; + + vec4 pl_positions[NUM_LIGHTS]; + vec4 pl_colors[NUM_LIGHTS]; + uint pl_intensities[NUM_LIGHTS]; // NOTE: 16 bytes * NUM_LIGHTS + + vec4 dl_directions[NUM_LIGHTS]; + vec4 dl_colors[NUM_LIGHTS]; + uint dl_intensities[NUM_LIGHTS]; // NOTE: 16 bytes * NUM_LIGHTS +}; + +const float CONSTANT_ATTENUATION = 0.1; +const float LINEAR_ATTENUATION = 0.2; +const float QUADRATIC_ATTENUATION = 0.02; + + +void main() +{ + vec4 diffuse_color = vec4(0); + + // NOTE: directional lights + for (uint i = 0u; i < active_d_lights; i++) { + vec4 light_direction = normalize(dl_directions[i]); + float diffuse_factor = + clamp(dot(vec4(frag_normal, 1), light_direction), 0, 1); + diffuse_color = diffuse_color + + dl_intensities[i] * diffuse_factor * dl_colors[i]; + } + + // NOTE: point lights + for (uint i = 0u; i < active_p_lights; i ++) { + vec3 direction = vec3(pl_positions[i]).xyz - frag_pos; + float distance = length(direction); + direction = direction / distance; + + float attenuation = CONSTANT_ATTENUATION + + LINEAR_ATTENUATION * distance + + QUADRATIC_ATTENUATION * pow(distance, 2); + float diffuse_factor = clamp(dot(frag_normal, direction), 0, 1); + vec4 added_color = pl_colors[i] * pl_intensities[i] + * diffuse_factor / attenuation; + + diffuse_color = diffuse_color + added_color; + } + + color = (ambient_color + diffuse_color) * texture(sampler, frag_uv.st); +} diff --git a/data/full_lighting.vert b/data/full_lighting.vert new file mode 100644 index 0000000..f6fe8be --- /dev/null +++ b/data/full_lighting.vert @@ -0,0 +1,27 @@ +#version 330 core + +layout (location = 0) in vec3 position; +layout (location = 1) in vec3 normal; +layout (location = 2) in vec2 uv; + +out vec3 frag_pos; +out vec3 frag_normal; +out vec2 frag_uv; + +layout (std140) uniform matrices +{ + mat4 view_xform; + mat4 proj_xform; + mat4 normal_xform; +}; + +uniform mat4 node_xform; + + +void main() +{ + frag_pos = (node_xform * vec4(position, 1)).xyz; + frag_uv = uv; + frag_normal = normalize(mat3(node_xform) * normal); + gl_Position = proj_xform * view_xform * node_xform * vec4(position, 1); +} diff --git a/data/icosphere.bin b/data/icosphere.bin new file mode 100644 index 0000000..9a8d721 Binary files /dev/null and b/data/icosphere.bin differ diff --git a/data/icosphere.gltf b/data/icosphere.gltf new file mode 100644 index 0000000..6e65847 --- /dev/null +++ b/data/icosphere.gltf @@ -0,0 +1,137 @@ +{ + "asset":{ + "generator":"Khronos glTF Blender I/O v4.4.56", + "version":"2.0" + }, + "scene":0, + "scenes":[ + { + "name":"Scene", + "nodes":[ + 0 + ] + } + ], + "nodes":[ + { + "mesh":0, + "name":"Icosphere" + } + ], + "materials":[ + { + "doubleSided":true, + "name":"Material.002", + "pbrMetallicRoughness":{ + "baseColorTexture":{ + "index":0 + }, + "metallicFactor":0, + "roughnessFactor":0.5 + } + } + ], + "meshes":[ + { + "name":"Icosphere.001", + "primitives":[ + { + "attributes":{ + "POSITION":0, + "NORMAL":1, + "TEXCOORD_0":2 + }, + "indices":3, + "material":0 + } + ] + } + ], + "textures":[ + { + "sampler":0, + "source":0 + } + ], + "images":[ + { + "mimeType":"image/png", + "name":"Color Palette 140", + "uri":"Color%20Palette%20140.png" + } + ], + "accessors":[ + { + "bufferView":0, + "componentType":5126, + "count":960, + "max":[ + 1, + 1, + 0.9999999403953552 + ], + "min":[ + -0.9999999403953552, + -1, + -0.9999999403953552 + ], + "type":"VEC3" + }, + { + "bufferView":1, + "componentType":5126, + "count":960, + "type":"VEC3" + }, + { + "bufferView":2, + "componentType":5126, + "count":960, + "type":"VEC2" + }, + { + "bufferView":3, + "componentType":5123, + "count":960, + "type":"SCALAR" + } + ], + "bufferViews":[ + { + "buffer":0, + "byteLength":11520, + "byteOffset":0, + "target":34962 + }, + { + "buffer":0, + "byteLength":11520, + "byteOffset":11520, + "target":34962 + }, + { + "buffer":0, + "byteLength":7680, + "byteOffset":23040, + "target":34962 + }, + { + "buffer":0, + "byteLength":1920, + "byteOffset":30720, + "target":34963 + } + ], + "samplers":[ + { + "magFilter":9729, + "minFilter":9987 + } + ], + "buffers":[ + { + "byteLength":32640, + "uri":"icosphere.bin" + } + ] +} diff --git a/data/texture_only.frag b/data/texture_only.frag new file mode 100644 index 0000000..311fa02 --- /dev/null +++ b/data/texture_only.frag @@ -0,0 +1,21 @@ +#version 330 core + +in vec2 frag_uv; + +out vec4 color; + +layout (std140) uniform matrices +{ + mat4 view_xform; + mat4 proj_xform; + mat4 normal_xform; +}; + +uniform mat4 node_xform; +uniform sampler2D sampler; + + +void main() +{ + color = texture(sampler, frag_uv.st); +} diff --git a/data/texture_only.vert b/data/texture_only.vert new file mode 100644 index 0000000..b5c343f --- /dev/null +++ b/data/texture_only.vert @@ -0,0 +1,22 @@ +#version 330 core + +layout (location = 0) in vec3 position; +layout (location = 1) in vec2 uv; + +out vec2 frag_uv; + +layout (std140) uniform matrices +{ + mat4 view_xform; + mat4 proj_xform; + mat4 normal_xform; +}; + +uniform mat4 node_xform; + + +void main() +{ + frag_uv = uv; + gl_Position = proj_xform * view_xform * node_xform * vec4(position, 1); +}