Skip to content

Commit

Permalink
Fix alpha discard
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim committed Feb 19, 2024
1 parent 397ca28 commit 52aee5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_wind_waker_shader"
version = "0.1.1"
version = "0.1.2"
authors = ["Jan Hohenheim <[email protected]>"]
edition = "2021"
exclude = ["./assets/"]
Expand Down
14 changes: 8 additions & 6 deletions src/assets/toon_shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,26 @@ fn fragment(
) -> FragmentOutput {
var pbr_input = pbr_input_from_standard_material(in, is_front);

// remove texture
let texture = pbr_input.material.base_color;
pbr_input.material.base_color = vec4<f32>(1.0, 1.0, 1.0, 1.0);

// alpha discard
pbr_input.material.base_color = alpha_discard(pbr_input.material, pbr_input.material.base_color);

#ifdef PREPASS_PIPELINE
// in deferred mode we can't modify anything after that, as lighting is run in a separate fullscreen shader.
let out = deferred_output(in, pbr_input);
#else

// remove texture
let texture = pbr_input.material.base_color;
pbr_input.material.base_color = vec4<f32>(1.0, 1.0, 1.0, 1.0);

var out: FragmentOutput;
out.color = apply_pbr_lighting(pbr_input);

// Source for cel shading: https://www.youtube.com/watch?v=mnxs6CR6Zrk]
// sample mask at the current fragment's intensity as u to get the cutoff
let uv = vec2<f32>(out.color.r, 0.0);
let toon_light = textureSample(mask, mask_sampler, uv);
out.color = mix(shadow_color, highlight_color, toon_light);
let quantization = textureSample(mask, mask_sampler, uv);
out.color = mix(shadow_color, highlight_color, quantization);

// apply rim highlights. Inspired by Breath of the Wild: https://www.youtube.com/watch?v=By7qcgaqGI4
let eye = normalize(view_bindings::view.world_position.xyz - in.world_position.xyz);
Expand All @@ -57,6 +58,7 @@ fn fragment(

// Reapply texture
out.color = out.color * texture;
pbr_input.material.base_color = texture;

// apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr)
// note this does not include fullscreen postprocessing effects like bloom.
Expand Down

0 comments on commit 52aee5c

Please sign in to comment.