36 : m_maxBatchSize(maxBatchSize)
41 m_compiler.
include(
"src/framework");
91 nscreenPos.x = 2.0f * ((
F32)(posIdx % w) + 0.5f) / (
F32)w - 1.0f;
92 nscreenPos.y = 2.0f * ((
F32)(posIdx / w) + 0.5f) / (
F32)h - 1.0f;
96 Vec4f worldPos4D = nscreenToWorld * nscreenPos;
97 Vec3f worldPos = worldPos4D.
getXYZ() / worldPos4D.w;
116 if( !batching(irays.
getSize(),numSamples, m_shadowStartIdx,newBatch, lo,hi) )
120 orays.
resize((hi-lo)*numSamples);
152 const float epsilon = 1e-3
f;
156 if( !batching(irays.
getSize(), numSamples, m_shadowStartIdx, newBatch, lo, hi) )
160 const S32 numOutputRays = (hi-lo)*numSamples;
161 orays.
resize(numOutputRays);
165 for(
int i=lo;i<hi;i++)
170 const float t =
max(0.f,(irayres.
t-epsilon));
173 for(
int j=0;j<numSamples;j++)
176 Vec3f direction = target - origin;
187 const S32 oindex = (i-lo)*numSamples+j;
188 orays.
setRay(oindex, oray);
201 if(!batching(irays.
getSize(), numSamples, m_aoStartIdx, newBatch, lo, hi))
204 orays.
resize((hi - lo) * numSamples);
343 return random(orays,bounds,numRays,closestHit, temp, PosDir, randomSeed);
349 if( !batching(numRays,1, m_randomStartIdx, newBatch, lo,hi) )
352 const S32 numOutputRays = (hi-lo);
353 orays.
resize(numOutputRays);
356 for(
int i=0;i<numRays;i++)
376 const float epsilon = 1e-4
f;
380 if( !batching(irays.
getSize(),numSamples, m_randomStartIdx,newBatch, lo,hi) )
384 const S32 numOutputRays = (hi-lo)*numSamples;
385 orays.
resize(numOutputRays);
390 for(
int i=lo;i<hi;i++)
395 const float t =
max(0.f,(irayres.
t-epsilon));
401 for(
int j=0;j<numSamples;j++)
422 const S32 oindex = (i-lo)*numSamples+j;
423 orays.
setRay(oindex, oray);
431 bool RayGen::batching(
S32 numInputRays,
S32 numSamples,
S32& startIdx,
bool& newBatch,
S32& lo,
S32& hi)
439 if(startIdx == numInputRays)
444 hi =
min(numInputRays, lo+m_maxBatchSize/numSamples);
FW_CUDA_FUNC T length(const VectorBase< T, L, S > &v)
S32 getSize() const
Gets size of the buffer (number of rays).
void primaryCPU(RayBuffer &orays, const Vec3f &origin, const Mat4f &nscreenToWorld, S32 w, S32 h, float maxDist)
Generates primary rays on the CPU.
void include(const String &path)
FW_CUDA_FUNC const Vec3f & max(void) const
CudaModule * compile(bool enablePrints=true, bool autoFail=true)
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule * module
Buffer & getIDToSlotBuffer()
Gets buffer mapping ids to slots.
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1 GLint GLfloat GLfloat GLfloat v2 GLint GLsizei const GLfloat value GLint GLsizei GLboolean const GLfloat value GLuint program GLuint GLfloat GLfloat GLfloat z GLuint GLint GLenum GLboolean normalized
Buffer & getTriNormalBuffer(void)
Returns triangle normal buffer.
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.
RayGen(S32 maxBatchSize=8 *1024 *1024)
Constructor.
FW_CUDA_FUNC bool hit(void) const
CUdeviceptr getCudaPtr(S64 ofs=0)
bool random(RayBuffer &orays, const AABB &bounds, int numRays, bool closestHit, bool PosDir=false, U32 randomSeed=0)
Generates random rays. Used for various tests.
bool randomReflection(RayBuffer &orays, RayBuffer &irays, Scene &scene, int numSamples, float maxDist, bool &newBatch, U32 randomSeed=0)
Generates random reflection rays.
CudaKernel getKernel(const String &name)
FW_CUDA_FUNC Vec3f getXYZ(void) const
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.
Definitions for the ray generator class.
const Ray & getRayForSlot(S32 slot) const
Gets a ray assigned to a given slot.
const U8 * getPtr(S64 ofs=0)
FW_CUDA_FUNC T dot(const VectorBase< T, L, S > &a, const VectorBase< T, L, V > &b)
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum target
Buffer & getRayBuffer()
Gets ray buffer.
void setSize(const Vec2i &size)
Buffer & getSlotToIDBuffer()
Gets buffer slots to ids.
CUdeviceptr getMutableCudaPtr(S64 ofs=0)
FW_CUDA_FUNC void degenerate(void)
Buffer & getResultBuffer()
Gets ray result buffer.
Ray buffer class. Stores rays.
U8 * getMutablePtr(S64 ofs=0)
FW_CUDA_FUNC T min(const VectorBase< T, L, S > &v)
void primary(RayBuffer &orays, const Vec3f &origin, const Mat4f &nscreenToWorld, S32 w, S32 h, float maxDist)
Generates primary rays on the GPU.
FW_CUDA_FUNC T max(const VectorBase< T, L, S > &v)
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.
Buffer & getIndexToPixel(void)
FW_CUDA_FUNC const Vec3f & min(void) const
FW_CUDA_FUNC void normalize(T len=(T) 1)
Buffer & getGlobal(const String &name)
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction f
const RayResult & getResultForSlot(S32 slot) const
Gets a ray result assigned to a given slot.
CudaKernel & launch(void)
void setRay(S32 slot, const Ray &ray)
Assigns ray to a slot. Id is same as slot.
FW_CUDA_FUNC S normalized(T len=(T) 1) const
void resize(S32 n)
Resizes the buffer.
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.
void setNeedClosestHit(bool c)
Sets whether the closet hit is needed.
void addOptions(const String &options)
void setSourceFile(const String &path)
FW_CUDA_FUNC T length(void) const