Properly render chunks while using normal meshing
This commit is contained in:
parent
50241f957e
commit
e830bf2654
@ -2,10 +2,10 @@
|
||||
|
||||
out vec4 out_frag_color;
|
||||
|
||||
in vec3 out_pos;
|
||||
in vec2 out_uv;
|
||||
|
||||
uniform vec4 uniform_color;
|
||||
uniform sampler2D uniform_texture_num;
|
||||
|
||||
void main() {
|
||||
out_frag_color = vec4(out_pos.x, out_pos.y, out_pos.z, 1);
|
||||
out_frag_color = texture(uniform_texture_num, out_uv);
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 in_pos;
|
||||
layout (location = 1) in vec2 in_uv;
|
||||
|
||||
out vec3 out_pos;
|
||||
out vec2 out_uv;
|
||||
|
||||
uniform mat4 uniform_model;
|
||||
uniform mat4 uniform_view;
|
||||
@ -9,5 +10,5 @@ uniform mat4 uniform_projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0f);
|
||||
out_pos = in_pos;
|
||||
out_uv = in_uv;
|
||||
}
|
||||
|
9
shaders/gl2/object_fragment.glsl
Normal file
9
shaders/gl2/object_fragment.glsl
Normal file
@ -0,0 +1,9 @@
|
||||
#version 110
|
||||
|
||||
varying vec2 out_uv;
|
||||
|
||||
uniform sampler2D uniform_texture_num;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = texture2D(uniform_texture_num, out_uv);
|
||||
}
|
14
shaders/gl2/object_vertex.glsl
Normal file
14
shaders/gl2/object_vertex.glsl
Normal file
@ -0,0 +1,14 @@
|
||||
#version 110
|
||||
attribute vec3 in_pos;
|
||||
attribute vec2 in_uv;
|
||||
|
||||
varying vec2 out_uv;
|
||||
|
||||
uniform mat4 uniform_projection;
|
||||
uniform mat4 uniform_view;
|
||||
uniform mat4 uniform_model;
|
||||
|
||||
void main() {
|
||||
gl_Position = uniform_projection * uniform_view * uniform_model * vec4(in_pos, 1.0);
|
||||
out_uv = in_uv;
|
||||
}
|
@ -24,6 +24,7 @@ SOFTWARE.
|
||||
|
||||
#include "game/engine/normal_meshing.hpp"
|
||||
|
||||
#include "common/logger.hpp"
|
||||
#include "common/math/vector.hpp"
|
||||
#include "common/world/chunk.hpp"
|
||||
|
||||
@ -43,10 +44,10 @@ static void push_uvs(float texture_unit_size, unsigned texture_index, std::vecto
|
||||
output_uvs.push_back(texture_unit_size*texture_index);
|
||||
output_uvs.push_back(1.0f);
|
||||
|
||||
output_uvs.push_back(texture_unit_size*texture_index+1.0f);
|
||||
output_uvs.push_back(texture_unit_size*texture_index+texture_unit_size);
|
||||
output_uvs.push_back(1.0f);
|
||||
|
||||
output_uvs.push_back(texture_unit_size*texture_index+1.0f);
|
||||
output_uvs.push_back(texture_unit_size*texture_index+texture_unit_size);
|
||||
output_uvs.push_back(0.0f);
|
||||
}
|
||||
|
||||
@ -65,136 +66,89 @@ void polygun::engine::normal_meshing::generate_mesh(const world::Chunk& chunk, f
|
||||
const bool front_node = (z<world::Chunk::CHUNK_SIZE-1 && chunk.get_node(math::Vector3i{x, y, z+1})>0);
|
||||
const bool bottom_node = (y>0 && chunk.get_node(math::Vector3i{x, y-1, z})>0);
|
||||
const bool top_node = (y<world::Chunk::CHUNK_SIZE-1 && chunk.get_node(math::Vector3i{x, y+1, z})>0);
|
||||
unsigned side_vertices_indices[8] = {0};
|
||||
if(!left_node) {
|
||||
side_vertices_indices[0] = vertex_count++;
|
||||
output_vertices.push_back(x);
|
||||
output_vertices.push_back(y+1);
|
||||
output_vertices.push_back(z);
|
||||
|
||||
side_vertices_indices[1] = vertex_count++;
|
||||
output_vertices.push_back(x);
|
||||
output_vertices.push_back(y);
|
||||
output_vertices.push_back(z);
|
||||
|
||||
side_vertices_indices[2] = vertex_count++;
|
||||
output_vertices.push_back(x);
|
||||
output_vertices.push_back(y);
|
||||
output_vertices.push_back(z+1);
|
||||
|
||||
side_vertices_indices[3] = vertex_count++;
|
||||
output_vertices.push_back(x);
|
||||
output_vertices.push_back(y+1);
|
||||
output_vertices.push_back(z+1);
|
||||
|
||||
vertex_count+=4;
|
||||
push_indices(vertex_count, output_indices);
|
||||
push_uvs(node_id, texture_unit_size, output_uvs);
|
||||
push_uvs(texture_unit_size, node_id-1, output_uvs);
|
||||
}
|
||||
if(!right_node) {
|
||||
side_vertices_indices[4] = vertex_count++;
|
||||
output_vertices.push_back(x+1);
|
||||
output_vertices.push_back(y+1);
|
||||
output_vertices.push_back(z);
|
||||
|
||||
side_vertices_indices[5] = vertex_count++;
|
||||
output_vertices.push_back(x+1);
|
||||
output_vertices.push_back(y);
|
||||
output_vertices.push_back(z);
|
||||
|
||||
side_vertices_indices[6] = vertex_count++;
|
||||
output_vertices.push_back(x+1);
|
||||
output_vertices.push_back(y);
|
||||
output_vertices.push_back(z+1);
|
||||
|
||||
side_vertices_indices[7] = vertex_count++;
|
||||
output_vertices.push_back(x+1);
|
||||
output_vertices.push_back(y+1);
|
||||
output_vertices.push_back(z+1);
|
||||
|
||||
vertex_count+=4;
|
||||
push_indices(vertex_count, output_indices);
|
||||
push_uvs(node_id, texture_unit_size, output_uvs);
|
||||
push_uvs(texture_unit_size, node_id-1, output_uvs);
|
||||
}
|
||||
if(!back_node) {
|
||||
if(left_node) {
|
||||
side_vertices_indices[0] = vertex_count++;
|
||||
output_vertices.push_back(x);
|
||||
output_vertices.push_back(y+1);
|
||||
output_vertices.push_back(z);
|
||||
output_uvs.push_back(texture_unit_size*node_id);
|
||||
output_uvs.push_back(0.0f);
|
||||
|
||||
side_vertices_indices[1] = vertex_count++;
|
||||
output_vertices.push_back(x);
|
||||
output_vertices.push_back(y);
|
||||
output_vertices.push_back(z);
|
||||
output_uvs.push_back(texture_unit_size*node_id);
|
||||
output_uvs.push_back(1.0f);
|
||||
}
|
||||
|
||||
output_indices.push_back(side_vertices_indices[0]);
|
||||
output_indices.push_back(side_vertices_indices[1]);
|
||||
|
||||
if(right_node) {
|
||||
side_vertices_indices[4] = vertex_count++;
|
||||
output_vertices.push_back(x+1);
|
||||
output_vertices.push_back(y+1);
|
||||
output_vertices.push_back(z);
|
||||
output_uvs.push_back(texture_unit_size*node_id+1.0f);
|
||||
output_uvs.push_back(1.0f);
|
||||
|
||||
side_vertices_indices[5] = vertex_count++;
|
||||
output_vertices.push_back(x+1);
|
||||
output_vertices.push_back(y);
|
||||
output_vertices.push_back(z);
|
||||
output_uvs.push_back(texture_unit_size*node_id+1.0f);
|
||||
output_uvs.push_back(0.0f);
|
||||
}
|
||||
|
||||
output_indices.push_back(side_vertices_indices[5]);
|
||||
output_indices.push_back(side_vertices_indices[5]);
|
||||
output_indices.push_back(side_vertices_indices[0]);
|
||||
output_indices.push_back(side_vertices_indices[4]);
|
||||
output_vertices.push_back(x+1);
|
||||
output_vertices.push_back(y+1);
|
||||
output_vertices.push_back(z);
|
||||
|
||||
vertex_count+=4;
|
||||
push_indices(vertex_count, output_indices);
|
||||
push_uvs(texture_unit_size, node_id-1, output_uvs);
|
||||
}
|
||||
if(!front_node) {
|
||||
if(left_node) {
|
||||
side_vertices_indices[2] = vertex_count++;
|
||||
output_vertices.push_back(x);
|
||||
output_vertices.push_back(y);
|
||||
output_vertices.push_back(z+1);
|
||||
output_uvs.push_back(texture_unit_size*node_id);
|
||||
output_uvs.push_back(0.0f);
|
||||
|
||||
side_vertices_indices[3] = vertex_count++;
|
||||
output_vertices.push_back(x);
|
||||
output_vertices.push_back(y+1);
|
||||
output_vertices.push_back(z+1);
|
||||
output_uvs.push_back(texture_unit_size*node_id);
|
||||
output_uvs.push_back(1.0f);
|
||||
}
|
||||
|
||||
output_indices.push_back(side_vertices_indices[3]);
|
||||
output_indices.push_back(side_vertices_indices[2]);
|
||||
|
||||
if(right_node) {
|
||||
side_vertices_indices[6] = vertex_count++;
|
||||
output_vertices.push_back(x+1);
|
||||
output_vertices.push_back(y);
|
||||
output_vertices.push_back(z+1);
|
||||
output_uvs.push_back(texture_unit_size*node_id+1.0f);
|
||||
output_uvs.push_back(1.0f);
|
||||
|
||||
side_vertices_indices[7] = vertex_count++;
|
||||
output_vertices.push_back(x+1);
|
||||
output_vertices.push_back(y+1);
|
||||
output_vertices.push_back(z+1);
|
||||
output_uvs.push_back(texture_unit_size*node_id+1.0f);
|
||||
output_uvs.push_back(0.0f);
|
||||
}
|
||||
|
||||
output_indices.push_back(side_vertices_indices[6]);
|
||||
output_indices.push_back(side_vertices_indices[6]);
|
||||
output_indices.push_back(side_vertices_indices[3]);
|
||||
output_indices.push_back(side_vertices_indices[7]);
|
||||
output_vertices.push_back(x+1);
|
||||
output_vertices.push_back(y);
|
||||
output_vertices.push_back(z+1);
|
||||
|
||||
vertex_count+=4;
|
||||
push_indices(vertex_count, output_indices);
|
||||
push_uvs(texture_unit_size, node_id-1, output_uvs);
|
||||
}
|
||||
if(!bottom_node) {
|
||||
output_vertices.push_back(x);
|
||||
@ -215,7 +169,7 @@ void polygun::engine::normal_meshing::generate_mesh(const world::Chunk& chunk, f
|
||||
|
||||
vertex_count+=4;
|
||||
push_indices(vertex_count, output_indices);
|
||||
push_uvs(node_id, texture_unit_size, output_uvs);
|
||||
push_uvs(texture_unit_size, node_id-1, output_uvs);
|
||||
}
|
||||
if(!top_node) {
|
||||
output_vertices.push_back(x);
|
||||
@ -236,7 +190,7 @@ void polygun::engine::normal_meshing::generate_mesh(const world::Chunk& chunk, f
|
||||
|
||||
vertex_count+=4;
|
||||
push_indices(vertex_count, output_indices);
|
||||
push_uvs(node_id, texture_unit_size, output_uvs);
|
||||
push_uvs(texture_unit_size, node_id-1, output_uvs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,6 +103,6 @@ void TextureAtlas::construct_thread_func() {
|
||||
release();
|
||||
delete[] surfaces;
|
||||
|
||||
m_texture_unit_size = static_cast<float>(max_texture_width)/static_cast<float>(max_texture_width)*surface_count;
|
||||
m_texture_unit_size = static_cast<float>(max_texture_width)/(static_cast<float>(max_texture_width)*surface_count);
|
||||
m_atlas_updated = true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user