Custom alpha-to-coverage
This commit is contained in:
parent
f00f5f2f77
commit
30f02e4ff2
|
|
@ -247,7 +247,7 @@ impl<'a> State<'a> {
|
|||
wgpu::MultisampleState {
|
||||
count: viewport.sample_count(),
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: true,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,15 +20,44 @@ struct VertexOutput {
|
|||
@location(0) vertex_color: vec4<f32>,
|
||||
}
|
||||
|
||||
struct FragmentOutput {
|
||||
@location(0) color: vec4<f32>,
|
||||
@builtin(sample_mask) mask: u32,
|
||||
}
|
||||
|
||||
fn hash(key : u32) -> u32 {
|
||||
var v = key;
|
||||
v *= 0xb384af1bu;
|
||||
v ^= v >> 15u;
|
||||
return v;
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn vs_main(ver: VertexInput) -> VertexOutput {
|
||||
var out: VertexOutput;
|
||||
out.vertex_color = mesh.color;
|
||||
var light = dot(ver.normal, normalize(vec3(1., 1., 1.)));
|
||||
light = .7 + .3 * light;
|
||||
out.vertex_color = light * mesh.color;
|
||||
out.clip_position = camera.mvp * vec4(ver.position, 1.);
|
||||
return out;
|
||||
}
|
||||
|
||||
@fragment
|
||||
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||
return in.vertex_color;
|
||||
fn fs_main(in: VertexOutput) -> FragmentOutput {
|
||||
var out: FragmentOutput;
|
||||
out.color = vec4(in.vertex_color.xyz, 1.);
|
||||
var x = bitcast<u32>(in.clip_position.x);
|
||||
var y = bitcast<u32>(in.clip_position.y);
|
||||
var z = bitcast<u32>(in.clip_position.z);
|
||||
var alpha = in.vertex_color.w;
|
||||
var seed = hash(hash(hash(x) ^ y) ^ z);
|
||||
var mask = 0u;
|
||||
for (var sample = 0u; sample < 8u; sample++) {
|
||||
var threshold = f32(hash(seed ^ sample)) / 0x1p32;
|
||||
if (alpha > threshold) {
|
||||
mask |= 1u << sample;
|
||||
}
|
||||
}
|
||||
out.mask = mask;
|
||||
return out;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user