diff --git a/.gitattributes b/.gitattributes index 534ef6b..3d750b8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,6 @@ *.png filter=lfs diff=lfs merge=lfs -text *.glb filter=lfs diff=lfs merge=lfs -text *.blend filter=lfs diff=lfs merge=lfs -text -examples/data/* filter=lfs diff=lfs merge=lfs -text examples/data/spaceship.bin filter=lfs diff=lfs merge=lfs -text examples/data/textured_cube.bin filter=lfs diff=lfs merge=lfs -text examples/data/spaceship.gltf filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore index 27a1a55..89c4241 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,4 @@ msvc/.vs/ msvc/x64/ tags *.swp -examples/data/* diff --git a/examples/data/Color Palette 140.png b/examples/data/Color Palette 140.png new file mode 100644 index 0000000..dd9ce0c --- /dev/null +++ b/examples/data/Color Palette 140.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:455cd0343c1784781ce4ab3b843ce76b3e9477c3e6c0aa158bfd14c1276c7326 +size 572604 diff --git a/examples/data/colored_vertices.frag b/examples/data/colored_vertices.frag new file mode 100644 index 0000000..363c8ce --- /dev/null +++ b/examples/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/examples/data/colored_vertices.vert b/examples/data/colored_vertices.vert new file mode 100644 index 0000000..464a63f --- /dev/null +++ b/examples/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/examples/data/debug.frag b/examples/data/debug.frag new file mode 100644 index 0000000..32af9c9 --- /dev/null +++ b/examples/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/examples/data/debug.vert b/examples/data/debug.vert new file mode 100644 index 0000000..aa39fa4 --- /dev/null +++ b/examples/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/examples/data/full_lighting.frag b/examples/data/full_lighting.frag new file mode 100644 index 0000000..f157004 --- /dev/null +++ b/examples/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/examples/data/full_lighting.vert b/examples/data/full_lighting.vert new file mode 100644 index 0000000..f6fe8be --- /dev/null +++ b/examples/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/examples/data/spaceship.bin b/examples/data/spaceship.bin new file mode 100644 index 0000000..c40ddd1 --- /dev/null +++ b/examples/data/spaceship.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0c00d1680565370153e795d05f10ddf423c62435f566e3796fb660afe04906b4 +size 63464 diff --git a/examples/data/spaceship.gltf b/examples/data/spaceship.gltf new file mode 100644 index 0000000..7851441 --- /dev/null +++ b/examples/data/spaceship.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85c6c24a696b4a169a2af0b1cf608578c5ea37e6cc84cfdeb96586b1a20d553a +size 11262 diff --git a/examples/data/texture_only.frag b/examples/data/texture_only.frag new file mode 100644 index 0000000..311fa02 --- /dev/null +++ b/examples/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/examples/data/texture_only.vert b/examples/data/texture_only.vert new file mode 100644 index 0000000..b5c343f --- /dev/null +++ b/examples/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); +} diff --git a/examples/data/textured_cube.bin b/examples/data/textured_cube.bin new file mode 100644 index 0000000..60b41af --- /dev/null +++ b/examples/data/textured_cube.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:750f0172d0640b7530d149ddc4b9ca599bcb76dd84bc89d69309845a79aa73e8 +size 840 diff --git a/examples/data/textured_cube.gltf b/examples/data/textured_cube.gltf new file mode 100644 index 0000000..6ddf061 --- /dev/null +++ b/examples/data/textured_cube.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:90cdd308dfb43cdd7ee05cb2abfb917998e24554818cf001b1054008c1274741 +size 3658