[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23794] trunk/blender: Deep Shadow Buffer

Brecht Van Lommel brecht at blender.org
Mon Oct 12 21:41:42 CEST 2009


Revision: 23794
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23794
Author:   blendix
Date:     2009-10-12 21:41:40 +0200 (Mon, 12 Oct 2009)

Log Message:
-----------
Deep Shadow Buffer

Since the deep shadow buffer summer of code project is not actively under
development anymore, I decided to build my own DSM implementation from
scratch, based on reusing as much existing shadow buffer code as possible.
It's not very advanced, but implements the basic algorithm. Just enough so
we can do shading tests with it, optimizations and other improvements can
be done later.

Supported:
* Classical shadow buffer options: filter, soft, bias, ..
* Multiple sample buffers, merged into one.
* Halfway trick to support lower bias.
* Compression with user defined threshold.
* Non-textured alpha transparency, using Casting Alpha value.
* Strand render.

Not Supported:
* Tiling disk cache, so can use a lot of memory.
* Per part rendering for lower memory usage during creation.
* Colored shadow.
* Textured color/alpha shadow.
* Mipmaps for faster filtering.
* Volume shadows.

Usage Hints:
* Use sample buffers + smaller size rather than large size.
* For example 512 size x 9 sample buffers instead of 2048 x 1.
* Compression threshold 0.05 works, but is on the conservative side.

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/buttons_data_lamp.py
    trunk/blender/source/blender/blenkernel/BKE_blender.h
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesdna/DNA_lamp_types.h
    trunk/blender/source/blender/makesrna/intern/rna_lamp.c
    trunk/blender/source/blender/makesrna/intern/rna_material.c
    trunk/blender/source/blender/render/intern/include/render_types.h
    trunk/blender/source/blender/render/intern/include/zbuf.h
    trunk/blender/source/blender/render/intern/source/convertblender.c
    trunk/blender/source/blender/render/intern/source/rendercore.c
    trunk/blender/source/blender/render/intern/source/shadbuf.c
    trunk/blender/source/blender/render/intern/source/shadeinput.c
    trunk/blender/source/blender/render/intern/source/strand.c
    trunk/blender/source/blender/render/intern/source/zbuf.c

Modified: trunk/blender/release/scripts/ui/buttons_data_lamp.py
===================================================================
--- trunk/blender/release/scripts/ui/buttons_data_lamp.py	2009-10-12 19:34:58 UTC (rev 23793)
+++ trunk/blender/release/scripts/ui/buttons_data_lamp.py	2009-10-12 19:41:40 UTC (rev 23794)
@@ -202,7 +202,7 @@
 			col.itemL(text="Buffer Type:")
 			col.row().itemR(lamp, "shadow_buffer_type", expand=True)
 
-			if lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY'):
+			if lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY', 'DEEP'):
 				split = layout.split()
 				
 				col = split.column()
@@ -218,6 +218,8 @@
 				sub = col.column(align=True)
 				sub.itemR(lamp, "shadow_buffer_size", text="Size")
 				sub.itemR(lamp, "shadow_buffer_samples", text="Samples")
+				if lamp.shadow_buffer_type == 'DEEP':
+					col.itemR(lamp, "compression_threshold")
 				
 			elif lamp.shadow_buffer_type == 'IRREGULAR':
 				layout.itemR(lamp, "shadow_buffer_bias", text="Bias")

Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h	2009-10-12 19:34:58 UTC (rev 23793)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h	2009-10-12 19:41:40 UTC (rev 23794)
@@ -43,7 +43,7 @@
 struct ReportList;
 
 #define BLENDER_VERSION			250
-#define BLENDER_SUBVERSION		5
+#define BLENDER_SUBVERSION		6
 
 #define BLENDER_MINVERSION		250
 #define BLENDER_MINSUBVERSION	0

Modified: trunk/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/object.c	2009-10-12 19:34:58 UTC (rev 23793)
+++ trunk/blender/source/blender/blenkernel/intern/object.c	2009-10-12 19:41:40 UTC (rev 23794)
@@ -772,6 +772,7 @@
 	la->samp= 3;
 	la->bias= 1.0f;
 	la->soft= 3.0f;
+	la->compressthresh= 0.05f;
 	la->ray_samp= la->ray_sampy= la->ray_sampz= 1; 
 	la->area_size=la->area_sizey=la->area_sizez= 1.0f; 
 	la->buffers= 1;

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2009-10-12 19:34:58 UTC (rev 23793)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2009-10-12 19:41:40 UTC (rev 23794)
@@ -9920,8 +9920,9 @@
 	}
 
 	/* put 2.50 compatibility code here until next subversion bump */
-	{
+	if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 6)) {
 		Object *ob;
+		Lamp *la;
 		
 		/* New variables for axis-angle rotations and/or quaternion rotations were added, and need proper initialisation */
 		for (ob= main->object.first; ob; ob= ob->id.next) {
@@ -9939,6 +9940,9 @@
 				}
 			}
 		}
+
+		for(la = main->lamp.first; la; la=la->id.next)
+			la->compressthresh= 0.05f;
 	}
 
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */

Modified: trunk/blender/source/blender/makesdna/DNA_lamp_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_lamp_types.h	2009-10-12 19:34:58 UTC (rev 23793)
+++ trunk/blender/source/blender/makesdna/DNA_lamp_types.h	2009-10-12 19:41:40 UTC (rev 23794)
@@ -63,7 +63,7 @@
 	short pad2;
 	
 	float clipsta, clipend, shadspotsize;
-	float bias, soft;
+	float bias, soft, compressthresh, pad5[3];
 	short bufsize, samp, buffers, filtertype;
 	char bufflag, buftype;
 	
@@ -167,6 +167,7 @@
 #define LA_SHADBUF_REGULAR		0
 #define LA_SHADBUF_IRREGULAR	1
 #define LA_SHADBUF_HALFWAY		2
+#define LA_SHADBUF_DEEP			3
 
 /* bufflag, auto clipping */
 #define LA_SHADBUF_AUTO_START	1

Modified: trunk/blender/source/blender/makesrna/intern/rna_lamp.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_lamp.c	2009-10-12 19:34:58 UTC (rev 23793)
+++ trunk/blender/source/blender/makesrna/intern/rna_lamp.c	2009-10-12 19:41:40 UTC (rev 23794)
@@ -570,6 +570,7 @@
 		{LA_SHADBUF_REGULAR	, "REGULAR", 0, "Classical", "Classic shadow buffer."},
 		{LA_SHADBUF_HALFWAY, "HALFWAY", 0, "Classic-Halfway", "Regular buffer, averaging the closest and 2nd closest Z value to reducing bias artifaces."},
 		{LA_SHADBUF_IRREGULAR, "IRREGULAR", 0, "Irregular", "Irregular buffer produces sharp shadow always, but it doesn't show up for raytracing."},
+		{LA_SHADBUF_DEEP, "DEEP", 0, "Deep", "Deep shadow buffer supports transparency and better filtering, at the cost of more memory usage and processing time."},
 		{0, NULL, 0, NULL, NULL}};
 
 	static EnumPropertyItem prop_shadbuffiltertype_items[] = {
@@ -690,6 +691,12 @@
 	RNA_def_property_boolean_sdna(prop, NULL, "bufflag", LA_SHADBUF_AUTO_END);
 	RNA_def_property_ui_text(prop, "Autoclip End", "Automatic calculation of clipping-end, based on visible vertices.");
 	RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
+
+	prop= RNA_def_property(srna, "compression_threshold", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "compressthresh");
+	RNA_def_property_range(prop, 0.0f, 1.0f);
+	RNA_def_property_ui_text(prop, "Compress", "Deep shadow map compression threshold.");
+	RNA_def_property_update(prop, 0, "rna_Lamp_update");
 }
 
 static void rna_def_sun_lamp(BlenderRNA *brna)

Modified: trunk/blender/source/blender/makesrna/intern/rna_material.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_material.c	2009-10-12 19:34:58 UTC (rev 23793)
+++ trunk/blender/source/blender/makesrna/intern/rna_material.c	2009-10-12 19:41:40 UTC (rev 23794)
@@ -1559,7 +1559,7 @@
 	prop= RNA_def_property(srna, "shadow_casting_alpha", PROP_FLOAT, PROP_FACTOR);
 	RNA_def_property_float_sdna(prop, NULL, "shad_alpha");
 	RNA_def_property_range(prop, 0.001, 1);
-	RNA_def_property_ui_text(prop, "Shadow Casting Alpha", "Shadow casting alpha, only in use for Irregular Shadowbuffer.");
+	RNA_def_property_ui_text(prop, "Shadow Casting Alpha", "Shadow casting alpha, in use for Irregular and Deep shadow buffer.");
 	RNA_def_property_update(prop, 0, "rna_Material_update");
 
 	prop= RNA_def_property(srna, "light_group", PROP_POINTER, PROP_NONE);

Modified: trunk/blender/source/blender/render/intern/include/render_types.h
===================================================================
--- trunk/blender/source/blender/render/intern/include/render_types.h	2009-10-12 19:34:58 UTC (rev 23793)
+++ trunk/blender/source/blender/render/intern/include/render_types.h	2009-10-12 19:41:40 UTC (rev 23794)
@@ -245,10 +245,17 @@
 
 struct ISBData;
 
+typedef struct DeepSample {
+	int z;
+	float v;
+} DeepSample;
+ 
 typedef struct ShadSampleBuf {
 	struct ShadSampleBuf *next, *prev;
 	intptr_t *zbuf;
 	char *cbuf;
+	DeepSample **deepbuf;
+	int *totbuf;
 } ShadSampleBuf;
 
 typedef struct ShadBuf {
@@ -258,7 +265,7 @@
 	float viewmat[4][4];
 	float winmat[4][4];
 	float *jit, *weight;
-	float d, clipend, pixsize, soft;
+	float d, clipend, pixsize, soft, compressthresh;
 	int co[3];
 	int size, bias;
 	ListBase buffers;
@@ -527,6 +534,8 @@
 	float clipend;
 	/** A small depth offset to prevent self-shadowing. */
 	float bias;
+	/* Compression threshold for deep shadow maps */
+	float compressthresh;
 	
 	short ray_samp, ray_sampy, ray_sampz, ray_samp_method, ray_samp_type, area_shape, ray_totsamp;
 	short xold[BLENDER_MAX_THREADS], yold[BLENDER_MAX_THREADS];	/* last jitter table for area lights */

Modified: trunk/blender/source/blender/render/intern/include/zbuf.h
===================================================================
--- trunk/blender/source/blender/render/intern/include/zbuf.h	2009-10-12 19:34:58 UTC (rev 23793)
+++ trunk/blender/source/blender/render/intern/include/zbuf.h	2009-10-12 19:41:40 UTC (rev 23794)
@@ -37,6 +37,7 @@
 struct ListBase;
 struct ZSpan;
 struct APixstrand;
+struct APixstr;
 struct StrandShadeCache;
 
 void fillrect(int *rect, int x, int y, int val);
@@ -50,11 +51,12 @@
 int testclip(float *v); 
 
 void zbuffer_shadow(struct Render *re, float winmat[][4], struct LampRen *lar, int *rectz, int size, float jitx, float jity);
+void zbuffer_abuf_shadow(struct Render *re, struct LampRen *lar, float winmat[][4], struct APixstr *APixbuf, struct APixstrand *apixbuf, struct ListBase *apsmbase, int size, int samples, float (*jit)[2]);
 void zbuffer_solid(struct RenderPart *pa, struct RenderLayer *rl, void (*fillfunc)(struct RenderPart*, struct ZSpan*, int, void*), void *data);
 
 unsigned short *zbuffer_transp_shade(struct RenderPart *pa, struct RenderLayer *rl, float *pass, struct ListBase *psmlist);
 void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(void*, int, int, int, int, int));
-int zbuffer_strands_abuf(struct Render *re, struct RenderPart *pa, struct RenderLayer *rl, struct APixstrand *apixbuf, struct ListBase *apsmbase, struct StrandShadeCache *cache);
+int zbuffer_strands_abuf(struct Render *re, struct RenderPart *pa, struct APixstrand *apixbuf, struct ListBase *apsmbase, unsigned int lay, int negzmask, float winmat[][4], int winx, int winy, int sample, float (*jit)[2], float clipcrop, int shadow, struct StrandShadeCache *cache);
 
 typedef struct APixstr {
     unsigned short mask[4];		/* jitter mask */
@@ -118,6 +120,7 @@
 /* exported to shadbuf.c */
 void zbufclip4(struct ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3, float *f4, int c1, int c2, int c3, int c4);
 void zbuf_free_span(struct ZSpan *zspan);
+void freepsA(struct ListBase *lb);
 
 /* to rendercore.c */
 void zspan_scanconvert(struct ZSpan *zpan, void *handle, float *v1, float *v2, float *v3, void (*func)(void *, int, int, float, float) );
@@ -128,7 +131,7 @@
 void zbufclipwire(struct ZSpan *zspan, int obi, int zvlnr, int ec, float *ho1, float *ho2, float *ho3, float *ho4, int c1, int c2, int c3, int c4);
 
 /* exported to shadeinput.c */
-void zbuf_make_winmat(Render *re, float duplimat[][4], float winmat[][4]);
+void zbuf_make_winmat(Render *re, float winmat[][4]);
 void zbuf_render_project(float winmat[][4], float *co, float *ho);
 
 #endif

Modified: trunk/blender/source/blender/render/intern/source/convertblender.c
===================================================================

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list