Revert "BlocksRenderer light conpressing & fix"
This reverts commit 13a96413922ce46e32e03bb1606a8512117521bf.
This commit is contained in:
parent
13a9641392
commit
a48af43008
@ -2,7 +2,7 @@
|
||||
|
||||
layout (location = 0) in vec3 v_position;
|
||||
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 vec2 a_texCoord;
|
||||
@ -18,27 +18,18 @@ uniform float u_gamma;
|
||||
uniform vec3 u_torchlightColor;
|
||||
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(){
|
||||
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 viewmodelpos = u_view * modelpos;
|
||||
vec4 decomp_light = decompress_light(v_light);
|
||||
vec3 light = decomp_light.rgb * 1.6;
|
||||
vec3 light = v_light.rgb * 1.6;
|
||||
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz)/u_torchlightDistance);
|
||||
light += torchlight * u_torchlightColor;
|
||||
a_color = vec4(pow(light, vec3(u_gamma)),1.0f);
|
||||
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);
|
||||
gl_Position = u_proj * viewmodelpos;
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ using glm::ivec3;
|
||||
using glm::vec3;
|
||||
using glm::vec4;
|
||||
|
||||
#define VERTEX_SIZE 6
|
||||
#define VERTEX_SIZE 9
|
||||
|
||||
BlocksRenderer::BlocksRenderer(size_t capacity,
|
||||
const Content* content,
|
||||
@ -50,17 +50,10 @@ void BlocksRenderer::vertex(const vec3& coord,
|
||||
vertexBuffer[vertexOffset++] = u;
|
||||
vertexBuffer[vertexOffset++] = v;
|
||||
|
||||
union {
|
||||
float floating;
|
||||
uint32_t integer;
|
||||
} compressed;
|
||||
|
||||
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;
|
||||
vertexBuffer[vertexOffset++] = light.r;
|
||||
vertexBuffer[vertexOffset++] = light.g;
|
||||
vertexBuffer[vertexOffset++] = light.b;
|
||||
vertexBuffer[vertexOffset++] = light.a;
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
return mesh;
|
||||
}
|
||||
|
||||
@ -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*/) {
|
||||
if (key == GLFW_KEY_UNKNOWN) return;
|
||||
if (action == GLFW_PRESS) {
|
||||
Events::_keys[key] = true;
|
||||
Events::_frames[key] = Events::_current;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user