[Bf-blender-cvs] [46cd87f5da6] blender2.8: Eevee: LTC area lights

Clément Foucault noreply at git.blender.org
Mon Apr 3 22:31:07 CEST 2017


Commit: 46cd87f5da6338577581055c6b0f453e29c7bc49
Author: Clément Foucault
Date:   Mon Apr 3 11:04:42 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB46cd87f5da6338577581055c6b0f453e29c7bc49

Eevee: LTC area lights

Using Linear Transform Cosines to compute area lighting. This is far more accurate than other techniques but also slower.

We use rotating quad to mimic sphere area light. For a better approximation, we use a rotating octogon.

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/eevee/eevee.c
M	source/blender/draw/engines/eevee/eevee_lights.c
A	source/blender/draw/engines/eevee/eevee_lut.h
M	source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
M	source/blender/draw/engines/eevee/shaders/bsdf_direct_lib.glsl
M	source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
A	source/blender/draw/engines/eevee/shaders/ltc_lib.glsl
M	source/blender/draw/intern/draw_manager.c
M	source/blender/gpu/GPU_texture.h
M	source/blender/gpu/intern/gpu_texture.c

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 04f25ab1fad..cf94fccd4e3 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -105,6 +105,7 @@ data_to_c_simple(engines/eevee/shaders/lit_surface_vert.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/tonemap_frag.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/bsdf_direct_lib.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/bsdf_common_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/ltc_lib.glsl SRC)
 
 data_to_c_simple(modes/shaders/common_globals_lib.glsl SRC)
 data_to_c_simple(modes/shaders/edit_overlay_frag.glsl SRC)
diff --git a/source/blender/draw/engines/eevee/eevee.c b/source/blender/draw/engines/eevee/eevee.c
index d40ce0baa38..7ce7a4df606 100644
--- a/source/blender/draw/engines/eevee/eevee.c
+++ b/source/blender/draw/engines/eevee/eevee.c
@@ -29,6 +29,7 @@
 
 #include "eevee.h"
 #include "eevee_private.h"
+#include "eevee_lut.h"
 
 #define EEVEE_ENGINE "BLENDER_EEVEE"
 
@@ -37,9 +38,12 @@ static struct {
 	struct GPUShader *default_lit;
 	struct GPUShader *depth_sh;
 	struct GPUShader *tonemap;
+	struct GPUTexture *ltc_mat;
+	struct GPUTexture *ltc_mag;
 	float camera_pos[3];
 } e_data = {NULL}; /* Engine data */
 
+extern char datatoc_ltc_lib_glsl[];
 extern char datatoc_bsdf_common_lib_glsl[];
 extern char datatoc_bsdf_direct_lib_glsl[];
 extern char datatoc_lit_surface_frag_glsl[];
@@ -70,6 +74,7 @@ static void EEVEE_engine_init(void *vedata)
 
 		DynStr *ds_vert = BLI_dynstr_new();
 		BLI_dynstr_append(ds_vert, datatoc_bsdf_common_lib_glsl);
+		BLI_dynstr_append(ds_vert, datatoc_ltc_lib_glsl);
 		BLI_dynstr_append(ds_vert, datatoc_bsdf_direct_lib_glsl);
 		lib_str = BLI_dynstr_get_cstring(ds_vert);
 		BLI_dynstr_free(ds_vert);
@@ -83,6 +88,14 @@ static void EEVEE_engine_init(void *vedata)
 		e_data.tonemap = DRW_shader_create_fullscreen(datatoc_tonemap_frag_glsl, NULL);
 	}
 
+	if (!e_data.ltc_mat) {
+		e_data.ltc_mat = DRW_texture_create_2D(64, 64, DRW_TEX_RGBA_16, DRW_TEX_FILTER, ltc_mat_ggx);
+	}
+
+	if (!e_data.ltc_mag) {
+		e_data.ltc_mag = DRW_texture_create_2D(64, 64, DRW_TEX_R_16, DRW_TEX_FILTER, ltc_mag_ggx);
+	}
+
 	if (stl->lights_info == NULL)
 		EEVEE_lights_init(stl);
 
