author | Radek Brich <radek.brich@devl.cz> |
Mon, 19 May 2008 22:59:04 +0200 | |
branch | pyrit |
changeset 98 | 64638385798a |
parent 95 | ca7d4c665531 |
permissions | -rw-r--r-- |
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 |
|
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
32 |
/* grid oversampling look up tables */ |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
33 |
static const int gridsamples[] = {1,4,9,16}; |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
34 |
static const Float osa4x[] = { -0.25f, +0.25f, +0.25f, -0.25f }; |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
35 |
static const Float osa4y[] = { -0.25f, -0.25f, +0.25f, +0.25f }; |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
36 |
static const Float osa9x[] = |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
37 |
{ |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
38 |
-0.34f, 0.00f, +0.34f, |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
39 |
-0.34f, 0.00f, +0.34f, |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
40 |
-0.34f, 0.00f, +0.34f |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
41 |
}; |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
42 |
static const Float osa9y[] = |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
43 |
{ |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
44 |
-0.34f, -0.34f, -0.34f, |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
45 |
0.00f, 0.00f, 0.00f, |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
46 |
+0.34f, +0.34f, +0.34f |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
47 |
}; |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
48 |
static const Float osa16x[] = |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
49 |
{ |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
50 |
-0.375f, -0.125f, +0.125f, +0.375f, |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
51 |
-0.375f, -0.125f, +0.125f, +0.375f, |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
52 |
-0.375f, -0.125f, +0.125f, +0.375f, |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
53 |
-0.375f, -0.125f, +0.125f, +0.375f |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
54 |
}; |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
55 |
static const Float osa16y[] = |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
56 |
{ |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
57 |
-0.375f, -0.375f, -0.375f, -0.375f, |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
58 |
-0.125f, -0.125f, -0.125f, -0.125f, |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
59 |
+0.125f, +0.125f, +0.125f, +0.125f, |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
60 |
+0.375f, +0.375f, +0.375f, +0.375f |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
61 |
}; |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
62 |
static const Float *osaSx[] = {NULL, osa4x, osa9x, osa16x}; |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
63 |
static const Float *osaSy[] = {NULL, osa4y, osa9y, osa16y}; |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
64 |
|
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
65 |
|
48
a4913301c626
begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
66 |
void DefaultSampler::init() |
a4913301c626
begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
67 |
{ |
a4913301c626
begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
68 |
phase = 0; |
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
69 |
packetable = (subsample <= 1); |
48
a4913301c626
begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
70 |
} |
a4913301c626
begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
71 |
|
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
72 |
int DefaultSampler::initSampleSet() |
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
73 |
{ |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
|
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
78 |
if ( phase == 0 ) |
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
79 |
{ |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
80 |
if (subsample > 1) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
81 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
82 |
phase = 1; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
83 |
sx = -1; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
84 |
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
|
85 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
86 |
else |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
87 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
88 |
phase = 2; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
89 |
sx = -1; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
90 |
return w*h*samples; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
91 |
} |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
92 |
} |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
93 |
if ( phase == 1 ) |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
94 |
{ |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
95 |
// finalize subsampling |
93 | 96 |
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
|
97 |
int num_samples = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
98 |
Colour ic; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
99 |
phase = 2; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
100 |
sx = -1; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
101 |
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
|
102 |
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
|
103 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
104 |
int x1 = x*subsample; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
105 |
int y1 = y*subsample; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
106 |
int x2 = (x+1)*subsample; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
107 |
int y2 = (y+1)*subsample; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
108 |
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
|
109 |
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
|
110 |
if (x1 == x2 || y1 == y2) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
111 |
continue; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
112 |
Float *p; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
113 |
p = buffer + 3*(y1*w + x1); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
114 |
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
|
115 |
p = buffer + 3*(y1*w + x2); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
116 |
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
|
117 |
p = buffer + 3*(y2*w + x1); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
118 |
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
|
119 |
p = buffer + 3*(y2*w + x2); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
120 |
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
|
121 |
Float m = (c1-c2).mag2(); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
122 |
m = max(m, (c2-c3).mag2()); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
123 |
m = max(m, (c3-c4).mag2()); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
124 |
m = max(m, (c4-c1).mag2()); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
125 |
if (m < 0.002) |
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 |
// interpolate |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
128 |
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
|
129 |
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
|
130 |
{ |
93 | 131 |
ic = c1*(Float)((subsample-i)*(subsample-j)*subsample2) |
132 |
+ c2*(Float)((i)*(subsample-j)*subsample2) |
|
133 |
+ c3*(Float)((subsample-i)*(j)*subsample2) |
|
134 |
+ c4*(Float)((i)*(j)*subsample2); |
|
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
135 |
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
|
136 |
*(p + 0) = ic.r; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
137 |
*(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
|
138 |
*(p + 2) = ic.b; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
139 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
140 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
141 |
else |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
142 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
143 |
// mark as to be computed |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
144 |
num_samples += subsample * subsample; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
145 |
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
|
146 |
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
|
147 |
if (oversample || i != 0 || j != 0) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
148 |
*(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
|
149 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
150 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
151 |
return num_samples; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
152 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
153 |
if ( phase == 2 && oversample ) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
154 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
155 |
// finalize oversampling |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
156 |
Float *buf; |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
157 |
if (subsample > 1) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
158 |
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
|
159 |
if (*(buf+1) < 0) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
160 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
161 |
// interpolated |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
162 |
*(buf+1) = -*(buf+1); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
163 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
164 |
else |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
165 |
{ |
93 | 166 |
*buf = *buf * (1.0f/samples); |
167 |
*(buf+1) = *(buf+1) * (1.0f/samples); |
|
168 |
*(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
|
169 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
170 |
else |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
171 |
for (buf = buffer; buf != buffer + w*h*3; buf++) |
93 | 172 |
*buf = *buf * (1.0f/samples); |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
173 |
} |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
174 |
phase = -1; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
175 |
return 0; |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
176 |
} |
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
177 |
|
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
178 |
bool DefaultSampler::nextSample(Sample* s) |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
179 |
{ |
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
|
180 |
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
|
181 |
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
|
182 |
|
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
183 |
if (phase == 1) |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
184 |
{ |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
185 |
// subsampling |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
186 |
if (sx < 0) |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
187 |
{ |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
188 |
// first sample |
93 | 189 |
s->x = -(Float)w/h/2.0f; |
190 |
s->y = -0.5f; |
|
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
191 |
sx = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
192 |
sy = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
193 |
osa_samp = 0; |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
194 |
} |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
195 |
else |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
196 |
{ |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
197 |
if (sx == w-1) |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
198 |
{ |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
199 |
if (sy == h-1) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
200 |
return false; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
201 |
sy += subsample; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
202 |
if (sy > h-1) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
203 |
sy = h-1; |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
204 |
sx = 0; |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
205 |
} |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
206 |
else |
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 |
sx += subsample; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
209 |
if (sx > w-1) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
210 |
sx = w-1; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
211 |
} |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
212 |
|
93 | 213 |
s->x = (Float)sx/h - (Float)w/h/2.0f; |
214 |
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
|
215 |
} |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
216 |
} |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
217 |
else if (phase == 2) |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
218 |
{ |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
219 |
/* grid oversampling */ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
220 |
const int samples = gridsamples[oversample]; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
221 |
const Float *osax = osaSx[oversample]; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
222 |
const Float *osay = osaSy[oversample]; |
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 |
if (sx < 0) |
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 |
// first sample |
93 | 227 |
s->x = -(Float)w/h/2.0f; |
228 |
s->y = -0.5f; |
|
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
229 |
sx = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
230 |
sy = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
231 |
osa_samp = 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 |
else |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
234 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
235 |
osa_samp++; |
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 (oversample && oversample <= 3 && osa_samp < samples) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
238 |
{ |
93 | 239 |
s->x = osax[osa_samp]/h + (Float)sx/h - (Float)w/h/2.0f; |
240 |
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
|
241 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
242 |
else |
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 |
if (subsample > 1) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
245 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
246 |
// 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
|
247 |
do |
77
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 |
sx++; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
250 |
if (sx >= w) |
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 |
sx = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
253 |
sy++; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
254 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
255 |
if (sy >= h) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
256 |
return false; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
257 |
} |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
258 |
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
|
259 |
} |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
260 |
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
|
261 |
{ |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
262 |
// 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
|
263 |
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
|
264 |
switch (j) |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
265 |
{ |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
266 |
case 0: |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
267 |
case 2: |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
268 |
sx++; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
269 |
break; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
270 |
case 1: |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
271 |
sx--; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
272 |
sy++; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
273 |
break; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
274 |
case 3: |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
275 |
sx++; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
276 |
if (sx >= w) |
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 |
sx = 0; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
279 |
sy++; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
280 |
} |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
281 |
else |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
282 |
sy--; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
283 |
if (sy >= h) |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
284 |
return false; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
285 |
break; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
286 |
} |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
287 |
} |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
288 |
else |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
289 |
{ |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
290 |
sx++; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
291 |
if (sx >= w) |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
292 |
{ |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
293 |
sx = 0; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
294 |
sy++; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
295 |
} |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
296 |
if (sy >= h) |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
88
diff
changeset
|
297 |
return false; |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
298 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
299 |
|
93 | 300 |
s->x = (Float)sx/h - (Float)w/h/2.0f; |
301 |
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
|
302 |
osa_samp = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
303 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
304 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
305 |
|
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
306 |
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
|
307 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
308 |
s->x += osax[0]/h; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
309 |
s->y += osay[0]/h; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
310 |
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
|
311 |
*(buf++) = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
312 |
*(buf++) = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
313 |
*(buf++) = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
314 |
} |
49
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 |
|
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
317 |
s->sx = sx; |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
318 |
s->sy = sy; |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
319 |
s->osa_samp = osa_samp; |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
320 |
|
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
321 |
return true; |
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 |
|
94 | 324 |
void DefaultSampler::saveSample(const Sample &samp, const Colour &col) |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
325 |
{ |
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
|
326 |
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
|
327 |
+ 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
|
328 |
if (phase == 2 && oversample) |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
329 |
{ |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
330 |
*(buf+0) += col.r; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
331 |
*(buf+1) += col.g; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
332 |
*(buf+2) += col.b; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
333 |
} |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
334 |
else |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
335 |
{ |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
336 |
*(buf++) = col.r; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
337 |
*(buf++) = col.g; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
338 |
*(buf++) = col.b; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
339 |
} |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
340 |
} |
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
341 |