directional light
This commit is contained in:
parent
da773cad56
commit
b559bd5e08
8 changed files with 273 additions and 55 deletions
shaders
Binary file not shown.
|
@ -149,11 +149,11 @@ uvec4 sample_color_from_scene_info(uint volume_start, uvec2 raster_pos, uint f)
|
|||
}
|
||||
|
||||
vec3 get_light_position(uint light_index) {
|
||||
return vec3(uintBitsToFloat(scene_info.infos[light_index]), uintBitsToFloat(scene_info.infos[light_index + 1]), uintBitsToFloat(scene_info.infos[light_index + 2]));
|
||||
return vec3(uintBitsToFloat(scene_info.infos[light_index + 1]), uintBitsToFloat(scene_info.infos[light_index + 2]), uintBitsToFloat(scene_info.infos[light_index + 3]));
|
||||
}
|
||||
|
||||
vec3 get_light_color(uint light_index) {
|
||||
return vec3(float(scene_info.infos[light_index + 3]) / 255.0, float(scene_info.infos[light_index + 4]) / 255.0, float(scene_info.infos[light_index + 5]) / 255.0);
|
||||
return vec3(float(scene_info.infos[light_index + 4]) / 255.0, float(scene_info.infos[light_index + 5]) / 255.0, float(scene_info.infos[light_index + 6]) / 255.0);
|
||||
}
|
||||
|
||||
vec3 normal_for_facing(uint facing) {
|
||||
|
@ -377,7 +377,7 @@ vec3 get_lighting_color(uint volume_start, vec3 starting_pos, vec4 orig_color_sa
|
|||
uint light_num = 0;
|
||||
|
||||
// initialize color
|
||||
vec3 color_sum = vec3(0.0, 0.0, 0.0) + (orig_color_sample.xyz * 0.01);
|
||||
vec3 color_sum = vec3(0.0, 0.0, 0.0);// + (orig_color_sample.xyz * 0.01);
|
||||
|
||||
uint max_iterations = max_num_lights * max_iterations_per_light;
|
||||
uint iteration = 0;
|
||||
|
@ -388,10 +388,20 @@ vec3 get_lighting_color(uint volume_start, vec3 starting_pos, vec4 orig_color_sa
|
|||
// abort if there is no new light
|
||||
break;
|
||||
}
|
||||
vec3 light_direction = get_light_position(light_index) - starting_pos;
|
||||
vec3 light_direction;
|
||||
float max_factor;
|
||||
if (scene_info.infos[light_index] == 0) {
|
||||
//point light
|
||||
light_direction = get_light_position(light_index) - starting_pos;
|
||||
max_factor = 1.0;
|
||||
} else if (scene_info.infos[light_index] == 1) {
|
||||
// directional light
|
||||
light_direction = -normalize(get_light_position(light_index));
|
||||
max_factor = pos_infinity;
|
||||
}
|
||||
vec3 light_color = get_light_color(light_index);
|
||||
|
||||
Tracing result = trace_ray(volume_start, starting_pos, light_direction, 1.0, iteration, max_iterations, false);
|
||||
Tracing result = trace_ray(volume_start, starting_pos, light_direction, max_factor, iteration, max_iterations, false);
|
||||
// add result, if there is a hit the null vector will be added
|
||||
color_sum += float(!result.has_hit) * result.color_mul * max(dot(normal, normalize(light_direction)), 0.0) * (orig_color_sample.xyz * light_color) / (length(light_direction) * length(light_direction));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue