Eevee: Add support for volumetrics in node tree.

Only volume scatter is implemented for now.
This commit is contained in:
2017-07-03 22:08:07 +02:00
parent 2eef097831
commit b09052002c
8 changed files with 160 additions and 75 deletions

View File

@@ -17,6 +17,44 @@ uniform vec4 viewvecs[2];
#define cameraPos ViewMatrixInverse[3].xyz
/* ------- Structures -------- */
#ifdef VOLUMETRICS
#define NODETREE_EXEC
struct Closure {
vec3 absorption;
vec3 scatter;
vec3 emission;
float anisotropy;
};
#define CLOSURE_DEFAULT Closure(vec3(0.0), vec3(0.0), vec3(0.0), 0.0);
Closure closure_mix(Closure cl1, Closure cl2, float fac)
{
Closure cl;
cl.absorption = mix(cl1.absorption, cl2.absorption, fac);
cl.scatter = mix(cl1.scatter, cl2.scatter, fac);
cl.emission = mix(cl1.emission, cl2.emission, fac);
cl.anisotropy = mix(cl1.anisotropy, cl2.anisotropy, fac);
return cl;
}
Closure closure_add(Closure cl1, Closure cl2)
{
Closure cl;
cl.absorption = cl1.absorption + cl2.absorption;
cl.scatter = cl1.scatter + cl2.scatter;
cl.emission = cl1.emission + cl2.emission;
cl.anisotropy = cl1.anisotropy + cl2.anisotropy;
return cl;
}
Closure nodetree_exec(void); /* Prototype */
#endif /* VOLUMETRICS */
struct LightData {
vec4 position_influence; /* w : InfluenceRadius */

View File

@@ -1,10 +1,42 @@
out vec4 FragColor;
#ifdef STEP_INTEGRATE
#ifdef VOLUMETRICS
uniform sampler2D depthFull;
void participating_media_properties(vec3 wpos, out vec3 absorption, out vec3 scattering, out float anisotropy)
{
Closure cl = nodetree_exec();
absorption = cl.absorption;
scattering = cl.scatter;
anisotropy = cl.anisotropy;
}
float phase_function_isotropic()
{
return 1.0 / (4.0 * M_PI);
}
float phase_function(vec3 v, vec3 l, float g)
{
#if 1
/* Henyey-Greenstein */
float cos_theta = dot(v, l);
float sqr_g = g * g;
return (1- sqr_g) / (4.0 * M_PI * pow(1 + sqr_g - 2 * g * cos_theta, 3.0 / 2.0));
#else
return phase_function_isotropic();
#endif
}
vec3 light_volume(LightData ld, vec4 l_vector, vec3 l_col)
{
float dist = max(1e-4, abs(l_vector.w - ld.l_radius));
return l_col * (4.0 * ld.l_radius * ld.l_radius * M_PI * M_PI) / (dist * dist);
}
float find_next_step(float near, float far, float noise, int iter, int iter_count)
{
const float lambda = 0.8f; /* TODO : Parameter */
@@ -22,38 +54,6 @@ float find_next_step(float near, float far, float noise, int iter, int iter_coun
}
}
void participating_media_properties(vec3 wpos, out vec3 absorption, out vec3 scattering, out float anisotropy)
{
/* TODO Call nodetree from here. */
absorption = vec3(0.00);
scattering = vec3(1.0) * step(-1.0, -wpos.z);
anisotropy = -0.8;
}
float phase_function_isotropic()
{
return 1.0 / (4.0 * M_PI);
}
float phase_function(vec3 v, vec3 l, float g)
{
#if 0
/* Henyey-Greenstein */
float cos_theta = dot(v, l);
float sqr_g = g * g;
return (1- sqr_g) / (4.0 * M_PI * pow(1 + sqr_g - 2 * g * cos_theta, 3.0 / 2.0));
#else
return phase_function_isotropic();
#endif
}
vec3 light_volume(LightData ld, vec4 l_vector, vec3 l_col)
{
float dist = max(1e-4, abs(l_vector.w - ld.l_radius));
return l_col * (4.0 * ld.l_radius * ld.l_radius * M_PI * M_PI) / (dist * dist);
}
/* Based on Frosbite Unified Volumetric.
* https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite */
void main()