I’m programming a ray tracer utilizing oxide and opengl, I’ve already made the ray observe I made a decision to implement a BVH tree (I haven’t got a lot expertise with these constructions), the code turned actually fallacious! Particularly:
The 3D mannequin is in place (0.0.0) within the 3D house, for some cause, once I look from one of many angles, there are triangles that don’t seem … however they seem once I take a look at the mannequin from the opposite facet of the angle X:
At first, I assumed it was a mistake in the way in which the triangles had been organized throughout the BVH, earlier than studying one of many vertices of the triangle to establish whether or not or not it was inside a field … I did this pondering that sooner or later , As I might use fashions with a greater triangles distribution, I might not want smaller packing containers than the triangles … however then I modified the system through which I uncover the AABB of the triangle and confirm if some a part of it’s contained in the field.
However that didn’t change something, so I assumed it might be an error in compensation for the dimensions of the packing containers, as a result of when a field shall be divided, as an alternative of creating an ideal division of the field, I made it divide it and broaden the image a bit to A facet that reduce with a small displacement … whatever the worth you set, the error nonetheless persists.
However that didn’t change something. Then I assumed it might be an error within the displacement of the dimensions of the packing containers, as a result of when a field shall be divided, as an alternative of creating an ideal division of the field, I made it divide and broaden the field a little bit to let it reduce it with a small Displacement … Whatever the worth you set, the error nonetheless persists.
Then, lastly, I assumed the error have to be within the perform that you just use contained in the shador to confirm if the lightning hits the field … and but, I couldn’t make it work.
I believe the error will not be within the perform decided by the AABB as a result of once I made the shador merely draw the work, they all the time come out with the correct format:
float rayIntersectsAABB(vec3 rayOrigin, vec3 rayDir, vec3 boxMin, vec3 boxMax){
vec3 invDir;
invDir.x = 1.0 / (abs(rayDir.x) 0.0) return tNear;
return -1.0;
}
However I believe there’s something fallacious in the way in which BVH and illustration course of:
float mrtd = 1e30;
// Ray Tracer
int stack(1024);
int stackPtr = 0;
stack(stackPtr++) = 0;
whereas(stackPtr > 0){
int nindex = stack(--stackPtr);
if(rayIntersectsAABB(ro,rd,pontomenor(nindex).xyz,pontomaior(nindex).xyz) != -1.0){
proc += 1.0;
if(pontomenor(nindex).a != -1.0){ // Nó Folha com Triângulos
for(int j = int(pontomenor(nindex).a); j 0.0 && rtd
Take into account that once I make a easy illustration (with out utilizing BVH), the mannequin is completely represented, however it is vitally heavy. So, the mannequin knowledge is appropriate, what I did in my code for many who have doubts, as a result of I loaded the 3D mannequin, I created a BVH tree based mostly on the house occupied by the vertices of the mannequin, then I distributed the triangles by the BVH And on the identical time I despatched a STD430 SSBO with solely 2 neighbor, one with the smallest level of the field and the opposite with the biggest level within the block, however the fourth worth of the primary neighbor4 is the triangle quantity indices to Ignore, the fourth worth of the second neighbor4 is the variety of triangles that shall be verified, I reorganized the mannequin triangles in order that it could actually confirm the information rapidly. If an image reveals nothing, obtain a -1.0 in each values. However so far as I do know, I’ve reviewed this knowledge lots and it appears to be appropriate, when the triangles rely throughout the BVH, none of them is repeated, the quantity inside is identical because the mannequin earlier than. It was positioned there … so I believe the error is in the way in which the illustration course of. There are 5850 triangles in complete, does anybody who scheduled a Ray Tracer program know what is going on?