refactor res/shaders
This commit is contained in:
parent
52381d5afa
commit
8e159009eb
@ -4,6 +4,6 @@ out vec4 f_color;
|
||||
uniform samplerCube u_cubemap;
|
||||
|
||||
void main(){
|
||||
vec3 dir = normalize(v_coord);
|
||||
f_color = texture(u_cubemap, dir);
|
||||
vec3 dir = normalize(v_coord);
|
||||
f_color = texture(u_cubemap, dir);
|
||||
}
|
||||
|
||||
@ -7,6 +7,6 @@ uniform float u_ar;
|
||||
uniform float u_zoom;
|
||||
|
||||
void main(){
|
||||
v_coord = (vec4(v_position*vec2(u_ar, 1.0f)*u_zoom, -1.0, 1.0) * u_view).xyz;
|
||||
gl_Position = vec4(v_position, 0.0, 1.0);
|
||||
v_coord = (vec4(v_position*vec2(u_ar, 1.0f)*u_zoom, -1.0, 1.0) * u_view).xyz;
|
||||
gl_Position = vec4(v_position, 0.0, 1.0);
|
||||
}
|
||||
|
||||
@ -1,12 +1,27 @@
|
||||
#ifndef COMMONS_GLSL_
|
||||
#define COMMONS_GLSL_
|
||||
|
||||
#include <constants>
|
||||
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#define PI2 (PI*2)
|
||||
|
||||
vec4 decompress_light(float compressed_light) {
|
||||
vec4 result;
|
||||
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;
|
||||
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_
|
||||
@ -2,5 +2,5 @@ in vec4 v_color;
|
||||
out vec4 f_color;
|
||||
|
||||
void main(){
|
||||
f_color = v_color;
|
||||
f_color = v_color;
|
||||
}
|
||||
|
||||
@ -6,6 +6,6 @@ out vec4 v_color;
|
||||
uniform mat4 u_projview;
|
||||
|
||||
void main(){
|
||||
v_color = a_color;
|
||||
gl_Position = u_projview * vec4(a_position, 1.0);
|
||||
v_color = a_color;
|
||||
gl_Position = u_projview * vec4(a_position, 1.0);
|
||||
}
|
||||
|
||||
@ -11,13 +11,14 @@ uniform float u_fogFactor;
|
||||
uniform float u_fogCurve;
|
||||
|
||||
void main(){
|
||||
vec3 fogColor = texture(u_cubemap, a_dir).rgb;
|
||||
vec4 tex_color = texture(u_texture0, a_texCoord);
|
||||
float depth = (a_distance/256.0);
|
||||
float alpha = a_color.a * tex_color.a;
|
||||
// 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.a = alpha;
|
||||
vec3 fogColor = texture(u_cubemap, a_dir).rgb;
|
||||
vec4 tex_color = texture(u_texture0, a_texCoord);
|
||||
float depth = (a_distance/256.0);
|
||||
float alpha = a_color.a * tex_color.a;
|
||||
// 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.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);
|
||||
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;
|
||||
vec4 modelpos = u_model * vec4(v_position, 1.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);
|
||||
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_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));
|
||||
gl_Position = u_proj * viewmodelpos;
|
||||
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 * FOG_POS_SCALE, 0.0));
|
||||
gl_Position = u_proj * viewmodelpos;
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ vec4 apply_vignette(vec4 color) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
f_color = texture(u_texture0, v_coord);
|
||||
f_color = apply_vignette(f_color);
|
||||
f_color = texture(u_texture0, v_coord);
|
||||
f_color = apply_vignette(f_color);
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ uniform float u_timer;
|
||||
uniform float u_dayTime;
|
||||
|
||||
void main(){
|
||||
v_coord = v_position * 0.5 + 0.5;
|
||||
gl_Position = vec4(v_position, 0.0, 1.0);
|
||||
v_coord = v_position * 0.5 + 0.5;
|
||||
gl_Position = vec4(v_position, 0.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ SOFTWARE.
|
||||
#define LIGHT_STEPS 4
|
||||
|
||||
vec3 calculate_scattering(
|
||||
vec3 start, // the start of the ray (the camera position)
|
||||
vec3 start, // the start of the ray (the camera position)
|
||||
vec3 dir, // the direction of the ray (the camera vector)
|
||||
float max_dist, // the maximum distance the ray can travel (because something is in the way, like an object)
|
||||
vec3 scene_color, // the color of the scene
|
||||
@ -201,16 +201,16 @@ vec3 calculate_scattering(
|
||||
|
||||
// and increment the position on this ray
|
||||
ray_pos_i += step_size_i;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// calculate how much light can pass through the atmosphere
|
||||
vec3 opacity = exp(-(beta_mie * opt_i.y + beta_ray * opt_i.x + beta_absorption * opt_i.z));
|
||||
|
||||
// calculate and return the final color
|
||||
// calculate and return the final color
|
||||
return (
|
||||
phase_ray * beta_ray * total_ray // rayleigh color
|
||||
+ phase_mie * beta_mie * total_mie // mie
|
||||
phase_ray * beta_ray * total_ray // rayleigh color
|
||||
+ phase_mie * beta_mie * total_mie // mie
|
||||
+ opt_i.x * beta_ambient // and ambient
|
||||
) * light_intensity + scene_color * opacity; // now make sure the background is rendered correctly
|
||||
}
|
||||
@ -264,7 +264,7 @@ void main() {
|
||||
vec3 col = vec3(0.0);//scene.xyz;
|
||||
// get the atmosphere color
|
||||
col += calculate_scattering(
|
||||
camera_position, // the position of the camera
|
||||
camera_position, // the position of the camera
|
||||
camera_vector, // the camera vector (ray direction of this pixel)
|
||||
1e12f, // max dist, essentially the scene depth
|
||||
vec3(0.0f), // scene color, the color of the current pixel being rendered
|
||||
|
||||
@ -3,6 +3,6 @@ layout (location = 0) in vec2 v_position;
|
||||
out vec2 v_coord;
|
||||
|
||||
void main(){
|
||||
v_coord = v_position;
|
||||
gl_Position = vec4(v_position, 0.0, 1.0);
|
||||
v_coord = v_position;
|
||||
gl_Position = vec4(v_position, 0.0, 1.0);
|
||||
}
|
||||
|
||||
@ -5,5 +5,5 @@ out vec4 f_color;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
void main(){
|
||||
f_color = a_color * texture(u_texture, a_textureCoord);
|
||||
f_color = a_color * texture(u_texture, a_textureCoord);
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ out vec4 a_color;
|
||||
uniform mat4 u_projview;
|
||||
|
||||
void main(){
|
||||
a_textureCoord = v_textureCoord;
|
||||
a_color = v_color;
|
||||
gl_Position = u_projview * vec4(v_position, 0.5, 1.0);
|
||||
a_textureCoord = v_textureCoord;
|
||||
a_color = v_color;
|
||||
gl_Position = u_projview * vec4(v_position, 0.5, 1.0);
|
||||
}
|
||||
|
||||
@ -5,6 +5,6 @@ out vec4 f_color;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
void main(){
|
||||
f_color = a_color * texture(u_texture, a_textureCoord);
|
||||
f_color = a_color * texture(u_texture, a_textureCoord);
|
||||
if (f_color.a == 0.0) discard;
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ uniform mat4 u_projview;
|
||||
uniform mat4 u_apply;
|
||||
|
||||
void main(){
|
||||
a_textureCoord = v_textureCoord;
|
||||
a_color = v_color;
|
||||
gl_Position = u_apply * u_projview * vec4(v_position, 1.0);
|
||||
a_textureCoord = v_textureCoord;
|
||||
a_color = v_color;
|
||||
gl_Position = u_apply * u_projview * vec4(v_position, 1.0);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user