[Bf-blender-cvs] [303a9ae0e8d] blender2.8: Eevee: Optimize Spherical Harmonic computation time (17ms -> 1ms)

Clément Foucault noreply at git.blender.org
Tue Apr 18 21:47:32 CEST 2017


Commit: 303a9ae0e8dc8c0ebf65f7470cb1c9b55f8dffb5
Author: Clément Foucault
Date:   Tue Apr 18 21:25:57 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB303a9ae0e8dc8c0ebf65f7470cb1c9b55f8dffb5

Eevee: Optimize Spherical Harmonic computation time (17ms -> 1ms)

===================================================================

M	source/blender/draw/engines/eevee/eevee.c
M	source/blender/draw/engines/eevee/eevee_probes.c
M	source/blender/draw/engines/eevee/shaders/probe_sh_frag.glsl

===================================================================

diff --git a/source/blender/draw/engines/eevee/eevee.c b/source/blender/draw/engines/eevee/eevee.c
index b496344478a..648e3b95af8 100644
--- a/source/blender/draw/engines/eevee/eevee.c
+++ b/source/blender/draw/engines/eevee/eevee.c
@@ -352,6 +352,7 @@ static void EEVEE_cache_init(void *vedata)
 
 		DRWShadingGroup *grp = DRW_shgroup_create(e_data.probe_spherical_harmonic_sh, psl->probe_sh_compute);
 		DRW_shgroup_uniform_int(grp, "probeSize", &stl->probes->shres, 1);
+		DRW_shgroup_uniform_float(grp, "lodBias", &stl->probes->lodfactor, 1);
 		DRW_shgroup_uniform_texture(grp, "probeHdr", txl->probe_rt, 0);
 
 		struct Batch *geom = DRW_cache_fullscreen_quad_get();
diff --git a/source/blender/draw/engines/eevee/eevee_probes.c b/source/blender/draw/engines/eevee/eevee_probes.c
index 809e175938e..a0e01ee1d80 100644
--- a/source/blender/draw/engines/eevee/eevee_probes.c
+++ b/source/blender/draw/engines/eevee/eevee_probes.c
@@ -208,7 +208,9 @@ void EEVEE_refresh_probe(EEVEE_Data *vedata)
 	DRW_framebuffer_texture_attach(fbl->probe_filter_fb, txl->probe_pool, 0, 0);
 
 	/* 4 - Compute spherical harmonics */
-	pinfo->shres = 64;
+	/* Tweaking parameters to balance perf. vs precision */
+	pinfo->shres = 16; /* Less texture fetches & reduce branches */
+	pinfo->lodfactor = 4.0f; /* Improve cache reuse */
 	DRW_framebuffer_bind(fbl->probe_sh_fb);
 	DRW_draw_pass(psl->probe_sh_compute);
 	DRW_framebuffer_read_data(0, 0, 9, 1, 3, 0, (float *)pinfo->shcoefs);
diff --git a/source/blender/draw/engines/eevee/shaders/probe_sh_frag.glsl b/source/blender/draw/engines/eevee/shaders/probe_sh_frag.glsl
index 068a5bbf8b2..d7dab0e085a 100644
--- a/source/blender/draw/engines/eevee/shaders/probe_sh_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/probe_sh_frag.glsl
@@ -1,6 +1,7 @@
 
 uniform samplerCube probeHdr;
 uniform int probeSize;
+uniform float lodBias;
 
 in vec3 worldPosition;
 
@@ -93,7 +94,7 @@ void main()
 					shcoef = 0.546274 * (cubevec.x * cubevec.x - cubevec.z * cubevec.z) * 1.0 / 4.0;
 				}
 
-				vec4 sample = textureCube(probeHdr, cubevec);
+				vec4 sample = textureCubeLod(probeHdr, cubevec, lodBias);
 				sh += sample.rgb * shcoef * weight;
 				weight_accum += weight;
 			}




More information about the Bf-blender-cvs mailing list