15 m_enableRandom (false),
126 if (bvhBuilder ==
"HLBVH")
161 printf(
"\nBuilding BVH...\nThis will take a while.\n");
217 printf(
"\nBuilding k-d tree...\nThis will take a while.\n");
250 F32 launchTime = 0.0f;
420 glPushAttrib(GL_ENABLE_BIT);
421 glDisable(GL_DEPTH_TEST);
463 F32 Renderer::calcNodeSAHCostKdtree(
const Platform& platform,
Buffer* nodes,
Buffer* tris,
S32 n,
AABB bbox,
S32 depth,
S32& maxDepth,
S32& sumDepth,
S32& numNodes,
S32& numLeaves,
F32& nodeArea,
F32 &weightedLeafArea,
F32& test)
481 float split = *(
float*)&cell.z;
483 AABB bboxLeft = bbox;
484 AABB bboxRight = bbox;
489 bboxLeft.
max().x = split;
490 bboxRight.
min().x = split;
494 bboxLeft.max().y = split;
495 bboxRight.min().y = split;
499 bboxLeft.max().z = split;
500 bboxRight.min().z = split;
509 weightedLeafArea +=
calcNodeSAHCostKdtree(platform, nodes, tris, nl, bboxLeft, depth+1, maxDepth, sumDepth, numNodes, numLeaves, nodeArea, weightedLeafArea, test);
510 weightedLeafArea +=
calcNodeSAHCostKdtree(platform, nodes, tris, nr, bboxRight, depth+1, maxDepth, sumDepth, numNodes, numLeaves, nodeArea, weightedLeafArea, test);
515 return platform.
getNodeCost(1) * nodeArea/pa + weightedLeafArea/pa;
532 int* idx = (
int*)triIdx + n;
535 while(idx[cnt] != 0x80000000)
bool enablePrints
Flag whether to enable prints about build progress.
Buffer & getTriMaterialColorBuffer(void)
Returns material color buffer.
void setScene(Scene *scene)
S32 getSize() const
Gets size of the buffer (number of rays).
const char * getPtr(void) const
Buffer & getTriVtxIndexBuffer(void)
Returns buffer of triangle's vertex indieces.
Stats * stats
Statistics collected during build phase. Set to NULL if no stats should be collected.
virtual void draw(GLContext *gl, CameraControls &camera)=0
The method used to draw the current state of visualization to the OpenGL context. ...
Class for the BVH visualization.
Mat4f setVGXform(const Mat4f &m)
virtual void setBVH(CudaAS *as)=0
bool GetStringValue(const char *name, char *value, const bool isFatal=false) const
void include(const String &path)
FW_CUDA_FUNC const Vec3f & max(void) const
CudaModule * compile(bool enablePrints=true, bool autoFail=true)
Buffer & getMaterialIds(void)
Returns material id buffer.
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule * module
const Image * getImage(void) const
F32 calcLeafSAHCostNum(const Platform &platform, S32 n, S32 &numLeaves)
Stats * stats
Statistics. If NULL, no statistics are gathered.
Renderer(AccelStructType as, Environment *env)
Buffer & getIDToSlotBuffer()
Gets buffer mapping ids to slots.
Cuda friendly KDTree representation.
CudaAS * getCudaBVH(void)
virtual BVHLayout getDesiredBVHLayout(void) const =0
void print() const
Prints the statistics to the console.
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.
const Texture & getAtlasTexture(void)
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 GLsizei const GLvoid pointer GLuint GLuint const GLchar name GLenum GLsizei GLenum GLsizei GLsizei height GLenum GLuint renderbuffer GLenum GLenum GLint * params
void addListener(Listener *listener)
CUdeviceptr getCudaPtr(S64 ofs=0)
TextureAtlas * getTextureAtlas(void)
Returns texture atlas holding scene's textures.
Strucure holding build parameters.
K-d tree acceleration structure class.
CudaKernel getKernel(const String &name)
virtual F32 traceBatch(RayBuffer &rays)=0
Structure holding ray statistics. Also provides print to the console. These statistics are used in a ...
Structure holding statistics about k-d tree.
Mat4f getWorldToClip(void) const
const U8 * getPtr(S64 ofs=0)
CudaVirtualTracer * m_cudaTracer
Sturcture for holding statistics about the BVH.
Mat4f xformFitToView(const Vec2f &pos, const Vec2f &size) const
void setTexRef(const String &name, Buffer &buf, CUarray_format format, int numComponents)
F32 renderFrame(GLContext *gl, const CameraControls &camera)
Buffer & getSlotToIDBuffer()
Gets buffer slots to ids.
Buffer & getTriShadedColorBuffer(void)
Returns shaded color buffer.
void drawImage(const Image &image, const Vec4f &pos, const Vec2f &align, bool topToBottom=true)
virtual void serialize(OutputStream &out)=0
Writes buffers to outpu stream.
Buffer & getTextureAtlasInfo(void)
Returns texture atlas information buffer.
CUdeviceptr getMutableCudaPtr(S64 ofs=0)
void removeListener(Listener *listener)
FW_CUDA_FUNC S invert(const MatrixBase< T, L, S > &v)
Buffer & getResultBuffer()
Gets ray result buffer.
FW_CUDA_FUNC float area(void) const
void showModalMessage(const String &msg)
U8 * getMutablePtr(S64 ofs=0)
void primary(RayBuffer &orays, const Vec3f &origin, const Mat4f &nscreenToWorld, S32 w, S32 h, float maxDist)
Generates primary rays on the GPU.
CudaAS * getCudaKDTree(void)
BVH acceleration structure class.
void setMesh(MeshBase *mesh)
String sprintf(const char *fmt,...)
F32 calcNodeSAHCostKdtree(const Platform &platform, Buffer *nodes, Buffer *tri, S32 n, AABB bbox, S32 depth, S32 &maxDepth, S32 &sumDepth, S32 &numNodes, S32 &numLeaves, F32 &nodeArea, F32 &weightedLeafArea, F32 &test)
void print() const
Prints statistics to stdout.
Buffer & getMaterialInfo(void)
Returns material info buffer.
void setVisible(bool visible)
Sets whether the visualization should be rendered or not.
void setParams(const Params ¶ms)
Buffer & getBuffer(void) const
BuilderType builder
Defines which builder type will be used to build the k-d tree.
U32 hashBits(U32 a, U32 b=FW_HASH_MAGIC, U32 c=0)
int getTotalNumRays(void)
Buffer & getGlobal(const String &name)
const Vec2i & getSize(void) const
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
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 n
virtual BVHLayout getLayout(void) const =0
Returns layout of buffers.
void printf(const char *fmt,...)
RayBuffer m_secondaryRays
Buffer & getVtxNormalBuffer(void)
Returns vertex normal buffer.
CudaKernel & launch(void)
virtual void setKernel(const String &kernelName)=0
bool enablePrints
Flag whether to print information during build phase.
U32 computeHash(void) const
Computes hash of the build parameters.
const Vec2i & getViewSize(void) const
BVH::BuildParams m_buildParams
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 depth
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
void setNeedClosestHit(bool c)
Sets whether the closet hit is needed.
Buffer & getVtxTexCoordBuffer(void)
Returns vertex texture coordinate buffer.
void addOptions(const String &options)
const Vec3f & getPosition(void) const
void setSourceFile(const String &path)
void displayResult(GLContext *gl)
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 size
CUDA tracer for the BVH acceleration structure. Performs BVH traversal on the GPU.
FW_CUDA_FUNC T min(void) const
F32 calcLeafSAHCostCompact(const Platform &platform, Buffer *triIdx, S32 n, S32 &numLeaves)
void mortonSort()
Performs morton sort.
Interface for acceleration structure.
Cuda tracer for the k-d tree acceleration structure. Performs kd-tree traversal on the GPU...
void beginFrame(GLContext *gl, const CameraControls &camera)