src/sampler.cc
author Radek Brich <radek.brich@devl.cz>
Thu, 24 Apr 2008 13:55:11 +0200
branchpyrit
changeset 82 930a2d3ecaed
parent 77 dbe8438d5dca
child 87 1081e3dd3f3e
permissions -rw-r--r--
prepare structures for packet tracing (it's already slightly faster, even without any explicit parallelization) supply missing virtual destructors
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
/*
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
 * scene.cc: screen sample generation and image reconstruction
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
 *
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
 * This file is part of Pyrit Ray Tracer.
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
 *
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
 * Copyright 2008  Radek Brich
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
 *
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
 * of this software and associated documentation files (the "Software"), to deal
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
 * in the Software without restriction, including without limitation the rights
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
 * copies of the Software, and to permit persons to whom the Software is
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
 * furnished to do so, subject to the following conditions:
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
 *
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
 * The above copyright notice and this permission notice shall be included in
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
 * all copies or substantial portions of the Software.
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
 *
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
 * THE SOFTWARE.
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
 */
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
#include <math.h>
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
#include "common.h"
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
#include "scene.h"
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
48
a4913301c626 begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    32
void DefaultSampler::init()
a4913301c626 begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    33
{
a4913301c626 begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    34
	phase = 0;
82
930a2d3ecaed prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    35
	packetable = (subsample <= 1);
48
a4913301c626 begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    36
}
a4913301c626 begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    37
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
int DefaultSampler::initSampleSet()
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
{
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    40
	static const int gridsamples[] = {1,5,9,16};
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    41
	const int samples = gridsamples[oversample];
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
	if ( phase == 0 )
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    44
		if (subsample > 1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    45
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    46
			phase = 1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    47
			sx = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    48
			return (w/subsample+1)*(h/subsample+1);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    49
		}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    50
		else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    51
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    52
			phase = 2;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    53
			sx = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    54
			return w*h*samples;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    55
		}
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    56
	}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    57
	if ( phase == 1 )
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    58
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    59
		// finalize subsampling
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    60
		const Float subsample2 = 1.0/(subsample*subsample);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    61
		int num_samples = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    62
		Colour ic;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    63
		phase = 2;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    64
		sx = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    65
		for (int y = 0; y < h/subsample; y++)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    66
			for (int x = 0; x < w/subsample; x++)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    67
			{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    68
				int x1 = x*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    69
				int y1 = y*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    70
				int x2 = (x+1)*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    71
				int y2 = (y+1)*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    72
				if (x2 > w-1)	x2 = w-1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    73
				if (y2 > h-1)	y2 = h-1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    74
				if (x1 == x2 || y1 == y2)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    75
					continue;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    76
				Float *p;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    77
				p = buffer + 3*(y1*w + x1);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    78
				Colour c1(*p, *(p+1), *(p+2));
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    79
				p = buffer + 3*(y1*w + x2);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    80
				Colour c2(*p, *(p+1), *(p+2));
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    81
				p = buffer + 3*(y2*w + x1);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    82
				Colour c3(*p, *(p+1), *(p+2));
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    83
				p = buffer + 3*(y2*w + x2);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    84
				Colour c4(*p, *(p+1), *(p+2));
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    85
				Float m = (c1-c2).mag2();
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    86
				m = max(m, (c2-c3).mag2());
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    87
				m = max(m, (c3-c4).mag2());
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    88
				m = max(m, (c4-c1).mag2());
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    89
				if (m < 0.002)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    90
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    91
					// interpolate
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    92
					for (int i = 0; i < subsample; i++)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    93
						for (int j = 0; j < subsample; j++)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    94
						{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    95
							ic = c1*(subsample-i)*(subsample-j)*subsample2
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    96
								+ c2*(i)*(subsample-j)*subsample2
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    97
								+ c3*(subsample-i)*(j)*subsample2
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    98
								+ c4*(i)*(j)*subsample2;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    99
							p = buffer + 3*((y1+j)*w + x1+i);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   100
							*(p + 0) = ic.r;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   101
							*(p + 1) = oversample ? -ic.g : ic.g;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   102
							*(p + 2) = ic.b;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   103
						}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   104
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   105
				else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   106
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   107
					// mark as to be computed
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   108
					num_samples += subsample * subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   109
					for (int i = 0; i < subsample; i++)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   110
						for (int j = 0; j < subsample; j++)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   111
							if (oversample || i != 0 || j != 0)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   112
								*(buffer + 3*((y1+j)*w + x1+i)) = -1.;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   113
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   114
			}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   115
		return num_samples;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   116
	}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   117
	if ( phase == 2 && oversample )
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   118
	{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   119
		// finalize oversampling
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   120
		Float *buf;
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   121
		if (subsample > 1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   122
			for (buf = buffer; buf != buffer + w*h*3; buf += 3)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   123
				if (*(buf+1) < 0)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   124
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   125
					// interpolated
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   126
					*(buf+1) = -*(buf+1);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   127
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   128
				else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   129
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   130
					*buf = *buf * (1.0/samples);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   131
					*(buf+1) = *(buf+1) * (1.0/samples);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   132
					*(buf+2) = *(buf+2) * (1.0/samples);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   133
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   134
		else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   135
			for (buf = buffer; buf != buffer + w*h*3; buf++)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   136
				*buf = *buf * (1.0/samples);
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   137
	}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   138
	phase = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   139
	return 0;
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   140
}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   141
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   142
bool DefaultSampler::nextSample(Sample* s)
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   143
{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   144
	if (phase == 1)
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   145
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   146
		// subsampling
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   147
		if (sx < 0)
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   148
		{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   149
			// first sample
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   150
			s->x = -(Float)w/h/2.0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   151
			s->y = -0.5;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   152
			sx = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   153
			sy = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   154
			osa_samp = 0;
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   155
		}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   156
		else
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   157
		{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   158
			if (sx == w-1)
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   159
			{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   160
				if (sy == h-1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   161
					return false;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   162
				sy += subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   163
				if (sy > h-1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   164
					sy = h-1;
50
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   165
				sx = 0;
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   166
			}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   167
			else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   168
			{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   169
				sx += subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   170
				if (sx > w-1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   171
					sx = w-1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   172
			}
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   173
50
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   174
			s->x = (Float)sx/h - (Float)w/h/2.0;
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   175
			s->y = (Float)sy/h - 0.5;
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   176
		}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   177
	}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   178
	else if (phase == 2)
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   179
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   180
		/* grid oversampling */
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   181
		static const int gridsamples[] = {1,5,9,16};
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   182
		static const Float osa5x[] = {0.0, -0.4, +0.4, +0.4, -0.4};
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   183
		static const Float osa5y[] = {0.0, -0.4, -0.4, +0.4, +0.4};
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   184
		static const Float osa9x[] = {-0.34,  0.00, +0.34,
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   185
			-0.34,  0.00, +0.34, -0.34,  0.00, +0.34};
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   186
		static const Float osa9y[] = {-0.34, -0.34, -0.34,
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   187
				0.00,  0.00,  0.00, +0.34, +0.34, +0.34};
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   188
		static const Float osa16x[] = {-0.375, -0.125, +0.125, +0.375,
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   189
			-0.375, -0.125, +0.125, +0.375, -0.375, -0.125, +0.125, +0.375,
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   190
			-0.375, -0.125, +0.125, +0.375};
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   191
		static const Float osa16y[] = {-0.375, -0.375, -0.375, -0.375,
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   192
			-0.125, -0.125, -0.125, -0.125, +0.125, +0.125, +0.125, +0.125,
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   193
			+0.375, +0.375, +0.375, +0.375};
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   194
		static const Float *osaSx[] = {NULL, osa5x, osa9x, osa16x};
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   195
		static const Float *osaSy[] = {NULL, osa5y, osa9y, osa16y};
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   196
		const int samples = gridsamples[oversample];
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   197
		const Float *osax = osaSx[oversample];
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   198
		const Float *osay = osaSy[oversample];
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   199
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   200
		if (sx < 0)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   201
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   202
			// first sample
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   203
			s->x = -(Float)w/h/2.0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   204
			s->y = -0.5;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   205
			sx = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   206
			sy = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   207
			osa_samp = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   208
		}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   209
		else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   210
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   211
			osa_samp++;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   212
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   213
			if (oversample && oversample <= 3 && osa_samp < samples)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   214
			{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   215
				s->x = osax[osa_samp]/h + (Float)sx/h - (Float)w/h/2.0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   216
				s->y = osay[osa_samp]/h + (Float)sy/h - 0.5;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   217
			}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   218
			else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   219
			{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   220
				sx++;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   221
				if (sx >= w)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   222
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   223
					sx = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   224
					sy++;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   225
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   226
				if (sy >= h)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   227
					return false;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   228
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   229
				if (subsample > 1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   230
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   231
					// find next not interpolated pixel
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   232
					while ( *(buffer + 3*(sy*w + sx)) >= 0. )
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   233
					{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   234
						sx++;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   235
						if (sx >= w)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   236
						{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   237
							sx = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   238
							sy++;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   239
						}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   240
						if (sy >= h)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   241
							return false;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   242
					}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   243
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   244
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   245
				s->x = (Float)sx/h - (Float)w/h/2.0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   246
				s->y = (Float)sy/h - 0.5;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   247
				osa_samp = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   248
			}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   249
		}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   250
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   251
		if (osa_samp == 0 && oversample && oversample <= 3)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   252
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   253
			s->x += osax[0]/h;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   254
			s->y += osay[0]/h;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   255
			Float *buf = buffer + 3*(sy*w + sx);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   256
			*(buf++) = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   257
			*(buf++) = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   258
			*(buf++) = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   259
		}
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   260
	}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   261
50
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   262
	s->sx = sx;
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   263
	s->sy = sy;
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   264
	s->osa_samp = osa_samp;
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   265
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   266
	return true;
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   267
}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   268
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   269
void DefaultSampler::saveSample(Sample &samp, Colour &col)
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   270
{
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   271
	Float *buf = buffer + 3*(samp.sy * w + samp.sx);
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   272
	if (phase == 2 && oversample)
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   273
	{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   274
		*(buf+0) += col.r;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   275
		*(buf+1) += col.g;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   276
		*(buf+2) += col.b;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   277
	}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   278
	else
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   279
	{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   280
		*(buf++) = col.r;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   281
		*(buf++) = col.g;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   282
		*(buf++) = col.b;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   283
	}
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   284
}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   285