Revert "BlocksRenderer light conpressing & fix"

This reverts commit 13a9641392.
This commit is contained in:
@clasher113
2023-11-22 19:18:03 +02:00
parent 13a9641392
commit a48af43008
3 changed files with 11 additions and 28 deletions
+5 -14
View File
@@ -2,7 +2,7 @@
layout (location = 0) in vec3 v_position; layout (location = 0) in vec3 v_position;
layout (location = 1) in vec2 v_texCoord; layout (location = 1) in vec2 v_texCoord;
layout (location = 2) in float v_light; layout (location = 2) in vec4 v_light;
out vec4 a_color; out vec4 a_color;
out vec2 a_texCoord; out vec2 a_texCoord;
@@ -18,27 +18,18 @@ uniform float u_gamma;
uniform vec3 u_torchlightColor; uniform vec3 u_torchlightColor;
uniform float u_torchlightDistance; uniform float u_torchlightDistance;
vec4 decompress_light(float compressed_light) {
vec4 result;
int compressed = floatBitsToInt(compressed_light);
result.r = ((compressed >> 24) & 0xFF) / 255.f;
result.g = ((compressed >> 16) & 0xFF) / 255.f;
result.b = ((compressed >> 8) & 0xFF) / 255.f;
result.a = (compressed & 0xFF) / 255.f;
return result;
}
void main(){ void main(){
vec2 pos2d = (u_model * vec4(v_position, 1.0)).xz-u_cameraPos.xz; vec2 pos2d = (u_model * vec4(v_position, 1.0)).xz-u_cameraPos.xz;
vec4 modelpos = u_model * vec4(v_position+vec3(0,pow(length(pos2d)*0.0, 3.0),0), 1.0); vec4 modelpos = u_model * vec4(v_position+vec3(0,pow(length(pos2d)*0.0, 3.0),0), 1.0);
vec4 viewmodelpos = u_view * modelpos; vec4 viewmodelpos = u_view * modelpos;
vec4 decomp_light = decompress_light(v_light); vec3 light = v_light.rgb * 1.6;
vec3 light = decomp_light.rgb * 1.6;
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz)/u_torchlightDistance); float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz)/u_torchlightDistance);
light += torchlight * u_torchlightColor; light += torchlight * u_torchlightColor;
a_color = vec4(pow(light, vec3(u_gamma)),1.0f); a_color = vec4(pow(light, vec3(u_gamma)),1.0f);
a_texCoord = v_texCoord; a_texCoord = v_texCoord;
a_color.rgb = max(a_color.rgb, u_skyLightColor.rgb*decomp_light.a); a_color.r = max(a_color.r, u_skyLightColor.r*v_light.a);
a_color.g = max(a_color.g, u_skyLightColor.g*v_light.a);
a_color.b = max(a_color.b, u_skyLightColor.b*v_light.a);
a_distance = length(viewmodelpos); a_distance = length(viewmodelpos);
gl_Position = u_proj * viewmodelpos; gl_Position = u_proj * viewmodelpos;
} }
+6 -13
View File
@@ -17,7 +17,7 @@ using glm::ivec3;
using glm::vec3; using glm::vec3;
using glm::vec4; using glm::vec4;
#define VERTEX_SIZE 6 #define VERTEX_SIZE 9
BlocksRenderer::BlocksRenderer(size_t capacity, BlocksRenderer::BlocksRenderer(size_t capacity,
const Content* content, const Content* content,
@@ -50,17 +50,10 @@ void BlocksRenderer::vertex(const vec3& coord,
vertexBuffer[vertexOffset++] = u; vertexBuffer[vertexOffset++] = u;
vertexBuffer[vertexOffset++] = v; vertexBuffer[vertexOffset++] = v;
union { vertexBuffer[vertexOffset++] = light.r;
float floating; vertexBuffer[vertexOffset++] = light.g;
uint32_t integer; vertexBuffer[vertexOffset++] = light.b;
} compressed; vertexBuffer[vertexOffset++] = light.a;
compressed.integer = (uint32_t(light.r * 255) & 0xff) << 24;
compressed.integer |= (uint32_t(light.g * 255) & 0xff) << 16;
compressed.integer |= (uint32_t(light.b * 255) & 0xff) << 8;
compressed.integer |= (uint32_t(light.a * 255) & 0xff);
vertexBuffer[vertexOffset++] = compressed.floating;
} }
void BlocksRenderer::index(int a, int b, int c, int d, int e, int f) { void BlocksRenderer::index(int a, int b, int c, int d, int e, int f) {
@@ -360,7 +353,7 @@ Mesh* BlocksRenderer::render(const Chunk* chunk, int atlas_size, const ChunksSto
const voxel* voxels = chunk->voxels; const voxel* voxels = chunk->voxels;
render(voxels, atlas_size); render(voxels, atlas_size);
const vattr attrs[]{ {3}, {2}, {1}, {0} }; const vattr attrs[]{ {3}, {2}, {4}, {0} };
Mesh* mesh = new Mesh(vertexBuffer, vertexOffset / VERTEX_SIZE, indexBuffer, indexSize, attrs); Mesh* mesh = new Mesh(vertexBuffer, vertexOffset / VERTEX_SIZE, indexBuffer, indexSize, attrs);
return mesh; return mesh;
} }
-1
View File
@@ -38,7 +38,6 @@ void mouse_button_callback(GLFWwindow*, int button, int action, int) {
} }
void key_callback(GLFWwindow*, int key, int scancode, int action, int /*mode*/) { void key_callback(GLFWwindow*, int key, int scancode, int action, int /*mode*/) {
if (key == GLFW_KEY_UNKNOWN) return;
if (action == GLFW_PRESS) { if (action == GLFW_PRESS) {
Events::_keys[key] = true; Events::_keys[key] = true;
Events::_frames[key] = Events::_current; Events::_frames[key] = Events::_current;