136 lines
3.8 KiB
GLSL
136 lines
3.8 KiB
GLSL
#version 330 core
|
|
|
|
uniform sampler2D u_tex;
|
|
uniform sampler2D u_tex_pos;
|
|
uniform sampler2D u_tex_normal;
|
|
uniform sampler2D u_tex_light;
|
|
|
|
uniform vec3 u_sun_color;
|
|
uniform vec3 u_sun_direction;
|
|
uniform vec3 u_ambient_color;
|
|
// uniform float u_farplane;
|
|
// uniform vec3 u_farplane_color;
|
|
// uniform float u_farplane_strength;
|
|
|
|
layout (location = 0) out vec4 o_color;
|
|
|
|
vec3 GetAmbientLight() {
|
|
return u_ambient_color;
|
|
}
|
|
|
|
vec3 GetSunLight(vec3 normal) {
|
|
float sun_intensity = max(dot(normal, u_sun_direction), 0.0);
|
|
return sun_intensity * u_sun_color;
|
|
}
|
|
|
|
void main() {
|
|
ivec2 int_pos = ivec2(gl_FragCoord.xy);
|
|
|
|
vec4 local_rgba = texelFetch(u_tex, int_pos, 0);
|
|
vec4 local_normal_4 = texelFetch(u_tex_normal, int_pos, 0);
|
|
vec4 local_light_4 = texelFetch(u_tex_light, int_pos, 0);
|
|
float local_dist = texelFetch(u_tex_pos, int_pos, 0).r;
|
|
|
|
vec3 local_rgb = local_rgba.rgb;
|
|
vec3 local_normal = local_normal_4.xyz;
|
|
vec3 local_light = local_light_4.rgb;
|
|
|
|
vec3 rr = GetAmbientLight() + GetSunLight(local_normal) + local_light;
|
|
// vec3 rr = max(GetAmbientLight(), max(GetSunLight(local_normal), local_light));
|
|
|
|
|
|
vec3 result = local_rgb * mix(vec3(1.0), rr, local_rgba.a);
|
|
|
|
|
|
o_color = vec4(result, 1.0);
|
|
|
|
// o_color = vec4(1.0);
|
|
|
|
// o_color = vec4(local_rgb, 1.0);
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
// in vec2 Poz;
|
|
layout (pixel_center_integer) in vec4 gl_FragCoord;
|
|
|
|
uniform sampler2D tex;
|
|
uniform sampler2D tex_pos;
|
|
uniform sampler2D tex_normal;
|
|
uniform sampler2D tex_light;
|
|
uniform sampler2D tex_transparent;
|
|
|
|
uniform float fadeAlpha;
|
|
|
|
uniform vec3 sunColor;
|
|
uniform vec3 sunDirection;
|
|
uniform vec3 ambientColor;
|
|
uniform float ambientStrength;
|
|
uniform float farplane;
|
|
uniform vec3 farplaneColor;
|
|
uniform float farplaneStrength;
|
|
|
|
uniform float time;
|
|
|
|
out vec4 FragColor;
|
|
|
|
float rand(vec2 co) {
|
|
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
|
|
}
|
|
|
|
vec3 noise(vec2 co, float t, float intensity) {
|
|
vec2 co_t = co * mod(t, 1.0);
|
|
return ((vec3(rand(co_t), rand(co_t * vec2(-1.0, 1.0)), rand(co_t * vec2(1.0, -1.0))) - 0.5) * intensity * 2.0);
|
|
}
|
|
|
|
float linearize_depth(float d, float zNear, float zFar) {
|
|
float z_n = 2.0 * d - 1.0;
|
|
return 2.0 * zNear * zFar / (zFar + zNear - z_n * (zFar - zNear));
|
|
}
|
|
|
|
void main() {
|
|
ivec2 iPoz = ivec2(gl_FragCoord.xy);
|
|
|
|
vec4 this_rgba = texelFetch(tex, iPoz, 0);
|
|
//vec4 this_posd = texelFetch(tex_pos, iPoz, 0);
|
|
vec4 this_normala = texelFetch(tex_normal, iPoz, 0);
|
|
vec4 this_lighta = texelFetch(tex_light, iPoz, 0);
|
|
// vec3 this_light = this_lighta.rgb / min(1.0, max(this_lighta.r, max(this_lighta.g, this_lighta.b)));
|
|
vec4 this_transparent = texelFetch(tex_transparent, iPoz, 0);
|
|
|
|
vec3 this_rgb = this_rgba.rgb;
|
|
//vec3 this_pos = this_posd.xyz;
|
|
vec3 this_normal = this_normala.xyz;
|
|
|
|
|
|
float Dist = texelFetch(tex_pos, iPoz, 0).r; //this_posd.w;
|
|
// vec3 this_pos = WorldPosFromDepth(Dist);
|
|
float LightAffected = this_normala.w;
|
|
|
|
// --- old fs
|
|
|
|
vec3 ambientResult = ambientStrength * ambientColor;
|
|
|
|
vec3 sunDir = normalize(sunDirection);
|
|
float sunIntensity = max(dot(this_normal, sunDir), 0.0);
|
|
vec3 sunResult = sunIntensity * sunColor;
|
|
|
|
// vec3 result = max(max(ambientResult, sunResult), this_lighta.rgb) * this_rgb;
|
|
vec3 result = (ambientResult + sunResult + this_lighta.rgb) * this_rgb;
|
|
|
|
vec3 litColor = mix(this_rgb, result, LightAffected);
|
|
|
|
|
|
//vec3 fragColor3 = litColor; //mix(litColor, farplaneColor, linearize_depth(Dist, 0.1, farplane) / farplane);
|
|
float fogIntensity = farplaneStrength * linearize_depth(Dist, 0.1, farplane) / farplane;
|
|
|
|
vec3 finalColor = mix(litColor, farplaneColor, fogIntensity);
|
|
vec3 fragColor3 = mix(finalColor, this_transparent.rgb, this_transparent.a);
|
|
|
|
FragColor = vec4(fragColor3 /*+ noise(gl_FragCoord.xy, time, 0.03)* /, 1.0);
|
|
}
|
|
|
|
*/
|