refactor res/shaders
This commit is contained in:
parent
52381d5afa
commit
8e159009eb
@ -1,3 +1,8 @@
|
||||
#ifndef COMMONS_GLSL_
|
||||
#define COMMONS_GLSL_
|
||||
|
||||
#include <constants>
|
||||
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#define PI2 (PI*2)
|
||||
|
||||
@ -10,3 +15,13 @@ vec4 decompress_light(float compressed_light) {
|
||||
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 = max(MAX_SKY_LIGHT, skyLightColor);
|
||||
return skyLightColor;
|
||||
}
|
||||
|
||||
#endif // COMMONS_GLSL_
|
||||
|
||||
15
res/shaders/lib/constants.glsl
Normal file
15
res/shaders/lib/constants.glsl
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef CONSTANTS_GLSL_
|
||||
#define CONSTANTS_GLSL_
|
||||
|
||||
// geometry
|
||||
#define CURVATURE_FACTOR 0.002
|
||||
|
||||
// lighting
|
||||
#define SKY_LIGHT_MUL 2.5
|
||||
#define SKY_LIGHT_TINT vec3(0.9, 0.8, 1.0)
|
||||
#define MAX_SKY_LIGHT vec3(0.1, 0.11, 0.14)
|
||||
|
||||
// fog
|
||||
#define FOG_POS_SCALE vec3(1.0, 0.2, 1.0)
|
||||
|
||||
#endif // CONSTANTS_GLSL_
|
||||
@ -18,6 +18,7 @@ void main(){
|
||||
// anyway it's any alpha-test alternative required
|
||||
if (alpha < 0.3f)
|
||||
discard;
|
||||
f_color = mix(a_color * tex_color, vec4(fogColor,1.0), min(1.0, pow(depth*u_fogFactor, u_fogCurve)));
|
||||
f_color = mix(a_color * tex_color, vec4(fogColor,1.0),
|
||||
min(1.0, pow(depth*u_fogFactor, u_fogCurve)));
|
||||
f_color.a = alpha;
|
||||
}
|
||||
|
||||
@ -20,29 +20,22 @@ uniform samplerCube u_cubemap;
|
||||
uniform vec3 u_torchlightColor;
|
||||
uniform float u_torchlightDistance;
|
||||
|
||||
#define SKY_LIGHT_MUL 2.5
|
||||
|
||||
|
||||
void main(){
|
||||
vec3 pos3d = (u_model * vec4(v_position, 1.0)).xyz-u_cameraPos.xyz;
|
||||
vec4 modelpos = u_model * vec4(v_position, 1.0);
|
||||
modelpos.y -= pow(length(pos3d.xz)*0.002, 3.0);
|
||||
vec3 pos3d = modelpos.xyz-u_cameraPos.xyz;
|
||||
modelpos.y -= pow(length(pos3d.xz)*CURVATURE_FACTOR, 3.0);
|
||||
vec4 viewmodelpos = u_view * modelpos;
|
||||
vec4 decomp_light = decompress_light(v_light);
|
||||
|
||||
vec3 light = decomp_light.rgb;
|
||||
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz)/u_torchlightDistance);
|
||||
a_dir = modelpos.xyz - u_cameraPos;
|
||||
light += torchlight * u_torchlightColor;
|
||||
a_color = vec4(pow(light, vec3(u_gamma)),1.0f);
|
||||
a_texCoord = v_texCoord;
|
||||
|
||||
vec3 skyLightColor = texture(u_cubemap, vec3(0.4f, 0.0f, 0.4f)).rgb;
|
||||
skyLightColor.g *= 0.9;
|
||||
skyLightColor.b *= 0.8;
|
||||
skyLightColor = min(vec3(1.0), skyLightColor*SKY_LIGHT_MUL);
|
||||
skyLightColor = max(vec3(0.1, 0.11, 0.14), skyLightColor);
|
||||
|
||||
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_distance = length(u_view * u_model * vec4(pos3d.x, pos3d.y*0.2, pos3d.z, 0.0));
|
||||
a_distance = length(u_view * u_model * vec4(pos3d * FOG_POS_SCALE, 0.0));
|
||||
gl_Position = u_proj * viewmodelpos;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user