src/sampler.cc
author Radek Brich <radek.brich@devl.cz>
Wed, 23 Apr 2008 19:35:03 +0200
branchpyrit
changeset 80 907929fa9b59
parent 77 dbe8438d5dca
child 82 930a2d3ecaed
permissions -rw-r--r--
remove forgotten noise.h includes common_ply.h: ignore invalid faces with duplicated points (this solves visual flaws in dragon model) extend loadShape for loading triangles realtime_dragon.cc demo: add kd-tree dump/load functionality, add colored perlin cloud texture
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;
a4913301c626 begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    35
}
a4913301c626 begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    36
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
int DefaultSampler::initSampleSet()
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
{
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    39
	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
    40
	const int samples = gridsamples[oversample];
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
	if ( phase == 0 )
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    43
		if (subsample > 1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    44
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    45
			phase = 1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    46
			sx = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    47
			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
    48
		}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    49
		else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    50
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    51
			phase = 2;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    52
			sx = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    53
			return w*h*samples;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    54
		}
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    55
	}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    56
	if ( phase == 1 )
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    57
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    58
		// finalize subsampling
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    59
		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
    60
		int num_samples = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    61
		Colour ic;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    62
		phase = 2;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    63
		sx = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    64
		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
    65
			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
    66
			{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    67
				int x1 = x*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    68
				int y1 = y*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    69
				int x2 = (x+1)*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    70
				int y2 = (y+1)*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    71
				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
    72
				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
    73
				if (x1 == x2 || y1 == y2)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    74
					continue;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    75
				Float *p;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    76
				p = buffer + 3*(y1*w + x1);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    77
				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
    78
				p = buffer + 3*(y1*w + x2);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    79
				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
    80
				p = buffer + 3*(y2*w + x1);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    81
				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
    82
				p = buffer + 3*(y2*w + x2);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    83
				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
    84
				Float m = (c1-c2).mag2();
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    85
				m = max(m, (c2-c3).mag2());
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    86
				m = max(m, (c3-c4).mag2());
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    87
				m = max(m, (c4-c1).mag2());
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    88
				if (m < 0.002)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    89
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    90
					// interpolate
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    91
					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
    92
						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
    93
						{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    94
							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
    95
								+ c2*(i)*(subsample-j)*subsample2
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    96
								+ c3*(subsample-i)*(j)*subsample2
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    97
								+ c4*(i)*(j)*subsample2;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    98
							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
    99
							*(p + 0) = ic.r;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   100
							*(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
   101
							*(p + 2) = ic.b;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   102
						}
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
				else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   105
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   106
					// mark as to be computed
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   107
					num_samples += subsample * subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   108
					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
   109
						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
   110
							if (oversample || i != 0 || j != 0)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   111
								*(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
   112
				}
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
		return num_samples;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   115
	}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   116
	if ( phase == 2 && oversample )
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   117
	{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   118
		// finalize oversampling
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   119
		Float *buf;
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   120
		if (subsample > 1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   121
			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
   122
				if (*(buf+1) < 0)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   123
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   124
					// interpolated
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   125
					*(buf+1) = -*(buf+1);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   126
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   127
				else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   128
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   129
					*buf = *buf * (1.0/samples);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   130
					*(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
   131
					*(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
   132
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   133
		else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   134
			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
   135
				*buf = *buf * (1.0/samples);
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   136
	}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   137
	phase = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   138
	return 0;
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   139
}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   140
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   141
bool DefaultSampler::nextSample(Sample* s)
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   142
{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   143
	if (phase == 1)
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   144
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   145
		// subsampling
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   146
		if (sx < 0)
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   147
		{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   148
			// first sample
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   149
			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
   150
			s->y = -0.5;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   151
			sx = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   152
			sy = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   153
			osa_samp = 0;
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   154
		}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   155
		else
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   156
		{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   157
			if (sx == w-1)
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   158
			{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   159
				if (sy == h-1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   160
					return false;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   161
				sy += subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   162
				if (sy > h-1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   163
					sy = h-1;
50
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   164
				sx = 0;
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   165
			}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   166
			else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   167
			{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   168
				sx += subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   169
				if (sx > w-1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   170
					sx = w-1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   171
			}
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   172
50
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   173
			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
   174
			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
   175
		}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   176
	}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   177
	else if (phase == 2)
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   178
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   179
		/* grid oversampling */
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   180
		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
   181
		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
   182
		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
   183
		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
   184
			-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
   185
		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
   186
				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
   187
		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
   188
			-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
   189
			-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
		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
   191
			-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
   192
			+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
   193
		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
   194
		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
   195
		const int samples = gridsamples[oversample];
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   196
		const Float *osax = osaSx[oversample];
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   197
		const Float *osay = osaSy[oversample];
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   198
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   199
		if (sx < 0)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   200
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   201
			// first sample
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   202
			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
   203
			s->y = -0.5;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   204
			sx = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   205
			sy = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   206
			osa_samp = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   207
		}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   208
		else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   209
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   210
			osa_samp++;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   211
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   212
			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
   213
			{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   214
				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
   215
				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
   216
			}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   217
			else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   218
			{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   219
				sx++;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   220
				if (sx >= w)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   221
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   222
					sx = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   223
					sy++;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   224
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   225
				if (sy >= h)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   226
					return false;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   227
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   228
				if (subsample > 1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   229
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   230
					// find next not interpolated pixel
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   231
					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
   232
					{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   233
						sx++;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   234
						if (sx >= w)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   235
						{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   236
							sx = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   237
							sy++;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   238
						}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   239
						if (sy >= h)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   240
							return false;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   241
					}
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
				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
   245
				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
   246
				osa_samp = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   247
			}
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
		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
   251
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   252
			s->x += osax[0]/h;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   253
			s->y += osay[0]/h;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   254
			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
   255
			*(buf++) = 0;
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
		}
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   259
	}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   260
50
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   261
	s->sx = sx;
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   262
	s->sy = sy;
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   263
	s->osa_samp = osa_samp;
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   264
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   265
	return true;
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   266
}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   267
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   268
void DefaultSampler::saveSample(Sample &samp, Colour &col)
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   269
{
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   270
	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
   271
	if (phase == 2 && oversample)
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   272
	{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   273
		*(buf+0) += col.r;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   274
		*(buf+1) += col.g;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   275
		*(buf+2) += col.b;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   276
	}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   277
	else
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   278
	{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   279
		*(buf++) = col.r;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   280
		*(buf++) = col.g;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   281
		*(buf++) = col.b;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   282
	}
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   283
}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   284