Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl
| Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | vec3 light_volume_light_vector(LightData ld, vec3 P) | ||||
| } | } | ||||
| } | } | ||||
| #define VOLUMETRIC_SHADOW_MAX_STEP 128.0 | #define VOLUMETRIC_SHADOW_MAX_STEP 128.0 | ||||
| vec3 participating_media_extinction(vec3 wpos, sampler3D volume_extinction) | vec3 participating_media_extinction(vec3 wpos, sampler3D volume_extinction) | ||||
| { | { | ||||
| /* Waiting for proper volume shadowmaps and out of frustum shadow map. */ | /* Waiting for proper volume shadowmaps and out of frustum shadow map. */ | ||||
| vec3 ndc = project_point(ViewProjectionMatrix, wpos); | vec3 ndc = project_point(ProjectionMatrix, transform_point(ViewMatrix, wpos)); | ||||
| vec3 volume_co = ndc_to_volume(ndc * 0.5 + 0.5); | vec3 volume_co = ndc_to_volume(ndc * 0.5 + 0.5); | ||||
| /* Let the texture be clamped to edge. This reduce visual glitches. */ | /* Let the texture be clamped to edge. This reduce visual glitches. */ | ||||
| return texture(volume_extinction, volume_co).rgb; | return texture(volume_extinction, volume_co).rgb; | ||||
| } | } | ||||
| vec3 light_volume_shadow(LightData ld, vec3 ray_wpos, vec4 l_vector, sampler3D volume_extinction) | vec3 light_volume_shadow(LightData ld, vec3 ray_wpos, vec4 l_vector, sampler3D volume_extinction) | ||||
| { | { | ||||
| Show All 13 Lines | #if defined(VOLUME_SHADOW) | ||||
| } | } | ||||
| /* Heterogeneous volume shadows */ | /* Heterogeneous volume shadows */ | ||||
| float dd = l_vector.w / volShadowSteps; | float dd = l_vector.w / volShadowSteps; | ||||
| vec3 L = l_vector.xyz / volShadowSteps; | vec3 L = l_vector.xyz / volShadowSteps; | ||||
| if (ld.l_type == SUN) { | if (ld.l_type == SUN) { | ||||
| /* For sun light we scan the whole frustum. So we need to get the correct endpoints. */ | /* For sun light we scan the whole frustum. So we need to get the correct endpoints. */ | ||||
| vec3 ndcP = project_point(ViewProjectionMatrix, ray_wpos); | vec3 ndcP = project_point(ProjectionMatrix, transform_point(ViewMatrix, ray_wpos)); | ||||
| vec3 ndcL = project_point(ViewProjectionMatrix, ray_wpos + l_vector.xyz) - ndcP; | vec3 ndcL = project_point(ProjectionMatrix, | ||||
| transform_point(ViewMatrix, ray_wpos + l_vector.xyz)) - | |||||
| ndcP; | |||||
| vec3 frustum_isect = ndcP + ndcL * line_unit_box_intersect_dist_safe(ndcP, ndcL); | vec3 frustum_isect = ndcP + ndcL * line_unit_box_intersect_dist_safe(ndcP, ndcL); | ||||
| L = project_point(ViewProjectionMatrixInverse, frustum_isect) - ray_wpos; | vec4 L_hom = ViewMatrixInverse * (ProjectionMatrixInverse * vec4(frustum_isect, 1.0)); | ||||
| L = (L_hom.xyz / L_hom.w) - ray_wpos; | |||||
| L /= volShadowSteps; | L /= volShadowSteps; | ||||
| dd = length(L); | dd = length(L); | ||||
| } | } | ||||
| vec3 shadow = vec3(1.0); | vec3 shadow = vec3(1.0); | ||||
| for (float s = 1.0; s < VOLUMETRIC_SHADOW_MAX_STEP && s <= volShadowSteps; s += 1.0) { | for (float s = 1.0; s < VOLUMETRIC_SHADOW_MAX_STEP && s <= volShadowSteps; s += 1.0) { | ||||
| vec3 pos = ray_wpos + L * s; | vec3 pos = ray_wpos + L * s; | ||||
| vec3 s_extinction = participating_media_extinction(pos, volume_extinction); | vec3 s_extinction = participating_media_extinction(pos, volume_extinction); | ||||
| Show All 35 Lines | |||||