src/sampler.cc
author Radek Brich <radek.brich@devl.cz>
Fri, 28 Mar 2008 00:53:20 +0100
branchpyrit
changeset 49 558fde7da82a
parent 48 a4913301c626
child 50 14a727b70d07
permissions -rw-r--r--
workaround for divide by zero bug in octree enable oversampling for DefaultSampler sampler and camera performance enhancements
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
	{
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    43
		cout << "phase 1" << endl;
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
		phase++;
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    45
		return w*h*samples;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    46
	}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    47
	else if ( phase == 1 && oversample )
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    48
	{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    49
		cout << "phase 2" << endl;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    50
		phase = -1;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    51
		Float *buf;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    52
		for (buf = buffer; buf != buffer + w*h*3; buf++)
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    53
			*buf = *buf * (1.0/samples);
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    54
		return 0;
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
	}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
	else
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
	{
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
		phase = -1;
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
		return 0;
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60
	}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    63
Sample* DefaultSampler::nextSample(Sample *prev)
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    64
{
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    65
	DefaultSample *s = new DefaultSample;
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    66
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    67
	/* grid oversampling */
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    68
	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
    69
	static const Float osa5x[] = {0.0, -0.4, +0.4, +0.4, -0.4};
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    70
	static const Float osa5y[] = {0.0, -0.4, -0.4, +0.4, +0.4};
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    71
	static const Float osa9x[] = {-0.34,  0.00, +0.34,
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    72
		-0.34,  0.00, +0.34, -0.34,  0.00, +0.34};
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    73
	static const Float osa9y[] = {-0.34, -0.34, -0.34,
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    74
			0.00,  0.00,  0.00, +0.34, +0.34, +0.34};
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    75
	static const Float osa16x[] = {-0.375, -0.125, +0.125, +0.375,
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    76
		-0.375, -0.125, +0.125, +0.375, -0.375, -0.125, +0.125, +0.375,
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    77
		-0.375, -0.125, +0.125, +0.375};
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    78
	static const Float osa16y[] = {-0.375, -0.375, -0.375, -0.375,
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    79
		-0.125, -0.125, -0.125, -0.125, +0.125, +0.125, +0.125, +0.125,
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    80
		+0.375, +0.375, +0.375, +0.375};
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    81
	static const Float *osaSx[] = {NULL, osa5x, osa9x, osa16x};
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    82
	static const Float *osaSy[] = {NULL, osa5y, osa9y, osa16y};
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    83
	const int samples = gridsamples[oversample];
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    84
	const Float *osax = osaSx[oversample];
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    85
	const Float *osay = osaSy[oversample];
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    86
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    87
	if (!prev)
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    88
	{
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    89
		// first sample
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    90
		s->x = -(Float)w/h/2.0;
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    91
		s->y = -0.5;
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    92
		s->sx = 0;
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    93
		s->sy = 0;
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    94
		s->osa_samp = 0;
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    95
	}
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    96
	else
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    97
	{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    98
		DefaultSample *sp = static_cast<DefaultSample*>(prev);
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    99
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   100
		s->osa_samp = sp->osa_samp + 1;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   101
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   102
		if (oversample && oversample <= 3 && s->osa_samp < samples)
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   103
		{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   104
			s->sx = sp->sx;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   105
			s->sy = sp->sy;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   106
			s->x = osax[s->osa_samp]/h + (Float)s->sx/h - (Float)w/h/2.0;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   107
			s->y = osay[s->osa_samp]/h + (Float)s->sy/h - 0.5;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   108
		}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   109
		else
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   110
		{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   111
			s->sx = sp->sx + 1;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   112
			s->sy = sp->sy;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   113
			if (s->sx >= w)
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   114
			{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   115
				s->sx = 0;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   116
				s->sy++;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   117
			}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   118
			if (s->sy >= h)
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   119
			{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   120
				delete s;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   121
				return NULL;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   122
			}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   123
			s->x = (Float)s->sx/h - (Float)w/h/2.0;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   124
			s->y = (Float)s->sy/h - 0.5;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   125
			s->osa_samp = 0;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   126
		}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   127
	}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   128
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   129
	if (s->osa_samp == 0 && oversample && oversample <= 3)
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   130
	{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   131
		s->x += osax[0]/h;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   132
		s->y += osay[0]/h;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   133
		Float *buf = buffer + 3*(s->sy*w + s->sx);
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   134
		*(buf++) = 0;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   135
		*(buf++) = 0;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   136
		*(buf++) = 0;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   137
	}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   138
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   139
	return s;
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
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   142
void DefaultSampler::saveSample(Sample *samp, Colour &col)
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   143
{
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   144
	DefaultSample *sp = static_cast<DefaultSample*>(samp);
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   145
	Float *buf = buffer + 3*(sp->sy*w + sp->sx);
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   146
	if (oversample)
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   147
	{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   148
		*(buf+0) += col.r;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   149
		*(buf+1) += col.g;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   150
		*(buf+2) += col.b;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   151
	}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   152
	else
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   153
	{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   154
		*(buf++) = col.r;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   155
		*(buf++) = col.g;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   156
		*(buf++) = col.b;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   157
	}
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   158
}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   159