clamp to quad
This commit is contained in:
parent
5bd181adc9
commit
1a30887a7d
7 changed files with 62 additions and 22 deletions
shaders
Binary file not shown.
Binary file not shown.
|
@ -4,6 +4,8 @@ layout(location = 0) in vec2 fragRasterPos;
|
|||
layout(location = 1) flat in uint fragVolumeStart;
|
||||
layout(location = 2) in vec3 origPosition;
|
||||
layout(location = 3) flat in uint facing;
|
||||
layout(location = 4) flat in uvec2 minRasterPos;
|
||||
layout(location = 5) flat in uvec2 maxRasterPos;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
|
@ -468,15 +470,21 @@ vec3 clamp_to_volume(uint volume_start, vec3 position) {
|
|||
return vec3(min(max(position.x, low_x_border), high_x_border), min(max(position.y, low_y_border), high_y_border), min(max(position.z, low_z_border), high_z_border));
|
||||
}
|
||||
|
||||
vec3 add_reflection(vec3 view_vector, uint f, uint volume_start, vec3 pos, uvec4 color_sample, vec3 color_sum) {
|
||||
vec3 orig_color_sample = vec3(float(color_sample.x) / 255.0, float(color_sample.y) / 255.0, float(color_sample.z) / 255.0);
|
||||
vec2 clamp_to_quad(vec2 raster_pos, uvec2 min_raster_pos, uvec2 max_raster_pos) {
|
||||
return vec2(max(min_raster_pos.x, min(max_raster_pos.x - 1, raster_pos.x)), max(min_raster_pos.y, min(max_raster_pos.y - 1, raster_pos.y)));
|
||||
}
|
||||
|
||||
vec3 reflection_direction = reflect_vector(view_vector, f);
|
||||
Tracing reflection_tracing = trace_ray(volume_start, pos, reflection_direction, pos_infinity, 0, max_iterations_per_light, true);
|
||||
vec3 add_reflection(vec3 view_vector, uint f, uint volume_start, vec3 pos, uvec4 color_sample, vec3 color_sum) {
|
||||
float reflectivity = 1.0 - float(color_sample.w) / 255.0;
|
||||
if (reflection_tracing.has_hit || reflection_tracing.has_transparent_hit) {
|
||||
vec3 color_from_reflection = diffuse_tracing(reflection_tracing.end_volume, reflection_tracing.end_raster, reflection_tracing.end_pos, reflection_tracing.end_facing) * orig_color_sample;
|
||||
color_sum = color_sum * (1.0 - reflectivity) + color_from_reflection * reflectivity;
|
||||
|
||||
if (reflectivity > 0.01) {
|
||||
vec3 orig_color_sample = vec3(float(color_sample.x) / 255.0, float(color_sample.y) / 255.0, float(color_sample.z) / 255.0);
|
||||
vec3 reflection_direction = reflect_vector(view_vector, f);
|
||||
Tracing reflection_tracing = trace_ray(volume_start, pos, reflection_direction, pos_infinity, 0, max_iterations_per_light, true);
|
||||
if (reflection_tracing.has_hit || reflection_tracing.has_transparent_hit) {
|
||||
vec3 color_from_reflection = diffuse_tracing(reflection_tracing.end_volume, reflection_tracing.end_raster, reflection_tracing.end_pos, reflection_tracing.end_facing) * orig_color_sample;
|
||||
color_sum = color_sum * (1.0 - reflectivity) + color_from_reflection * reflectivity;
|
||||
}
|
||||
}
|
||||
|
||||
return color_sum;
|
||||
|
@ -484,13 +492,14 @@ vec3 add_reflection(vec3 view_vector, uint f, uint volume_start, vec3 pos, uvec4
|
|||
|
||||
void main() {
|
||||
vec3 clamped_pos = clamp_to_volume(fragVolumeStart, origPosition);
|
||||
uvec4 color_roughness = sample_color_from_scene_info(fragVolumeStart, fragRasterPos, facing);
|
||||
vec2 clamped_raster_pos = clamp_to_quad(fragRasterPos, minRasterPos, maxRasterPos);
|
||||
uvec4 color_roughness = sample_color_from_scene_info(fragVolumeStart, clamped_raster_pos, facing);
|
||||
vec3 orig_color_sample = vec3(float(color_roughness.x) / 255.0, float(color_roughness.y) / 255.0, float(color_roughness.z) / 255.0);
|
||||
vec3 color_sum;
|
||||
|
||||
uint orig_neighbor = sample_neighbor_from_scene_info(fragVolumeStart, fragRasterPos, facing);
|
||||
uint orig_neighbor = sample_neighbor_from_scene_info(fragVolumeStart, clamped_raster_pos, facing);
|
||||
if (orig_neighbor != 0) {
|
||||
vec3 color_direct = diffuse_tracing(fragVolumeStart, fragRasterPos, clamped_pos, facing);
|
||||
vec3 color_direct = diffuse_tracing(fragVolumeStart, clamped_raster_pos, clamped_pos, facing);
|
||||
color_direct = add_reflection(normalize(clamped_pos - ubo.camera_pos), facing, fragVolumeStart, clamped_pos, color_roughness, color_direct);
|
||||
|
||||
Tracing t = trace_ray(fragVolumeStart, ubo.camera_pos, clamped_pos - ubo.camera_pos, pos_infinity, 0, max_iterations_per_light, false);
|
||||
|
@ -507,11 +516,10 @@ void main() {
|
|||
}
|
||||
}
|
||||
else {
|
||||
color_sum = diffuse_tracing(fragVolumeStart, fragRasterPos, clamped_pos, facing);
|
||||
color_sum = diffuse_tracing(fragVolumeStart, clamped_raster_pos, clamped_pos, facing);
|
||||
|
||||
color_sum = add_reflection(normalize(clamped_pos - ubo.camera_pos), facing, fragVolumeStart, clamped_pos, color_roughness, color_sum);
|
||||
}
|
||||
|
||||
outColor = vec4(color_sum, 1.0);
|
||||
//outColor = vec4(orig_color_sample, 1.0);
|
||||
}
|
|
@ -14,12 +14,17 @@ layout(location = 0) in vec3 inPosition;
|
|||
layout(location = 1) in uvec2 inRasterPos;
|
||||
layout(location = 2) in uint inVolumeStart;
|
||||
layout(location = 3) in uint inFacing;
|
||||
layout(location = 4) in uvec2 inMinRasterPos;
|
||||
layout(location = 5) in uvec2 inMaxRasterPos;
|
||||
|
||||
layout(location = 0) out vec2 rasterPos;
|
||||
layout(location = 1) flat out uint volumeStart;
|
||||
layout(location = 2) out vec3 origPosition;
|
||||
layout(location = 3) flat out uint facing;
|
||||
|
||||
layout(location = 4) flat out uvec2 minRasterPos;
|
||||
layout(location = 5) flat out uvec2 maxRasterPos;
|
||||
|
||||
void main() {
|
||||
if (ubo.use_geom_shader[0]) {
|
||||
gl_Position = ubo.geom_rot * ubo.model * vec4(inPosition, 1.0);
|
||||
|
@ -30,4 +35,7 @@ void main() {
|
|||
volumeStart = inVolumeStart;
|
||||
origPosition = inPosition;
|
||||
facing = inFacing;
|
||||
|
||||
minRasterPos = inMinRasterPos;
|
||||
maxRasterPos = inMaxRasterPos;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue