| 1 |
/* |
| 2 |
Copyright (c) 2005-2021 Intel Corporation |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
/* |
| 18 |
The original source for this example is |
| 19 |
Copyright (c) 1994-2008 John E. Stone |
| 20 |
All rights reserved. |
| 21 |
|
| 22 |
Redistribution and use in source and binary forms, with or without |
| 23 |
modification, are permitted provided that the following conditions |
| 24 |
are met: |
| 25 |
1. Redistributions of source code must retain the above copyright |
| 26 |
notice, this list of conditions and the following disclaimer. |
| 27 |
2. Redistributions in binary form must reproduce the above copyright |
| 28 |
notice, this list of conditions and the following disclaimer in the |
| 29 |
documentation and/or other materials provided with the distribution. |
| 30 |
3. The name of the author may not be used to endorse or promote products |
| 31 |
derived from this software without specific prior written permission. |
| 32 |
|
| 33 |
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 34 |
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 35 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 36 |
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 37 |
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 38 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 39 |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 40 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 41 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 42 |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 43 |
SUCH DAMAGE. |
| 44 |
*/ |
| 45 |
|
| 46 |
/* |
| 47 |
* trace.cpp - This file contains the functions for firing primary rays |
| 48 |
* and handling subsequent calculations |
| 49 |
*/ |
| 50 |
|
| 51 |
#include "machine.hpp" |
| 52 |
#include "types.hpp" |
| 53 |
#include "macros.hpp" |
| 54 |
#include "vector.hpp" |
| 55 |
#include "tgafile.hpp" |
| 56 |
#include "trace.hpp" |
| 57 |
#include "light.hpp" |
| 58 |
#include "shade.hpp" |
| 59 |
#include "camera.hpp" |
| 60 |
#include "util.hpp" |
| 61 |
#include "intersect.hpp" |
| 62 |
#include "global.hpp" |
| 63 |
#include "ui.hpp" |
| 64 |
#include "tachyon_video.hpp" |
| 65 |
|
| 66 |
color trace(ray *primary) { |
| 67 |
if (primary->depth > 0) { |
| 68 |
VNorm(&primary->d); |
| 69 |
reset_intersection(primary->intstruct); |
| 70 |
intersect_objects(primary); |
| 71 |
return shader(primary); |
| 72 |
} |
| 73 |
|
| 74 |
/* if ray is truncated, return the background as its color */ |
| 75 |
return primary->scene->background; |
| 76 |
} |
| 77 |
|
| 78 |
void *thread_io(void *parms) { |
| 79 |
thr_io_parms p; |
| 80 |
|
| 81 |
p = *((thr_io_parms *)parms); |
| 82 |
writetgaregion(p.tga, p.iwidth, p.iheight, p.startx, p.starty, p.stopx, p.stopy, p.buffer); |
| 83 |
free(p.buffer); /* free the buffer once we are done with it.. */ |
| 84 |
free(parms); |
| 85 |
|
| 86 |
return (nullptr); |
| 87 |
} |
| 88 |
|
| 89 |
void trace_shm(scenedef scene, /*char * buffer, */ int startx, int stopx, int starty, int stopy) { |
| 90 |
thr_parms *parms; |
| 91 |
|
| 92 |
parms = (thr_parms *)rt_getmem(sizeof(thr_parms)); |
| 93 |
|
| 94 |
parms->tid = 0; |
| 95 |
parms->nthr = 1; |
| 96 |
parms->scene = scene; |
| 97 |
parms->startx = startx; |
| 98 |
parms->stopx = stopx; |
| 99 |
parms->starty = starty; |
| 100 |
parms->stopy = stopy; |
| 101 |
|
| 102 |
thread_trace(parms); |
| 103 |
|
| 104 |
rt_freemem(parms); |
| 105 |
} |
| 106 |
|
| 107 |
void trace_region(scenedef scene, void *tga, int startx, int starty, int stopx, int stopy) { |
| 108 |
if (scene.verbosemode) { |
| 109 |
char msgtxt[2048]; |
| 110 |
sprintf(msgtxt, |
| 111 |
"Node %3d tracing region %4d, %4d ---> %4d, %4d \n", |
| 112 |
0, |
| 113 |
startx, |
| 114 |
starty, |
| 115 |
stopx, |
| 116 |
stopy); |
| 117 |
rt_ui_message(MSG_0, msgtxt); |
| 118 |
} |
| 119 |
|
| 120 |
trace_shm(scene, /*buffer,*/ startx, stopx, starty, stopy); |
| 121 |
/* not used now |
| 122 |
writetgaregion(tga, scene.hres, scene.vres, |
| 123 |
startx, starty, stopx, stopy, global_buffer); |
| 124 |
|
| 125 |
if (scene.rawimage != nullptr) { |
| 126 |
int x, y; |
| 127 |
int totalx = stopx - startx + 1; |
| 128 |
for (y=starty; y<=stopy; y++) { |
| 129 |
for (x=0; x<scene.hres; x++) { |
| 130 |
scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3] = global_buffer[(y-starty)*totalx*3 + x*3 + 2]; |
| 131 |
scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3 +1] = global_buffer[(y-starty)*totalx*3 + x*3 + 1]; |
| 132 |
scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3 +2] = global_buffer[(y-starty)*totalx*3 + x*3]; |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
*/ |
| 137 |
} |