Skip to content

Commit

Permalink
Make alpha always 1 for solid objects
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikNoren committed Oct 20, 2023
1 parent 4d35702 commit 4a1624c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions crates/renderer/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub(crate) struct GlobalParams {
pub fog_height_falloff: f32,
pub fog_density: f32,
pub debug_params: ShaderDebugParams,
pub output_alpha: f32,
padding: Vec3,
}

impl Default for GlobalParams {
Expand All @@ -72,7 +74,9 @@ impl Default for GlobalParams {
time: 0.,
fog_height_falloff: 0.5,
fog_density: 0.5,
output_alpha: 1.,
debug_params: Default::default(),
padding: Default::default(),
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/renderer/src/globals.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ struct ForwardGlobalParams {
debug_metallic_roughness: f32,
debug_normals: f32,
debug_shading: f32,
debug_padding: f32,

output_alpha: f32,
};

struct ShadowCamera {
Expand Down Expand Up @@ -316,7 +319,7 @@ fn shading(material: MaterialOutput, world_position: vec4<f32>) -> vec4<f32> {

// let color = vec3<f32>(max(dot(material.normal, l), 0.0), 0.0, 0.0);

return vec4<f32>(color, material.opacity);
return vec4<f32>(color, mix(1., material.opacity, global_params.output_alpha));
}

struct FSOutput {
Expand Down
14 changes: 8 additions & 6 deletions crates/renderer/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,17 @@ impl Renderer {
let settings = SettingsKey.get(assets).render;

let normals_format = to_linear_format(gpu.swapchain_format()).into();
let mut forward_globals = ForwardGlobals::new(
gpu,
renderer_resources.globals_layout.clone(),
shadow_cascades,
config.scene,
);
forward_globals.params.output_alpha = 0.;

Self {
culling: Culling::new(gpu, assets, config.clone()),
forward_globals: ForwardGlobals::new(
gpu,
renderer_resources.globals_layout.clone(),
shadow_cascades,
config.scene,
),
forward_globals,
forward_collect_state: RendererCollectState::new(gpu),
shadows,
overlays: OverlayRenderer::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/ui_native/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl ElementComponent for Image {
normalmap: DefaultNormalMapViewKey.get(&assets),
metallic_roughness: PixelTextureViewKey::white().get(&assets),
sampler: SamplerKey::LINEAR_CLAMP_TO_EDGE.get(&assets),
transparent: None,
transparent: Some(false),
double_sided: None,
depth_write_enabled: None,
},
Expand Down

0 comments on commit 4a1624c

Please sign in to comment.