src/sampler.cc
author Radek Brich <radek.brich@devl.cz>
Tue, 06 May 2008 09:39:58 +0200
branchpyrit
changeset 93 96d65f841791
parent 92 9af5c039b678
child 94 4c8abb8977dc
permissions -rw-r--r--
more build script tuning make all float constants single precision solve many warnings from msvc and gcc with various -W... flags add common.cc file for dbgmsg() function witch apparently cannot be inlined fix python module building with msvc, add manifest file handling remove forgotten RenderrowData class add stanford models download script for windows (.bat)
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];
88
f7edb3b90816 merge pixmap handling from sampler, material.h and ccdemos's image module to new Pixmap class
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
    42
	const int &w = pixmap.getWidth(), &h = pixmap.getHeight();
f7edb3b90816 merge pixmap handling from sampler, material.h and ccdemos's image module to new Pixmap class
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
    43
	Float *&buffer = pixmap.getFloatData();
f7edb3b90816 merge pixmap handling from sampler, material.h and ccdemos's image module to new Pixmap class
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
    44
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
	if ( phase == 0 )
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    47
		if (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
			phase = 1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    50
			sx = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    51
			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
    52
		}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    53
		else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    54
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    55
			phase = 2;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    56
			sx = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    57
			return w*h*samples;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    58
		}
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    59
	}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    60
	if ( phase == 1 )
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    61
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    62
		// finalize subsampling
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
    63
		const Float subsample2 = 1.0f / (subsample*subsample);
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    64
		int num_samples = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    65
		Colour ic;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    66
		phase = 2;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    67
		sx = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    68
		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
    69
			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
    70
			{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    71
				int x1 = x*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    72
				int y1 = y*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    73
				int x2 = (x+1)*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    74
				int y2 = (y+1)*subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    75
				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
    76
				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
    77
				if (x1 == x2 || y1 == y2)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    78
					continue;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    79
				Float *p;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    80
				p = buffer + 3*(y1*w + x1);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    81
				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
    82
				p = buffer + 3*(y1*w + x2);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    83
				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
    84
				p = buffer + 3*(y2*w + x1);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    85
				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
    86
				p = buffer + 3*(y2*w + x2);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    87
				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
    88
				Float m = (c1-c2).mag2();
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    89
				m = max(m, (c2-c3).mag2());
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    90
				m = max(m, (c3-c4).mag2());
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    91
				m = max(m, (c4-c1).mag2());
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    92
				if (m < 0.002)
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
					// interpolate
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
    95
					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
    96
						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
    97
						{
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
    98
							ic = c1*(Float)((subsample-i)*(subsample-j)*subsample2)
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
    99
								+ c2*(Float)((i)*(subsample-j)*subsample2)
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   100
								+ c3*(Float)((subsample-i)*(j)*subsample2)
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   101
								+ c4*(Float)((i)*(j)*subsample2);
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   102
							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
   103
							*(p + 0) = ic.r;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   104
							*(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
   105
							*(p + 2) = ic.b;
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
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   108
				else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   109
				{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   110
					// mark as to be computed
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   111
					num_samples += subsample * subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   112
					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
   113
						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
   114
							if (oversample || i != 0 || j != 0)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   115
								*(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
   116
				}
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
		return num_samples;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   119
	}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   120
	if ( phase == 2 && oversample )
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   121
	{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   122
		// finalize oversampling
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   123
		Float *buf;
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   124
		if (subsample > 1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   125
			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
   126
				if (*(buf+1) < 0)
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
					// interpolated
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   129
					*(buf+1) = -*(buf+1);
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   130
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   131
				else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   132
				{
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   133
					*buf = *buf * (1.0f/samples);
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   134
					*(buf+1) = *(buf+1) * (1.0f/samples);
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   135
					*(buf+2) = *(buf+2) * (1.0f/samples);
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   136
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   137
		else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   138
			for (buf = buffer; buf != buffer + w*h*3; buf++)
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   139
				*buf = *buf * (1.0f/samples);
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   140
	}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   141
	phase = -1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   142
	return 0;
47
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
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   145
bool DefaultSampler::nextSample(Sample* s)
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   146
{
88
f7edb3b90816 merge pixmap handling from sampler, material.h and ccdemos's image module to new Pixmap class
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   147
	const int &w = pixmap.getWidth(), &h = pixmap.getHeight();
f7edb3b90816 merge pixmap handling from sampler, material.h and ccdemos's image module to new Pixmap class
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   148
	Float *&buffer = pixmap.getFloatData();
f7edb3b90816 merge pixmap handling from sampler, material.h and ccdemos's image module to new Pixmap class
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   149
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   150
	if (phase == 1)
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   151
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   152
		// subsampling
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   153
		if (sx < 0)
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   154
		{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   155
			// first sample
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   156
			s->x = -(Float)w/h/2.0f;
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   157
			s->y = -0.5f;
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   158
			sx = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   159
			sy = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   160
			osa_samp = 0;
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   161
		}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   162
		else
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   163
		{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   164
			if (sx == w-1)
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
				if (sy == h-1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   167
					return false;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   168
				sy += subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   169
				if (sy > h-1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   170
					sy = h-1;
50
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   171
				sx = 0;
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   172
			}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   173
			else
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   174
			{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   175
				sx += subsample;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   176
				if (sx > w-1)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   177
					sx = w-1;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   178
			}
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   179
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   180
			s->x = (Float)sx/h - (Float)w/h/2.0f;
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   181
			s->y = (Float)sy/h - 0.5f;
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   182
		}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   183
	}
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   184
	else if (phase == 2)
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   185
	{
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   186
		/* grid oversampling */
87
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 82
diff changeset
   187
		static const int gridsamples[] = {1,4,9,16};
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   188
		static const Float osa4x[] = {-0.25f, +0.25f, +0.25f, -0.25f};
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   189
		static const Float osa4y[] = {-0.25f, -0.25f, +0.25f, +0.25f};
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   190
		static const Float osa9x[] = {-0.34f,  0.00f, +0.34f,
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   191
			-0.34f,  0.00f, +0.34f, -0.34f,  0.00f, +0.34f};
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   192
		static const Float osa9y[] = {-0.34f, -0.34f, -0.34f,
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   193
				0.00f,  0.00f,  0.00f, +0.34f, +0.34f, +0.34f};
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   194
		static const Float osa16x[] = {-0.375f, -0.125f, +0.125f, +0.375f,
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   195
			-0.375f, -0.125f, +0.125f, +0.375f, -0.375f, -0.125f, +0.125f, +0.375f,
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   196
			-0.375f, -0.125f, +0.125f, +0.375f};
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   197
		static const Float osa16y[] = {-0.375f, -0.375f, -0.375f, -0.375f,
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   198
			-0.125f, -0.125f, -0.125f, -0.125f, +0.125f, +0.125f, +0.125f, +0.125f,
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   199
			+0.375f, +0.375f, +0.375f, +0.375f};
87
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 82
diff changeset
   200
		static const Float *osaSx[] = {NULL, osa4x, osa9x, osa16x};
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 82
diff changeset
   201
		static const Float *osaSy[] = {NULL, osa4y, osa9y, osa16y};
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   202
		const int samples = gridsamples[oversample];
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   203
		const Float *osax = osaSx[oversample];
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   204
		const Float *osay = osaSy[oversample];
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   205
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   206
		if (sx < 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
			// first sample
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   209
			s->x = -(Float)w/h/2.0f;
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   210
			s->y = -0.5f;
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   211
			sx = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   212
			sy = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   213
			osa_samp = 0;
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
		else
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
			osa_samp++;
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
			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
   220
			{
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   221
				s->x = osax[osa_samp]/h + (Float)sx/h - (Float)w/h/2.0f;
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   222
				s->y = osay[osa_samp]/h + (Float)sy/h - 0.5f;
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   223
			}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   224
			else
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 (subsample > 1)
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
					// find next not interpolated pixel
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   229
					do
77
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
						sx++;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   232
						if (sx >= w)
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 = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   235
							sy++;
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
						if (sy >= h)
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   238
							return false;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   239
					}
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   240
					while ( *(buffer + 3*(sy*w + sx)) >= 0. );
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   241
				}
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   242
				else if (!oversample && !(w&1) && !(h&1))
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   243
				{
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   244
					// generate good raster for packet tracing
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   245
					const int j = ((sy&1)<<1) + (sx&1);
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   246
					switch (j)
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   247
					{
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   248
						case 0:
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   249
						case 2:
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   250
							sx++;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   251
							break;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   252
						case 1:
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   253
							sx--;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   254
							sy++;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   255
							break;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   256
						case 3:
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   257
							sx++;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   258
							if (sx >= w)
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   259
							{
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   260
								sx = 0;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   261
								sy++;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   262
							}
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   263
							else
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   264
								sy--;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   265
							if (sy >= h)
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   266
								return false;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   267
							break;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   268
					}
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   269
				}
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   270
				else
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   271
				{
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   272
					sx++;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   273
					if (sx >= w)
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   274
					{
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   275
						sx = 0;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   276
						sy++;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   277
					}
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   278
					if (sy >= h)
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   279
						return false;
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   280
				}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   281
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   282
				s->x = (Float)sx/h - (Float)w/h/2.0f;
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   283
				s->y = (Float)sy/h - 0.5f;
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   284
				osa_samp = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   285
			}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   286
		}
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   287
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   288
		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
   289
		{
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   290
			s->x += osax[0]/h;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   291
			s->y += osay[0]/h;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   292
			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
   293
			*(buf++) = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   294
			*(buf++) = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   295
			*(buf++) = 0;
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   296
		}
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   297
	}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   298
50
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   299
	s->sx = sx;
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   300
	s->sy = sy;
14a727b70d07 rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   301
	s->osa_samp = osa_samp;
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   302
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   303
	return true;
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   304
}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   305
53
228cb8bfdd54 slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   306
void DefaultSampler::saveSample(Sample &samp, Colour &col)
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   307
{
88
f7edb3b90816 merge pixmap handling from sampler, material.h and ccdemos's image module to new Pixmap class
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   308
	Float *buf = pixmap.getFloatData()
f7edb3b90816 merge pixmap handling from sampler, material.h and ccdemos's image module to new Pixmap class
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   309
		+ 3*(samp.sy * pixmap.getWidth() + samp.sx);
77
dbe8438d5dca rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
   310
	if (phase == 2 && oversample)
49
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   311
	{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   312
		*(buf+0) += col.r;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   313
		*(buf+1) += col.g;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   314
		*(buf+2) += col.b;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   315
	}
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   316
	else
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   317
	{
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   318
		*(buf++) = col.r;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   319
		*(buf++) = col.g;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   320
		*(buf++) = col.b;
558fde7da82a workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   321
	}
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   322
}
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   323