Add antialiasing
This commit is contained in:
parent
53221856aa
commit
91a66e3bb4
|
|
@ -38,6 +38,21 @@ fn fs_solid(vertex: VertexOutput) -> @location(0) vec4<f32> {
|
|||
var ray: Ray;
|
||||
ray.origin = vertex.world_space_position.xyz;
|
||||
ray.direction = normalize(vertex.world_space_position.xyz - uniforms.camera_position.xyz);
|
||||
// Spread rays into RGSS antialiasing pattern.
|
||||
let ray_dx = dpdy(ray.direction);
|
||||
let ray_dy = dpdy(ray.direction);
|
||||
var ray_directions: array<vec3<f32>,4>;
|
||||
ray_directions[0] = ray.direction + 0.125*ray_dx + 0.375*ray_dy;
|
||||
ray_directions[1] = ray.direction - 0.125*ray_dx - 0.375*ray_dy;
|
||||
ray_directions[2] = ray.direction + 0.375*ray_dx + 0.125*ray_dy;
|
||||
ray_directions[3] = ray.direction - 0.375*ray_dx - 0.125*ray_dy;
|
||||
|
||||
// Possibly these ray directions could be stored in a matrix and we could
|
||||
// evaluate them all at once instead of looping.
|
||||
|
||||
var color_accumulator = vec4<f32>(0);
|
||||
for(var i=0; i<4; i++) {
|
||||
ray.direction = ray_directions[i];
|
||||
|
||||
var root_node: BoundingNode;
|
||||
root_node.index = vec2<u32>(0);
|
||||
|
|
@ -56,7 +71,8 @@ fn fs_solid(vertex: VertexOutput) -> @location(0) vec4<f32> {
|
|||
&hit_location,
|
||||
&hit_normal) {
|
||||
// Calculate light
|
||||
let sun_direction = (uniforms.camera_to_world_matrix
|
||||
let sun_direction =
|
||||
(uniforms.camera_to_world_matrix
|
||||
* vec4<f32>(normalize(vec3<f32>(1.0, 1.0, 1.0)), 0.0)).xyz;
|
||||
let l = dot(hit_normal, sun_direction);
|
||||
var shadow_ray :Ray;
|
||||
|
|
@ -74,8 +90,11 @@ fn fs_solid(vertex: VertexOutput) -> @location(0) vec4<f32> {
|
|||
&hit_index,
|
||||
&dummy0,
|
||||
&dummy1));
|
||||
return vec4<f32>(vec3<f32>(l)*shadow_value, 1.0);
|
||||
} else {
|
||||
color_accumulator += vec4<f32>(vec3<f32>(l)*shadow_value, 1.0);
|
||||
}
|
||||
}
|
||||
if color_accumulator.w == 0.0 {
|
||||
discard;
|
||||
}
|
||||
return color_accumulator * 0.25;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue