[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15720] branches/soc-2007-joeedh/source/ blender/render/intern/source: forgot even more files, heh
Joseph Eagar
joeedh at gmail.com
Wed Jul 23 20:50:00 CEST 2008
Revision: 15720
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15720
Author: joeedh
Date: 2008-07-23 20:50:00 +0200 (Wed, 23 Jul 2008)
Log Message:
-----------
forgot even more files, heh
Added Paths:
-----------
branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_func.c
branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_soft.c
Added: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_func.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_func.c (rev 0)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_func.c 2008-07-23 18:50:00 UTC (rev 15720)
@@ -0,0 +1,574 @@
+/**
+ * $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.
+ *
+ * The Original Code is Copyright (C) 2007 by the Blender Foundation.
+ * All rights reserved. Copyright is specifically transferred to
+ * the blender foundation by Joseph Eagar.
+ *
+ * Contributors: Joseph Eagar
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <math.h>
+#include <float.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+
+#include "BLI_arithb.h"
+#include "MTC_matrixops.h"
+#include "BLI_blenlib.h"
+#include "BLI_threads.h"
+#include "BLI_jitter.h"
+#include "BLI_memarena.h"
+
+#include "BKE_tile.h"
+#include "BKE_dsm.h"
+#include "BKE_bucketbuffer.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
+
+#include "DNA_material_types.h"
+#include "DNA_object_types.h"
+#include "DNA_lamp_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_group_types.h"
+
+#include "RE_render_ext.h"
+#include "RE_shader_ext.h"
+
+#include "gammaCorrectionTables.h"
+#include "pixelblending.h"
+#include "render_types.h"
+#include "renderpipeline.h"
+#include "renderdatabase.h"
+#include "rendercore.h"
+#include "shadbuf.h"
+#include "shading.h"
+#include "sss.h"
+#include "zbuf.h"
+#include "qmc.h"
+#include "dsm.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BIF_space.h"
+#include "BIF_editview.h"
+
+#include "PIL_time.h"
+
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
+
+extern Render R;
+static TCS_TilePool *deepbuffer_pool = NULL;
+
+/*The Loop of Doom.
+ One loop to merge them all, One loop to find them;
+ One loop to compress them all, and in the darkness, bind them!*/
+#define COMPSTATE_PROCESSING 0
+#define COMPSTATE_PROCESSING2 1
+#define COMPSTATE_COMPRESSING 2
+#define COMPSTATE_DONE 3
+
+void DSM_MergeLayerListNew(DSMTile *tile, int x, int y, _ClrEntry *row, ListBase (*transfuncs)[3],
+ int totface, void *scratchmem1, void *scratchmem2, void *scratchmem3,
+ int scratchlen, float *weight, int samplewid, float error)
+{
+ DSMFunction *func[3];
+ DSMLayerSample *cursamp[3]={NULL, NULL, NULL}, *samp;
+ DSMLayerSample *sout[3] = {scratchmem1, scratchmem2, scratchmem3};
+ _ClrEntry *csamp, *lastcsamp[3]={NULL, NULL, NULL};
+ double slope[3]={0.0, 0.0, 0.0}, accum[3] = {1.0, 1.0, 1.0}, s1, s2;
+ double start[3], end[3], ostartpoint[3], oendpoint[3];
+ double startpoint[3] = {-1.0, -1.0, -1.0}, endpoint[3] = {-1.0, -1.0, -1.0}, err=error; // /2.0;
+ int i, ci, totfaces[3] = {0, 0, 0}, cursor[3]={0, 0, 0};
+ int state[3] = {COMPSTATE_PROCESSING, COMPSTATE_PROCESSING, COMPSTATE_PROCESSING};
+ int totface2[3] = {0, 0, 0}, count[3]={0, 0, 0};
+
+ /*first alloc, then assign, as internally the function
+ array may be reallocated to increase its size (thus invalidating
+ existing pointers).*/
+ for (i=0; i<3; i++) {
+ switch (i) {
+ case 0:
+ dsm_function_alloc(tile, &tile->r_rect[y*tile->sizex+x]);
+ break;
+ case 1:
+ dsm_function_alloc(tile, &tile->g_rect[y*tile->sizex+x]);
+ break;
+ case 2:
+ dsm_function_alloc(tile, &tile->b_rect[y*tile->sizex+x]);
+ break;
+ }
+ }
+
+ for (i=0; i<3; i++) {
+ switch (i) {
+ case 0:
+ func[i] = &tile->funcarray[tile->r_rect[y*tile->sizex+x]];
+ break;
+ case 1:
+ func[i] = &tile->funcarray[tile->g_rect[y*tile->sizex+x]];
+ break;
+ case 2:
+ func[i] = &tile->funcarray[tile->b_rect[y*tile->sizex+x]];
+ break;
+ }
+ memset(func[i], 0, sizeof(DSMFunction));
+
+ func[i]->samples = (DSMLayerSample*) sout[i];
+ cursamp[i] = sout[i];
+ func[i]->totsamples = 0;
+ func[i]->zmin = 0x7FFFFFFF;
+ func[i]->zmax = -0x7FFFFFFF;
+ }
+
+ /*we add 1 to totface to compensate for how compression must lag behind merging.*/
+ for (i=0, csamp=row; i<totface; i++, csamp++) {
+ ci = csamp->index;
+ BASSERT(ci >= 0 && ci < 3);
+ samp = func[ci]->samples + totfaces[ci];
+
+ /*we've hit a sample in one of the other rgb color component
+ visibility functions, or we've hit an excluded sample, so continue*/
+ if (!csamp->srclist) {
+ continue;
+ }
+
+ samp->orig_totsamples = 0;
+ samp->depth = csamp->depth;
+ if (samp->depth > func[ci]->zmax) func[ci]->zmax = csamp->depth;
+ if (samp->depth < func[ci]->zmin) func[ci]->zmin = csamp->depth;
+
+ if (lastcsamp[ci]) accum[ci] = accum[ci] + (double)(csamp->depth-lastcsamp[ci]->depth)*slope[ci];
+ samp->value = (float) accum[ci];
+
+ if (csamp->next && csamp->next->depth == csamp->depth) {
+ accum[ci] += weight[csamp->samplenr]*(csamp->next->value-csamp->value);
+ }
+
+ if (csamp->next) {
+ if (csamp->next->depth != csamp->depth) {
+ s2 = ((double)(csamp->next->value - csamp->value)) / (double)(csamp->next->depth - csamp->depth);
+ if (csamp->prev) {
+ if (csamp->prev->depth != csamp->depth) {
+ s1 = ((double)(csamp->value - csamp->prev->value)) / (double)(csamp->depth - csamp->prev->depth);
+ slope[ci] += weight[csamp->samplenr]*(s2 - s1);
+ } else {
+ slope[ci] += weight[csamp->samplenr]*s2;
+ }
+ } else {
+ slope[ci] += weight[csamp->samplenr]*s2;
+ }
+ } else {
+ if (csamp->prev && csamp->prev->depth != csamp->depth) {
+ s1 = csamp->value - csamp->prev->value;
+ s1 /= csamp->depth - csamp->prev->depth;
+ slope[ci] -= weight[csamp->samplenr]*s1;
+ }
+ }
+ } else {
+ if (csamp->prev) {
+ if (csamp->prev->depth == csamp->depth) {
+ //accum[ci] += weight[csamp->samplenr]*(csamp->value-csamp->prev->value);
+ } else {
+ s1 = ((double)(csamp->value - csamp->prev->value)) / (double)(csamp->depth - csamp->prev->depth);
+ slope[ci] -= weight[csamp->samplenr]*s1;
+ }
+ }
+ }
+
+ if (accum[ci] < -0.001f) {
+ printf("EVIL! accum: %f\n", accum[ci]);
+ accum[ci] = 0.0f;
+ }
+ else if (accum[ci] > 1.001f) {
+ printf("EVIL 2! accum: %f\n", accum[ci]);
+ accum[ci] = 1.0f;
+ }
+
+ lastcsamp[ci] = csamp;
+
+ totfaces[ci]++;
+
+ /*
+ //continue;
+ //compression has to lag behind merging by 1 samples.
+ if (totfaces[ci] <= 1) continue;
+
+ if (state[ci] == COMPSTATE_PROCESSING) {
+ *cursamp[ci] = sout[ci][cursor[ci]];
+
+ //store the number of original samples between this one and
+ //the last, this is actually used by the (probably coded post-
+ //GSoC) soft shadow method.
+ cursamp[ci]->orig_totsamples = 0;
+
+ if (state[ci] != COMPSTATE_DONE && cursor[ci] >= totfaces[ci]) { //func[ci]->totsamples - 1) {
+ totface2[ci]++;
+ state[ci] = COMPSTATE_DONE;
+ continue;
+ }
+
+ start[ci] = (sout[ci][cursor[ci]+1].value+err) - cursamp[ci]->value;
+ end[ci] = (sout[ci][cursor[ci]+1].value-err) - cursamp[ci]->value;
+ if (sout[ci][cursor[ci]+1].depth != cursamp[ci]->depth) {
+ start[ci] /= (double)(sout[ci][cursor[ci]+1].depth - cursamp[ci]->depth);
+ end[ci] /= (double)(sout[ci][cursor[ci]+1].depth - cursamp[ci]->depth);
+ }
+ cursor[ci] += 1;
+
+ state[ci] = COMPSTATE_COMPRESSING;
+ }
+
+ if (state[ci] == COMPSTATE_COMPRESSING) {
+ ostartpoint[ci] = startpoint[ci];
+ oendpoint[ci] = endpoint[ci];
+ if (sout[ci][cursor[ci]].depth == cursamp[ci]->depth) {
+ //startpoint = cursamp->value + err;
+ //endpoint = cursamp->value - err;
+ break;
+ } else {
+ startpoint[ci] = cursamp[ci]->value + start[ci] * (double)(sout[ci][cursor[ci]].depth - cursamp[ci]->depth);
+ endpoint[ci] = cursamp[ci]->value + end[ci] * (double)(sout[ci][cursor[ci]].depth - cursamp[ci]->depth);
+ }
+ if (startpoint[ci] > sout[ci][cursor[ci]].value && endpoint[ci] < sout[ci][cursor[ci]].value) {
+ if (startpoint[ci] > sout[ci][cursor[ci]].value+err) {
+ start[ci] = (sout[ci][cursor[ci]].value+err) - cursamp[ci]->value;
+ if (sout[ci][cursor[ci]].depth != cursamp[ci]->depth) {
+ start[ci] /= (double)(sout[ci][cursor[ci]].depth - cursamp[ci]->depth);
+ }
+ }
+ if (endpoint[ci] < sout[ci][cursor[ci]].value-err) {
+ end[ci] = (sout[ci][cursor[ci]].value-err) - cursamp[ci]->value;
+ if (sout[ci][cursor[ci]].depth != cursamp[ci]->depth) {
+ end[ci] /= (double)(sout[ci][cursor[ci]].depth - cursamp[ci]->depth);
+ }
+ }
+ } else {
+ cursor[ci] -= 1;
+ state[ci] = COMPSTATE_PROCESSING2;
+ }
+ cursamp[ci]->orig_totsamples++;
+ cursor[ci] += 1;
+ }
+
+ if (state[ci] == COMPSTATE_PROCESSING2) {
+ cursamp[ci]++;
+ totface2[ci]++;
+
+ if (cursor[ci] >= func[ci]->totsamples) {
+ *cursamp[ci] = sout[ci][totfaces[ci]-1]; //samp[func->totsamples-1];
+ cursamp[ci]++;
+ totface2[ci]++;
+ }
+ state[ci] = COMPSTATE_PROCESSING;
+ }*/
+ }
+
+
+ for (i=0; i<3; i++) {
+ totface2[i] = totfaces[i];
+
+ /*compression doesn't occur if only 1 sample.*/
+ if (totfaces[i]==1) totface2[i] = 1;
+
+ func[i]->totsamples = totface2[i];
+ //func[i]->samples = BLI_memarena_alloc(tile->arena, sizeof(DSMLayerSample)*totface2[i]);
+ //memcpy(func[i]->samples, sout[i], sizeof(DSMLayerSample)*totface2[i]);
+ BASSERT(accum[i] < 1.0001);
+
+ DSM_CompressFunction(tile->arena, func[i], error);
+ }
+}
+/*
+ This function removes extraneous points
+ from a density function. It works by
+ casting a triangular "beam" from a vertex,
+ then clipping it with subsequent vertices's
+ opacity - err and opacity + err, until it
+ no longer exists.
+
+ See original Deep Shadow Maps paper for more details.
+*/
+void DSM_CompressFunction(MemArena *arena, DSMFunction *func, float error)
+{
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list