first implementation, clamp seems to be off?
This commit is contained in:
parent
7a58ba9733
commit
b581364f5a
8 changed files with 157 additions and 132 deletions
shaders
Binary file not shown.
|
@ -45,9 +45,12 @@ uvec4 unpack_color(uint val) {
|
|||
return uvec4(val4, val3, val2, val1);
|
||||
}
|
||||
|
||||
uint array_descr_offset = 6 + max_num_lights;
|
||||
uint color_array_offset = 24 + 1;
|
||||
|
||||
uint sample_neighbor_from_scene_info(uint volume_start, uvec2 raster_pos, uint f) {
|
||||
uint array_descr_start = volume_start + 6 + max_num_lights;
|
||||
uint color_array_start = array_descr_start + 24;
|
||||
uint array_descr_start = volume_start + array_descr_offset;
|
||||
uint color_array_start = array_descr_start + color_array_offset;
|
||||
|
||||
uint top_color_size_u = scene_info.infos[array_descr_start];
|
||||
uint top_color_size_v = scene_info.infos[array_descr_start + 1];
|
||||
|
@ -116,8 +119,8 @@ uint sample_neighbor_from_scene_info(uint volume_start, vec2 raster_pos, uint f)
|
|||
}
|
||||
|
||||
uvec4 sample_color_from_scene_info(uint volume_start, uvec2 raster_pos, uint f) {
|
||||
uint array_descr_start = volume_start + 6 + max_num_lights;
|
||||
uint color_array_start = array_descr_start + 24;
|
||||
uint array_descr_start = volume_start + array_descr_offset;
|
||||
uint color_array_start = array_descr_start + color_array_offset;
|
||||
|
||||
uint top_color_size_u = scene_info.infos[array_descr_start];
|
||||
uint top_color_size_v = scene_info.infos[array_descr_start + 1];
|
||||
|
@ -216,9 +219,10 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
|
|||
uint cycle = start_cycle;
|
||||
// setup volume info
|
||||
uint volume_index = volume_start;
|
||||
uint volume_pos_x = scene_info.infos[volume_index + 0];
|
||||
uint volume_pos_y = scene_info.infos[volume_index + 1];
|
||||
uint volume_pos_z = scene_info.infos[volume_index + 2];
|
||||
float volume_scale = uintBitsToFloat(scene_info.infos[volume_index + array_descr_offset + color_array_offset - 1]);
|
||||
float volume_pos_x = uintBitsToFloat(scene_info.infos[volume_index + 0]);
|
||||
float volume_pos_y = uintBitsToFloat(scene_info.infos[volume_index + 1]);
|
||||
float volume_pos_z = uintBitsToFloat(scene_info.infos[volume_index + 2]);
|
||||
|
||||
bool x_pos = direction.x > 0.0;
|
||||
bool x_null = (direction.x == 0.0);
|
||||
|
@ -249,9 +253,9 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
|
|||
|
||||
while (cycle < max_cycle) {
|
||||
cycle ++;
|
||||
float x_border = float(volume_pos_x + (scene_info.infos[volume_index + 3]) * uint(x_pos)) - 0.5;
|
||||
float y_border = float(volume_pos_y + (scene_info.infos[volume_index + 4]) * uint(y_pos)) - 0.5;
|
||||
float z_border = float(volume_pos_z + (scene_info.infos[volume_index + 5]) * uint(z_pos)) - 0.5;
|
||||
float x_border = volume_pos_x + float((scene_info.infos[volume_index + 3]) * uint(x_pos)) * volume_scale - 0.5 * volume_scale;
|
||||
float y_border = volume_pos_y + float((scene_info.infos[volume_index + 4]) * uint(y_pos)) * volume_scale - 0.5 * volume_scale;
|
||||
float z_border = volume_pos_z + float((scene_info.infos[volume_index + 5]) * uint(z_pos)) * volume_scale - 0.5 * volume_scale;
|
||||
|
||||
bool needs_next_light = false;
|
||||
|
||||
|
@ -283,10 +287,10 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
|
|||
hit_facing = uint(is_x_smallest) * (2 + uint(x_pos)) + uint(is_y_smallest) * (4 + uint(y_pos)) + uint(is_z_smallest && !z_pos);
|
||||
float smallest_factor = min(min(x_factor, y_factor), z_factor); // maybe use multiplication instead?
|
||||
vec3 intersection_pos = pos + smallest_factor * direction;
|
||||
u = uint(is_x_smallest) * (uint(round(intersection_pos.y)) - volume_pos_y) +
|
||||
uint(is_y_smallest || is_z_smallest) * (uint(round(intersection_pos.x)) - volume_pos_x);
|
||||
v = uint(is_x_smallest || is_y_smallest) * (uint(round(intersection_pos.z)) - volume_pos_z) +
|
||||
uint(is_z_smallest) * (uint(round(intersection_pos.y)) - volume_pos_y);
|
||||
u = uint(is_x_smallest) * (uint(round((intersection_pos.y - volume_pos_y) / volume_scale))) +
|
||||
uint(is_y_smallest || is_z_smallest) * (uint(round((intersection_pos.x - volume_pos_x) / volume_scale)));
|
||||
v = uint(is_x_smallest || is_y_smallest) * (uint(round((intersection_pos.z - volume_pos_z) / volume_scale))) +
|
||||
uint(is_z_smallest) * (uint(round((intersection_pos.y - volume_pos_y) / volume_scale)));
|
||||
|
||||
uint next_neighbor = sample_neighbor_from_scene_info(volume_index, uvec2(u, v), hit_facing);
|
||||
uvec4 color_sample = sample_color_from_scene_info(volume_index, uvec2(u, v), hit_facing);
|
||||
|
@ -295,9 +299,10 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
|
|||
// not a color hit, so check neighbor
|
||||
if (next_neighbor != 0) {
|
||||
volume_index = next_neighbor;
|
||||
volume_pos_x = scene_info.infos[volume_index + 0];
|
||||
volume_pos_y = scene_info.infos[volume_index + 1];
|
||||
volume_pos_z = scene_info.infos[volume_index + 2];
|
||||
volume_scale = uintBitsToFloat(scene_info.infos[volume_index + array_descr_offset + color_array_offset - 1]);
|
||||
volume_pos_x = uintBitsToFloat(scene_info.infos[volume_index + 0]);
|
||||
volume_pos_y = uintBitsToFloat(scene_info.infos[volume_index + 1]);
|
||||
volume_pos_z = uintBitsToFloat(scene_info.infos[volume_index + 2]);
|
||||
} else {
|
||||
// neighbor miss
|
||||
end_color_transparent = uvec4(255, 0, 0, 255);
|
||||
|
@ -311,9 +316,10 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
|
|||
color_mul_transparent = result.color_mul;
|
||||
|
||||
volume_index = next_neighbor;
|
||||
volume_pos_x = scene_info.infos[volume_index + 0];
|
||||
volume_pos_y = scene_info.infos[volume_index + 1];
|
||||
volume_pos_z = scene_info.infos[volume_index + 2];
|
||||
volume_scale = uintBitsToFloat(scene_info.infos[volume_index + array_descr_offset + color_array_offset - 1]);
|
||||
volume_pos_x = uintBitsToFloat(scene_info.infos[volume_index + 0]);
|
||||
volume_pos_y = uintBitsToFloat(scene_info.infos[volume_index + 1]);
|
||||
volume_pos_z = uintBitsToFloat(scene_info.infos[volume_index + 2]);
|
||||
result.color_mul = result.color_mul * vec3(float(color_sample.x) / 255.0, float(color_sample.y) / 255.0, float(color_sample.z) / 255.0);
|
||||
result.has_transparent_hit = true;
|
||||
result.end_volume = volume_index;
|
||||
|
@ -455,17 +461,18 @@ vec3 diffuse_tracing(uint volume_start, vec2 raster_pos, vec3 pos, uint f) {
|
|||
}
|
||||
|
||||
vec3 clamp_to_volume(uint volume_start, vec3 position) {
|
||||
uint volume_pos_x = scene_info.infos[volume_start + 0];
|
||||
uint volume_pos_y = scene_info.infos[volume_start + 1];
|
||||
uint volume_pos_z = scene_info.infos[volume_start + 2];
|
||||
float volume_pos_x = uintBitsToFloat(scene_info.infos[volume_start + 0]);
|
||||
float volume_pos_y = uintBitsToFloat(scene_info.infos[volume_start + 1]);
|
||||
float volume_pos_z = uintBitsToFloat(scene_info.infos[volume_start + 2]);
|
||||
float volume_scale = uintBitsToFloat(scene_info.infos[volume_start + array_descr_offset + color_array_offset - 1]);
|
||||
|
||||
float high_x_border = float(volume_pos_x + (scene_info.infos[volume_start + 3])) - 0.5;
|
||||
float high_y_border = float(volume_pos_y + (scene_info.infos[volume_start + 4])) - 0.5;
|
||||
float high_z_border = float(volume_pos_z + (scene_info.infos[volume_start + 5])) - 0.5;
|
||||
float high_x_border = volume_pos_x + float(scene_info.infos[volume_start + 3]) * volume_scale - 0.5 * volume_scale;
|
||||
float high_y_border = volume_pos_y + float(scene_info.infos[volume_start + 4]) * volume_scale - 0.5 * volume_scale;
|
||||
float high_z_border = volume_pos_z + float(scene_info.infos[volume_start + 5]) * volume_scale - 0.5 * volume_scale;
|
||||
|
||||
float low_x_border = float(volume_pos_x) - 0.5;
|
||||
float low_y_border = float(volume_pos_y) - 0.5;
|
||||
float low_z_border = float(volume_pos_z) - 0.5;
|
||||
float low_x_border = float(volume_pos_x) - 0.5 * volume_scale;
|
||||
float low_y_border = float(volume_pos_y) - 0.5 * volume_scale;
|
||||
float low_z_border = float(volume_pos_z) - 0.5 * volume_scale;
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue