Differential D16243 Diff 58431 source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl
| #pragma BLENDER_REQUIRE(volumetric_lib.glsl) | #pragma BLENDER_REQUIRE(volumetric_lib.glsl) | ||||
| /* Based on Frosbite Unified Volumetric. | /* Based on Frosbite Unified Volumetric. | ||||
| * https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite */ | * https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite */ | ||||
| /* Step 2 : Evaluate all light scattering for each froxels. | /* Step 2 : Evaluate all light scattering for each froxels. | ||||
| * Also do the temporal reprojection to fight aliasing artifacts. */ | * Also do the temporal reprojection to fight aliasing artifacts. */ | ||||
| uniform sampler3D volumeScattering; | |||||
| uniform sampler3D volumeExtinction; | |||||
| uniform sampler3D volumeEmission; | |||||
| uniform sampler3D volumePhase; | |||||
| uniform sampler3D historyScattering; | |||||
| uniform sampler3D historyTransmittance; | |||||
| flat in int slice; | |||||
| layout(location = 0) out vec4 outScattering; | |||||
| layout(location = 1) out vec4 outTransmittance; | |||||
| void main() | void main() | ||||
| { | { | ||||
| ivec3 volume_cell = ivec3(ivec2(gl_FragCoord.xy), slice); | ivec3 volume_cell = ivec3(ivec2(gl_FragCoord.xy), volumetric_geom_iface.slice); | ||||
| /* Emission */ | /* Emission */ | ||||
| outScattering = texelFetch(volumeEmission, volume_cell, 0); | outScattering = texelFetch(volumeEmission, volume_cell, 0); | ||||
| outTransmittance = texelFetch(volumeExtinction, volume_cell, 0); | outTransmittance = texelFetch(volumeExtinction, volume_cell, 0); | ||||
| vec3 s_scattering = texelFetch(volumeScattering, volume_cell, 0).rgb; | vec3 s_scattering = texelFetch(volumeScattering, volume_cell, 0).rgb; | ||||
| vec3 volume_ndc = volume_to_ndc((vec3(volume_cell) + volJitter.xyz) * volInvTexSize.xyz); | vec3 volume_ndc = volume_to_ndc((vec3(volume_cell) + volJitter.xyz) * volInvTexSize.xyz); | ||||
| vec3 P = get_world_space_from_depth(volume_ndc.xy, volume_ndc.z); | vec3 P = get_world_space_from_depth(volume_ndc.xy, volume_ndc.z); | ||||
| vec3 V = cameraVec(P); | vec3 V = cameraVec(P); | ||||
| Show All 26 Lines | for (int i = 0; i < MAX_LIGHT && i < laNumLight; i++) { | ||||
| outScattering.rgb += Li * vis * s_scattering * | outScattering.rgb += Li * vis * s_scattering * | ||||
| phase_function(-V, l_vector.xyz / l_vector.w, s_anisotropy); | phase_function(-V, l_vector.xyz / l_vector.w, s_anisotropy); | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Temporal supersampling */ | /* Temporal supersampling */ | ||||
| /* Note : this uses the cell non-jittered position (texel center). */ | /* Note : this uses the cell non-jittered position (texel center). */ | ||||
| vec3 curr_ndc = volume_to_ndc(vec3(gl_FragCoord.xy, float(slice) + 0.5) * volInvTexSize.xyz); | vec3 curr_ndc = volume_to_ndc(vec3(gl_FragCoord.xy, float(volumetric_geom_iface.slice) + 0.5) * | ||||
| volInvTexSize.xyz); | |||||
| vec3 wpos = get_world_space_from_depth(curr_ndc.xy, curr_ndc.z); | vec3 wpos = get_world_space_from_depth(curr_ndc.xy, curr_ndc.z); | ||||
| vec3 prev_ndc = project_point(pastViewProjectionMatrix, wpos); | vec3 prev_ndc = project_point(pastViewProjectionMatrix, wpos); | ||||
| vec3 prev_volume = ndc_to_volume(prev_ndc * 0.5 + 0.5); | vec3 prev_volume = ndc_to_volume(prev_ndc * 0.5 + 0.5); | ||||
| if ((volHistoryAlpha > 0.0) && all(greaterThan(prev_volume, vec3(0.0))) && | if ((volHistoryAlpha > 0.0) && all(greaterThan(prev_volume, vec3(0.0))) && | ||||
| all(lessThan(prev_volume, vec3(1.0)))) { | all(lessThan(prev_volume, vec3(1.0)))) { | ||||
| vec4 h_Scattering = texture(historyScattering, prev_volume); | vec4 h_Scattering = texture(historyScattering, prev_volume); | ||||
| vec4 h_Transmittance = texture(historyTransmittance, prev_volume); | vec4 h_Transmittance = texture(historyTransmittance, prev_volume); | ||||
| Show All 10 Lines | |||||