mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-09 18:27:00 +00:00
Merge upstream/main into belt-printer
Brings the belt-printer work up to date with 591 upstream commits.
Conflict resolutions (12 files, 42 hunks):
- GCode.cpp: adopted upstream's per-filament/per-nozzle config refactor
(get_filament_config_index, NOZZLE_CONFIG), the extracted
generate_timelapse_gcode + farthest-point timelapse, and the
ConfigOptionFloatsNullable calibration options. Re-applied the belt
hooks on top: init_belt_writer / axis remap / FirstLayerPlane setup,
on_set_origin, the belt-corrected calib_z for the volumetric speed
tower, and path_on_first_layer (belt's per-path first-layer test) in
place of upstream's layer-index on_first_layer() in the acceleration,
jerk and overhang-detection paths. Swept upstream's new m_writer.
uses to m_writer-> since belt holds the writer by unique_ptr.
- interpolate_value_across_layers: kept upstream's banded stepping and
belt's object-Z-span ratio; dropped upstream's duplicate ratio decl.
- Plater.cpp: took upstream's guarded add_model(...) early-returns and
the VFA vfa_layer_height plumbing; kept the belt temp-tower path,
_calib_apply_belt_mode and belt_calib_flip_ringing_tower. Dropped the
VFA "cut upper" block, superseded upstream by model scaling.
- Brim.cpp: upstream's ObjectInstanceID-keyed brimAreaMap, keeping the
belt early-return.
- 3DScene.cpp: kept both the belt build-plate tilt up_direction and
upstream's per-extruder printable-height shading.
- GCodeViewer.cpp: kept upstream's dim-previous-layers setup and belt's
exemption from the same-result early return.
- TreeSupport.cpp: upstream's >= 0 roof-layer fix inside belt's
belt-floor branch.
- calib.cpp / GCode.hpp / GCodeWriter.{cpp,hpp} / Print.hpp: upstream's
additions adapted to belt's pointer-held writer and helpers.
- Custom.json: kept profile version 02.04.00.03 (belt) over upstream's
02.04.00.01; both bumped from 02.04.00.00.
Building this tree needs the wxInspector dependency, which upstream
added in the interim (python3 and wxWidgets 3.3.2 were already present
in the shared deps prefix).
This commit is contained in:
@@ -47,10 +47,24 @@ uniform vec2 screen_size;
|
||||
#endif // ENABLE_ENVIRONMENT_MAP
|
||||
|
||||
uniform PrintVolumeDetection print_volume;
|
||||
// BBS H2D/H2C per-extruder printable height (3DScene.cpp): .x = flag (>=1 active), .y/.z = the two
|
||||
// extruders' Z limits. Inert unless the CPU sets .x >= 1.0 (multi-extruder printers only), so the
|
||||
// shared object shader stays pixel-identical for single-extruder printers. See 3DScene.cpp.
|
||||
uniform vec3 extruder_printable_heights;
|
||||
const float ONE_OVER_EPSILON = 1e4;
|
||||
|
||||
uniform float z_far;
|
||||
uniform float z_near;
|
||||
|
||||
// Depth-based shadow map (object-on-object and self shadows). shadow_intensity == 0 disables it.
|
||||
uniform sampler2D shadow_map;
|
||||
uniform mat4 shadow_light_vp;
|
||||
uniform float shadow_intensity;
|
||||
uniform float shadow_map_texel;
|
||||
|
||||
// LIGHT_TOP_DIR in eye space (matches the diffuse light used for shading in gouraud.vs).
|
||||
const vec3 SHADOW_LIGHT_DIR = vec3(-0.4574957, 0.4574957, 0.7624929);
|
||||
|
||||
varying vec3 clipping_planes_dots;
|
||||
varying float color_clip_plane_dot;
|
||||
|
||||
@@ -126,6 +140,35 @@ float DetectSilho(vec2 fragCoord)
|
||||
);
|
||||
}
|
||||
|
||||
// Returns a lighting multiplier in [1 - shadow_intensity, 1]: < 1 where the fragment is
|
||||
// occluded from the light in the shadow map. 3x3 PCF softens the edges.
|
||||
float shadow_shade()
|
||||
{
|
||||
if (shadow_intensity <= 0.0)
|
||||
return 1.0;
|
||||
|
||||
vec4 lp = shadow_light_vp * world_pos;
|
||||
vec3 proj = lp.xyz / lp.w;
|
||||
proj = proj * 0.5 + 0.5;
|
||||
if (proj.z > 1.0)
|
||||
return 1.0;
|
||||
|
||||
// Slope-scaled depth bias: larger where the surface grazes / faces away from the light. This
|
||||
// suppresses self-shadow acne without discarding real shadows cast by other objects onto
|
||||
// back-facing surfaces (e.g. the shaded back/tip of a cone sitting inside a larger shadow).
|
||||
float NdotL = dot(normalize(eye_normal), SHADOW_LIGHT_DIR);
|
||||
float bias = mix(0.0004, 0.004, clamp(1.0 - NdotL, 0.0, 1.0));
|
||||
// 5x5 PCF: softens shadow edges into a smooth penumbra and blurs residual facet acne.
|
||||
float sum = 0.0;
|
||||
for (int x = -2; x <= 2; ++x) {
|
||||
for (int y = -2; y <= 2; ++y) {
|
||||
float closest = texture2D(shadow_map, proj.xy + vec2(float(x), float(y)) * shadow_map_texel).r;
|
||||
sum += (proj.z - bias > closest) ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
return 1.0 - shadow_intensity * (sum / 25.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
if (any(lessThan(clipping_planes_dots, ZERO)))
|
||||
@@ -167,9 +210,20 @@ void main()
|
||||
}
|
||||
color.rgb = (any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))) ? mix(color.rgb, ZERO, 0.3333) : color.rgb;
|
||||
|
||||
// BBS per-extruder printable-height shading (H2D/H2C). Gated on the flag so it is inert for
|
||||
// single-extruder printers. Darkens the band between the two extruders' Z limits inside the bed
|
||||
// rect (the zone only the taller extruder can reach). Math kept byte-identical to BBS gouraud.fs.
|
||||
if (extruder_printable_heights.x >= 1.0) {
|
||||
vec3 eph_check_min = (world_pos.xyz - vec3(print_volume.xy_data.x, print_volume.xy_data.y, extruder_printable_heights.y)) * ONE_OVER_EPSILON;
|
||||
vec3 eph_check_max = (world_pos.xyz - vec3(print_volume.xy_data.z, print_volume.xy_data.w, extruder_printable_heights.z)) * ONE_OVER_EPSILON;
|
||||
bool is_out_printable_height = (all(greaterThan(eph_check_min, vec3(1.0))) && all(lessThan(eph_check_max, vec3(1.0))));
|
||||
color.rgb = is_out_printable_height ? mix(color.rgb, ZERO, 0.7) : color.rgb;
|
||||
}
|
||||
float shade = shadow_shade();
|
||||
|
||||
//BBS: add outline_color
|
||||
if (is_outline) {
|
||||
color = vec4(vec3(intensity.y) + color.rgb * intensity.x, color.a);
|
||||
color = vec4((vec3(intensity.y) + color.rgb * intensity.x) * shade, color.a);
|
||||
vec2 fragCoord = gl_FragCoord.xy;
|
||||
float s = DetectSilho(fragCoord);
|
||||
// Makes silhouettes thicker.
|
||||
@@ -177,13 +231,15 @@ void main()
|
||||
{
|
||||
s = max(s, DetectSilho(fragCoord.xy + vec2(i, 0)));
|
||||
s = max(s, DetectSilho(fragCoord.xy + vec2(0, i)));
|
||||
}
|
||||
}
|
||||
if (s < 0.01)
|
||||
discard;
|
||||
gl_FragColor = vec4(mix(color.rgb, getBackfaceColor(color.rgb), s), color.a);
|
||||
}
|
||||
#ifdef ENABLE_ENVIRONMENT_MAP
|
||||
else if (use_environment_tex)
|
||||
gl_FragColor = vec4(0.45 * texture(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color.rgb * intensity.x, color.a);
|
||||
gl_FragColor = vec4((0.45 * texture(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color.rgb * intensity.x) * shade, color.a);
|
||||
#endif
|
||||
else
|
||||
gl_FragColor = vec4(vec3(intensity.y) + color.rgb * intensity.x, color.a);
|
||||
gl_FragColor = vec4((vec3(intensity.y) + color.rgb * intensity.x) * shade, color.a);
|
||||
}
|
||||
@@ -31,6 +31,8 @@ uniform mat4 projection_matrix;
|
||||
uniform mat3 view_normal_matrix;
|
||||
uniform mat4 volume_world_matrix;
|
||||
uniform SlopeDetection slope;
|
||||
uniform bool is_outline;
|
||||
uniform vec2 screen_size;
|
||||
|
||||
// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane.
|
||||
uniform vec2 z_range;
|
||||
@@ -76,6 +78,15 @@ void main()
|
||||
world_normal_z = slope.actived ? dot(normalize(slope.volume_world_normal_matrix * v_normal), slope.up_direction) : 0.0;
|
||||
|
||||
gl_Position = projection_matrix * position;
|
||||
if (is_outline) {
|
||||
vec3 n = normalize((view_normal_matrix * v_normal).xyz);
|
||||
vec2 dir = normalize(n.xy);
|
||||
if (dot(dir, dir) > 0.0) {
|
||||
//set outline thickness
|
||||
float px = 3.0;
|
||||
gl_Position.xy += dir * (px * 2.0 / screen_size) * gl_Position.w;
|
||||
}
|
||||
}
|
||||
// Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded.
|
||||
clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z);
|
||||
color_clip_plane_dot = dot(world_pos, color_clip_plane);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#version 110
|
||||
|
||||
uniform sampler2D Texture;
|
||||
uniform sampler2D s_texture;
|
||||
|
||||
varying vec2 Frag_UV;
|
||||
varying vec4 Frag_Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);
|
||||
gl_FragColor = Frag_Color * texture2D(s_texture, Frag_UV.st);
|
||||
}
|
||||
@@ -65,6 +65,12 @@ uniform float z_far;
|
||||
uniform float z_near;
|
||||
uniform bool enable_ssao;
|
||||
|
||||
// Depth-based shadow map (object-on-object and self shadows). shadow_intensity == 0 disables it.
|
||||
uniform sampler2D shadow_map;
|
||||
uniform mat4 shadow_light_vp;
|
||||
uniform float shadow_intensity;
|
||||
uniform float shadow_map_texel;
|
||||
|
||||
varying vec3 clipping_planes_dots;
|
||||
varying float color_clip_plane_dot;
|
||||
|
||||
@@ -167,10 +173,39 @@ vec3 compute_window_reflection(vec3 normal, vec3 view_dir)
|
||||
|
||||
float intensity = window_light * bars * (0.15 + 0.15 * fresnel) * facing;
|
||||
intensity = clamp(intensity, 0.0, 0.25);
|
||||
|
||||
|
||||
return vec3(intensity);
|
||||
}
|
||||
|
||||
// Returns a lighting multiplier in [1 - shadow_intensity, 1]: < 1 where the fragment is
|
||||
// occluded from the light in the shadow map. 3x3 PCF softens the edges.
|
||||
float shadow_shade()
|
||||
{
|
||||
if (shadow_intensity <= 0.0)
|
||||
return 1.0;
|
||||
|
||||
vec4 lp = shadow_light_vp * world_pos;
|
||||
vec3 proj = lp.xyz / lp.w;
|
||||
proj = proj * 0.5 + 0.5;
|
||||
if (proj.z > 1.0)
|
||||
return 1.0;
|
||||
|
||||
// Slope-scaled depth bias: larger where the surface grazes / faces away from the light. This
|
||||
// suppresses self-shadow acne without discarding real shadows cast by other objects onto
|
||||
// back-facing surfaces (e.g. the shaded back/tip of a cone sitting inside a larger shadow).
|
||||
float NdotL = dot(normalize(eye_normal), LIGHT_TOP_DIR);
|
||||
float bias = mix(0.0004, 0.004, clamp(1.0 - NdotL, 0.0, 1.0));
|
||||
// 5x5 PCF: softens shadow edges into a smooth penumbra and blurs residual facet acne.
|
||||
float sum = 0.0;
|
||||
for (int x = -2; x <= 2; ++x) {
|
||||
for (int y = -2; y <= 2; ++y) {
|
||||
float closest = texture2D(shadow_map, proj.xy + vec2(float(x), float(y)) * shadow_map_texel).r;
|
||||
sum += (proj.z - bias > closest) ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
return 1.0 - shadow_intensity * (sum / 25.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
if (any(lessThan(clipping_planes_dots, ZERO)))
|
||||
@@ -226,8 +261,10 @@ void main()
|
||||
|
||||
// SSAO is applied in post-process pass. Keep base lighting unchanged here.
|
||||
|
||||
float shade = shadow_shade();
|
||||
|
||||
if (is_outline) {
|
||||
vec3 shaded_rgb = (vec3(specular) + window_reflection + color.rgb * diffuse) * PHONG_BRIGHTNESS;
|
||||
vec3 shaded_rgb = (vec3(specular) + window_reflection + color.rgb * diffuse) * PHONG_BRIGHTNESS * shade;
|
||||
vec4 shaded_color = vec4(clamp(shaded_rgb, vec3(0.0), vec3(1.0)), color.a);
|
||||
vec2 fragCoord = gl_FragCoord.xy;
|
||||
float s = DetectSilho(fragCoord);
|
||||
@@ -236,12 +273,14 @@ void main()
|
||||
s = max(s, DetectSilho(fragCoord.xy + vec2(i, 0)));
|
||||
s = max(s, DetectSilho(fragCoord.xy + vec2(0, i)));
|
||||
}
|
||||
if (s < 0.01)
|
||||
discard;
|
||||
gl_FragColor = vec4(mix(shaded_color.rgb, getBackfaceColor(shaded_color.rgb), s), shaded_color.a);
|
||||
}
|
||||
#ifdef ENABLE_ENVIRONMENT_MAP
|
||||
else if (use_environment_tex)
|
||||
gl_FragColor = vec4(clamp((0.45 * texture2D(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + window_reflection + 0.8 * color.rgb * diffuse) * PHONG_BRIGHTNESS, vec3(0.0), vec3(1.0)), color.a);
|
||||
gl_FragColor = vec4(clamp((0.45 * texture2D(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + window_reflection + 0.8 * color.rgb * diffuse) * PHONG_BRIGHTNESS * shade, vec3(0.0), vec3(1.0)), color.a);
|
||||
#endif
|
||||
else
|
||||
gl_FragColor = vec4(clamp((vec3(specular) + window_reflection + color.rgb * diffuse) * PHONG_BRIGHTNESS, vec3(0.0), vec3(1.0)), color.a);
|
||||
gl_FragColor = vec4(clamp((vec3(specular) + window_reflection + color.rgb * diffuse) * PHONG_BRIGHTNESS * shade, vec3(0.0), vec3(1.0)), color.a);
|
||||
}
|
||||
@@ -14,6 +14,8 @@ uniform mat4 projection_matrix;
|
||||
uniform mat3 view_normal_matrix;
|
||||
uniform mat4 volume_world_matrix;
|
||||
uniform SlopeDetection slope;
|
||||
uniform bool is_outline;
|
||||
uniform vec2 screen_size;
|
||||
|
||||
// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane.
|
||||
uniform vec2 z_range;
|
||||
@@ -48,6 +50,15 @@ void main()
|
||||
world_normal_z = slope.actived ? (normalize(slope.volume_world_normal_matrix * v_normal)).z : 0.0;
|
||||
|
||||
gl_Position = projection_matrix * position;
|
||||
if (is_outline) {
|
||||
vec3 n = normalize((view_normal_matrix * v_normal).xyz);
|
||||
vec2 dir = normalize(n.xy);
|
||||
if (dot(dir, dir) > 0.0) {
|
||||
//set outline thickness
|
||||
float px = 3.0;
|
||||
gl_Position.xy += dir * (px * 2.0 / screen_size) * gl_Position.w;
|
||||
}
|
||||
}
|
||||
// Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded.
|
||||
clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z);
|
||||
color_clip_plane_dot = dot(world_pos, color_clip_plane);
|
||||
|
||||
40
resources/shaders/110/printbed_shadow.fs
Normal file
40
resources/shaders/110/printbed_shadow.fs
Normal file
@@ -0,0 +1,40 @@
|
||||
#version 110
|
||||
|
||||
// Draws the build-plate as a receiver of the same depth shadow map used for object/self shadows,
|
||||
// so the plate, objects, and self-shadows all come from one unified technique.
|
||||
uniform sampler2D shadow_map;
|
||||
uniform mat4 shadow_light_vp;
|
||||
uniform float shadow_intensity;
|
||||
uniform float shadow_map_texel;
|
||||
|
||||
varying vec4 world_pos;
|
||||
|
||||
// Fraction of the 5x5 PCF kernel occluded from the light. Matches the object shadow shader.
|
||||
float shadow_occlusion()
|
||||
{
|
||||
vec4 lp = shadow_light_vp * world_pos;
|
||||
vec3 proj = lp.xyz / lp.w;
|
||||
proj = proj * 0.5 + 0.5;
|
||||
if (proj.z > 1.0)
|
||||
return 0.0;
|
||||
|
||||
// The plate is a pure receiver (never rendered into the shadow map), so a tiny constant
|
||||
// bias for numerical safety is enough here.
|
||||
float bias = 0.0004;
|
||||
float sum = 0.0;
|
||||
for (int x = -2; x <= 2; ++x) {
|
||||
for (int y = -2; y <= 2; ++y) {
|
||||
float closest = texture2D(shadow_map, proj.xy + vec2(float(x), float(y)) * shadow_map_texel).r;
|
||||
sum += (proj.z - bias > closest) ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
return sum / 25.0;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float occ = shadow_occlusion();
|
||||
if (occ <= 0.0)
|
||||
discard;
|
||||
gl_FragColor = vec4(0.0, 0.0, 0.0, shadow_intensity * occ);
|
||||
}
|
||||
16
resources/shaders/110/printbed_shadow.vs
Normal file
16
resources/shaders/110/printbed_shadow.vs
Normal file
@@ -0,0 +1,16 @@
|
||||
#version 110
|
||||
|
||||
uniform mat4 view_model_matrix;
|
||||
uniform mat4 projection_matrix;
|
||||
|
||||
attribute vec3 v_position;
|
||||
|
||||
// The plate mask quad is authored directly in world coordinates (z = 0 plane),
|
||||
// so v_position is already the world position of the fragment.
|
||||
varying vec4 world_pos;
|
||||
|
||||
void main()
|
||||
{
|
||||
world_pos = vec4(v_position, 1.0);
|
||||
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
|
||||
}
|
||||
@@ -11,6 +11,7 @@ uniform sampler2D normal_texture;
|
||||
uniform vec2 inv_tex_size;
|
||||
uniform float z_near;
|
||||
uniform float z_far;
|
||||
uniform bool is_outline;
|
||||
|
||||
varying vec2 tex_coord;
|
||||
|
||||
@@ -22,6 +23,10 @@ float linearize_depth(float depth)
|
||||
|
||||
void main()
|
||||
{
|
||||
if (is_outline) {
|
||||
gl_FragColor = vec4(texture2D(color_texture, tex_coord).rgb, 1.0);
|
||||
return;
|
||||
}
|
||||
vec3 base = texture2D(color_texture, tex_coord).rgb;
|
||||
float depth_center = linearize_depth(texture2D(depth_texture, tex_coord).r);
|
||||
|
||||
|
||||
@@ -46,10 +46,24 @@ uniform vec2 screen_size;
|
||||
#endif // ENABLE_ENVIRONMENT_MAP
|
||||
|
||||
uniform PrintVolumeDetection print_volume;
|
||||
// BBS H2D/H2C per-extruder printable height (3DScene.cpp): .x = flag (>=1 active), .y/.z = the two
|
||||
// extruders' Z limits. Inert unless the CPU sets .x >= 1.0 (multi-extruder printers only), so the
|
||||
// shared object shader stays pixel-identical for single-extruder printers. See 3DScene.cpp.
|
||||
uniform vec3 extruder_printable_heights;
|
||||
const float ONE_OVER_EPSILON = 1e4;
|
||||
|
||||
uniform float z_far;
|
||||
uniform float z_near;
|
||||
|
||||
// Depth-based shadow map (object-on-object and self shadows). shadow_intensity == 0 disables it.
|
||||
uniform sampler2D shadow_map;
|
||||
uniform mat4 shadow_light_vp;
|
||||
uniform float shadow_intensity;
|
||||
uniform float shadow_map_texel;
|
||||
|
||||
// LIGHT_TOP_DIR in eye space (matches the diffuse light used for shading in gouraud.vs).
|
||||
const vec3 SHADOW_LIGHT_DIR = vec3(-0.4574957, 0.4574957, 0.7624929);
|
||||
|
||||
in vec3 clipping_planes_dots;
|
||||
in float color_clip_plane_dot;
|
||||
|
||||
@@ -125,6 +139,35 @@ float DetectSilho(vec2 fragCoord)
|
||||
);
|
||||
}
|
||||
|
||||
// Returns a lighting multiplier in [1 - shadow_intensity, 1]: < 1 where the fragment is
|
||||
// occluded from the light in the shadow map. 3x3 PCF softens the edges.
|
||||
float shadow_shade()
|
||||
{
|
||||
if (shadow_intensity <= 0.0)
|
||||
return 1.0;
|
||||
|
||||
vec4 lp = shadow_light_vp * world_pos;
|
||||
vec3 proj = lp.xyz / lp.w;
|
||||
proj = proj * 0.5 + 0.5;
|
||||
if (proj.z > 1.0)
|
||||
return 1.0;
|
||||
|
||||
// Slope-scaled depth bias: larger where the surface grazes / faces away from the light. This
|
||||
// suppresses self-shadow acne without discarding real shadows cast by other objects onto
|
||||
// back-facing surfaces (e.g. the shaded back/tip of a cone sitting inside a larger shadow).
|
||||
float NdotL = dot(normalize(eye_normal), SHADOW_LIGHT_DIR);
|
||||
float bias = mix(0.0004, 0.004, clamp(1.0 - NdotL, 0.0, 1.0));
|
||||
// 5x5 PCF: softens shadow edges into a smooth penumbra and blurs residual facet acne.
|
||||
float sum = 0.0;
|
||||
for (int x = -2; x <= 2; ++x) {
|
||||
for (int y = -2; y <= 2; ++y) {
|
||||
float closest = texture(shadow_map, proj.xy + vec2(float(x), float(y)) * shadow_map_texel).r;
|
||||
sum += (proj.z - bias > closest) ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
return 1.0 - shadow_intensity * (sum / 25.0);
|
||||
}
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main()
|
||||
@@ -168,9 +211,20 @@ void main()
|
||||
}
|
||||
color.rgb = (any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))) ? mix(color.rgb, ZERO, 0.3333) : color.rgb;
|
||||
|
||||
// BBS per-extruder printable-height shading (H2D/H2C). Gated on the flag so it is inert for
|
||||
// single-extruder printers. Darkens the band between the two extruders' Z limits inside the bed
|
||||
// rect (the zone only the taller extruder can reach). Math kept byte-identical to BBS gouraud.fs.
|
||||
if (extruder_printable_heights.x >= 1.0) {
|
||||
vec3 eph_check_min = (world_pos.xyz - vec3(print_volume.xy_data.x, print_volume.xy_data.y, extruder_printable_heights.y)) * ONE_OVER_EPSILON;
|
||||
vec3 eph_check_max = (world_pos.xyz - vec3(print_volume.xy_data.z, print_volume.xy_data.w, extruder_printable_heights.z)) * ONE_OVER_EPSILON;
|
||||
bool is_out_printable_height = (all(greaterThan(eph_check_min, vec3(1.0))) && all(lessThan(eph_check_max, vec3(1.0))));
|
||||
color.rgb = is_out_printable_height ? mix(color.rgb, ZERO, 0.7) : color.rgb;
|
||||
}
|
||||
float shade = shadow_shade();
|
||||
|
||||
//BBS: add outline_color
|
||||
if (is_outline) {
|
||||
color = vec4(vec3(intensity.y) + color.rgb * intensity.x, color.a);
|
||||
color = vec4((vec3(intensity.y) + color.rgb * intensity.x) * shade, color.a);
|
||||
vec2 fragCoord = gl_FragCoord.xy;
|
||||
float s = DetectSilho(fragCoord);
|
||||
// Makes silhouettes thicker.
|
||||
@@ -178,13 +232,15 @@ void main()
|
||||
{
|
||||
s = max(s, DetectSilho(fragCoord.xy + vec2(i, 0)));
|
||||
s = max(s, DetectSilho(fragCoord.xy + vec2(0, i)));
|
||||
}
|
||||
}
|
||||
if (s < 0.01)
|
||||
discard;
|
||||
out_color = vec4(mix(color.rgb, getBackfaceColor(color.rgb), s), color.a);
|
||||
}
|
||||
#ifdef ENABLE_ENVIRONMENT_MAP
|
||||
else if (use_environment_tex)
|
||||
out_color = vec4(0.45 * texture(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color.rgb * intensity.x, color.a);
|
||||
out_color = vec4((0.45 * texture(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color.rgb * intensity.x) * shade, color.a);
|
||||
#endif
|
||||
else
|
||||
out_color = vec4(vec3(intensity.y) + color.rgb * intensity.x, color.a);
|
||||
out_color = vec4((vec3(intensity.y) + color.rgb * intensity.x) * shade, color.a);
|
||||
}
|
||||
@@ -31,6 +31,8 @@ uniform mat4 projection_matrix;
|
||||
uniform mat3 view_normal_matrix;
|
||||
uniform mat4 volume_world_matrix;
|
||||
uniform SlopeDetection slope;
|
||||
uniform bool is_outline;
|
||||
uniform vec2 screen_size;
|
||||
|
||||
// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane.
|
||||
uniform vec2 z_range;
|
||||
@@ -76,6 +78,15 @@ void main()
|
||||
world_normal_z = slope.actived ? dot(normalize(slope.volume_world_normal_matrix * v_normal), slope.up_direction) : 0.0;
|
||||
|
||||
gl_Position = projection_matrix * position;
|
||||
if (is_outline) {
|
||||
vec3 n = normalize((view_normal_matrix * v_normal).xyz);
|
||||
vec2 dir = normalize(n.xy);
|
||||
if (dot(dir, dir) > 0.0) {
|
||||
//set outline thickness
|
||||
float px = 3.0;
|
||||
gl_Position.xy += dir * (px * 2.0 / screen_size) * gl_Position.w;
|
||||
}
|
||||
}
|
||||
// Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded.
|
||||
clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z);
|
||||
color_clip_plane_dot = dot(world_pos, color_clip_plane);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#version 140
|
||||
|
||||
uniform sampler2D Texture;
|
||||
uniform sampler2D s_texture;
|
||||
|
||||
in vec2 Frag_UV;
|
||||
in vec4 Frag_Color;
|
||||
@@ -9,5 +9,5 @@ out vec4 out_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
out_color = Frag_Color * texture(Texture, Frag_UV.st);
|
||||
out_color = Frag_Color * texture(s_texture, Frag_UV.st);
|
||||
}
|
||||
@@ -65,6 +65,12 @@ uniform float z_far;
|
||||
uniform float z_near;
|
||||
uniform bool enable_ssao;
|
||||
|
||||
// Depth-based shadow map (object-on-object and self shadows). shadow_intensity == 0 disables it.
|
||||
uniform sampler2D shadow_map;
|
||||
uniform mat4 shadow_light_vp;
|
||||
uniform float shadow_intensity;
|
||||
uniform float shadow_map_texel;
|
||||
|
||||
in vec3 clipping_planes_dots;
|
||||
in float color_clip_plane_dot;
|
||||
|
||||
@@ -170,11 +176,40 @@ vec3 compute_window_reflection(vec3 normal, vec3 view_dir)
|
||||
|
||||
|
||||
float intensity = window_light * bars * (0.15 + 0.15 * fresnel) * facing;
|
||||
intensity = clamp(intensity, 0.0, 0.25);
|
||||
|
||||
intensity = clamp(intensity, 0.0, 0.25);
|
||||
|
||||
return vec3(intensity);
|
||||
}
|
||||
|
||||
// Returns a lighting multiplier in [1 - shadow_intensity, 1]: < 1 where the fragment is
|
||||
// occluded from the light in the shadow map. 3x3 PCF softens the edges.
|
||||
float shadow_shade()
|
||||
{
|
||||
if (shadow_intensity <= 0.0)
|
||||
return 1.0;
|
||||
|
||||
vec4 lp = shadow_light_vp * world_pos;
|
||||
vec3 proj = lp.xyz / lp.w;
|
||||
proj = proj * 0.5 + 0.5;
|
||||
if (proj.z > 1.0)
|
||||
return 1.0;
|
||||
|
||||
// Slope-scaled depth bias: larger where the surface grazes / faces away from the light. This
|
||||
// suppresses self-shadow acne without discarding real shadows cast by other objects onto
|
||||
// back-facing surfaces (e.g. the shaded back/tip of a cone sitting inside a larger shadow).
|
||||
float NdotL = dot(normalize(eye_normal), LIGHT_TOP_DIR);
|
||||
float bias = mix(0.0004, 0.004, clamp(1.0 - NdotL, 0.0, 1.0));
|
||||
// 5x5 PCF: softens shadow edges into a smooth penumbra and blurs residual facet acne.
|
||||
float sum = 0.0;
|
||||
for (int x = -2; x <= 2; ++x) {
|
||||
for (int y = -2; y <= 2; ++y) {
|
||||
float closest = texture(shadow_map, proj.xy + vec2(float(x), float(y)) * shadow_map_texel).r;
|
||||
sum += (proj.z - bias > closest) ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
return 1.0 - shadow_intensity * (sum / 25.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
if (any(lessThan(clipping_planes_dots, ZERO)))
|
||||
@@ -230,8 +265,10 @@ void main()
|
||||
|
||||
// SSAO is applied in post-process pass. Keep base lighting unchanged here.
|
||||
|
||||
float shade = shadow_shade();
|
||||
|
||||
if (is_outline) {
|
||||
vec3 shaded_rgb = (vec3(specular) + window_reflection + color.rgb * diffuse) * PHONG_BRIGHTNESS;
|
||||
vec3 shaded_rgb = (vec3(specular) + window_reflection + color.rgb * diffuse) * PHONG_BRIGHTNESS * shade;
|
||||
vec4 shaded_color = vec4(clamp(shaded_rgb, vec3(0.0), vec3(1.0)), color.a);
|
||||
vec2 fragCoord = gl_FragCoord.xy;
|
||||
float s = DetectSilho(fragCoord);
|
||||
@@ -240,12 +277,14 @@ void main()
|
||||
s = max(s, DetectSilho(fragCoord.xy + vec2(i, 0)));
|
||||
s = max(s, DetectSilho(fragCoord.xy + vec2(0, i)));
|
||||
}
|
||||
if (s < 0.01)
|
||||
discard;
|
||||
out_color = vec4(mix(shaded_color.rgb, getBackfaceColor(shaded_color.rgb), s), shaded_color.a);
|
||||
}
|
||||
#ifdef ENABLE_ENVIRONMENT_MAP
|
||||
else if (use_environment_tex)
|
||||
out_color = vec4(clamp((0.45 * texture(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + window_reflection + 0.8 * color.rgb * diffuse) * PHONG_BRIGHTNESS, vec3(0.0), vec3(1.0)), color.a);
|
||||
out_color = vec4(clamp((0.45 * texture(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + window_reflection + 0.8 * color.rgb * diffuse) * PHONG_BRIGHTNESS * shade, vec3(0.0), vec3(1.0)), color.a);
|
||||
#endif
|
||||
else
|
||||
out_color = vec4(clamp((vec3(specular) + window_reflection + color.rgb * diffuse) * PHONG_BRIGHTNESS, vec3(0.0), vec3(1.0)), color.a);
|
||||
out_color = vec4(clamp((vec3(specular) + window_reflection + color.rgb * diffuse) * PHONG_BRIGHTNESS * shade, vec3(0.0), vec3(1.0)), color.a);
|
||||
}
|
||||
@@ -14,6 +14,8 @@ uniform mat4 projection_matrix;
|
||||
uniform mat3 view_normal_matrix;
|
||||
uniform mat4 volume_world_matrix;
|
||||
uniform SlopeDetection slope;
|
||||
uniform bool is_outline;
|
||||
uniform vec2 screen_size;
|
||||
|
||||
// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane.
|
||||
uniform vec2 z_range;
|
||||
@@ -48,6 +50,15 @@ void main()
|
||||
world_normal_z = slope.actived ? (normalize(slope.volume_world_normal_matrix * v_normal)).z : 0.0;
|
||||
|
||||
gl_Position = projection_matrix * position;
|
||||
if (is_outline) {
|
||||
vec3 n = normalize((view_normal_matrix * v_normal).xyz);
|
||||
vec2 dir = normalize(n.xy);
|
||||
if (dot(dir, dir) > 0.0) {
|
||||
//set outline thickness
|
||||
float px = 3.0;
|
||||
gl_Position.xy += dir * (px * 2.0 / screen_size) * gl_Position.w;
|
||||
}
|
||||
}
|
||||
// Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded.
|
||||
clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z);
|
||||
color_clip_plane_dot = dot(world_pos, color_clip_plane);
|
||||
|
||||
42
resources/shaders/140/printbed_shadow.fs
Normal file
42
resources/shaders/140/printbed_shadow.fs
Normal file
@@ -0,0 +1,42 @@
|
||||
#version 140
|
||||
|
||||
// Draws the build-plate as a receiver of the same depth shadow map used for object/self shadows,
|
||||
// so the plate, objects, and self-shadows all come from one unified technique.
|
||||
uniform sampler2D shadow_map;
|
||||
uniform mat4 shadow_light_vp;
|
||||
uniform float shadow_intensity;
|
||||
uniform float shadow_map_texel;
|
||||
|
||||
in vec4 world_pos;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
// Fraction of the 5x5 PCF kernel occluded from the light. Matches the object shadow shader.
|
||||
float shadow_occlusion()
|
||||
{
|
||||
vec4 lp = shadow_light_vp * world_pos;
|
||||
vec3 proj = lp.xyz / lp.w;
|
||||
proj = proj * 0.5 + 0.5;
|
||||
if (proj.z > 1.0)
|
||||
return 0.0;
|
||||
|
||||
// The plate is a pure receiver (never rendered into the shadow map), so a tiny constant
|
||||
// bias for numerical safety is enough here.
|
||||
float bias = 0.0004;
|
||||
float sum = 0.0;
|
||||
for (int x = -2; x <= 2; ++x) {
|
||||
for (int y = -2; y <= 2; ++y) {
|
||||
float closest = texture(shadow_map, proj.xy + vec2(float(x), float(y)) * shadow_map_texel).r;
|
||||
sum += (proj.z - bias > closest) ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
return sum / 25.0;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float occ = shadow_occlusion();
|
||||
if (occ <= 0.0)
|
||||
discard;
|
||||
out_color = vec4(0.0, 0.0, 0.0, shadow_intensity * occ);
|
||||
}
|
||||
16
resources/shaders/140/printbed_shadow.vs
Normal file
16
resources/shaders/140/printbed_shadow.vs
Normal file
@@ -0,0 +1,16 @@
|
||||
#version 140
|
||||
|
||||
uniform mat4 view_model_matrix;
|
||||
uniform mat4 projection_matrix;
|
||||
|
||||
in vec3 v_position;
|
||||
|
||||
// The plate mask quad is authored directly in world coordinates (z = 0 plane),
|
||||
// so v_position is already the world position of the fragment.
|
||||
out vec4 world_pos;
|
||||
|
||||
void main()
|
||||
{
|
||||
world_pos = vec4(v_position, 1.0);
|
||||
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ uniform sampler2D depth_texture;
|
||||
uniform sampler2D normal_texture;
|
||||
uniform float z_near;
|
||||
uniform float z_far;
|
||||
uniform bool is_outline;
|
||||
|
||||
in vec2 tex_coord;
|
||||
out vec4 frag_color;
|
||||
@@ -22,6 +23,10 @@ float linearize_depth(float depth)
|
||||
|
||||
void main()
|
||||
{
|
||||
if (is_outline) {
|
||||
frag_color = vec4(texture(color_texture, tex_coord).rgb, 1.0);
|
||||
return;
|
||||
}
|
||||
ivec2 pixel = ivec2(gl_FragCoord.xy);
|
||||
float center_depth = linearize_depth(texelFetch(depth_texture, pixel, 0).r);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user