Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/shaders/lights_lib.glsl
| Show First 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | if (ld.l_type >= SPOT) { | ||||
| vis *= step(0.0, -dot(l_vector.xyz, ld.l_forward)); | vis *= step(0.0, -dot(l_vector.xyz, ld.l_forward)); | ||||
| } | } | ||||
| if (ld.l_type != SUN) { | if (ld.l_type != SUN) { | ||||
| vis *= distance_attenuation(l_vector.w * l_vector.w, ld.l_influence); | vis *= distance_attenuation(l_vector.w * l_vector.w, ld.l_influence); | ||||
| } | } | ||||
| return vis; | return vis; | ||||
| } | } | ||||
| float light_shadowing(LightData ld, | float light_shadowing(LightData ld, vec3 W, float vis) | ||||
| vec3 W, | |||||
| #ifndef VOLUMETRICS | |||||
| vec3 viewPosition, | |||||
| float tracing_depth, | |||||
| vec3 true_normal, | |||||
| float rand_x, | |||||
| const bool use_contact_shadows, | |||||
| #endif | |||||
| float vis) | |||||
| { | { | ||||
| #if !defined(VOLUMETRICS) || defined(VOLUME_SHADOW) | #if !defined(VOLUMETRICS) || defined(VOLUME_SHADOW) | ||||
| /* shadowing */ | |||||
| if (ld.l_shadowid >= 0.0 && vis > 0.001) { | if (ld.l_shadowid >= 0.0 && vis > 0.001) { | ||||
| if (ld.l_type == SUN) { | if (ld.l_type == SUN) { | ||||
| vis *= sample_cascade_shadow(int(ld.l_shadowid), W); | vis *= sample_cascade_shadow(int(ld.l_shadowid), W); | ||||
| } | } | ||||
| else { | else { | ||||
| vis *= sample_cube_shadow(int(ld.l_shadowid), W); | vis *= sample_cube_shadow(int(ld.l_shadowid), W); | ||||
| } | } | ||||
| } | |||||
| #endif | |||||
| return vis; | |||||
| } | |||||
| # ifndef VOLUMETRICS | #ifndef VOLUMETRICS | ||||
| float light_contact_shadows( | |||||
| LightData ld, vec3 P, vec3 vP, float tracing_depth, vec3 vNg, float rand_x, float vis) | |||||
| { | |||||
| if (ld.l_shadowid >= 0.0 && vis > 0.001) { | |||||
| ShadowData sd = shadows_data[int(ld.l_shadowid)]; | ShadowData sd = shadows_data[int(ld.l_shadowid)]; | ||||
| /* Only compute if not already in shadow. */ | /* Only compute if not already in shadow. */ | ||||
| if (use_contact_shadows && sd.sh_contact_dist > 0.0 && vis > 1e-8) { | if (sd.sh_contact_dist > 0.0) { | ||||
| /* Contact Shadows. */ | /* Contact Shadows. */ | ||||
| vec3 ray_ori, ray_dir; | vec3 ray_ori, ray_dir; | ||||
| float trace_distance; | float trace_distance; | ||||
| if (ld.l_type == SUN) { | if (ld.l_type == SUN) { | ||||
| trace_distance = sd.sh_contact_dist; | trace_distance = sd.sh_contact_dist; | ||||
| ray_dir = shadows_cascade_data[int(sd.sh_data_index)].sh_shadow_vec * trace_distance; | ray_dir = shadows_cascade_data[int(sd.sh_data_index)].sh_shadow_vec * trace_distance; | ||||
| } | } | ||||
| else { | else { | ||||
| ray_dir = shadows_cube_data[int(sd.sh_data_index)].position.xyz - W; | ray_dir = shadows_cube_data[int(sd.sh_data_index)].position.xyz - P; | ||||
| float len = length(ray_dir); | float len = length(ray_dir); | ||||
| trace_distance = min(sd.sh_contact_dist, len); | trace_distance = min(sd.sh_contact_dist, len); | ||||
| ray_dir *= trace_distance / len; | ray_dir *= trace_distance / len; | ||||
| } | } | ||||
| ray_dir = transform_direction(ViewMatrix, ray_dir); | ray_dir = transform_direction(ViewMatrix, ray_dir); | ||||
| ray_ori = vec3(viewPosition.xy, tracing_depth) + true_normal * sd.sh_contact_offset; | ray_ori = vec3(vP.xy, tracing_depth) + vNg * sd.sh_contact_offset; | ||||
| vec3 hit_pos = raycast( | vec3 hit_pos = raycast( | ||||
| -1, ray_ori, ray_dir, sd.sh_contact_thickness, rand_x, 0.1, 0.001, false); | -1, ray_ori, ray_dir, sd.sh_contact_thickness, rand_x, 0.1, 0.001, false); | ||||
| if (hit_pos.z > 0.0) { | if (hit_pos.z > 0.0) { | ||||
| hit_pos = get_view_space_from_depth(hit_pos.xy, hit_pos.z); | hit_pos = get_view_space_from_depth(hit_pos.xy, hit_pos.z); | ||||
| float hit_dist = distance(viewPosition, hit_pos); | float hit_dist = distance(vP, hit_pos); | ||||
| float dist_ratio = hit_dist / trace_distance; | float dist_ratio = hit_dist / trace_distance; | ||||
| return vis * saturate(dist_ratio * 3.0 - 2.0); | return saturate(dist_ratio * 3.0 - 2.0); | ||||
| } | } | ||||
| } | } | ||||
| # endif /* VOLUMETRICS */ | |||||
| } | } | ||||
| #endif | return 1.0; | ||||
| return vis; | |||||
| } | } | ||||
| #endif /* VOLUMETRICS */ | |||||
| float light_visibility(LightData ld, | float light_visibility(LightData ld, vec3 W, vec4 l_vector) | ||||
| vec3 W, | |||||
| #ifndef VOLUMETRICS | |||||
| vec3 viewPosition, | |||||
| float tracing_depth, | |||||
| vec3 true_normal, | |||||
| float rand_x, | |||||
| const bool use_contact_shadows, | |||||
| #endif | |||||
| vec4 l_vector) | |||||
| { | { | ||||
| float l_atten = light_attenuation(ld, l_vector); | float l_atten = light_attenuation(ld, l_vector); | ||||
| return light_shadowing(ld, | return light_shadowing(ld, W, l_atten); | ||||
| W, | |||||
| #ifndef VOLUMETRICS | |||||
| viewPosition, | |||||
| tracing_depth, | |||||
| true_normal, | |||||
| rand_x, | |||||
| use_contact_shadows, | |||||
| #endif | |||||
| l_atten); | |||||
| } | } | ||||
| float light_diffuse(LightData ld, vec3 N, vec3 V, vec4 l_vector) | float light_diffuse(LightData ld, vec3 N, vec3 V, vec4 l_vector) | ||||
| { | { | ||||
| if (ld.l_type == AREA_RECT) { | if (ld.l_type == AREA_RECT) { | ||||
| vec3 corners[4]; | vec3 corners[4]; | ||||
| corners[0] = normalize((l_vector.xyz + ld.l_right * -ld.l_sizex) + ld.l_up * ld.l_sizey); | corners[0] = normalize((l_vector.xyz + ld.l_right * -ld.l_sizex) + ld.l_up * ld.l_sizey); | ||||
| corners[1] = normalize((l_vector.xyz + ld.l_right * -ld.l_sizex) + ld.l_up * -ld.l_sizey); | corners[1] = normalize((l_vector.xyz + ld.l_right * -ld.l_sizex) + ld.l_up * -ld.l_sizey); | ||||
| ▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines | |||||