This commit is contained in:
2026-02-24 11:44:01 -08:00
parent c9839c9be6
commit 1c3c30e6ce
34 changed files with 1629 additions and 1271 deletions

View File

@ -8,10 +8,10 @@
// const float compoDOFLength = 160.0; // Focal length in mm 18-200
// const float compoDOFFstop = 128.0; // F-stop value
const int samples = 6; // Samples on the first ring
const int samples = 8; // Samples on the first ring
const int rings = 6; // Ring count
const vec2 focus = vec2(0.5, 0.5);
const float coc = 0.11; // Circle of confusion size in mm (35mm film = 0.03mm)
const float coc = 0.03; // Circle of confusion size in mm (35mm film = 0.03mm)
const float maxblur = 1.0;
const float threshold = 0.5; // Highlight threshold
const float gain = 2.0; // Highlight gain
@ -55,21 +55,26 @@ vec3 dof(
float f = DOFLength; // Focal length in mm
float d = fDepth * 1000.0; // Focal plane in mm
float o = depth * 1000.0; // Depth in mm
float a = (o * f) / (o - f);
float b = (d * f) / (d - f);
float c = (d - f) / (d * DOFFStop * coc);
float a = (o > f) ? (o * f) / (o - f) : 0.0;
float b = (d > f) ? (d * f) / (d - f) : 0.0;
float sensorSize = max(DOFFStop, 10.0);
float c = (d - f) / (d * sensorSize * coc);
float blur = abs(a - b) * c;
blur = clamp(blur, 0.0, 1.0);
vec2 noise = rand2(texCoord) * namount * blur;
float w = (texStep.x) * blur * maxblur + noise.x;
float h = (texStep.y) * blur * maxblur + noise.y;
vec3 col = vec3(0.0);
if (blur < 0.05) {
col = textureLod(tex, texCoord, 0.0).rgb;
}
else {
col = textureLod(tex, texCoord, 0.0).rgb;
vec3 sharpCol = textureLod(tex, texCoord, 0.0).rgb;
vec3 col = sharpCol;
float blurThreshold = 0.02;
float blurRange = 0.06;
if (blur > blurThreshold) {
float blurAmount = smoothstep(blurThreshold, blurThreshold + blurRange, blur);
vec3 blurredCol = sharpCol;
float s = 1.0;
int ringsamples;
@ -81,11 +86,12 @@ vec3 dof(
float ph = (sin(float(j) * step) * float(i));
float p = 1.0;
// if (pentagon) p = penta(vec2(pw, ph));
col += color(texCoord + vec2(pw * w, ph * h), blur, tex, texStep) * mix(1.0, (float(i)) / (float(rings)), bias) * p;
blurredCol += color(texCoord + vec2(pw * w, ph * h), blur, tex, texStep) * mix(1.0, (float(i)) / (float(rings)), bias) * p;
s += 1.0 * mix(1.0, (float(i)) / (float(rings)), bias) * p;
}
}
col /= s;
blurredCol /= s;
col = mix(sharpCol, blurredCol, blurAmount);
}
return col;
}