@@ -134,6 +147,8 @@ static void EEVEE_cache_init(void *vedata)
 		DRW_shgroup_uniform_block(stl->g_data->default_lit_grp, "light_block", stl->lights_ubo, 0);
 		DRW_shgroup_uniform_int(stl->g_data->default_lit_grp, "light_count", &stl->lights_info->light_count, 1);
 		DRW_shgroup_uniform_vec3(stl->g_data->default_lit_grp, "cameraPos", e_data.camera_pos, 1);
+		DRW_shgroup_uniform_texture(stl->g_data->default_lit_grp, "ltcMat", e_data.ltc_mat, 0);
+		DRW_shgroup_uniform_texture(stl->g_data->default_lit_grp, "ltcMag", e_data.ltc_mag, 1);
 	}
 
 	{
@@ -220,6 +235,10 @@ static void EEVEE_engine_free(void)
 		DRW_shader_free(e_data.default_lit);
 	if (e_data.tonemap)
 		DRW_shader_free(e_data.tonemap);
+	if (e_data.ltc_mat)
+		DRW_texture_free(e_data.ltc_mat);
+	if (e_data.ltc_mag)
+		DRW_texture_free(e_data.ltc_mag);
 }
 
 static void EEVEE_collection_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
diff --git a/source/blender/draw/engines/eevee/eevee_lights.c b/source/blender/draw/engines/eevee/eevee_lights.c
index 9d2523ada6b..6a6947bdc3f 100644
--- a/source/blender/draw/engines/eevee/eevee_lights.c
+++ b/source/blender/draw/engines/eevee/eevee_lights.c
@@ -133,17 +133,17 @@ void EEVEE_lights_update(EEVEE_StorageList *stl)
 			}
 		}
 		else {
-			evli->sizex = MAX2(0.0001f, la->area_size);
+			evli->sizex = MAX2(0.001f, la->area_size);
 		}
 
 		/* Make illumination power constant */
 		if (la->type == LA_AREA) {
 			power = 1.0f / (evli->sizex * evli->sizey * 4.0f * M_PI) /* 1/(w*h*Pi) */
-			        * M_PI * 10.0f; /* XXX : Empirical, Fit cycles power */
+			        * 80.0f; /* XXX : Empirical, Fit cycles power */
 		}
 		else if (la->type == LA_SPOT || la->type == LA_LOCAL) {
 			power = 1.0f / (4.0f * evli->sizex * evli->sizex * M_PI * M_PI) /* 1/(4*r²*Pi²) */
-			        * M_PI * 100.0; /* XXX : Empirical, Fit cycles power */
+			        * M_PI * M_PI * M_PI * 10.0; /* XXX : Empirical, Fit cycles power */
 
 			/* for point lights (a.k.a radius == 0.0) */
 			// power = M_PI * M_PI * 0.78; /* XXX : Empirical, Fit cycles power */
diff --git a/source/blender/draw/engines/eevee/eevee_lut.h b/source/blender/draw/engines/eevee/eevee_lut.h
new file mode 100644
index 00000000000..3181a907466
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_lut.h
@@ -0,0 +1,38 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Clement Foucault.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file GPU_ltc.h
+ *  \ingroup gpu
+ */
+
+#ifndef __EEVEE_LUT_H__
+#define __EEVEE_LUT_H__
+
+static float ltc_mat_ggx[64*64*4] = {0.000200, -0.000000, 1.000000, -0.000000, 0.000504, -0.000000, 1.000000, -0.000000, 0.002016, -0.000000, 1.000000, -0.000000, 0.004535, -0.000000, 1.000000, -0.000000, 0.008063, -0.000000, 1.000000, -0.000000, 0.012598, -0.000000, 1.000000, -0.000000, 0.018141, -0.000000, 1.000000, -0.000000, 0.024692, -0.000000, 1.000000, -0.000000, 0.032252, -0.000000, 1.000000, -0.000000, 0.040821, -0.000000, 1.000000, -0.000000, 0.050400, -0.000000, 1.000000, -0.0 [...]

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list