15 changed files with 222 additions and 2 deletions
Binary file not shown.
@ -0,0 +1,11 @@ |
|||||||
|
#version 330 core |
||||||
|
|
||||||
|
in vec3 frag_color; |
||||||
|
|
||||||
|
out vec4 color; |
||||||
|
|
||||||
|
|
||||||
|
void main() |
||||||
|
{ |
||||||
|
color = vec4(frag_color, 1); |
||||||
|
} |
||||||
@ -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); |
||||||
|
} |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
#version 330 core |
||||||
|
|
||||||
|
in vec3 frag_normal; |
||||||
|
|
||||||
|
out vec4 color; |
||||||
|
|
||||||
|
|
||||||
|
void main() |
||||||
|
{ |
||||||
|
color = vec4(frag_normal, 1); |
||||||
|
} |
||||||
@ -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); |
||||||
|
} |
||||||
@ -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); |
||||||
|
} |
||||||
@ -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); |
||||||
|
} |
||||||
Binary file not shown.
Binary file not shown.
@ -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); |
||||||
|
} |
||||||
@ -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); |
||||||
|
} |
||||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue