[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27520] branches/render25: Render Branch: indirect light shading / bump.

Brecht Van Lommel brecht at blender.org
Mon Mar 15 21:02:47 CET 2010


Revision: 27520
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27520
Author:   blendix
Date:     2010-03-15 21:02:47 +0100 (Mon, 15 Mar 2010)

Log Message:
-----------
Render Branch: indirect light shading / bump. The bump method settings
has been removed and replaced with a shading method setting. There are
three options:

* No Shading: no bump mapping and assuming lambert shader.
* Full Shading: execute BSDF for each ray and includes bump mapping. When
  combined with irradiance cache, will generally require many more samples
  for bumped surfaces and execute textures 2x.
* Shade Once: execute BSDF once using averaged ligth direction for each
  RGB channel. Bump mapping is also done after irradiance caching this way.
  Requires fewer samples in irradiance cache and only needs to do textures
  once. This is basically the trick from "An Approximate Global Illumination
  System for Computer Generated Films" used by Dreamworks.

Decided to use averaged light direction instead of spherical harmonics,
uses less memory and these can be used with BSDF's. This trick is not really
accurate but seems believable enough for e.g. Minnaert and Oren-Nayar shaders,
though for example with Toon it fails to give similar results.

This commit also fixes AO falloff strength not being taken into account.

Modified Paths:
--------------
    branches/render25/release/scripts/ui/properties_world.py
    branches/render25/source/blender/blenkernel/intern/world.c
    branches/render25/source/blender/makesdna/DNA_world_types.h
    branches/render25/source/blender/makesrna/intern/rna_world.c
    branches/render25/source/blender/render/intern/include/material.h
    branches/render25/source/blender/render/intern/include/raytrace.h
    branches/render25/source/blender/render/intern/source/cache.c
    branches/render25/source/blender/render/intern/source/diskocclusion.c
    branches/render25/source/blender/render/intern/source/rayshade.c
    branches/render25/source/blender/render/intern/source/shadeoutput.c

Modified: branches/render25/release/scripts/ui/properties_world.py
===================================================================
--- branches/render25/release/scripts/ui/properties_world.py	2010-03-15 18:52:22 UTC (rev 27519)
+++ branches/render25/release/scripts/ui/properties_world.py	2010-03-15 20:02:47 UTC (rev 27520)
@@ -261,7 +261,8 @@
         col = split.column()
 
         col.prop(light, "use_cache")
-        col.prop(light, "bump_method")
+        if light.gather_method == 'RAYTRACE':
+            col.prop(light, "shading_method", text="")
 
         if light.gather_method == 'RAYTRACE':
             col.label(text="Attenuation:")

Modified: branches/render25/source/blender/blenkernel/intern/world.c
===================================================================
--- branches/render25/source/blender/blenkernel/intern/world.c	2010-03-15 18:52:22 UTC (rev 27519)
+++ branches/render25/source/blender/blenkernel/intern/world.c	2010-03-15 20:02:47 UTC (rev 27520)
@@ -108,6 +108,7 @@
 	wrld->aobias= 0.05f;
 	wrld->ao_samp_method = WO_LIGHT_SAMP_HAMMERSLEY;	
 	wrld->ao_approx_error= 0.25f;
+	wrld->ao_shading_method = WO_LIGHT_SHADE_ONCE;	
 	
 	wrld->preview = NULL;
 

Modified: branches/render25/source/blender/makesdna/DNA_world_types.h
===================================================================
--- branches/render25/source/blender/makesdna/DNA_world_types.h	2010-03-15 18:52:22 UTC (rev 27519)
+++ branches/render25/source/blender/makesdna/DNA_world_types.h	2010-03-15 20:02:47 UTC (rev 27520)
@@ -103,7 +103,7 @@
 	float ao_adapt_thresh, ao_adapt_speed_fac;
 	float ao_approx_error, ao_approx_correction;
 	float ao_indirect_energy, ao_env_energy, ao_pad2;
-	short ao_indirect_bounces, ao_bump_method;
+	short ao_indirect_bounces, ao_shading_method;
 	short ao_samp_method, ao_gather_method, ao_approx_passes;
 	
 	/* assorted settings (in the middle of ambient occlusion settings for padding reasons) */
@@ -168,10 +168,10 @@
 #define WO_LIGHT_GATHER_RAYTRACE	0
 #define WO_LIGHT_GATHER_APPROX		1
 
-/* ao_bump_method */
-#define WO_LIGHT_BUMP_NONE		0
-#define WO_LIGHT_BUMP_APPROX	1
-#define WO_LIGHT_BUMP_FULL		2
+/* ao_shading_method */
+#define WO_LIGHT_SHADE_NONE		0
+#define WO_LIGHT_SHADE_ONCE		1
+#define WO_LIGHT_SHADE_FULL		2
 
 /* texco (also in DNA_material_types.h) */
 #define TEXCO_ANGMAP	64

Modified: branches/render25/source/blender/makesrna/intern/rna_world.c
===================================================================
--- branches/render25/source/blender/makesrna/intern/rna_world.c	2010-03-15 18:52:22 UTC (rev 27519)
+++ branches/render25/source/blender/makesrna/intern/rna_world.c	2010-03-15 20:02:47 UTC (rev 27520)
@@ -208,10 +208,10 @@
 		{WO_LIGHT_GATHER_APPROX, "APPROXIMATE", 0, "Approximate", "Inaccurate, but faster and without noise"},
 		{0, NULL, 0, NULL, NULL}};
 
-	static EnumPropertyItem prop_bump_method_items[] = {
-		{WO_LIGHT_BUMP_NONE, "NONE", 0, "None", "Do not use bump mapping for world lighting."},
-		//{WO_LIGHT_BUMP_APPROX, "APPROXIMATE", 0, "Approximate", "Approximate bump mapping to keep cache samples low"},
-		{WO_LIGHT_BUMP_FULL, "FULL", 0, "Full", "Use full bump mapping, can lead to many more cache samples"},
+	static EnumPropertyItem prop_shading_method_items[] = {
+		{WO_LIGHT_SHADE_NONE, "NONE", 0, "No Shading", "Do not use bump mapping for world lighting"},
+		{WO_LIGHT_SHADE_ONCE, "ONCE", 0, "Shade Once", "Shade once using the averaged incoming light direction, only approximately correct"},
+		{WO_LIGHT_SHADE_FULL, "FULL", 0, "Full Shading", "Use full shade, more accurate but slower and can lead to many more cache samples"},
 		{0, NULL, 0, NULL, NULL}};
 
 	srna= RNA_def_struct(brna, "WorldLighting", NULL);
@@ -282,10 +282,10 @@
 	RNA_def_property_ui_text(prop, "Gather Method", "");
 	RNA_def_property_update(prop, 0, "rna_World_update");
 
-	prop= RNA_def_property(srna, "bump_method", PROP_ENUM, PROP_NONE);
-	RNA_def_property_enum_sdna(prop, NULL, "ao_bump_method");
-	RNA_def_property_enum_items(prop, prop_bump_method_items);
-	RNA_def_property_ui_text(prop, "Bump Method", "Method to use for bump mapping");
+	prop= RNA_def_property(srna, "shading_method", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "ao_shading_method");
+	RNA_def_property_enum_items(prop, prop_shading_method_items);
+	RNA_def_property_ui_text(prop, "Shading Method", "Method to use for shading");
 	RNA_def_property_update(prop, 0, "rna_World_update");
 
 	prop= RNA_def_property(srna, "passes", PROP_INT, PROP_NONE);

Modified: branches/render25/source/blender/render/intern/include/material.h
===================================================================
--- branches/render25/source/blender/render/intern/include/material.h	2010-03-15 18:52:22 UTC (rev 27519)
+++ branches/render25/source/blender/render/intern/include/material.h	2010-03-15 20:02:47 UTC (rev 27520)
@@ -75,7 +75,8 @@
 
 void mat_emit(float emit[3], struct ShadeMaterial *mat, struct ShadeGeometry *geom, int thread);
 
-/* Displacement in camere space coordinates at current location */
+/* Displacement in camere space coordinates at current location,
+   this can be called outside of mat_shading_begin/end */
 
 void mat_displacement(struct Render *re, struct ShadeInput *shi, float displacement[3]);
 

Modified: branches/render25/source/blender/render/intern/include/raytrace.h
===================================================================
--- branches/render25/source/blender/render/intern/include/raytrace.h	2010-03-15 18:52:22 UTC (rev 27519)
+++ branches/render25/source/blender/render/intern/include/raytrace.h	2010-03-15 20:02:47 UTC (rev 27520)
@@ -30,7 +30,15 @@
 	struct ShadeResult *shr);
 
 void ray_ao_env_indirect(struct Render *re, struct ShadeInput *shi,
-	float *ao, float *env, float *indirect, float *Rmean, int use_bent_normal);
+	float *ao, float env[3], float indirect[3],
+	float dir_ao[3], float dir_env[3][3], float dir_indirect[3][3],
+	float *Rmean, int for_cache);
 
+/* Irradiance Cache Helper */
+
+void ray_cache_post_apply(struct Render *re, struct ShadeInput *shi,
+	float *ao, float env[3], float indirect[3],
+	float dir_ao[3], float dir_env[3][3], float dir_indirect[3][3]);
+
 #endif /* __RENDER_RAYTRACE_H__ */
 

Modified: branches/render25/source/blender/render/intern/source/cache.c
===================================================================
--- branches/render25/source/blender/render/intern/source/cache.c	2010-03-15 18:52:22 UTC (rev 27519)
+++ branches/render25/source/blender/render/intern/source/cache.c	2010-03-15 20:02:47 UTC (rev 27520)
@@ -40,6 +40,7 @@
 
 #include "cache.h"
 #include "diskocclusion.h"
+#include "material.h"
 #include "object_strand.h"
 #include "part.h"
 #include "raytrace.h"
@@ -401,7 +402,7 @@
 #define MAX_ERROR_K				1.0f
 #define WEIGHT_NORMAL_DENOM		65.823047821929777f		/* 1/(1 - cos(10°)) */
 #define SINGULAR_VALUE_EPSILON	1e-4f
-#define MAX_CACHE_DIMENSION		((3+3+1)*9)
+#define MAX_CACHE_DIMENSION		((3+3+1)*4)
 
 /* Data Structures */
 
@@ -444,7 +445,7 @@
 	int lsq_reconstruction;
 	int locked;
 	int dimension;
-	int use_SH;
+	int use_light_dir;
 
 	/* test: a stable global coordinate system may help */
 };
@@ -540,10 +541,8 @@
 	if(re->db.wrld.mode & WO_INDIRECT_LIGHT)
 		cache->dimension += 3;
 
-	if(re->db.wrld.ao_bump_method == WO_LIGHT_BUMP_APPROX) {
-		cache->use_SH= 1;
-		cache->dimension *= 9;
-	}
+	if(re->db.wrld.ao_shading_method == WO_LIGHT_SHADE_ONCE)
+		cache->dimension *= 4;
 
 	return cache;
 }
@@ -586,77 +585,81 @@
 	return (float*)((char*)sample + sizeof(IrrCacheSample));
 }
 
