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>2017-06-04 17:50:22 +0300
committerClément Foucault <foucault.clem@gmail.com>2017-06-04 17:50:22 +0300
commit819b8adb94f5ab617a0b2bcac37678eb4874dfbd (patch)
treec332ee04fd4431fe4c7ac7f5baf53bf8b363eb07 /source/blender/draw/engines/eevee/shaders
parent28b597b6df46b6d2581d7948578922bb3566d242 (diff)
Eevee: Move Spherical Harmonics to a new Probe UBO.
Keep data packing tight to prevent use of padding floats
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders')
-rw-r--r--source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl47
-rw-r--r--source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl37
2 files changed, 63 insertions, 21 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 8963ad2b93e..b0b11c489b6 100644
--- a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
@@ -9,6 +9,23 @@
/* ------- Structures -------- */
+struct ProbeData {
+ vec4 position_influence; /* w : InfluenceRadius */
+ vec4 shcoefs[7];
+};
+
+#define p_position position_influence.xyz
+#define p_spec position_influence.w
+#define shcoef0 shcoefs[0].rgb
+#define shcoef1 vec3(shcoefs[0].a, shcoefs[1].rg)
+#define shcoef2 vec3(shcoefs[1].ba, shcoefs[2].r)
+#define shcoef3 shcoefs[2].gba
+#define shcoef4 shcoefs[3].rgb
+#define shcoef5 vec3(shcoefs[3].a, shcoefs[4].rg)
+#define shcoef6 vec3(shcoefs[4].ba, shcoefs[5].r)
+#define shcoef7 shcoefs[5].gba
+#define shcoef8 shcoefs[6].rgb
+
struct LightData {
vec4 position_influence; /* w : InfluenceRadius */
vec4 color_spec; /* w : Spec Intensity */
@@ -172,34 +189,34 @@ float buffer_depth(bool is_persp, float z, float zf, float zn)
#define spherical_harmonics spherical_harmonics_L2
/* http://seblagarde.wordpress.com/2012/01/08/pi-or-not-to-pi-in-game-lighting-equation/ */
-vec3 spherical_harmonics_L1(vec3 N, vec3 shcoefs[9])
+vec3 spherical_harmonics_L1(vec3 N, vec4 shcoefs[3])
{
vec3 sh = vec3(0.0);
- sh += 0.282095 * shcoefs[0];
+ sh += 0.282095 * shcoef0;
- sh += -0.488603 * N.z * shcoefs[1];
- sh += 0.488603 * N.y * shcoefs[2];
- sh += -0.488603 * N.x * shcoefs[3];
+ sh += -0.488603 * N.z * shcoef1;
+ sh += 0.488603 * N.y * shcoef2;
+ sh += -0.488603 * N.x * shcoef3;
return sh;
}
-vec3 spherical_harmonics_L2(vec3 N, vec3 shcoefs[9])
+vec3 spherical_harmonics_L2(vec3 N, vec4 shcoefs[7])
{
vec3 sh = vec3(0.0);
- sh += 0.282095 * shcoefs[0];
+ sh += 0.282095 * shcoef0;
- sh += -0.488603 * N.z * shcoefs[1];
- sh += 0.488603 * N.y * shcoefs[2];
- sh += -0.488603 * N.x * shcoefs[3];
+ sh += -0.488603 * N.z * shcoef1;
+ sh += 0.488603 * N.y * shcoef2;
+ sh += -0.488603 * N.x * shcoef3;
- sh += 1.092548 * N.x * N.z * shcoefs[4];
- sh += -1.092548 * N.z * N.y * shcoefs[5];
- sh += 0.315392 * (3.0 * N.y * N.y - 1.0) * shcoefs[6];
- sh += -1.092548 * N.x * N.y * shcoefs[7];
- sh += 0.546274 * (N.x * N.x - N.z * N.z) * shcoefs[8];
+ sh += 1.092548 * N.x * N.z * shcoef4;
+ sh += -1.092548 * N.z * N.y * shcoef5;
+ sh += 0.315392 * (3.0 * N.y * N.y - 1.0) * shcoef6;
+ sh += -1.092548 * N.x * N.y * shcoef7;
+ sh += 0.546274 * (N.x * N.x - N.z * N.z) * shcoef8;
return sh;
}
diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
index b8eb84f24de..5ee0cb74894 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
@@ -1,5 +1,6 @@
uniform int light_count;
+uniform int probe_count;
uniform mat4 ProjectionMatrix;
uniform mat4 ViewMatrixInverse;
@@ -15,6 +16,10 @@ uniform sampler2DArray utilTex;
uniform sampler2DArray shadowCubes;
uniform sampler2DArrayShadow shadowCascades;
+layout(std140) uniform probe_block {
+ ProbeData probes_data[MAX_PROBE];
+};
+
layout(std140) uniform light_block {
LightData lights_data[MAX_LIGHT];
};
@@ -191,6 +196,13 @@ void light_visibility(LightData ld, ShadingData sd, out float vis)
}
}
+void probe_lighting(ShadingData sd, int index, vec3 spec_dir, float roughness, out vec3 diff, out vec3 spec)
+{
+ ProbeData pd = probes_data[index];
+ spec = textureLod_octahedron(probeCubes, vec4(spec_dir, index), roughness * lodMax).rgb;
+ diff = spherical_harmonics(sd.N, pd.shcoefs);
+}
+
vec3 eevee_surface_lit(vec3 world_normal, vec3 albedo, vec3 f0, float roughness, float ao)
{
float roughnessSquared = roughness * roughness;
@@ -203,8 +215,6 @@ vec3 eevee_surface_lit(vec3 world_normal, vec3 albedo, vec3 f0, float roughness,
sd.W = worldPosition;
vec3 radiance = vec3(0.0);
- vec3 indirect_radiance = vec3(0.0);
-
/* Analitic Lights */
for (int i = 0; i < MAX_LIGHT && i < light_count; ++i) {
LightData ld = lights_data[i];
@@ -219,14 +229,29 @@ vec3 eevee_surface_lit(vec3 world_normal, vec3 albedo, vec3 f0, float roughness,
radiance += vis * (diff + spec) * ld.l_color;
}
- vec3 spec_dir = get_specular_dominant_dir(sd.N, reflect(-sd.V, sd.N), roughnessSquared);
/* Envmaps */
+ vec3 spec_dir = get_specular_dominant_dir(sd.N, reflect(-sd.V, sd.N), roughnessSquared);
vec2 uv = lut_coords(dot(sd.N, sd.V), roughness);
vec2 brdf_lut = texture(utilTex, vec3(uv, 1.0)).rg;
- vec3 Li = textureLod_octahedron(probeCubes, vec4(spec_dir, 0.0), roughness * lodMax).rgb;
- indirect_radiance += Li * F_ibl(f0, brdf_lut);
- indirect_radiance += spherical_harmonics(sd.N, shCoefs) * albedo;
+
+ vec4 spec_accum = vec4(0.0);
+ vec4 diff_accum = vec4(0.0);
+ /* Start at 1 because 0 is world probe */
+ for (int i = 1; i < MAX_PROBE && i < probe_count; ++i) {
+ /* TODO */
+ }
+
+ if (spec_accum.a < 1.0 || diff_accum.a < 1.0) {
+ vec3 diff, spec;
+ probe_lighting(sd, 0, spec_dir, roughness, diff, spec);
+ diff_accum.rgb += diff * (1.0 - diff_accum.a);
+ spec_accum.rgb += spec * (1.0 - spec_accum.a);
+ }
+
+ vec3 indirect_radiance =
+ spec_accum.rgb * F_ibl(f0, brdf_lut) +
+ diff_accum.rgb * albedo;
return radiance + indirect_radiance * ao;
} \ No newline at end of file