Working, but...
This commit is contained in:
parent
0c042c79d7
commit
b1edaf6fc1
20 changed files with 807 additions and 0 deletions
25
shaders/chunk.frag
Normal file
25
shaders/chunk.frag
Normal file
|
@ -0,0 +1,25 @@
|
|||
#version 330 core
|
||||
|
||||
layout (location = 0) out vec4 fragColor;
|
||||
|
||||
const vec3 gamma = vec3(2.2);
|
||||
const vec3 inv_gamma = 1 / gamma;
|
||||
|
||||
uniform sampler2D u_texture_0;
|
||||
|
||||
in vec3 voxel_color;
|
||||
in vec2 uv;
|
||||
in float shading;
|
||||
|
||||
|
||||
void main() {
|
||||
vec3 tex_col = texture(u_texture_0, uv).rgb;
|
||||
tex_col = pow(tex_col, gamma);
|
||||
|
||||
tex_col.rgb *= voxel_color;
|
||||
//tex_col = tex_col * 0.001 + vec3(1);
|
||||
tex_col *= shading;
|
||||
|
||||
tex_col = pow(tex_col, inv_gamma);
|
||||
fragColor = vec4(tex_col, 1);
|
||||
}
|
51
shaders/chunk.vert
Normal file
51
shaders/chunk.vert
Normal file
|
@ -0,0 +1,51 @@
|
|||
#version 330 core
|
||||
|
||||
layout (location = 0) in ivec3 in_position;
|
||||
layout (location = 1) in int voxel_id;
|
||||
layout (location = 2) in int face_id;
|
||||
layout (location = 3) in int ao_id;
|
||||
layout (location = 4) in int flip_id;
|
||||
|
||||
uniform mat4 m_proj;
|
||||
uniform mat4 m_view;
|
||||
uniform mat4 m_model;
|
||||
|
||||
out vec3 voxel_color;
|
||||
out vec2 uv;
|
||||
out float shading;
|
||||
|
||||
const float ao_values[4] = float[4](0.1, 0.25, 0.1, 1.0);
|
||||
|
||||
const float face_shading[6] = float[6](
|
||||
1.0, 0.5, // top bottom
|
||||
0.5, 0.8, // right left
|
||||
0.5, 0.8 // front back
|
||||
);
|
||||
|
||||
const vec2 uv_coords[4] = vec2[4](
|
||||
vec2(0, 0), vec2(0, 1),
|
||||
vec2(1, 0), vec2(1, 1)
|
||||
);
|
||||
|
||||
const int uv_indices[24] = int[24](
|
||||
1, 0, 2, 1, 2, 3, // tex coord indices for vertices of an even face
|
||||
3, 0, 2, 3, 1, 0, // odd face
|
||||
3, 1, 0, 3, 0, 2, // even flipped face
|
||||
1, 2, 3, 1, 0, 2 // odd flipped face
|
||||
);
|
||||
|
||||
|
||||
vec3 hash31(float p) {
|
||||
vec3 p3 = fract(vec3(p * 21.2) * vec3(0.1031, 0.1030, 0.0973));
|
||||
p3 += dot(p3, p3.yzx + 33.33);
|
||||
return fract((p3.xxy + p3.yzz) * p3.zyx) + 0.05;
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
int uv_index = gl_VertexID % 6 + ((face_id & 1) + flip_id * 2) * 6;
|
||||
uv = uv_coords[uv_indices[uv_index]];
|
||||
voxel_color = hash31(voxel_id);
|
||||
shading = face_shading[face_id] * ao_values[ao_id];
|
||||
gl_Position = m_proj * m_view * m_model * vec4(in_position, 1.0);
|
||||
}
|
10
shaders/quad.frag
Normal file
10
shaders/quad.frag
Normal file
|
@ -0,0 +1,10 @@
|
|||
#version 330 core
|
||||
|
||||
layout (location = 0) out vec4 fragColor;
|
||||
|
||||
in vec3 color;
|
||||
|
||||
|
||||
void main() {
|
||||
fragColor = vec4(color, 1.0);
|
||||
}
|
16
shaders/quad.vert
Normal file
16
shaders/quad.vert
Normal file
|
@ -0,0 +1,16 @@
|
|||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec3 in_position;
|
||||
layout (location = 1) in vec3 in_color;
|
||||
|
||||
uniform mat4 m_proj;
|
||||
uniform mat4 m_view;
|
||||
uniform mat4 m_model;
|
||||
|
||||
out vec3 color;
|
||||
|
||||
|
||||
void main() {
|
||||
color = in_color;
|
||||
gl_Position = m_proj * m_view * m_model * vec4(in_position, 1.0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue