mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 00:49:19 +02:00
Specgloss shaders improvements + experimental SSAO (debug only)
This commit is contained in:
@@ -13,3 +13,16 @@ vec3 envmap_color( vec3 normal )
|
||||
#endif
|
||||
return envcolor;
|
||||
}
|
||||
|
||||
// Roughness-aware env map lookup — uses mip levels for blurry reflections.
|
||||
// lod 0.0 = mirror sharp, lod ~8.0 = fully diffuse blur.
|
||||
vec3 envmap_color_lod(vec3 fragnormal, float lod)
|
||||
{
|
||||
#if ENVMAP_ENABLED
|
||||
vec3 refvec = reflect(f_pos.xyz, fragnormal); // view space — matches envmap_color exactly
|
||||
refvec = vec3(inv_view * vec4(refvec, 0.0)); // world space — was missing
|
||||
return textureLod(envmap, refvec, lod).rgb;
|
||||
#else
|
||||
return vec3(0.5); // was vec3(0.0), match the non-LOD fallback
|
||||
#endif
|
||||
}
|
||||
@@ -60,7 +60,15 @@ vec2 calc_light(vec3 light_dir, vec3 fragnormal)
|
||||
vec3 halfway_dir = normalize(light_dir + view_dir);
|
||||
|
||||
float diffuse_v = max(dot(fragnormal, light_dir), 0.0);
|
||||
float specular_v = pow(max(dot(fragnormal, halfway_dir), 0.0), max(glossiness, 0.01)) * diffuse_v;
|
||||
|
||||
// Energy-conserving Blinn-Phong normalization:
|
||||
// (n+8)/(8*pi) ensures the specular lobe integrates to the same
|
||||
// total energy regardless of glossiness — low glossiness stays dim
|
||||
// and spreads wide (blurry), high glossiness is bright and tight (sharp).
|
||||
float n = max(glossiness, 0.01);
|
||||
float normalization = (n + 8.0) / (8.0 * 3.14159265);
|
||||
float NdotH = max(dot(fragnormal, halfway_dir), 0.0);
|
||||
float specular_v = normalization * pow(NdotH, n);
|
||||
|
||||
return vec2(diffuse_v, specular_v);
|
||||
}
|
||||
@@ -121,71 +129,65 @@ vec2 calc_headlights(light_s light, vec3 fragnormal)
|
||||
// do magic here
|
||||
vec3 apply_lights(vec3 fragcolor, vec3 fragnormal, vec3 texturecolor, float reflectivity, float specularity, float shadowtone)
|
||||
{
|
||||
vec3 basecolor = param[0].rgb;
|
||||
vec3 basecolor = param[0].rgb;
|
||||
fragcolor *= basecolor;
|
||||
|
||||
fragcolor *= basecolor;
|
||||
vec3 emissioncolor = basecolor * emission;
|
||||
|
||||
vec3 emissioncolor = basecolor * emission;
|
||||
vec3 envcolor = envmap_color(fragnormal);
|
||||
vec3 view_dir = normalize(-f_pos.xyz);
|
||||
float NdotV = max(dot(fragnormal, view_dir), 0.0);
|
||||
vec3 F0 = mix(vec3(0.04), texturecolor, metalic);
|
||||
vec3 fresnel = F0 + (1.0 - F0) * pow(1.0 - NdotV, 5.0);
|
||||
|
||||
// yuv path
|
||||
vec3 texturecoloryuv = rgb2yuv(texturecolor);
|
||||
vec3 texturecolorfullv = yuv2rgb(vec3(0.2176, texturecoloryuv.gb));
|
||||
// hsl path
|
||||
// vec3 texturecolorhsl = rgb2hsl(texturecolor);
|
||||
// vec3 texturecolorfullv = hsl2rgb(vec3(texturecolorhsl.rg, 0.5));
|
||||
const float MAX_REFLECTION_LOD = 8.0;
|
||||
float env_roughness = 1.0 - clamp(glossiness / max(abs(param[1].w), 1.0), 0.0, 1.0);
|
||||
vec3 envcolor = envmap_color_lod(fragnormal, env_roughness * MAX_REFLECTION_LOD);
|
||||
|
||||
vec3 envyuv = rgb2yuv(envcolor);
|
||||
texturecolor = mix(texturecolor, texturecolorfullv, envyuv.r * reflectivity);
|
||||
// Tint texture toward fully-saturated under strong env, weighted by fresnel
|
||||
vec3 texturecoloryuv = rgb2yuv(texturecolor);
|
||||
vec3 texturecolorfullv = yuv2rgb(vec3(0.2176, texturecoloryuv.gb));
|
||||
vec3 envyuv = rgb2yuv(envcolor);
|
||||
texturecolor = mix(texturecolor, texturecolorfullv, envyuv.r * reflectivity * fresnel.r);
|
||||
|
||||
if(lights_count == 0U)
|
||||
return (fragcolor + emissioncolor + envcolor * reflectivity) * texturecolor;
|
||||
if (lights_count == 0U)
|
||||
return (fragcolor + emissioncolor) * texturecolor
|
||||
+ envcolor * fresnel * reflectivity;
|
||||
|
||||
// fragcolor *= lights[0].intensity;
|
||||
vec2 sunlight = calc_dir_light(lights[0], fragnormal);
|
||||
vec2 sunlight = calc_dir_light(lights[0], fragnormal);
|
||||
float diffuseamount = sunlight.x * param[1].x * lights[0].intensity;
|
||||
|
||||
float diffuseamount = (sunlight.x * param[1].x) * lights[0].intensity;
|
||||
// fragcolor += mix(lights[0].color * diffuseamount, envcolor, reflectivity);
|
||||
float shadow1 = 0.0;
|
||||
if (shadowtone < 1.0)
|
||||
{
|
||||
shadow1 = (1 - shadowtone) * clamp(calc_shadow(), 0.0, 1.00);
|
||||
}
|
||||
fragcolor += lights[0].color * 5.0 * (1.0 - shadow1) * diffuseamount;
|
||||
fragcolor = mix(fragcolor * 0.35, envcolor, reflectivity);
|
||||
float shadow1 = 0.0;
|
||||
if (shadowtone < 1.0)
|
||||
shadow1 = (1.0 - shadowtone) * clamp(calc_shadow(), 0.0, 1.0);
|
||||
|
||||
for (uint i = 1U; i < lights_count; i++)
|
||||
{
|
||||
light_s light = lights[i];
|
||||
vec2 part = vec2(0.0);
|
||||
fragcolor += lights[0].color * 5.0 * (1.0 - shadow1) * diffuseamount;
|
||||
|
||||
// if (light.type == LIGHT_SPOT)
|
||||
// part = calc_spot_light(light, fragnormal);
|
||||
// else if (light.type == LIGHT_POINT)
|
||||
// part = calc_point_light(light, fragnormal);
|
||||
// else if (light.type == LIGHT_DIR)
|
||||
// part = calc_dir_light(light, fragnormal);
|
||||
// else if (light.type == LIGHT_HEADLIGHTS)
|
||||
part = calc_headlights(light, fragnormal);
|
||||
for (uint i = 1U; i < lights_count; i++)
|
||||
{
|
||||
light_s light = lights[i];
|
||||
vec2 part = calc_headlights(light, fragnormal);
|
||||
fragcolor += light.color * (part.x * param[1].x + part.y * param[1].y) * light.intensity;
|
||||
}
|
||||
|
||||
fragcolor += light.color * (part.x * param[1].x + part.y * param[1].y) * light.intensity;
|
||||
}
|
||||
float specularamount = sunlight.y * param[1].y * specularity * lights[0].intensity
|
||||
* clamp(1.0 - shadowtone, 0.0, 1.0);
|
||||
if (shadowtone < 1.0)
|
||||
specularamount *= clamp(1.0 - shadow1, 0.0, 1.0);
|
||||
|
||||
float specularamount = (sunlight.y * param[1].y * specularity) * lights[0].intensity * clamp(1.0 - shadowtone, 0.0, 1.0);
|
||||
if (shadowtone < 1.0)
|
||||
{
|
||||
//float shadow = calc_shadow();
|
||||
specularamount *= clamp(1.0 - shadow1, 0.0, 1.00);
|
||||
//fragcolor = mix(fragcolor, fragcolor * shadowtone, clamp((diffuseamount) * shadow1 , 0.0, 1.0));
|
||||
}
|
||||
fragcolor += emissioncolor;
|
||||
vec3 specularcolor = specularamount * lights[0].color;
|
||||
fragcolor += emissioncolor;
|
||||
vec3 specularcolor = specularamount * lights[0].color;
|
||||
|
||||
if (param[1].w < 0.0)
|
||||
{
|
||||
float metalic = 1.0;
|
||||
}
|
||||
fragcolor = mix(((fragcolor + specularcolor) * texturecolor),(fragcolor * texturecolor + specularcolor),metalic) ;
|
||||
// Env reflection tracked separately — must NOT go through the albedo multiply below
|
||||
vec3 env_reflection = envcolor * fresnel * reflectivity * (1.0 - shadow1 * 0.5);
|
||||
|
||||
return fragcolor;
|
||||
}
|
||||
// Diffuse + specular: albedo tints diffuse, metals also tint specular
|
||||
vec3 result = mix(
|
||||
(fragcolor + specularcolor) * texturecolor,
|
||||
fragcolor * texturecolor + specularcolor,
|
||||
metalic);
|
||||
|
||||
// Env added after albedo multiply: raw for dielectrics, albedo-tinted for metals
|
||||
result += mix(env_reflection, env_reflection * texturecolor, metalic);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ void main()
|
||||
float reflectivity = param[1].z;
|
||||
float specularity = texture(specgloss, f_coord).r;
|
||||
glossiness = texture(specgloss, f_coord).g * abs(param[1].w);
|
||||
float metalic = texture(specgloss, f_coord).b;
|
||||
metalic = texture(specgloss, f_coord).b;
|
||||
|
||||
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
|
||||
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
|
||||
|
||||
@@ -68,7 +68,7 @@ void main()
|
||||
float reflectivity = reflblend > 1.0 ? param[1].z * 1.0 : param[1].z * reflblend;
|
||||
float specularity = specgloss_map.r;
|
||||
glossiness = specgloss_map.g * abs(param[1].w);
|
||||
float metalic = specgloss_map.b;
|
||||
metalic = specgloss_map.b;
|
||||
|
||||
|
||||
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
|
||||
|
||||
@@ -73,8 +73,8 @@ void main()
|
||||
vec3 fragnormal = normalize(f_tbn * normalize(vec3(normal.xy + normaldetail.xy, normal.z)));
|
||||
float reflectivity = param[1].z * normal_map.a;
|
||||
float specularity = specgloss_map.r;
|
||||
float glossiness = specgloss_map.g * abs(param[1].w);
|
||||
float metalic = specgloss_map.b;
|
||||
glossiness = specgloss_map.g * abs(param[1].w);
|
||||
metalic = specgloss_map.b;
|
||||
|
||||
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ void main()
|
||||
float reflectivity = param[1].z * texture(normalmap, f_coord).a;
|
||||
float specularity = texture(specgloss, f_coord).r;
|
||||
glossiness = texture(specgloss, f_coord).g * abs(param[1].w);
|
||||
float metalic = texture(specgloss, f_coord).b;
|
||||
metalic = texture(specgloss, f_coord).b;
|
||||
|
||||
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ void main()
|
||||
float reflectivity = param[1].z * texture(normalmap, f_coord_p).a;
|
||||
float specularity = texture(specgloss, f_coord_p).r;
|
||||
glossiness = texture(specgloss, f_coord_p).g * abs(param[1].w);
|
||||
float metalic = texture(specgloss, f_coord_p).b;
|
||||
metalic = texture(specgloss, f_coord_p).b;
|
||||
|
||||
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ void main()
|
||||
float reflectivity = param[1].z * texture(reflmap, f_coord).a;
|
||||
float specularity = texture(specgloss, f_coord).r;
|
||||
glossiness = texture(specgloss, f_coord).g * abs(param[1].w);
|
||||
float metalic = texture(specgloss, f_coord).b;
|
||||
metalic = texture(specgloss, f_coord).b;
|
||||
|
||||
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ void main()
|
||||
float reflectivity = param[1].z * texture(normalmap, f_coord).a;
|
||||
float specularity = texture(specgloss, f_coord).r;
|
||||
glossiness = texture(specgloss, f_coord).g * abs(param[1].w);
|
||||
float metalic = texture(specgloss, f_coord).b;
|
||||
metalic = texture(specgloss, f_coord).b;
|
||||
|
||||
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, 1.0);
|
||||
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
|
||||
|
||||
@@ -36,59 +36,62 @@ uniform sampler2D specgloss;
|
||||
|
||||
vec3 apply_lights_sunless(vec3 fragcolor, vec3 fragnormal, vec3 texturecolor, float reflectivity, float specularity, float shadowtone)
|
||||
{
|
||||
vec3 basecolor = param[0].rgb;
|
||||
vec3 basecolor = param[0].rgb;
|
||||
fragcolor *= basecolor;
|
||||
|
||||
fragcolor *= basecolor;
|
||||
vec3 emissioncolor = basecolor * emission;
|
||||
|
||||
vec3 emissioncolor = basecolor * emission;
|
||||
vec3 envcolor = envmap_color(fragnormal);
|
||||
vec3 view_dir = normalize(-f_pos.xyz);
|
||||
float NdotV = max(dot(fragnormal, view_dir), 0.0);
|
||||
vec3 F0 = mix(vec3(0.04), texturecolor, metalic);
|
||||
vec3 fresnel = F0 + (1.0 - F0) * pow(1.0 - NdotV, 5.0);
|
||||
|
||||
// yuv path
|
||||
vec3 texturecoloryuv = rgb2yuv(texturecolor);
|
||||
vec3 texturecolorfullv = yuv2rgb(vec3(0.2176, texturecoloryuv.gb));
|
||||
// hsl path
|
||||
// vec3 texturecolorhsl = rgb2hsl(texturecolor);
|
||||
// vec3 texturecolorfullv = hsl2rgb(vec3(texturecolorhsl.rg, 0.5));
|
||||
const float MAX_REFLECTION_LOD = 8.0;
|
||||
float env_roughness = 1.0 - clamp(glossiness / max(abs(param[1].w), 1.0), 0.0, 1.0);
|
||||
vec3 envcolor = envmap_color_lod(fragnormal, env_roughness * MAX_REFLECTION_LOD);
|
||||
|
||||
vec3 envyuv = rgb2yuv(envcolor);
|
||||
texturecolor = mix(texturecolor, texturecolorfullv, envyuv.r * reflectivity);
|
||||
vec3 texturecoloryuv = rgb2yuv(texturecolor);
|
||||
vec3 texturecolorfullv = yuv2rgb(vec3(0.2176, texturecoloryuv.gb));
|
||||
vec3 envyuv = rgb2yuv(envcolor);
|
||||
texturecolor = mix(texturecolor, texturecolorfullv, envyuv.r * reflectivity * fresnel.r);
|
||||
|
||||
if(lights_count == 0U)
|
||||
return (fragcolor + emissioncolor + envcolor * reflectivity) * texturecolor;
|
||||
if (lights_count == 0U)
|
||||
return (fragcolor + emissioncolor) * texturecolor
|
||||
+ envcolor * fresnel * reflectivity;
|
||||
|
||||
vec2 sunlight = calc_dir_light(lights[0], fragnormal);
|
||||
vec2 sunlight = calc_dir_light(lights[0], fragnormal);
|
||||
float diffuseamount = sunlight.x * param[1].x * lights[0].intensity;
|
||||
|
||||
float diffuseamount = (sunlight.x * param[1].x) * lights[0].intensity;
|
||||
fragcolor += envcolor * reflectivity;
|
||||
float specularamount = (sunlight.y * param[1].y * specularity) * lights[0].intensity;
|
||||
float specularamount = sunlight.y * param[1].y * specularity * lights[0].intensity;
|
||||
|
||||
for (uint i = 1U; i < lights_count; i++)
|
||||
{
|
||||
light_s light = lights[i];
|
||||
vec2 part = vec2(0.0);
|
||||
for (uint i = 1U; i < lights_count; i++)
|
||||
{
|
||||
light_s light = lights[i];
|
||||
vec2 part = calc_headlights(light, fragnormal);
|
||||
fragcolor += light.color * (part.x * param[1].x + part.y * param[1].y) * light.intensity;
|
||||
}
|
||||
|
||||
// if (light.type == LIGHT_SPOT)
|
||||
// part = calc_spot_light(light, fragnormal);
|
||||
// else if (light.type == LIGHT_POINT)
|
||||
// part = calc_point_light(light, fragnormal);
|
||||
// else if (light.type == LIGHT_DIR)
|
||||
// part = calc_dir_light(light, fragnormal);
|
||||
// else if (light.type == LIGHT_HEADLIGHTS)
|
||||
part = calc_headlights(light, fragnormal);
|
||||
if (shadowtone < 1.0)
|
||||
{
|
||||
float shadow = calc_shadow();
|
||||
specularamount *= clamp(1.0 - shadow, 0.0, 1.0);
|
||||
fragcolor = mix(fragcolor, fragcolor * shadowtone, clamp(diffuseamount * shadow, 0.0, 1.0));
|
||||
}
|
||||
|
||||
fragcolor += light.color * (part.x * param[1].x + part.y * param[1].y) * light.intensity;
|
||||
}
|
||||
fragcolor += emissioncolor;
|
||||
vec3 specularcolor = specularamount * lights[0].color;
|
||||
|
||||
if (shadowtone < 1.0)
|
||||
{
|
||||
float shadow = calc_shadow();
|
||||
specularamount *= clamp(1.0 - shadow, 0.0, 1.0);
|
||||
fragcolor = mix(fragcolor, fragcolor * shadowtone, clamp(diffuseamount * shadow + specularamount, 0.0, 1.0));
|
||||
}
|
||||
fragcolor += emissioncolor;
|
||||
fragcolor *= texturecolor;
|
||||
|
||||
return fragcolor;
|
||||
// Env reflection separate from albedo multiply — same fix as apply_lights
|
||||
vec3 env_reflection = envcolor * fresnel * reflectivity;
|
||||
|
||||
vec3 result = mix(
|
||||
(fragcolor + specularcolor) * texturecolor,
|
||||
fragcolor * texturecolor + specularcolor,
|
||||
metalic);
|
||||
|
||||
result += mix(env_reflection, env_reflection * texturecolor, metalic);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void main()
|
||||
@@ -110,7 +113,7 @@ void main()
|
||||
float reflectivity = param[1].z * texture(normalmap, f_coord).a;
|
||||
float specularity = texture(specgloss, f_coord).r;
|
||||
glossiness = texture(specgloss, f_coord).g * abs(param[1].w);
|
||||
float metalic = texture(specgloss, f_coord).b;
|
||||
metalic = texture(specgloss, f_coord).b;
|
||||
|
||||
fragcolor = apply_lights_sunless(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
|
||||
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
|
||||
|
||||
72
shaders/postfx_ssao.frag
Normal file
72
shaders/postfx_ssao.frag
Normal file
@@ -0,0 +1,72 @@
|
||||
in vec2 f_coords;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
#texture (depth_tex, 0, R)
|
||||
uniform sampler2D depth_tex;
|
||||
|
||||
#texture (noise_tex, 1, RGB)
|
||||
uniform sampler2D noise_tex;
|
||||
|
||||
#include <common>
|
||||
|
||||
vec3 view_pos_from_depth(vec2 uv, float depth) {
|
||||
vec4 clip = vec4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
|
||||
vec4 view = inverse(projection) * clip;
|
||||
return view.xyz / view.w;
|
||||
}
|
||||
|
||||
// Deterministic hemisphere sample (z > 0), mimics the C++ kernel generator
|
||||
vec3 kernel_sample(int i) {
|
||||
float fi = float(i);
|
||||
vec3 dir = normalize(vec3(
|
||||
fract(sin(fi * 12.9898) * 43758.5453) * 2.0 - 1.0,
|
||||
fract(sin(fi * 78.2330) * 43758.5453) * 2.0 - 1.0,
|
||||
fract(sin(fi * 37.7190) * 43758.5453) // z >= 0 -> hemisphere
|
||||
));
|
||||
float len = fract(sin(fi * 94.6720) * 43758.5453);
|
||||
float scale = fi / 32.0;
|
||||
scale = mix(0.1, 1.0, scale * scale); // bias samples inward
|
||||
return dir * len * scale;
|
||||
}
|
||||
|
||||
void main() {
|
||||
float d = texture(depth_tex, f_coords).r;
|
||||
if (d >= 1.0) { out_color = vec4(1.0); return; } // skybox -> no occlusion
|
||||
|
||||
vec3 pos = view_pos_from_depth(f_coords, d);
|
||||
|
||||
vec3 ddx = dFdx(pos);
|
||||
vec3 ddy = dFdy(pos);
|
||||
vec3 n = normalize(cross(ddx, ddy));
|
||||
|
||||
// derive screen size from the depth texture instead of a UBO field
|
||||
vec2 screen_size = vec2(textureSize(depth_tex, 0));
|
||||
vec2 noise_uv = f_coords * (screen_size / 4.0);
|
||||
vec3 rvec = texture(noise_tex, noise_uv).xyz;
|
||||
|
||||
vec3 t = normalize(rvec - n * dot(rvec, n));
|
||||
vec3 b = cross(n, t);
|
||||
mat3 TBN = mat3(t, b, n);
|
||||
|
||||
const int KERNEL = 32;
|
||||
const float RADIUS = 0.5;
|
||||
const float BIAS = 0.025;
|
||||
|
||||
float occ = 0.0;
|
||||
for (int i = 0; i < KERNEL; ++i) {
|
||||
vec3 sp = TBN * kernel_sample(i);
|
||||
sp = pos + sp * RADIUS;
|
||||
|
||||
vec4 clip = projection * vec4(sp, 1.0);
|
||||
vec3 ndc = clip.xyz / clip.w;
|
||||
vec2 suv = ndc.xy * 0.5 + 0.5;
|
||||
|
||||
float sd = texture(depth_tex, suv).r;
|
||||
float szv = view_pos_from_depth(suv, sd).z;
|
||||
|
||||
float range = smoothstep(0.0, 1.0, RADIUS / abs(pos.z - szv));
|
||||
occ += (szv >= sp.z + BIAS ? 1.0 : 0.0) * range;
|
||||
}
|
||||
|
||||
out_color = vec4(1.0 - occ / float(KERNEL));
|
||||
}
|
||||
22
shaders/postfx_ssao_apply.frag
Normal file
22
shaders/postfx_ssao_apply.frag
Normal file
@@ -0,0 +1,22 @@
|
||||
in vec2 f_coords;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
#texture (color_tex, 0, RGB)
|
||||
uniform sampler2D color_tex;
|
||||
|
||||
#texture (ssao_tex, 1, R)
|
||||
uniform sampler2D ssao_tex;
|
||||
|
||||
const float SSAO_STRENGTH = 0.8;
|
||||
const float SSAO_MIN = 0.3; // floor on darkening so shadows don't go pitch black
|
||||
|
||||
void main() {
|
||||
vec3 c = texture(color_tex, f_coords).rgb;
|
||||
float occ = texture(ssao_tex, f_coords).r;
|
||||
|
||||
// remap occlusion with strength and a minimum floor
|
||||
occ = pow(clamp(occ, 0.0, 1.0), SSAO_STRENGTH);
|
||||
occ = mix(SSAO_MIN, 1.0, occ);
|
||||
|
||||
out_color = vec4(c * occ, 1.0);
|
||||
}
|
||||
14
shaders/postfx_ssao_blur.frag
Normal file
14
shaders/postfx_ssao_blur.frag
Normal file
@@ -0,0 +1,14 @@
|
||||
in vec2 f_coords;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
#texture (ssao_tex, 0, R)
|
||||
uniform sampler2D ssao_tex;
|
||||
|
||||
void main() {
|
||||
vec2 texel = 1.0 / vec2(textureSize(ssao_tex, 0));
|
||||
float sum = 0.0;
|
||||
for (int x = -2; x < 2; ++x)
|
||||
for (int y = -2; y < 2; ++y)
|
||||
sum += texture(ssao_tex, f_coords + vec2(x, y) * texel).r;
|
||||
out_color = vec4(sum / 16.0);
|
||||
}
|
||||
Reference in New Issue
Block a user