diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-10-27 17:20:33 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-10-27 23:49:15 +0300 |
commit | 4f7665c84410e9e25360b0d80ce073c54242e5d4 (patch) | |
tree | 58b248d3fd41d1312e6f7bfd455cb583f251137b /source/blender/draw/engines/eevee/shaders | |
parent | 18ba7e26ad445981fb2750ec4bef1273f11d1554 (diff) |
Eevee: Volumetrics: Add Volume object support.
This is quite basic as it only support boundbing boxes.
But the material can refine the volume shape in anyway the user like.
To overcome this limitation, a voxelisation should be done on the mesh (generating a SDF maybe?) and tested against every volumetric cell.
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders')
3 files changed, 59 insertions, 3 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl index eb0b93d5ac4..b2c72126c40 100644 --- a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl @@ -574,7 +574,8 @@ Closure closure_add(Closure cl1, Closure cl2) cl.anisotropy = (cl1.anisotropy + cl2.anisotropy) / 2.0; /* Average phase (no multi lobe) */ return cl; } -#else + +#else /* VOLUMETRICS */ struct Closure { vec3 radiance; diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl index a3e2979a9b4..00e01e753f9 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl @@ -7,12 +7,21 @@ uniform ivec3 volumeTextureSize; uniform vec3 volume_jitter; +#ifdef MESH_SHADER +uniform mat4 volumeObjectMatrix; +uniform vec3 volumeOrcoLoc; +uniform vec3 volumeOrcoSize; +#endif + flat in int slice; /* Warning: theses are not attributes, theses are global vars. */ vec3 worldPosition = vec3(0.0); vec3 viewPosition = vec3(0.0); vec3 viewNormal = vec3(0.0); +#ifdef MESH_SHADER +vec3 volumeObjectLocalCoord = vec3(0.0); +#endif layout(location = 0) out vec4 volumeScattering; layout(location = 1) out vec4 volumeExtinction; @@ -28,11 +37,30 @@ void main() viewPosition = get_view_space_from_depth(ndc_cell.xy, ndc_cell.z); worldPosition = transform_point(ViewMatrixInverse, viewPosition); +#ifdef MESH_SHADER + volumeObjectLocalCoord = transform_point(volumeObjectMatrix, worldPosition); + volumeObjectLocalCoord = (volumeObjectLocalCoord - volumeOrcoLoc + volumeOrcoSize) / (volumeOrcoSize * 2.0); + + if (any(lessThan(volumeObjectLocalCoord, vec3(0.0))) || + any(greaterThan(volumeObjectLocalCoord, vec3(1.0)))) + discard; +#endif +#ifdef CLEAR + Closure cl = CLOSURE_DEFAULT; +#else Closure cl = nodetree_exec(); +#endif volumeScattering = vec4(cl.scatter, 1.0); volumeExtinction = vec4(max(vec3(1e-4), cl.absorption + cl.scatter), 1.0); volumeEmissive = vec4(cl.emission, 1.0); - volumePhase = vec4(cl.anisotropy, vec3(1.0)); + + /* Do not add phase weight if no scattering. */ + if (all(equal(cl.scatter, vec3(0.0)))) { + volumePhase = vec4(0.0); + } + else { + volumePhase = vec4(cl.anisotropy, vec3(1.0)); + } } diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_geom.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_geom.glsl index f944184058d..208e8165689 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_geom.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_geom.glsl @@ -1,11 +1,36 @@ +#ifdef MESH_SHADER +/* TODO tight slices */ layout(triangles) in; layout(triangle_strip, max_vertices=3) out; +#else /* World */ +layout(triangles) in; +layout(triangle_strip, max_vertices=3) out; +#endif in vec4 vPos[]; flat out int slice; +#ifdef MESH_SHADER +/* TODO tight slices */ +void main() { + gl_Layer = slice = int(vPos[0].z); + + gl_Position = vPos[0].xyww; + EmitVertex(); + + gl_Position = vPos[1].xyww; + EmitVertex(); + + gl_Position = vPos[2].xyww; + EmitVertex(); + + EndPrimitive(); +} + +#else /* World */ + /* This is just a pass-through geometry shader that send the geometry * to the layer corresponding to it's depth. */ @@ -22,4 +47,6 @@ void main() { EmitVertex(); EndPrimitive(); -}
\ No newline at end of file +} + +#endif |