42 |
|
char *mat, *obj; |
43 |
|
} RadianceDef; |
44 |
|
|
45 |
– |
|
45 |
|
|
47 |
– |
/* Colour code is as follows: global = blue |
48 |
– |
precomp global = cyan |
49 |
– |
caustic = red |
50 |
– |
volume = green |
51 |
– |
direct = magenta |
52 |
– |
contrib = yellow */ |
46 |
|
const RadianceDef radDefs [] = { |
47 |
< |
{ "void plastic mat.global\n0\n0\n5 0 0 1 0 0\n", |
47 |
> |
{ "void plastic mat.global\n0\n0\n5 %f %f %f 0 0\n", |
48 |
|
"mat.global sphere obj.global\n0\n0\n4 %g %g %g %g\n" |
49 |
|
}, |
50 |
< |
{ "void plastic mat.pglobal\n0\n0\n5 0 1 1 0 0\n", |
50 |
> |
{ "void plastic mat.pglobal\n0\n0\n5 %f %f %f 0 0\n", |
51 |
|
"mat.pglobal sphere obj.global\n0\n0\n4 %g %g %g %g\n" |
52 |
|
}, |
53 |
< |
{ "void plastic mat.caustic\n0\n0\n5 1 0 0 0 0\n", |
53 |
> |
{ "void plastic mat.caustic\n0\n0\n5 %f %f %f 0 0\n", |
54 |
|
"mat.caustic sphere obj.caustic\n0\n0\n4 %g %g %g %g\n" |
55 |
|
}, |
56 |
< |
{ "void plastic mat.volume\n0\n0\n5 0 1 0 0 0\n", |
56 |
> |
{ "void plastic mat.volume\n0\n0\n5 %f %f %f 0 0\n", |
57 |
|
"mat.volume sphere obj.volume\n0\n0\n4 %g %g %g %g\n" |
58 |
|
}, |
59 |
< |
{ "void plastic mat.direct\n0\n0\n5 1 0 1 0 0\n", |
59 |
> |
{ "void plastic mat.direct\n0\n0\n5 %f %f %f 0 0\n", |
60 |
|
"mat.direct sphere obj.direct\n0\n0\n4 %g %g %g %g\n" |
61 |
|
}, |
62 |
< |
{ "void plastic mat.contrib\n0\n0\n5 1 1 0 0 0\n", |
62 |
> |
{ "void plastic mat.contrib\n0\n0\n5 %f %f %f 0 0\n", |
63 |
|
"mat.contrib sphere obj.contrib\n0\n0\n4 %g %g %g %g\n" |
64 |
|
} |
65 |
|
}; |
66 |
|
|
67 |
+ |
/* Default colour codes are as follows: global = blue |
68 |
+ |
precomp global = cyan |
69 |
+ |
caustic = red |
70 |
+ |
volume = green |
71 |
+ |
direct = magenta |
72 |
+ |
contrib = yellow */ |
73 |
+ |
const COLOR colDefs [] = { |
74 |
+ |
{0, 0, 1}, {0, 1, 1}, {1, 0, 0}, {0, 1, 0}, {1, 0, 1}, {1, 1, 0} |
75 |
+ |
}; |
76 |
|
|
77 |
|
|
78 |
|
int main (int argc, char** argv) |
79 |
|
{ |
80 |
< |
char format [128]; |
81 |
< |
RREAL rad, radScale = RADSCALE, vol, dumpRatio; |
82 |
< |
unsigned arg, j, ptype; |
80 |
> |
char format [MAXFMTLEN]; |
81 |
> |
RREAL rad, radScale = RADSCALE, extent, dumpRatio; |
82 |
> |
unsigned arg, j, ptype, dim; |
83 |
|
long numSpheres = NSPHERES; |
84 |
+ |
COLOR customCol = {0, 0, 0}; |
85 |
|
FILE *pmapFile; |
86 |
|
PhotonMap pm; |
87 |
|
PhotonPrimary pri; |
92 |
|
|
93 |
|
if (argc < 2) { |
94 |
|
puts("Dump photon maps as RADIANCE scene description\n"); |
95 |
< |
printf("Usage: %s [-r radscale1] [-n nspheres1] pmap1 " |
96 |
< |
"[-r radscale2] [-n nspheres2] pmap2 ...\n", argv [0]); |
95 |
> |
printf("Usage: %s " |
96 |
> |
"[-r radscale1] [-n nspheres1] [-c rcol1 gcol1 bcol1] pmap1 " |
97 |
> |
"[-r radscale2] [-n nspheres2] [-c rcol2 gcol2 bcol2] pmap2 " |
98 |
> |
"...\n", argv [0]); |
99 |
|
return 1; |
100 |
|
} |
101 |
|
|
113 |
|
error(USER, "invalid number of spheres"); |
114 |
|
break; |
115 |
|
|
116 |
+ |
case 'c': |
117 |
+ |
for (j = 0; j < 3; j++) |
118 |
+ |
if ((customCol [j] = atof(argv [++arg])) <= 0) |
119 |
+ |
error(USER, "invalid RGB colour"); |
120 |
+ |
break; |
121 |
+ |
|
122 |
|
default: |
123 |
|
sprintf(errmsg, "unknown option %s", argv [arg]); |
124 |
|
error(USER, errmsg); |
162 |
|
printargs(argc, argv, stdout); |
163 |
|
fputc('\n', stdout); |
164 |
|
|
165 |
< |
/* Dump material def */ |
166 |
< |
fputs(radDefs [ptype].mat, stdout); |
165 |
> |
/* Dump material def */ |
166 |
> |
if (intens(customCol) > 0) |
167 |
> |
printf(radDefs [ptype].mat, |
168 |
> |
customCol [0], customCol [1], customCol [2]); |
169 |
> |
else |
170 |
> |
printf(radDefs [ptype].mat, |
171 |
> |
colDefs [ptype][0], colDefs [ptype][1], colDefs [ptype][2]); |
172 |
|
fputc('\n', stdout); |
173 |
|
|
174 |
|
/* Get number of photons */ |
188 |
|
for (j = 0; j < 4; j++) |
189 |
|
getflt(pmapFile); |
190 |
|
|
191 |
< |
/* Sphere radius based on avg intersphere dist |
192 |
< |
(= sphere distrib density ^-1/3) */ |
193 |
< |
vol = (pm.maxPos [0] - pm.minPos [0]) * (pm.maxPos [1] - pm.minPos [1]) * |
194 |
< |
(pm.maxPos [2] - pm.minPos [2]); |
195 |
< |
rad = radScale * RADCOEFF * pow(vol / numSpheres, 1./3.); |
191 |
> |
/* Sphere radius based on avg intersphere dist depending on |
192 |
> |
whether the distribution occupies a 1D line (!), a 2D plane, |
193 |
> |
or 3D volume (= sphere distrib density ^-1/d, where d is the |
194 |
> |
dimensionality of the distribution) */ |
195 |
> |
for (j = 0, extent = 1.0, dim = 0; j < 3; j++) { |
196 |
> |
rad = pm.maxPos [j] - pm.minPos [j]; |
197 |
> |
|
198 |
> |
if (rad > FTINY) { |
199 |
> |
dim++; |
200 |
> |
extent *= rad; |
201 |
> |
} |
202 |
> |
} |
203 |
> |
|
204 |
> |
rad = radScale * RADCOEFF * pow(extent / numSpheres, 1./dim); |
205 |
|
|
206 |
|
/* Photon dump probability to satisfy target sphere count */ |
207 |
|
dumpRatio = numSpheres < pm.numPhotons |
210 |
|
/* Skip primary rays */ |
211 |
|
pm.numPrimary = getint(sizeof(pm.numPrimary), pmapFile); |
212 |
|
while (pm.numPrimary-- > 0) { |
213 |
< |
getint(sizeof(pri.srcIdx) + sizeof(pri.dir), pmapFile); |
213 |
> |
/* Skip source index & incident dir */ |
214 |
> |
getint(sizeof(pri.srcIdx), pmapFile); |
215 |
> |
#ifdef PMAP_PRIMARYDIR |
216 |
> |
/* Skip primary incident dir */ |
217 |
> |
getint(sizeof(pri.dir), pmapFile); |
218 |
> |
#endif |
219 |
> |
#ifdef PMAP_PRIMARYPOS |
220 |
> |
/* Skip primary hitpoint */ |
221 |
|
for (j = 0; j < 3; j++) |
222 |
|
getflt(pmapFile); |
223 |
+ |
#endif |
224 |
|
} |
225 |
|
|
226 |
|
#ifdef PMAP_OOC |
286 |
|
/* Reset defaults for next dump */ |
287 |
|
radScale = RADSCALE; |
288 |
|
numSpheres = NSPHERES; |
289 |
+ |
customCol [0] = customCol [1] = customCol [2] = 0; |
290 |
|
} |
291 |
|
|
292 |
|
return 0; |