Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/shaders/volumetric_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 */ | ||||
| /* Store volumetric properties into the froxel textures. */ | /* Store volumetric properties into the froxel textures. */ | ||||
| flat in int slice; | |||||
| /* WARNING: these are not attributes, these are global vars. */ | /* WARNING: these are not attributes, these are global vars. */ | ||||
| vec3 worldPosition = vec3(0.0); | vec3 worldPosition = vec3(0.0); | ||||
| vec3 objectPosition = vec3(0.0); | vec3 objectPosition = vec3(0.0); | ||||
| vec3 viewPosition = vec3(0.0); | vec3 viewPosition = vec3(0.0); | ||||
| vec3 viewNormal = vec3(0.0); | vec3 viewNormal = vec3(0.0); | ||||
| vec3 volumeOrco = vec3(0.0); | vec3 volumeOrco = vec3(0.0); | ||||
| layout(location = 0) out vec4 volumeScattering; | |||||
| layout(location = 1) out vec4 volumeExtinction; | |||||
| layout(location = 2) out vec4 volumeEmissive; | |||||
| layout(location = 3) out vec4 volumePhase; | |||||
| int attr_id = 0; | int attr_id = 0; | ||||
| #ifndef CLEAR | #ifndef CLEAR | ||||
| GlobalData init_globals(void) | GlobalData init_globals(void) | ||||
| { | { | ||||
| GlobalData surf; | GlobalData surf; | ||||
| surf.P = worldPosition; | surf.P = worldPosition; | ||||
| surf.N = vec3(0.0); | surf.N = vec3(0.0); | ||||
| Show All 34 Lines | |||||
| vec3 coordinate_incoming(vec3 P) | vec3 coordinate_incoming(vec3 P) | ||||
| { | { | ||||
| return cameraVec(P); | return cameraVec(P); | ||||
| } | } | ||||
| #endif | #endif | ||||
| 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); | ||||
| vec3 ndc_cell = volume_to_ndc((vec3(volume_cell) + volJitter.xyz) * volInvTexSize.xyz); | vec3 ndc_cell = volume_to_ndc((vec3(volume_cell) + volJitter.xyz) * volInvTexSize.xyz); | ||||
| viewPosition = get_view_space_from_depth(ndc_cell.xy, ndc_cell.z); | viewPosition = get_view_space_from_depth(ndc_cell.xy, ndc_cell.z); | ||||
| worldPosition = point_view_to_world(viewPosition); | worldPosition = point_view_to_world(viewPosition); | ||||
| #ifdef MESH_SHADER | #ifdef MESH_SHADER | ||||
| objectPosition = point_world_to_object(worldPosition); | objectPosition = point_world_to_object(worldPosition); | ||||
| volumeOrco = OrcoTexCoFactors[0].xyz + objectPosition * OrcoTexCoFactors[1].xyz; | volumeOrco = OrcoTexCoFactors[0].xyz + objectPosition * OrcoTexCoFactors[1].xyz; | ||||
| Show All 10 Lines | |||||
| #ifdef CLEAR | #ifdef CLEAR | ||||
| volumeScattering = vec4(0.0, 0.0, 0.0, 1.0); | volumeScattering = vec4(0.0, 0.0, 0.0, 1.0); | ||||
| volumeExtinction = vec4(0.0, 0.0, 0.0, 1.0); | volumeExtinction = vec4(0.0, 0.0, 0.0, 1.0); | ||||
| volumeEmissive = vec4(0.0, 0.0, 0.0, 1.0); | volumeEmissive = vec4(0.0, 0.0, 0.0, 1.0); | ||||
| volumePhase = vec4(0.0, 0.0, 0.0, 0.0); | volumePhase = vec4(0.0, 0.0, 0.0, 0.0); | ||||
| #else | #else | ||||
| g_data = init_globals(); | g_data = init_globals(); | ||||
| # ifndef NO_ATTRIB_LOAD | |||||
| attrib_load(); | attrib_load(); | ||||
| # endif | |||||
| Closure cl = nodetree_exec(); | Closure cl = nodetree_exec(); | ||||
| # ifdef MESH_SHADER | # ifdef MESH_SHADER | ||||
| cl.scatter *= drw_volume.density_scale; | cl.scatter *= drw_volume.density_scale; | ||||
| cl.absorption *= drw_volume.density_scale; | cl.absorption *= drw_volume.density_scale; | ||||
| cl.emission *= drw_volume.density_scale; | cl.emission *= drw_volume.density_scale; | ||||
| # endif | # endif | ||||
| volumeScattering = vec4(cl.scatter, 1.0); | volumeScattering = vec4(cl.scatter, 1.0); | ||||
| ▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines | |||||