37 #define NO_NODE FW_S32_MIN
56 #define COLOR_NODE 0x14FFFFFF
57 #define COLOR_SIBLING 0x14000000
58 #define COLOR_LEFT 0x330000FF
59 #define COLOR_RIGHT 0x3300FF00
60 #define COLOR_RAY 0xFFFFFFFF
61 #define COLOR_TRI_INVIS 0xFF000000
62 #define COLOR_TRI_VIS 0xFFFFFFFF
64 #define COLOR_LEFT_SAH 0x330000FF
65 #define COLOR_RIGHT_SAH 0x3300FF00
66 #define COLOR_LEFT_SVBH 0x33FF00FF
67 #define COLOR_RIGHT_SVBH 0x33FFFF00
68 #define COLOR_LEFT_OSAH 0x3300FFFF
69 #define COLOR_RIGHT_OSAH 0x33FF0000
78 m_bvh->
getNode(m_node.addr, &m_nodeSplit, m_left.box, m_right.box, m_left.addr, m_right.addr);
79 m_node.box = m_left.box + m_right.box;
136 for(
int i = 0; i < emptyBoxes.
getSize(); i++)
137 addBoxQuads(emptyBoxes[i], boxes);
144 for(
int r = 0; r < 2; r++)
145 for(
int g = 0; g < 2; g++)
146 for(
int b = 0; b < 2; b++)
148 colorPalette.
add(
Vec4f((
float)r, (
float)g, (
float)b, 0.33
f));
149 for(
int i = 0; i < emptyBoxes.
getSize(); i++)
150 for(
int j = 0; j < 6*4; j++)
152 colors.
add(colorPalette[i % colorPalette.
getSize()]);
153 lineColors.
add(colorPalette[i % colorPalette.
getSize()]);
162 if(visibility !=
NULL)
257 if(!m_bvh->
isLeaf(m_node.addr))
259 m_bvh->
getNode(m_node.addr, &m_nodeSplit, m_left.box, m_right.box, m_left.addr, m_right.addr);
279 if(m_bvh->
isLeaf(m_left.addr))
285 if(!m_bvh->
isLeaf(m_node.addr))
287 m_bvh->
getNode(m_node.addr, &m_nodeSplit, m_left.box, m_right.box, m_left.addr, m_right.addr);
304 m_nodeStack.
add(m_node.addr);
313 if(m_bvh->
isLeaf(m_right.addr))
319 if(!m_bvh->
isLeaf(m_node.addr))
321 m_bvh->
getNode(m_node.addr, &m_nodeSplit, m_left.box, m_right.box, m_left.addr, m_right.addr);
338 m_nodeStack.
add(m_node.addr);
375 glPushAttrib(GL_ENABLE_BIT);
376 glEnable(GL_DEPTH_TEST);
377 glDepthFunc(GL_LESS);
378 glEnable(GL_CULL_FACE);
399 glDisable(GL_DEPTH_TEST);
400 glDisable(GL_CULL_FACE);
403 drawNodes(gl,
false);
418 void VisualizationBVH::getFromIndex(
S32 idx)
420 if(idx < 0 || idx > m_nodeStack.
getSize()-1)
423 if(!m_bvh->
isLeaf(m_nodeStack[idx]))
425 m_bvh->
getNode(m_nodeStack[idx], &m_nodeSplit, m_left.box, m_right.box, m_left.addr, m_right.addr);
435 S32 parent = m_nodeStack[idx-1];
436 NodeData left, right;
438 m_bvh->
getNode(parent,
NULL, left.box, right.box, left.addr, right.addr);
440 if(left.addr == m_nodeStack[idx])
453 m_node.addr = m_nodeStack[idx];
454 m_node.box = m_left.box + m_right.box;
465 void VisualizationBVH::growParentBox()
467 float incrTop = (m_node.box.max() - m_node.box.min()).
length() / 50.0f;
469 m_node.box.grow(m_node.box.min()-incrTop);
470 m_node.box.grow(m_node.box.max()+incrTop);
474 m_sibling.box.grow(m_sibling.box.min()-incrTop);
475 m_sibling.box.grow(m_sibling.box.max()+incrTop);
481 void VisualizationBVH::drawNodes(
GLContext* gl,
bool onlyChildren)
508 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
513 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
521 void VisualizationBVH::drawBox(
GLContext* gl,
const NodeData &node,
U32 abgr)
526 gl->
drawBox(node.box.min(), node.box.max(), abgr);
527 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
529 gl->
drawBox(node.box.min(), node.box.max(), abgr | 0xFF000000);
530 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
536 void VisualizationBVH::drawRays(
GLContext* gl,
U32 abgr)
548 void VisualizationBVH::drawPrimitives(
GLContext* gl)
552 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
555 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
561 void VisualizationBVH::drawPathInfo(
GLContext* gl)
570 char leftBox[100], rightBox[100];
571 m_left.box.min().sprint(leftBox, 100);
572 strcat_s(leftBox,
", ");
573 m_left.box.max().sprint(leftBox + strlen(leftBox), 100-strlen(leftBox));
574 m_right.box.min().sprint(rightBox, 100);
575 strcat_s(rightBox,
", ");
576 m_right.box.max().sprint(rightBox + strlen(rightBox), 100-strlen(rightBox));
582 pos.y -= (
F32)fontSize;
584 m_left.box.area(), leftBox, m_right.box.area(), rightBox), pos,
Vec2f(0.0
f, 1.0
f), 0xFFFFFFFF);
589 m_left.box.area(), leftBox, m_right.box.area(), rightBox), pos,
Vec2f(0.0
f, 1.0
f), 0xFFFFFFFF);
591 pos.y -= (
F32)fontSize;
592 gl->
drawLabel(
sprintf(
"Current depth: %d Path depth: %d OSAH split counts: %d x- %d y- %d z-axis",
594 pos.y -= (
F32)fontSize;
596 const float rightMargin = 100.0f;
597 String header(
"Split path: ");
607 pos.y -= (
F32)fontSize;
619 pos.y -= (
F32)fontSize;
630 pos.y -= (
F32)fontSize;
644 void VisualizationBVH::setColorMapping()
672 void VisualizationBVH::prepareTreeData(
S32 node)
684 memset(m_osahSplits, 0,
sizeof(m_osahSplits));
686 while(stackIndex > 0)
698 for(
int i = 0; i < indices.
getSize(); i++)
706 for(
int j = 0; j < 3; j++)
720 S32 child0Addr, child1Addr;
723 m_bvh->
getNode(node, &splitInfo, child0, child1, child0Addr, child1Addr);
725 rightChild = child1Addr;
729 m_osahSplits[splitInfo.
getAxis()]++;
734 addBoxQuads(child0, boxes);
735 addBoxQuads(child1, boxes);
739 stack[stackIndex++] = child1Addr;
743 node = stack[stackIndex];
775 buffer.
add(
Vec4f(min.x, min.y, min.z, 1.0f));
776 buffer.
add(
Vec4f(min.x, max.y, min.z, 1.0f));
777 buffer.
add(
Vec4f(min.x, max.y, max.z, 1.0f));
778 buffer.
add(
Vec4f(min.x, min.y, max.z, 1.0f));
780 buffer.
add(
Vec4f(max.x, max.y, max.z, 1.0f));
781 buffer.
add(
Vec4f(max.x, max.y, min.z, 1.0f));
782 buffer.
add(
Vec4f(max.x, min.y, min.z, 1.0f));
783 buffer.
add(
Vec4f(max.x, min.y, max.z, 1.0f));
785 buffer.
add(
Vec4f(min.x, min.y, min.z, 1.0f));
786 buffer.
add(
Vec4f(min.x, min.y, max.z, 1.0f));
787 buffer.
add(
Vec4f(max.x, min.y, max.z, 1.0f));
788 buffer.
add(
Vec4f(max.x, min.y, min.z, 1.0f));
790 buffer.
add(
Vec4f(max.x, max.y, max.z, 1.0f));
791 buffer.
add(
Vec4f(min.x, max.y, max.z, 1.0f));
792 buffer.
add(
Vec4f(min.x, max.y, min.z, 1.0f));
793 buffer.
add(
Vec4f(max.x, max.y, min.z, 1.0f));
795 buffer.
add(
Vec4f(min.x, min.y, min.z, 1.0f));
796 buffer.
add(
Vec4f(max.x, min.y, min.z, 1.0f));
797 buffer.
add(
Vec4f(max.x, max.y, min.z, 1.0f));
798 buffer.
add(
Vec4f(min.x, max.y, min.z, 1.0f));
800 buffer.
add(
Vec4f(max.x, max.y, max.z, 1.0f));
801 buffer.
add(
Vec4f(max.x, min.y, max.z, 1.0f));
802 buffer.
add(
Vec4f(min.x, min.y, max.z, 1.0f));
803 buffer.
add(
Vec4f(min.x, max.y, max.z, 1.0f));
Class for the visualization.
FW_CUDA_FUNC T length(const VectorBase< T, L, S > &v)
S32 getSize() const
Gets size of the buffer (number of rays).
Definitions for the BVH visualization framework.
void set(const void *ptr)
Buffer & getTriVtxIndexBuffer(void)
Returns buffer of triangle's vertex indieces.
S32 m_currentDepth
Current node's depth information.
Buffer m_emptyLineColors
Buffer holding line colors of empty boxes as quad primitives.
Mat4f setVGXform(const Mat4f &m)
void setDefaultFont(void)
U32 m_nodeColor
Color of the current node.
FW_CUDA_FUNC const Vec3f & max(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 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
String getTypeName() const
bool m_showEmpty
Flag whether to show empty nodes.
void draw(GLContext *gl, CameraControls &camera)
The method used to draw the current state of visualization to the OpenGL context. ...
S32 m_osahSplits[3]
Counters of the number of OSAH splits in the subtree under the set node in the x, y and z dimensions...
Buffer m_rays
Buffer holding some rays as line segments.
void moveDown()
Sets the node to be visualized to be the succesor of the currently visualized node on the set path...
Buffer & getVtxPosBuffer(void)
Returns vertex position buffer.
Vec2i drawLabel(const String &str, const Vec4f &pos, const Vec2f &align, U32 fgABGR, U32 bgABGR)
FW_CUDA_FUNC bool hit(void) const
U32 m_leftColor
Color of the left child of the current node.
Buffer m_emptyBoxes
Buffer holding empty boxes as quad primitives.
void moveUp()
Sets the node to be visualized to be the predecesor of the currently visualized node on the set path...
bool getOSAHChosen() const
void drawBuffer(Buffer &buffer, GLenum mode, int offset, U32 abgr)
void moveToRight()
Sets the node to be visualized to be the right child of the currently visualized node.
Vec2i getStringSize(const String &str)
Mat4f getWorldToClip(void) const
const Ray & getRayForSlot(S32 slot) const
Gets a ray assigned to a given slot.
const U8 * getPtr(S64 ofs=0)
S32 getNumBytes(void) const
void drawColorBuffer(Buffer &buffer, Buffer &color, GLenum mode, int offset)
bool m_splitColors
Flag whether to map left/right children colors based on the split type.
Mat4f xformFitToView(const Vec2f &pos, const Vec2f &size) const
bool m_showAllOSAH
Flag whether to show all OSAH split nodes.
SplitAxis getAxis() const
const T & getLast(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 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
void moveToLeft()
Sets the node to be visualized to be the left child of the currently visualized node.
void moveToSibling()
Sets the node to be visualized to be the sibling of the currently visualized node.
Buffer m_visTris
Buffer holding invisible selected triangles.
Ray buffer class. Stores rays.
FW_CUDA_FUNC T min(const VectorBase< T, L, S > &v)
FW_CUDA_FUNC T max(const VectorBase< T, L, S > &v)
void setFont(const String &name, int size, U32 style)
int getNumTriangles(void) const
String getAxisName() const
U32 m_rayColor
Color of the ray line indices.
Array< String > m_splitPath
Text representation of the VisualizationBVH::m_nodeStack path.
Mat4f xformMatchPixels(void) const
FW_CUDA_FUNC const Vec3f & min(void) const
String sprintf(const char *fmt,...)
void moveToParent()
Sets the node to be visualized to be the parent of the currently visualized node. ...
bool isVisible() const
Return whether the visualization renders its output.
VisualizationBVH(CudaBVH *bvh, Scene *scene, const Array< AABB > &emptyBoxes, const RayBuffer *rays=NULL, Buffer *visibility=NULL)
Constructor.
Class holding information about a split of a BVH node.
bool m_showRays
Flag whether to show the ray segments.
Buffer m_emptyColors
Buffer holding colors of empty boxes as quad primitives.
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 stride
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
U32 m_rightPrims
Number of primitives in the right child of the current node.
const RayResult & getResultForSlot(S32 slot) const
Gets a ray result assigned to a given slot.
virtual bool handleEvent(const Window::Event &ev)
Handles visualization events - key commands influencing the output.
bool m_showChildren
Flag whether to show children of the current node.
void drawBox(const Vec3f &min, const Vec3f &max, U32 abgr)
Buffer m_boxes
Buffer holding selected boxes as quad primitives.
T set(S idx, const T &item)
U32 m_rightColor
Color of the right child of the current node.
void getTriangleIndices(S32 node, Array< S32 > &indices)
const Vec2i & getViewSize(void) const
bool m_showCurrTris
Flag whether to show triangles of the current node.};.
void getNode(S32 node, SplitInfo *splitInfo, AABB &child0, AABB &child1, S32 &child0Addr, S32 &child1Addr)
const T * getPtr(S32idx=0) const
U32 m_siblingColor
Color of the sibling of the current node.
void resizeDiscard(S64 size)
U32 m_leftPrims
Number of primitives in the left child of the current node.
Array< S32 > m_visibility
Visibility of individual triangles.
~VisualizationBVH(void)
Destructor.
Buffer m_invisTris
Buffer holding visible selected triangles.
SplitType getType() const