![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 /* 00002 Copyright 2005-2010 Intel Corporation. All Rights Reserved. 00003 00004 This file is part of Threading Building Blocks. 00005 00006 Threading Building Blocks is free software; you can redistribute it 00007 and/or modify it under the terms of the GNU General Public License 00008 version 2 as published by the Free Software Foundation. 00009 00010 Threading Building Blocks is distributed in the hope that it will be 00011 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00012 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with Threading Building Blocks; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 As a special exception, you may use this file as part of a free software 00020 library without restriction. Specifically, if other files instantiate 00021 templates or use macros or inline functions from this file, or you compile 00022 this file and link it with other files to produce an executable, this 00023 file does not by itself cause the resulting executable to be covered by 00024 the GNU General Public License. This exception does not however 00025 invalidate any other reasons why the executable file might be covered by 00026 the GNU General Public License. 00027 */ 00028 00029 /* 00030 The original source for this example is 00031 Copyright (c) 1994-2008 John E. Stone 00032 All rights reserved. 00033 00034 Redistribution and use in source and binary forms, with or without 00035 modification, are permitted provided that the following conditions 00036 are met: 00037 1. Redistributions of source code must retain the above copyright 00038 notice, this list of conditions and the following disclaimer. 00039 2. Redistributions in binary form must reproduce the above copyright 00040 notice, this list of conditions and the following disclaimer in the 00041 documentation and/or other materials provided with the distribution. 00042 3. The name of the author may not be used to endorse or promote products 00043 derived from this software without specific prior written permission. 00044 00045 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 00046 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00047 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00048 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00049 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00050 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00051 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00052 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00053 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00054 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00055 SUCH DAMAGE. 00056 */ 00057 00058 #include "machine.h" 00059 #include "types.h" 00060 #include "macros.h" 00061 #include "vector.h" 00062 #include "tgafile.h" 00063 #include "trace.h" 00064 #include "light.h" 00065 #include "shade.h" 00066 #include "camera.h" 00067 #include "util.h" 00068 #include "intersect.h" 00069 #include "global.h" 00070 #include "ui.h" 00071 #include "video.h" 00072 00073 // shared but read-only so could be private too 00074 static thr_parms *all_parms; 00075 static scenedef scene; 00076 static int startx; 00077 static int stopx; 00078 static int starty; 00079 static int stopy; 00080 static flt jitterscale; 00081 static int totaly; 00082 00083 static color_t render_one_pixel (int x, int y, unsigned int *local_mbox, unsigned int &serial, 00084 int startx, int stopx, int starty, int stopy) 00085 { 00086 /* private vars moved inside loop */ 00087 ray primary, sample; 00088 color col, avcol; 00089 int R,G,B; 00090 intersectstruct local_intersections; 00091 int alias; 00092 /* end private */ 00093 00094 primary=camray(&scene, x, y); 00095 primary.intstruct = &local_intersections; 00096 primary.flags = RT_RAY_REGULAR; 00097 00098 serial++; 00099 primary.serial = serial; 00100 primary.mbox = local_mbox; 00101 primary.maxdist = FHUGE; 00102 primary.scene = &scene; 00103 col=trace(&primary); 00104 00105 serial = primary.serial; 00106 00107 /* perform antialiasing if enabled.. */ 00108 if (scene.antialiasing > 0) { 00109 for (alias=0; alias < scene.antialiasing; alias++) { 00110 00111 serial++; /* increment serial number */ 00112 sample=primary; /* copy the regular primary ray to start with */ 00113 sample.serial = serial; 00114 00115 { 00116 sample.d.x+=((std::rand() % 100) - 50) / jitterscale; 00117 sample.d.y+=((std::rand() % 100) - 50) / jitterscale; 00118 sample.d.z+=((std::rand() % 100) - 50) / jitterscale; 00119 } 00120 00121 avcol=trace(&sample); 00122 00123 serial = sample.serial; /* update our overall serial # */ 00124 00125 col.r += avcol.r; 00126 col.g += avcol.g; 00127 col.b += avcol.b; 00128 } 00129 00130 col.r /= (scene.antialiasing + 1.0); 00131 col.g /= (scene.antialiasing + 1.0); 00132 col.b /= (scene.antialiasing + 1.0); 00133 } 00134 00135 /* Handle overexposure and underexposure here... */ 00136 R=(int) (col.r*255); 00137 if (R > 255) R = 255; 00138 else if (R < 0) R = 0; 00139 00140 G=(int) (col.g*255); 00141 if (G > 255) G = 255; 00142 else if (G < 0) G = 0; 00143 00144 B=(int) (col.b*255); 00145 if (B > 255) B = 255; 00146 else if (B < 0) B = 0; 00147 00148 return video->get_color(R, G, B); 00149 00150 } 00151 00152 static void parallel_thread (void) 00153 { 00154 // thread-local storage 00155 unsigned int serial = 1; 00156 unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20); 00157 unsigned int * local_mbox = (unsigned int *) alloca(mboxsize); 00158 memset(local_mbox,0,mboxsize); 00159 00160 for (int y = starty; y < stopy; y++) { { 00161 drawing_area drawing(startx, totaly-y, stopx-startx, 1); 00162 for (int x = startx; x < stopx; x++) { 00163 color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy); 00164 drawing.put_pixel(c); 00165 } } 00166 if(!video->next_frame()) return; 00167 } 00168 } 00169 00170 void * thread_trace(thr_parms * parms) 00171 { 00172 // shared but read-only so could be private too 00173 all_parms = parms; 00174 scene = parms->scene; 00175 startx = parms->startx; 00176 stopx = parms->stopx; 00177 starty = parms->starty; 00178 stopy = parms->stopy; 00179 jitterscale = 40.0*(scene.hres + scene.vres); 00180 totaly = parms->scene.vres-1; 00181 00182 parallel_thread (); 00183 00184 return(NULL); 00185 }
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.