author | Radek Brich <radek.brich@devl.cz> |
Mon, 28 Apr 2008 11:44:11 +0200 | |
branch | pyrit |
changeset 88 | f7edb3b90816 |
parent 87 | 1081e3dd3f3e |
child 92 | 9af5c039b678 |
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 |
|
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 |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
63 |
const Float subsample2 = 1.0/(subsample*subsample); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
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 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
98 |
ic = c1*(subsample-i)*(subsample-j)*subsample2 |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
99 |
+ c2*(i)*(subsample-j)*subsample2 |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
100 |
+ c3*(subsample-i)*(j)*subsample2 |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
101 |
+ c4*(i)*(j)*subsample2; |
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 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
133 |
*buf = *buf * (1.0/samples); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
134 |
*(buf+1) = *(buf+1) * (1.0/samples); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
135 |
*(buf+2) = *(buf+2) * (1.0/samples); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
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++) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
139 |
*buf = *buf * (1.0/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 |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
156 |
s->x = -(Float)w/h/2.0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
157 |
s->y = -0.5; |
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 |
|
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
180 |
s->x = (Float)sx/h - (Float)w/h/2.0; |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
181 |
s->y = (Float)sy/h - 0.5; |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
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}; |
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
188 |
static const Float osa4x[] = {-0.25, +0.25, +0.25, -0.25}; |
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
189 |
static const Float osa4y[] = {-0.25, -0.25, +0.25, +0.25}; |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
190 |
static const Float osa9x[] = {-0.34, 0.00, +0.34, |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
191 |
-0.34, 0.00, +0.34, -0.34, 0.00, +0.34}; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
192 |
static const Float osa9y[] = {-0.34, -0.34, -0.34, |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
193 |
0.00, 0.00, 0.00, +0.34, +0.34, +0.34}; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
194 |
static const Float osa16x[] = {-0.375, -0.125, +0.125, +0.375, |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
195 |
-0.375, -0.125, +0.125, +0.375, -0.375, -0.125, +0.125, +0.375, |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
196 |
-0.375, -0.125, +0.125, +0.375}; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
197 |
static const Float osa16y[] = {-0.375, -0.375, -0.375, -0.375, |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
198 |
-0.125, -0.125, -0.125, -0.125, +0.125, +0.125, +0.125, +0.125, |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
199 |
+0.375, +0.375, +0.375, +0.375}; |
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 |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
209 |
s->x = -(Float)w/h/2.0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
210 |
s->y = -0.5; |
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 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
221 |
s->x = osax[osa_samp]/h + (Float)sx/h - (Float)w/h/2.0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
222 |
s->y = osay[osa_samp]/h + (Float)sy/h - 0.5; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
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 |
sx++; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
227 |
if (sx >= w) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
228 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
229 |
sx = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
230 |
sy++; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
231 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
232 |
if (sy >= h) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
233 |
return false; |
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 |
if (subsample > 1) |
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 |
// find next not interpolated pixel |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
238 |
while ( *(buffer + 3*(sy*w + sx)) >= 0. ) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
239 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
240 |
sx++; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
241 |
if (sx >= w) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
242 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
243 |
sx = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
244 |
sy++; |
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 |
if (sy >= h) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
247 |
return false; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
248 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
249 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
250 |
|
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
251 |
s->x = (Float)sx/h - (Float)w/h/2.0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
252 |
s->y = (Float)sy/h - 0.5; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
253 |
osa_samp = 0; |
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 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
256 |
|
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
257 |
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
|
258 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
259 |
s->x += osax[0]/h; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
260 |
s->y += osay[0]/h; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
261 |
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
|
262 |
*(buf++) = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
263 |
*(buf++) = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
264 |
*(buf++) = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
265 |
} |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
266 |
} |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
267 |
|
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
268 |
s->sx = sx; |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
269 |
s->sy = sy; |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
270 |
s->osa_samp = osa_samp; |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
271 |
|
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
272 |
return true; |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
273 |
} |
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
274 |
|
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
275 |
void DefaultSampler::saveSample(Sample &samp, Colour &col) |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
276 |
{ |
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
|
277 |
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
|
278 |
+ 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
|
279 |
if (phase == 2 && oversample) |
49
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
280 |
{ |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
281 |
*(buf+0) += col.r; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
282 |
*(buf+1) += col.g; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
283 |
*(buf+2) += col.b; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
284 |
} |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
285 |
else |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
286 |
{ |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
287 |
*(buf++) = col.r; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
288 |
*(buf++) = col.g; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
289 |
*(buf++) = col.b; |
558fde7da82a
workaround for divide by zero bug in octree
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
290 |
} |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
291 |
} |
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
292 |