Skip to content

Commit 31b07d4

Browse files
authored
Fix computation of alpha channel for transparent objects (#110)
* shaders/PbrTransparent : fix how accumulation and revealage computed in fragment shader + weight applies to accum.a, not to revealage (account for change in blend formula) * Update CHANGELOG
1 parent dd9643e commit 31b07d4

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
### Fixed
2525

2626
- Fixed visual effects with SSAO + MSAA. Have SSAO sample from resolved multisampled depth texture (https://github.com/Simple-Robotics/candlewick/pull/105)
27+
- Fix WBOIT transparent shader formulas, fixing transparency visual appearance and alpha channel in PNG screenshots (https://github.com/Simple-Robotics/candlewick/pull/110)
2728

2829
## [0.10.1] - 2026-01-19
2930

shaders/compiled/PbrTransparent.frag.msl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ struct KernelContext_0
192192
float weight_0 = clamp((alpha_0 * 10.0 + 0.00999999977648258) * (1.0 - fragCoord_0.z * 0.30000001192092896), 0.00999999977648258, 1000.0);
193193

194194
thread FSOutput_0 output_0;
195-
(&output_0)->accum_0 = float4(pow(uncharted2ToneMapping_0(float3(0.02999999932944775) * mat_0.baseColor_0.xyz * float3(mat_0.ao_0) + Lo_0), float3(0.45454543828964233) ) * float3(alpha_0) * float3(weight_0) , alpha_0);
196-
(&output_0)->reveal_0 = 1.0 - alpha_0 * weight_0;
195+
(&output_0)->accum_0 = float4(pow(uncharted2ToneMapping_0(float3(0.02999999932944775) * mat_0.baseColor_0.xyz * float3(mat_0.ao_0) + Lo_0), float3(0.45454543828964233) ) * float3(alpha_0) * float3(weight_0) , alpha_0 * weight_0);
196+
(&output_0)->reveal_0 = alpha_0;
197197
return output_0;
198198
}
-20 Bytes
Binary file not shown.

shaders/src/PbrTransparent.frag.slang

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ FSOutput main([vk::location(0)] float3 fragViewPos,
4141
float weight = clamp(w1 * (1.0 - z * 0.3), 1e-2, 1e3);
4242

4343
FSOutput output;
44-
output.accum = float4(color * alpha * weight, alpha);
45-
output.reveal = 1.0 - alpha * weight;
44+
output.accum = float4(color * alpha * weight, alpha * weight);
45+
output.reveal = alpha;
4646
return output;
4747
}

0 commit comments

Comments
 (0)