Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-01-21 19:25:10 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-01-22 01:16:59 +0300
commita507c251b23f2fd6ef7758e443939ce0c5c09e61 (patch)
tree9fe4e1ac28c23cb52e334cd0ec7b92c83f4ffd5a /source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl
parent790025c01ed76c06e69e6054f1a718ca57771e28 (diff)
Eevee: Put all constant uniforms in a global UBO.
This is an optimization / cleanup commit. The use of a global ubo remove lots of uniform lookups and only transfert data when needed. Lots of renaming for more consistent codestyle.
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl')
-rw-r--r--source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl28
1 files changed, 10 insertions, 18 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl
index e12554bfabc..1a8167c2830 100644
--- a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl
@@ -2,22 +2,16 @@
/* Based on Frosbite Unified Volumetric.
* https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite */
-uniform float volume_light_clamp;
-
-uniform vec3 volume_param; /* Parameters to the volume Z equation */
-
-uniform vec2 volume_uv_ratio; /* To convert volume uvs to screen uvs */
-
/* Volume slice to view space depth. */
float volume_z_to_view_z(float z)
{
if (ProjectionMatrix[3][3] == 0.0) {
/* Exponential distribution */
- return (exp2(z / volume_param.z) - volume_param.x) / volume_param.y;
+ return (exp2(z / volDepthParameters.z) - volDepthParameters.x) / volDepthParameters.y;
}
else {
/* Linear distribution */
- return mix(volume_param.x, volume_param.y, z);
+ return mix(volDepthParameters.x, volDepthParameters.y, z);
}
}
@@ -25,11 +19,11 @@ float view_z_to_volume_z(float depth)
{
if (ProjectionMatrix[3][3] == 0.0) {
/* Exponential distribution */
- return volume_param.z * log2(depth * volume_param.y + volume_param.x);
+ return volDepthParameters.z * log2(depth * volDepthParameters.y + volDepthParameters.x);
}
else {
/* Linear distribution */
- return (depth - volume_param.x) * volume_param.z;
+ return (depth - volDepthParameters.x) * volDepthParameters.z;
}
}
@@ -38,7 +32,7 @@ vec3 volume_to_ndc(vec3 cos)
{
cos.z = volume_z_to_view_z(cos.z);
cos.z = get_depth_from_view_z(cos.z);
- cos.xy /= volume_uv_ratio;
+ cos.xy /= volCoordScale.xy;
return cos;
}
@@ -46,7 +40,7 @@ vec3 ndc_to_volume(vec3 cos)
{
cos.z = get_view_z_from_depth(cos.z);
cos.z = view_z_to_volume_z(cos.z);
- cos.xy *= volume_uv_ratio;
+ cos.xy *= volCoordScale.xy;
return cos;
}
@@ -90,15 +84,13 @@ vec3 light_volume(LightData ld, vec4 l_vector)
power /= (l_vector.w * l_vector.w);
- lum = min(lum * power, volume_light_clamp);
+ lum = min(lum * power, volLightClamp);
return tint * lum;
}
#define VOLUMETRIC_SHADOW_MAX_STEP 32.0
-uniform float volume_shadows_steps;
-
vec3 participating_media_extinction(vec3 wpos, sampler3D volume_extinction)
{
/* Waiting for proper volume shadowmaps and out of frustum shadow map. */
@@ -113,11 +105,11 @@ vec3 light_volume_shadow(LightData ld, vec3 ray_wpos, vec4 l_vector, sampler3D v
{
#if defined(VOLUME_SHADOW)
/* Heterogeneous volume shadows */
- float dd = l_vector.w / volume_shadows_steps;
+ float dd = l_vector.w / volShadowSteps;
vec3 L = l_vector.xyz * l_vector.w;
vec3 shadow = vec3(1.0);
- for (float s = 0.5; s < VOLUMETRIC_SHADOW_MAX_STEP && s < (volume_shadows_steps - 0.1); s += 1.0) {
- vec3 pos = ray_wpos + L * (s / volume_shadows_steps);
+ for (float s = 0.5; s < VOLUMETRIC_SHADOW_MAX_STEP && s < (volShadowSteps - 0.1); s += 1.0) {
+ vec3 pos = ray_wpos + L * (s / volShadowSteps);
vec3 s_extinction = participating_media_extinction(pos, volume_extinction);
shadow *= exp(-s_extinction * dd);
}