Skip to content

Commit

Permalink
fix: use premultiplied alpha blend state and account for sRGB transfo…
Browse files Browse the repository at this point in the history
…rmation
  • Loading branch information
mosure committed Nov 27, 2023
1 parent 46a9524 commit b99751f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 1 addition & 12 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,7 @@ impl SpecializedRenderPipeline for GaussianCloudPipeline {
entry_point: "fs_main".into(),
targets: vec![Some(ColorTargetState {
format: TextureFormat::Rgba8UnormSrgb,
blend: Some(BlendState {
color: BlendComponent {
src_factor: BlendFactor::One,
dst_factor: BlendFactor::OneMinusSrcAlpha,
operation: BlendOperation::Add,
},
alpha: BlendComponent {
src_factor: BlendFactor::Zero,
dst_factor: BlendFactor::OneMinusSrcAlpha,
operation: BlendOperation::Add,
},
}),
blend: Some(BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask: ColorWrites::ALL,
})],
}),
Expand Down
14 changes: 13 additions & 1 deletion src/render/spherical_harmonics.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ const shc = array<f32, 16>(
-0.5900435899266435,
);

fn srgb_to_linear(srgb_color: vec3<f32>) -> vec3<f32> {
var linear_color: vec3<f32>;
for (var i = 0u; i < 3u; i = i + 1u) {
if (srgb_color[i] <= 0.04045) {
linear_color[i] = srgb_color[i] / 12.92;
} else {
linear_color[i] = pow((srgb_color[i] + 0.055) / 1.055, 2.4);
}
}
return linear_color;
}

fn spherical_harmonics_lookup(
ray_direction: vec3<f32>,
sh: array<f32, #{MAX_SH_COEFF_COUNT}>,
Expand Down Expand Up @@ -47,5 +59,5 @@ fn spherical_harmonics_lookup(
color += shc[14] * vec3<f32>(sh[42], sh[43], sh[44]) * ray_direction.z * (rds.x - rds.y);
color += shc[15] * vec3<f32>(sh[45], sh[46], sh[47]) * ray_direction.x * (rds.x - 3.0 * rds.y);

return color;
return srgb_to_linear(color);
}

0 comments on commit b99751f

Please sign in to comment.