Supersample the shard 3x3

Pass 2 magnifies the object sheet where the surface steepens at the cracks,
so a one-pixel silhouette showed up as hard blocks. Nine jittered rays per
pixel give the edge a soft ramp instead.
This commit is contained in:
emil28092005
2026-10-30 21:33:18 +03:00
parent 62355eb047
commit aeea839b66
2 changed files with 29 additions and 18 deletions
+19 -8
View File
@@ -100,10 +100,17 @@ void main() {
float solid = 0.45; // sheet 1 keeps its plasma, but its alpha becomes coverage float solid = 0.45; // sheet 1 keeps its plasma, but its alpha becomes coverage
if (layer > 0.5 && layer < 1.5) { if (layer > 0.5 && layer < 1.5) {
vec3 ro = vec3(0.0, 0.0, 6.0); vec3 ro = vec3(0.0, 0.0, 6.0);
vec3 rd = normalize(vec3((uv - 0.5) * 2.0 * vec2(u_res.x / u_res.y, 1.0), -1.0)); vec3 lit = vec3(0.0);
float hits = 0.0;
// 3x3 supersample: pass 2 magnifies this sheet where the surface steepens at the
// cracks, and a one-pixel silhouette would show up there as big hard steps.
for (int sy = 0; sy < 3; sy++) {
for (int sx = 0; sx < 3; sx++) {
vec2 jitter = (vec2(float(sx), float(sy)) / 3.0 + 1.0 / 6.0 - 0.5) / u_res;
vec3 rd = normalize(vec3((uv + jitter - 0.5) * 2.0 * vec2(u_res.x / u_res.y, 1.0), -1.0));
float b = dot(ro, rd); float b = dot(ro, rd);
float disc = b * b - dot(ro, ro) + 2.4 * 2.4; float disc = b * b - dot(ro, ro) + 2.4 * 2.4;
if (disc > 0.0) { if (disc <= 0.0) continue;
float near = max(-b - sqrt(disc), 0.0); float near = max(-b - sqrt(disc), 0.0);
float t = near, d = 1.0; float t = near, d = 1.0;
for (int k = 0; k < 40; k++) { for (int k = 0; k < 40; k++) {
@@ -111,10 +118,9 @@ void main() {
if (d < 0.003 || t > near + 5.0) break; if (d < 0.003 || t > near + 5.0) break;
t += d; t += d;
} }
if (d < 0.003) { if (d >= 0.003) continue;
solid = 1.0;
vec3 pos = ro + rd * t;
float e2 = 0.004; float e2 = 0.004;
vec3 pos = ro + rd * t;
vec3 nrm = normalize(vec3( vec3 nrm = normalize(vec3(
sdShard(pos + vec3(e2, 0.0, 0.0), phase) - sdShard(pos - vec3(e2, 0.0, 0.0), phase), sdShard(pos + vec3(e2, 0.0, 0.0), phase) - sdShard(pos - vec3(e2, 0.0, 0.0), phase),
sdShard(pos + vec3(0.0, e2, 0.0), phase) - sdShard(pos - vec3(0.0, e2, 0.0), phase), sdShard(pos + vec3(0.0, e2, 0.0), phase) - sdShard(pos - vec3(0.0, e2, 0.0), phase),
@@ -124,11 +130,16 @@ void main() {
float key = max(dot(nrm, normalize(vec3(-0.45, 0.72, 0.52))), 0.0); float key = max(dot(nrm, normalize(vec3(-0.45, 0.72, 0.52))), 0.0);
float fill = max(dot(nrm, normalize(vec3(0.60, -0.20, -0.75))), 0.0); float fill = max(dot(nrm, normalize(vec3(0.60, -0.20, -0.75))), 0.0);
float rim = pow(1.0 - max(dot(nrm, -rd), 0.0), 4.0); float rim = pow(1.0 - max(dot(nrm, -rd), 0.0), 4.0);
col = mix(vec3(0.004, 0.016, 0.026), vec3(0.060, 0.290, 0.340), key); vec3 c = mix(vec3(0.004, 0.016, 0.026), vec3(0.060, 0.290, 0.340), key);
col += vec3(0.010, 0.060, 0.080) * fill; c += vec3(0.010, 0.060, 0.080) * fill;
col += vec3(0.20, 0.62, 0.72) * rim * 0.55; c += vec3(0.20, 0.62, 0.72) * rim * 0.55;
lit += c;
hits += 1.0;
} }
} }
float cov = hits / 9.0;
col = mix(col, lit / max(hits, 1.0), cov);
solid = mix(0.45, 1.0, cov);
} }
float alpha = (layer > 0.5 && layer < 1.5) ? solid : (0.42 + layer * 0.26) / 2.6; float alpha = (layer > 0.5 && layer < 1.5) ? solid : (0.42 + layer * 0.26) / 2.6;
gl_FragColor = vec4(col, alpha); gl_FragColor = vec4(col, alpha);
+1 -1
View File
File diff suppressed because one or more lines are too long