Slide 68
Slide 68 text
specular = light_valid ? specular_with_mask(
L, V, N, albedo.rgb, roughness, metallicness,
energy,
shadow_level
) : specular;
const ivec3 image_size = imageSize( gbuffer );
const vec3 optical_flow = imageLoad( gbuffer, ivec3( screen_pos, 5 ) ).xyz;
const uint instance = uint( imageLoad( gbuffer, ivec3( screen_pos, 4 ) ).z );
const ivec2 previous_screen_pos =
screen_pos - ivec2( ( optical_flow.xy * vec2( 0.5, 0.5 ) ) * ( vec2( image_size.xy ) ) );
vec4 existing_diffuse = vec4( 0.0, 0.0, 0.0, 1.0 );
vec4 existing_specular = vec4( 0.0, 0.0, 0.0, 1.0 );
uvec2 hist = uvec2( 0, instance );
const bool history_in_range = (
previous_screen_pos.x >= 0 &&
previous_screen_pos.x < image_size.x &&
previous_screen_pos.y >= 0 &&
previous_screen_pos.y < image_size.y
);
const uvec2 history_value = imageLoad( previous_history, previous_screen_pos ).xy;
const vec4 diffuse_value = imageLoad( previous_diffuse_image, previous_screen_pos );
const vec4 specular_value = imageLoad( previous_specular_image, previous_screen_pos );
const bool history_valid = history_in_range && ( history_value.y == instance );
existing_diffuse = history_valid ? diffuse_value : existing_diffuse;
existing_specular = history_valid ? specular_value : existing_specular;
hist = history_valid ? history_value : hist;
const float speed = length( optical_flow.xy );
hist.x = min( hist.x, uint( mix( 300.0, 1.0, speed ) ) );
imageStore( diffuse_image, screen_pos, ( vec4( diffuse, 1.0 ) + existing_diffuse * hist.x )/( hist.x + 1 ) );
imageStore( specular_image, screen_pos, ( vec4( specular, 1.0 ) + existing_specular * hist.x )/( hist.x +
1 ) );
lighting.comp
Optical FlowΛͬͯաڈͷϑϨʔϜͰͷ֦ࢄͱࣹΛҾ͖ܧ͙