Revert to simpler blur implementation with configurable sample count
Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
This commit is contained in:
parent
bb2ce2552b
commit
c33d349390
|
@ -19,41 +19,31 @@ out vec4 out_color;
|
||||||
void main() {
|
void main() {
|
||||||
vec2 texelSize = 1.0 / in_resolution;
|
vec2 texelSize = 1.0 / in_resolution;
|
||||||
vec4 result = vec4(0.0);
|
vec4 result = vec4(0.0);
|
||||||
float totalWeight = 0.0;
|
float totalSamples = 0.0;
|
||||||
|
|
||||||
// High-quality blur with configurable sample count
|
// Simple box blur with configurable sample count
|
||||||
int samples = min(u_samples, 128); // Clamp to reasonable maximum
|
// Based on the original cross pattern but with more samples
|
||||||
int radius = int(u_radius);
|
int samples = min(u_samples, 128);
|
||||||
|
float radius = u_radius;
|
||||||
|
|
||||||
// Use a more sophisticated sampling pattern for better quality
|
// Calculate how many samples to take in each direction
|
||||||
for (int x = -radius; x <= radius; x++) {
|
int sampleRadius = int(sqrt(float(samples)) / 2.0);
|
||||||
for (int y = -radius; y <= radius; y++) {
|
|
||||||
// Calculate distance from center for weighting
|
// Sample in a grid pattern around the center
|
||||||
float distance = length(vec2(float(x), float(y)));
|
for (int x = -sampleRadius; x <= sampleRadius; x++) {
|
||||||
|
for (int y = -sampleRadius; y <= sampleRadius; y++) {
|
||||||
// Skip samples beyond the circular radius
|
vec2 offset = vec2(float(x), float(y)) * texelSize * radius;
|
||||||
if (distance > u_radius) continue;
|
|
||||||
|
|
||||||
// Calculate sample position
|
|
||||||
vec2 offset = vec2(float(x), float(y)) * texelSize;
|
|
||||||
vec2 sampleUV = in_uv + offset;
|
vec2 sampleUV = in_uv + offset;
|
||||||
|
|
||||||
// Only sample if within texture bounds
|
// Only sample if within texture bounds
|
||||||
if (sampleUV.x >= 0.0 && sampleUV.x <= 1.0 && sampleUV.y >= 0.0 && sampleUV.y <= 1.0) {
|
if (sampleUV.x >= 0.0 && sampleUV.x <= 1.0 && sampleUV.y >= 0.0 && sampleUV.y <= 1.0) {
|
||||||
// Use Gaussian-like weighting for better quality
|
result += texture(in_texture, sampleUV);
|
||||||
float weight = exp(-(distance * distance) / (2.0 * (u_radius * 0.5) * (u_radius * 0.5)));
|
totalSamples += 1.0;
|
||||||
result += texture(in_texture, sampleUV) * weight;
|
|
||||||
totalWeight += weight;
|
|
||||||
|
|
||||||
// Limit actual samples processed for performance
|
|
||||||
samples--;
|
|
||||||
if (samples <= 0) break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (samples <= 0) break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out_color = totalWeight > 0.0 ? result / totalWeight : texture(in_texture, in_uv);
|
out_color = totalSamples > 0.0 ? result / totalSamples : texture(in_texture, in_uv);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue