[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26611] branches/render25: Render Branch: stupid path tracer I'm using for consistency testing,

Brecht Van Lommel brecht at blender.org
Thu Feb 4 21:48:37 CET 2010


Revision: 26611
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26611
Author:   blendix
Date:     2010-02-04 21:48:35 +0100 (Thu, 04 Feb 2010)

Log Message:
-----------
Render Branch: stupid path tracer I'm using for consistency testing,
only does environment lighting + diffuse at the moment, don't expect
this to make it into trunk.

Modified Paths:
--------------
    branches/render25/release/scripts/ui/properties_render.py
    branches/render25/source/blender/makesdna/DNA_scene_types.h
    branches/render25/source/blender/makesrna/intern/rna_scene.c
    branches/render25/source/blender/render/intern/include/rendercore.h
    branches/render25/source/blender/render/intern/source/pipeline.c

Added Paths:
-----------
    branches/render25/source/blender/render/intern/source/path.c

Modified: branches/render25/release/scripts/ui/properties_render.py
===================================================================
--- branches/render25/release/scripts/ui/properties_render.py	2010-02-04 20:41:49 UTC (rev 26610)
+++ branches/render25/release/scripts/ui/properties_render.py	2010-02-04 20:48:35 UTC (rev 26611)
@@ -60,7 +60,10 @@
         col.operator("screen.render", text="Animation", icon='RENDER_ANIMATION').animation = True
 
         layout.prop(rd, "display_mode", text="Display")
+        layout.prop(rd, "integrator")
 
+        if rd.integrator == 'PATH_TRACER':
+            layout.prop(rd, "path_samples")
 
 class RENDER_PT_layers(RenderButtonsPanel):
     bl_label = "Layers"

Modified: branches/render25/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/render25/source/blender/makesdna/DNA_scene_types.h	2010-02-04 20:41:49 UTC (rev 26610)
+++ branches/render25/source/blender/makesdna/DNA_scene_types.h	2010-02-04 20:48:35 UTC (rev 26611)
@@ -379,6 +379,10 @@
 	float pad2;			//  XXX deprecated since 2.5
 	struct Text *dometext;	//  XXX deprecated since 2.5
 
+	/* path tracing */
+	int integrator;
+	int path_samples;
+
 	/* render engine */
 	char engine[32];
 } RenderData;
@@ -966,6 +970,10 @@
 #define R_BAKE_SPACE_OBJECT	 2
 #define R_BAKE_SPACE_TANGENT 3
 
+/* r->integrator */
+#define R_INTEGRATOR_RASTERIZER	0
+#define R_INTEGRATOR_PATHTRACER	1
+
 /* **************** SCENE ********************* */
 
 /* for general use */

Modified: branches/render25/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- branches/render25/source/blender/makesrna/intern/rna_scene.c	2010-02-04 20:41:49 UTC (rev 26610)
+++ branches/render25/source/blender/makesrna/intern/rna_scene.c	2010-02-04 20:48:35 UTC (rev 26611)
@@ -1753,6 +1753,11 @@
 		{0, "BLENDER_RENDER", 0, "Blender Render", ""},
 		{0, NULL, 0, NULL, NULL}};
 
+	static EnumPropertyItem integrator_items[] = {
+		{R_INTEGRATOR_RASTERIZER, "RASTERIZER", 0, "Rasterizer", ""},
+		{R_INTEGRATOR_PATHTRACER, "PATH_TRACER", 0, "Path Tracer", ""},
+		{0, NULL, 0, NULL, NULL}};
+
 	srna= RNA_def_struct(brna, "SceneRenderData", NULL);
 	RNA_def_struct_sdna(srna, "RenderData");
 	RNA_def_struct_nested(brna, srna, "Scene");
@@ -2442,6 +2447,17 @@
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Use Game Engine", "Current rendering engine is a game engine.");
 
+	/* path */
+	prop= RNA_def_property(srna, "integrator", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_items(prop, integrator_items);
+	RNA_def_property_ui_text(prop, "Integrator", "Integrator to use for rendering.");
+	RNA_def_property_update(prop, NC_WINDOW, NULL);
+
+	prop= RNA_def_property(srna, "path_samples", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_range(prop, 1, INT_MAX);
+	RNA_def_property_ui_text(prop, "Path Samples", "Number of samples to use for path tracer.");
+	RNA_def_property_update(prop, NC_WINDOW, NULL);
+
 	/* simplify */
 	prop= RNA_def_property(srna, "use_simplify", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mode", R_SIMPLIFY);

Modified: branches/render25/source/blender/render/intern/include/rendercore.h
===================================================================
--- branches/render25/source/blender/render/intern/include/rendercore.h	2010-02-04 20:41:49 UTC (rev 26610)
+++ branches/render25/source/blender/render/intern/include/rendercore.h	2010-02-04 20:48:35 UTC (rev 26611)
@@ -37,6 +37,7 @@
 
 void render_rasterize_part(struct Render *re, struct RenderPart *pa);
 void render_sss_bake_part(struct Render *re, struct RenderPart *pa);
+void render_path_trace_part(struct Render *re, struct RenderPart *pa);
 
 /* Rasterization Per Pixel Structs */
 

Added: branches/render25/source/blender/render/intern/source/path.c
===================================================================
--- branches/render25/source/blender/render/intern/source/path.c	                        (rev 0)
+++ branches/render25/source/blender/render/intern/source/path.c	2010-02-04 20:48:35 UTC (rev 26611)
@@ -0,0 +1,259 @@
+/*
+ * $Id$
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * Contributor(s): Blender Foundation.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "DNA_material_types.h"
+
+#include "BKE_utildefines.h"
+
+#include "BLI_math.h"
+#include "BLI_rand.h"
+
+#include "RE_raytrace.h"
+
+#include "camera.h"
+#include "database.h"
+#include "environment.h"
+#include "material.h"
+#include "object_mesh.h"
+#include "part.h"
+#include "render_types.h"
+#include "rendercore.h"
+#include "sampler.h"
+#include "shading.h"
+
+typedef struct Hit {
+	ObjectInstanceRen *obi;
+	VlakRen *vlr;
+	float co[3];
+	float vec[3];
+	float n[3];
+	float u, v;
+} Hit;
+
+static void shadeinput_from_hit(Render *re, RenderLayer *rl, ShadeInput *shi, Hit *hit, float view[3])
+{
+	memset(shi, 0, sizeof(ShadeInput));
+
+	copy_v3_v3(shi->geometry.view, view);
+	copy_v3_v3(shi->geometry.co, hit->co);
+
+	shi->material.mat_override= rl->mat_override;
+	shi->material.mat= hit->vlr->mat;
+	shade_input_init_material(re, shi);
+	shade_input_set_triangle_i(re, shi, hit->obi, hit->vlr, 0, 1, 2);
+
+	shi->geometry.u= hit->u;
+	shi->geometry.v= hit->v;
+	shi->geometry.dx_u= shi->geometry.dx_v= shi->geometry.dy_u= shi->geometry.dy_v= 0.0f;
+
+	/*shade_input_set_normals(shi);*/
+	shade_input_set_shade_texco(re, shi);
+	copy_v3_v3(shi->geometry.vn, hit->n);
+
+	if(dot_v3v3(shi->geometry.facenor, shi->geometry.view) > 0.0f)
+		shade_input_flip_normals(shi);
+}
+
+static int isec_trace_ray(Render *re, Hit *from, Hit *to, int depth)
+{
+	Isect isec;
+
+	memset(&isec, 0, sizeof(isec));
+
+	copy_v3_v3(isec.start, from->co);
+	mul_v3_v3fl(isec.vec, from->vec, 100.0f);
+	isec.labda= 1.0f;
+
+	isec.mode= RE_RAY_MIRROR;
+	isec.skip = RE_SKIP_VLR_NEIGHBOUR|RE_SKIP_VLR_RENDER_CHECK;
+
+	isec.orig.ob = from->obi;
+	isec.orig.face = from->vlr;
+
+	isec.lay= -1;
+
+	if(!RE_rayobject_raycast(re->db.raytree, &isec))
+		return 0;
+	
+	to->obi= isec.hit.ob;
+	to->vlr= isec.hit.face;
+	to->u= isec.u;
+	to->v= isec.v;
+
+	madd_v3_v3v3fl(to->co, isec.start, isec.vec, isec.labda);
+	copy_v3_v3(to->n, to->vlr->n);
+	mul_v3_fl(to->n, -1.0f);
+
+	return 1;
+}
+
+static void integrate_path(Render *re, RenderLayer *rl, int thread, Hit *from, float sample[3], int depth, float hemi[2])
+{
+	Hit to;
+	ShadeInput shi;
+	float bsdf[3], nsample[3], view[3], probability, basis[3][3], r[2];
+
+	if(isec_trace_ray(re, from, &to, depth)) {
+		copy_v3_v3(view, from->vec);
+		negate_v3(view);
+
+		shadeinput_from_hit(re, rl, &shi, &to, view);
+
+		mat_shading_begin(re, &shi, &shi.material);
+
+		/* generate new ray */
+		if(!hemi) {
+			r[0]= BLI_thread_frand(thread);
+			r[1]= BLI_thread_frand(thread);
+		}
+		else
+			copy_v2_v2(r, hemi);
+
+		sample_project_hemi_cosine_weighted(to.vec, r);
+
+		copy_v3_v3(basis[2], shi.geometry.vn);
+		ortho_basis_v3v3_v3(basis[0], basis[1], shi.geometry.vn);
+		mul_m3_v3(basis, to.vec);
+
+		/* sample emit & bsdf */
+		mat_emit(sample, &shi.material, &shi.geometry, shi.shading.thread);
+		mat_bsdf_f(bsdf, &shi.material, &shi.geometry, shi.shading.thread, to.vec, BSDF_DIFFUSE);
+
+		mat_shading_end(re, &shi.material);
+
+		if(!is_zero_v3(bsdf)) {
+			/* russian roulette */
+			//probability= (bsdf[0] + bsdf[1] + bsdf[2])/3.0f;
+			//probability= CLAMPIS(probability, 0.0f, 0.9f);
+			probability= (depth > 0)? 0.9f: 1.0f;
+
+			if(probability == 1.0f || BLI_thread_frand(thread) < probability) {
+				/* keep going */
+				integrate_path(re, rl, thread, &to, nsample, depth+1, NULL);
+
+				/* bsdf & correction for russian roulette */
+				nsample[0]= bsdf[0]*nsample[0];
+				nsample[1]= bsdf[1]*nsample[1];
+				nsample[2]= bsdf[2]*nsample[2];
+				mul_v3_fl(nsample, (float)M_PI/(probability*dot_v3v3(to.vec, shi.geometry.vn)));
+
+				/* accumulate */
+				add_v3_v3v3(sample, sample, nsample);
+			}
+			else
+				; /* path terminated */
+		}
+	}
+	else {
+		/* no hit, sample environment */
+		environment_shade(re, sample, NULL, from->vec, NULL, thread);
+	}
+}
+
+static void integrate_pixel(Render *re, RenderLayer *rl, int thread, int x, int y, float color[3])
+{
+	Hit from;
+	QMCSampler *qsa, *qsa2;
+	float accum[3], sample[3], raster[2], hemi[2];
+	int a, tot_samples = re->params.r.path_samples;
+
+	accum[0]= accum[1]= accum[2]= 0.0f;
+
+	qsa = sampler_acquire(re, thread, SAMP_TYPE_HAMMERSLEY, tot_samples);
+	qsa2 = sampler_acquire(re, thread, SAMP_TYPE_HAMMERSLEY, tot_samples);
+
+	for(a=0; a<tot_samples; a++) {
+		/* random raster location */
+		sampler_get_float_2d(raster, qsa, a);
+		raster[0] += x;
+		raster[1] += y;
+
+		/* raster to ray */
+		memset(&from, 0, sizeof(from));
+		camera_raster_to_ray(&re->cam, from.co, from.vec, raster[0], raster[1]);
+
+		/* integrate path */
+		sampler_get_float_2d(hemi, qsa2, a);
+		integrate_path(re, rl, thread, &from, sample, 0, hemi);
+
+		add_v3_v3v3(accum, accum, sample);
+	}
+
+	mul_v3_fl(accum, 1.0f/re->params.r.path_samples);
+	copy_v3_v3(color, accum);
+
+	sampler_release(re, qsa);
+	sampler_release(re, qsa2);
+}
+
+void render_path_trace_part(Render *re, RenderPart *pa)
+{
+	RenderResult *rr= pa->result;
+	RenderLayer *rl= rr->layers.first;
+	float sample[3], *fp;
+	int x, y, seed=0, offs=0, crop= 0;
+
+	if(re->cb.test_break(re->cb.tbh)) return; 
+	if(!re->db.raytree) return;
+
+	/* filtered render, for now we assume only 1 filter size */
+	if(pa->crop) {
+		crop= 1;
+		offs= pa->rectx + 1;
+	}
+	
+	/* initialize scanline updates for main thread,
+	   scanline updates have to be 2 lines behind for crop */
+	rr->renrect.ymin= 0;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list