NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RayGen.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2011, NVIDIA Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA Corporation nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
33 #pragma once
34 #include "base/Math.hpp"
35 #include "base/Array.hpp"
36 #include "gpu/CudaCompiler.hpp"
37 #include "ray/RayBuffer.hpp"
38 #include "ray/PixelTable.hpp"
39 #include "Scene.hpp"
40 
41 namespace FW
42 {
43 
47 class RayGen
48 {
49 public:
50 
55  RayGen(S32 maxBatchSize = 8*1024*1024);
56 
57  // true if batch continues
67  void primary (RayBuffer& orays, const Vec3f& origin, const Mat4f& nscreenToWorld, S32 w,S32 h,float maxDist);
68 
80  bool shadow (RayBuffer& orays, RayBuffer& irays, int numSamples, const Vec3f& lightPos, float lightRadius, bool& newBatch, U32 randomSeed=0);
81 
93  bool ao (RayBuffer& orays, RayBuffer& irays, Scene& scene, int numSamples, float maxDist, bool& newBatch, U32 randomSeed=0); // non-const because of Buffer transfers
94 
104  void primaryCPU(RayBuffer& orays, const Vec3f& origin, const Mat4f& nscreenToWorld, S32 w,S32 h,float maxDist);
105 
117  bool shadowCPU (RayBuffer& orays, RayBuffer& irays, int numSamples, const Vec3f& lightPos, float lightRadius, bool& newBatch, U32 randomSeed=0);
118 
130  bool aoCPU (RayBuffer& orays, RayBuffer& irays, Scene& scene, int numSamples, float maxDist, bool& newBatch, U32 randomSeed=0); // non-const because of Buffer transfers
131 
132  // these are hack for various tests
143  bool random (RayBuffer& orays, const AABB& bounds, int numRays, bool closestHit, bool PosDir=false, U32 randomSeed=0);
144 
156  bool random (RayBuffer& orays, const AABB& bounds, int numRays, bool closestHit, bool PosDir, bool& newBatch, U32 randomSeed=0);
157 
169  bool randomReflection (RayBuffer& orays, RayBuffer& irays, Scene& scene, int numSamples, float maxDist, bool& newBatch, U32 randomSeed=0);
170 
171 private:
182  bool batching(S32 numInputRays,S32 numSamples,S32& startIdx,bool& newBatch, S32& lo,S32& hi);
183 
184  S32 m_maxBatchSize;
185  CudaCompiler m_compiler;
186  PixelTable m_pixelTable;
187 
188  S32 m_shadowStartIdx;
189  S32 m_aoStartIdx;
190  S32 m_randomStartIdx;
191 };
192 
193 } //
void primaryCPU(RayBuffer &orays, const Vec3f &origin, const Mat4f &nscreenToWorld, S32 w, S32 h, float maxDist)
Generates primary rays on the CPU.
Definition: RayGen.cpp:74
bool ao(RayBuffer &orays, RayBuffer &irays, Scene &scene, int numSamples, float maxDist, bool &newBatch, U32 randomSeed=0)
Generates ao rays on the GPU. Batches rays if necessary.
Definition: RayGen.cpp:196
RayGen(S32 maxBatchSize=8 *1024 *1024)
Constructor.
Definition: RayGen.cpp:35
bool random(RayBuffer &orays, const AABB &bounds, int numRays, bool closestHit, bool PosDir=false, U32 randomSeed=0)
Generates random rays. Used for various tests.
Definition: RayGen.cpp:340
bool randomReflection(RayBuffer &orays, RayBuffer &irays, Scene &scene, int numSamples, float maxDist, bool &newBatch, U32 randomSeed=0)
Generates random reflection rays.
Definition: RayGen.cpp:374
bool shadowCPU(RayBuffer &orays, RayBuffer &irays, int numSamples, const Vec3f &lightPos, float lightRadius, bool &newBatch, U32 randomSeed=0)
Generates shadow rays on the CPU. Batches rays if necessary.
Definition: RayGen.cpp:150
Ray buffer class. Stores rays.
Definition: RayBuffer.hpp:38
void primary(RayBuffer &orays, const Vec3f &origin, const Mat4f &nscreenToWorld, S32 w, S32 h, float maxDist)
Generates primary rays on the GPU.
Definition: RayGen.cpp:44
signed int S32
Definition: Defs.hpp:88
bool shadow(RayBuffer &orays, RayBuffer &irays, int numSamples, const Vec3f &lightPos, float lightRadius, bool &newBatch, U32 randomSeed=0)
Generates shadow rays on the GPU. Batches rays if necessary.
Definition: RayGen.cpp:112
unsigned int U32
Definition: Defs.hpp:85
Class holding 3d scene.
Definition: Scene.hpp:44
bool aoCPU(RayBuffer &orays, RayBuffer &irays, Scene &scene, int numSamples, float maxDist, bool &newBatch, U32 randomSeed=0)
Generates ao rays on the CPU. Batches rays if necessary.
Definition: RayGen.cpp:232
Ray generator class. Generates rays for both the GPU and the CPU.
Definition: RayGen.hpp:47