-static void irr_sample_set(IrrCacheSample *sample, int use_SH, float *ao, float *env, float *indirect)
+static void irr_sample_set(Render *re, IrrCacheSample *sample, float *ao, float env[3], float indirect[3], float ldir_ao[3], float ldir_env[3][3], float ldir_indirect[3][3])
 {
 	float *C= irr_sample_C(sample);
-	int offset= 0;
+	int method= re->db.wrld.ao_shading_method;
 
-	if(!use_SH) {
-		/* copy regular values */
-		if(ao)
-			C[offset++]= *ao;
-		if(env) {
-			C[offset++]= env[0];
-			C[offset++]= env[1];
-			C[offset++]= env[2];
+	/* pack colors and light directions into a single array */
+
+	if(ao) {
+		*C= *ao;
+		C++;
+
+		if(method == WO_LIGHT_SHADE_ONCE) {
+			copy_v3_v3(C, ldir_ao);
+			C += 3;
 		}
-		if(indirect) {
-			C[offset++]= indirect[0];
-			C[offset++]= indirect[1];
-			C[offset++]= indirect[2];
+	}
+
+	if(env) {
+		copy_v3_v3(C, env);
+		C += 3;
+
+		if(method == WO_LIGHT_SHADE_ONCE) {
+			memcpy(C, ldir_env, sizeof(float)*3*3);
+			C += 3*3;
 		}
 	}
-	else {
-		/* copy spherical harmonics */
-		if(ao)
-			copy_sh_sh(&C[9*offset++], ao);
-		if(env) {
-			copy_sh_sh(&C[9*offset++], env);
-			copy_sh_sh(&C[9*offset++], env+9);
-			copy_sh_sh(&C[9*offset++], env+18);
+
+	if(indirect) {
+		copy_v3_v3(C, indirect);
+		C += 3;
+
+		if(method == WO_LIGHT_SHADE_ONCE) {
+			memcpy(C, ldir_indirect, sizeof(float)*3*3);
+			C += 3*3;
 		}
-		if(indirect) {
-			copy_sh_sh(&C[9*offset++], indirect);
-			copy_sh_sh(&C[9*offset++], indirect+9);
-			copy_sh_sh(&C[9*offset++], indirect+18);
-		}
 	}
 }
 
-static void irr_sample_get(float *C, int use_SH, float N[3], float *ao, float env[3], float indirect[3])
+static void irr_sample_eval(Render *re, ShadeInput *shi, float *C, float *ao, float env[3], float indirect[3])
 {
-	int offset= 0;
+	float *dir_ao= NULL, (*dir_env)[3]= NULL, (*dir_indirect)[3]= NULL;
+	int method= re->db.wrld.ao_shading_method;
 
-	if(!use_SH) {
-		/* simple copy from C array to ao/env/indirect */
-		if(ao)
-			*ao= C[offset++];
-		if(env) {
-			env[0]= C[offset++];
-			env[1]= C[offset++];
-			env[2]= C[offset++];
+	if(ao) {
+		*ao= *C;
+		C++;
+
+		if(method == WO_LIGHT_SHADE_ONCE) {
+			dir_ao= C;
+			C += 3;
 		}
-		if(indirect) {
-			indirect[0]= C[offset++];
-			indirect[1]= C[offset++];
-			indirect[2]= C[offset++];
+	}
+
+	if(env) {
+		copy_v3_v3(env, C);
+		C += 3;
+
+		if(method == WO_LIGHT_SHADE_ONCE) {
+			dir_env = (float(*)[3])C;
+			C += 3*3;
 		}
 	}
-	else {
-		/* evaluate spherical harmonics using normal */
-		if(ao)
-			*ao= eval_shv3(&C[9*offset++], N);
-		if(env) {
-			env[0]= eval_shv3(&C[9*offset++], N);
-			env[1]= eval_shv3(&C[9*offset++], N);
-			env[2]= eval_shv3(&C[9*offset++], N);
+
+	if(indirect) {
+		copy_v3_v3(indirect, C);
+		C += 3;
+
+		if(method == WO_LIGHT_SHADE_ONCE) {
+			dir_indirect = (float(*)[3])C;
+			C += 3*3;
 		}
-		if(indirect) {
-			indirect[0]= eval_shv3(&C[9*offset++], N);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list