File indexing completed on 2026-04-09 07:49:01
0001 #include "scuda.h"
0002 #include "sqat4.h"
0003
0004 #include <optix_device.h>
0005
0006 #define DEBUG6 1
0007 #include "csg_intersect_leaf.h"
0008 #include "csg_intersect_node.h"
0009 #include "csg_intersect_tree.h"
0010
0011 #include "CSGPrim.h"
0012 #include "CSGNode.h"
0013
0014 rtDeclareVariable(optix::Ray, ray, rtCurrentRay, );
0015
0016 rtDeclareVariable(float3, position, attribute position, );
0017 rtDeclareVariable(float3, shading_normal, attribute shading_normal, );
0018 rtDeclareVariable(unsigned, intersect_identity, attribute intersect_identity, );
0019
0020 rtDeclareVariable(unsigned, identity, ,);
0021
0022
0023
0024
0025 rtBuffer<CSGPrim> prim_buffer;
0026
0027
0028 rtBuffer<CSGNode> node_buffer;
0029 rtBuffer<qat4> itra_buffer;
0030 rtBuffer<float4> plan_buffer;
0031
0032
0033
0034
0035
0036
0037
0038 RT_PROGRAM void intersect(int primIdx)
0039 {
0040 const CSGPrim* prim = &prim_buffer[primIdx] ;
0041 int nodeOffset = prim->nodeOffset() ;
0042 const CSGNode* node = &node_buffer[nodeOffset] ;
0043 const float4* plan = &plan_buffer[0] ;
0044 const qat4* itra = &itra_buffer[0] ;
0045
0046 float4 isect ;
0047 bool valid_isect = intersect_prim(isect, node, plan, itra, ray.tmin , ray.origin, ray.direction ) ;
0048
0049 #ifdef DEBUG_SIX
0050 rtPrintf("//SIX/geo_OptiXTest.cu:intersect identity %d primIdx %d nodeOffset %d valid_isect %d isect.w %10.4f \n",
0051 identity, primIdx, nodeOffset, valid_isect, isect.w );
0052 #endif
0053
0054 if(valid_isect)
0055 {
0056 if(rtPotentialIntersection(isect.w))
0057 {
0058 position = ray.origin + isect.w*ray.direction ;
0059 shading_normal = make_float3( isect.x, isect.y, isect.z );
0060 intersect_identity = (( (1u+primIdx) & 0xff ) << 24 ) | ( identity & 0x00ffffff ) ;
0061 rtReportIntersection(0);
0062 }
0063 }
0064 }
0065
0066 RT_PROGRAM void bounds (int primIdx, float result[6])
0067 {
0068 const CSGPrim* prim = &prim_buffer[primIdx] ;
0069 int nodeOffset = prim->nodeOffset() ;
0070 const float* aabb = prim->AABB();
0071
0072 result[0] = *(aabb+0);
0073 result[1] = *(aabb+1);
0074 result[2] = *(aabb+2);
0075 result[3] = *(aabb+3);
0076 result[4] = *(aabb+4);
0077 result[5] = *(aabb+5);
0078
0079 #ifdef DEBUG_SIX
0080 rtPrintf("//SIX/geo_OptiXTest.cu:bounds identity %d primIdx %d nodeOffset %d aabb %10.3f %10.3f %10.3f %10.3f %10.3f %10.3f \n",
0081 identity, primIdx, nodeOffset,
0082 result[0], result[1], result[2],
0083 result[3], result[4], result[5]
0084 );
0085 #endif
0086 }
0087
0088