Merge pull request #494 from REDxEYE/vertex_structures
Use vertex structures instead of plain float arrays
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
layout (location = 0) in vec3 v_position;
|
||||
layout (location = 1) in vec2 v_texCoord;
|
||||
layout (location = 2) in vec3 v_color;
|
||||
layout (location = 3) in float v_light;
|
||||
layout (location = 3) in vec4 v_light;
|
||||
|
||||
out vec4 a_color;
|
||||
out vec2 a_texCoord;
|
||||
@@ -31,8 +31,7 @@ void main() {
|
||||
vec3 pos3d = modelpos.xyz - u_cameraPos;
|
||||
modelpos.xyz = apply_planet_curvature(modelpos.xyz, pos3d);
|
||||
|
||||
vec4 decomp_light = decompress_light(v_light);
|
||||
vec3 light = decomp_light.rgb;
|
||||
vec3 light = v_light.rgb;
|
||||
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz) /
|
||||
u_torchlightDistance);
|
||||
light += torchlight * u_torchlightColor;
|
||||
@@ -41,7 +40,7 @@ void main() {
|
||||
|
||||
a_dir = modelpos.xyz - u_cameraPos;
|
||||
vec3 skyLightColor = pick_sky_color(u_cubemap);
|
||||
a_color.rgb = max(a_color.rgb, skyLightColor.rgb*decomp_light.a) * v_color;
|
||||
a_color.rgb = max(a_color.rgb, skyLightColor.rgb*v_light.a) * v_color;
|
||||
a_color.a = u_opacity;
|
||||
|
||||
float dist = length(u_view * u_model * vec4(pos3d * FOG_POS_SCALE, 0.0));
|
||||
|
||||
@@ -1,28 +1,17 @@
|
||||
#ifndef COMMONS_GLSL_
|
||||
#define COMMONS_GLSL_
|
||||
|
||||
#include <constants>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
vec3 pick_sky_color(samplerCube cubemap) {
|
||||
vec3 skyLightColor = texture(cubemap, vec3(0.4f, 0.0f, 0.4f)).rgb;
|
||||
skyLightColor *= SKY_LIGHT_TINT;
|
||||
skyLightColor = min(vec3(1.0), skyLightColor*SKY_LIGHT_MUL);
|
||||
skyLightColor = min(vec3(1.0f), skyLightColor * SKY_LIGHT_MUL);
|
||||
skyLightColor = max(MIN_SKY_LIGHT, skyLightColor);
|
||||
return skyLightColor;
|
||||
}
|
||||
|
||||
vec3 apply_planet_curvature(vec3 modelPos, vec3 pos3d) {
|
||||
modelPos.y -= pow(length(pos3d.xz)*CURVATURE_FACTOR, 3.0);
|
||||
modelPos.y -= pow(length(pos3d.xz) * CURVATURE_FACTOR, 3.0f);
|
||||
return modelPos;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -27,13 +27,12 @@ uniform vec3 u_torchlightColor;
|
||||
uniform float u_torchlightDistance;
|
||||
|
||||
void main() {
|
||||
vec4 modelpos = u_model * vec4(v_position, 1.0);
|
||||
vec4 modelpos = u_model * vec4(v_position, 1.0f);
|
||||
vec3 pos3d = modelpos.xyz-u_cameraPos;
|
||||
modelpos.xyz = apply_planet_curvature(modelpos.xyz, pos3d);
|
||||
|
||||
vec4 decomp_light = decompress_light(v_light);
|
||||
vec3 light = decomp_light.rgb;
|
||||
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz) /
|
||||
vec3 light = v_light.rgb;
|
||||
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);
|
||||
@@ -41,7 +40,7 @@ void main() {
|
||||
|
||||
a_dir = modelpos.xyz - u_cameraPos;
|
||||
vec3 skyLightColor = pick_sky_color(u_cubemap);
|
||||
a_color.rgb = max(a_color.rgb, skyLightColor.rgb*decomp_light.a);
|
||||
a_color.rgb = max(a_color.rgb, skyLightColor.rgb*v_light.a);
|
||||
|
||||
a_distance = length(u_view * u_model * vec4(pos3d * FOG_POS_SCALE, 0.0));
|
||||
float depth = (a_distance / 256.0);
|
||||
|
||||
Reference in New Issue
Block a user