Files
OrcaSlicer/resources/shaders/110/ssao.fs
Rodrigo Faselli cf8bb38dc6 Realistic View: Phong Shading + Ambient Oclusion + Cast Shadows (#13704)
* Phong Shading

* Add shader selection to graphics preferences

* SSAO

* 3D canvas menu

Co-Authored-By: yw4z <yw4z@outlook.com>

* better SSAO

* Adjust

* phong in preview mode

* cast shadows

sombra 3

sombra 2

* fix 1

* SSAO independent

* Fix 2

* clean 1

* shadows availables with gouraud

* Update Preferences.cpp

* tweeks

* No Normal textures

* Depth texture allocation

* avoid rebinding/redefining state each render.

* free SSAO

* set shadow fill color

* remove duplicated code

* cached model to avoid per-frame uploads

* yw4z suggestion

Co-Authored-By: yw4z <yw4z@outlook.com>

* Update Preferences.cpp

Co-Authored-By: yw4z <yw4z@outlook.com>

* Update GLCanvas3D.cpp

* only gouraud for preview mode

* Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Add new OpenGL shading model setting

* Update src/slic3r/GUI/GLCanvas3D.cpp

* Apply suggestion from @RF47

* Title Case

* normal textures

* gamma 2.2

Co-Authored-By: Ian Bassi <12130714+ianalexis@users.noreply.github.com>

* Revert "gamma 2.2"

This reverts commit 909a84af604a080b3f4b8dd67d13956473a77afe.

* Reapply "gamma 2.2"

This reverts commit 0f0c3d9ec0d2c9647ce06afac4fe9266b5ffda97.

* AO blend

Co-Authored-By: Ian Bassi <12130714+ianalexis@users.noreply.github.com>

* Revert "AO blend"

This reverts commit c5c9a3aa6b295704e71299451b937648e5c5f109.

* 4.0 pixel radius

* windows light effect

direccion

brillo

* smoothing

* ajuste de brillo

* ajustes de brillo

* No SSAO  for bed

* disable realistic view on paint gismos

* Update ssao.fs

* circular panel

---------

Co-authored-by: yw4z <yw4z@outlook.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Ian Bassi <ian.bassi@outlook.com>
Co-authored-by: Ian Bassi <12130714+ianalexis@users.noreply.github.com>
Co-authored-by: SoftFever <softfeverever@gmail.com>
2026-06-04 18:22:06 +08:00

85 lines
2.9 KiB
GLSL

#version 110
/**
* SSAO Shader - GLSL 110 version with highlight protection
* Preserves brightness on upward-facing surfaces (top areas)
*/
uniform sampler2D color_texture;
uniform sampler2D depth_texture;
uniform sampler2D normal_texture;
uniform vec2 inv_tex_size;
uniform float z_near;
uniform float z_far;
varying vec2 tex_coord;
float linearize_depth(float depth)
{
float z = depth * 2.0 - 1.0;
return (2.0 * z_near * z_far) / (z_far + z_near - z * (z_far - z_near));
}
void main()
{
vec3 base = texture2D(color_texture, tex_coord).rgb;
float depth_center = linearize_depth(texture2D(depth_texture, tex_coord).r);
// Sample normal at current fragment (range: -1 to 1)
vec3 normal_center = texture2D(normal_texture, tex_coord).rgb * 2.0 - 1.0;
// Calculate how much the surface faces upward
// up_factor = 1.0 for surfaces pointing straight up (0,0,1)
// up_factor = 0.0 for surfaces pointing down or sideways
float up_factor = max(0.0, normal_center.z); // Assuming Z is up axis
// Alternative: if Y is up, use normal_center.y
// Adaptive sampling radius
float radius = mix(2.0, 4.0, depth_center / z_far);
vec2 offsets[8];
offsets[0] = vec2( 1.0, 0.0);
offsets[1] = vec2( 0.707, 0.707);
offsets[2] = vec2( 0.0, 1.0);
offsets[3] = vec2(-0.707, 0.707);
offsets[4] = vec2(-1.0, 0.0);
offsets[5] = vec2(-0.707,-0.707);
offsets[6] = vec2( 0.0, -1.0);
offsets[7] = vec2( 0.707,-0.707);
float occlusion = 0.0;
int valid_samples = 0;
for (int i = 0; i < 8; ++i) {
vec2 uv = tex_coord + offsets[i] * inv_tex_size * radius;
uv = clamp(uv, vec2(0.001), vec2(0.999));
float sample_depth = linearize_depth(texture2D(depth_texture, uv).r);
float depth_diff = max(0.0, depth_center - sample_depth);
float threshold = 0.015 * (0.5 + depth_center / z_far);
float contribution = smoothstep(0.001, threshold, depth_diff);
float diagonal_weight = 1.0 - abs(offsets[i].x * offsets[i].y) * 0.5;
occlusion += contribution * diagonal_weight;
valid_samples++;
}
if (valid_samples > 0)
occlusion /= float(valid_samples);
// flatter/top-like surfaces get less darkening
float ao_intensity = 0.55;
float ambient_occlusion = 1.0 - occlusion * ao_intensity;
// Different min values for top vs bottom surfaces
float ao_min = mix(0.45, 0.70, up_factor); // Bottom: 0.45, Top: 0.70
ambient_occlusion = clamp(ambient_occlusion, ao_min, 1.0);
// Boost brightness on top surfaces (optional)
float brightness_boost = 1.0 + up_factor * 0.15; // 15% extra brightness on top
ambient_occlusion = pow(ambient_occlusion, 2.2) * brightness_boost;
ambient_occlusion = clamp(ambient_occlusion, 0.45, 1.05);
gl_FragColor = vec4(base * ambient_occlusion, 1.0);
}