Jump to content
  • Advertisement
GreenGodDiary

3D [SOLVED] artifacts in Ray-OBB intersection test

Recommended Posts

SOLUTION: The problem seemed to be due to the different epsilon values (comparison value with dot-product) not being consistent throughout all tests. I realized this when I replaced them all with EPSILON being #defined. It still confuses me how that could generate those artifacts, though.

Hi, i wasnt sure where to post this but i suppose this is good enough


I'm implementing a bunch of Ray collision tests for a ray-tracer assignment for school.  All tests (plane, sphere, triangle) have worked fine but the OBB one gives weird results.

To test the ray in order to get the distance from the ray origin to the intersection I'm using the algorithm presented in Real-time Rendering, third edition (Three slabs method)

The actual intersection test seems to work fine, however when I'm calculating the normal for the intersection (in order to shade it), a lot of pixels seem to fail the tests and thus aren't shaded properly. 

Here's the code where I calculate this normal:

 

pointOnSurface = camPos + lastT*ray_dir.xyz; //world space position of intersection
			
obb_type o = obb_data[objIndex]; //Contains centre of box, basis vectors and half widths
vec4 arr[3] = {o.u_hu, o.v_hv, o.w_hw}; //xyz = basis, w = half width
vec3 normal; 

for (int i = 0; i < 3; i++) //for every basis vector
{
	//vector from pointOnSurface to middle of plane
    //If pointOnSurface is on the same plane we are testing, the dot product calculated
    //later will be close to 0
	vec3 planeVector = (o.centre.xyz + (arr[i].xyz * arr[i].w)) - pointOnSurface;

	float dotProduct = dot(planeVector, arr[i].xyz);
				
	if ( (dotProduct > -0.00001) && (dotProduct < 0.00001) )
	{
		normal = normalize(arr[i].xyz);
	}
	else //check other plane in slab (arr.xyz * -1.0)
	{
		vec3 planeVector = (o.centre.xyz - (arr[i].xyz * arr[i].w)) - pointOnSurface;
		dotProduct = dot(planeVector, arr[i].xyz);

		if ( (dotProduct > -0.000001) && (dotProduct < 0.000001) )
		{
			normal = normalize(arr[i].xyz * -1.0);
		}
	}
}
return shade(pointOnSurface, normal, obb_data[objIndex].colour.xyz);


As you can see, if the dot product is never close to 0, the normal is never changed with means shade() gets the wrong normal, creating the artifacts.
So, why does this test fail for so many pixels? I've tried changing the tolerance both up and down without success. There is always some significant error.

Worth noting is that for three of the planes on the box, the artifacts show up only when I zoom out very far. For the other three, they disappear when I get very close.

 

I'm really at a loss here...

 

Here's a snapshot of the box:

3d2faa57b0f780cfa97cb2f3a79c84fb.png

Edited by GreenGodDiary
solved

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
  • Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By CocoaColetto
      I am basically brand new to the gaming industry business wise although I have been a gamer for years. I officially started my game publishing company, and being as though I am only 20, I have no connects to the gaming industry. Of course, I'm still going to do more internet research, but I thought why not ask folks who may have business hands in the gaming community? If anyone is questioning, my game prototype is basically done (I designed it myself) and its very detailed and I am going to start searching for a team to help me build it. Thank you. 
    • By BearishSun
      bs::framework is a newly released, free and open-source C++ game development framework. It aims to provide a modern C++14 API & codebase, focus on high-end technologies comparable to commercial engine offerings and a highly optimized core capable of running demanding projects. Additionally it aims to offer a clean, simple architecture with lightweight implementations that allow the framework to be easily enhanced with new features and therefore be ready for future growth.
      Some of the currently available features include a physically based renderer based on Vulkan, DirectX and OpenGL, unified shading language, systems for animation, audio, GUI, physics, scripting, heavily multi-threaded core, full API documentation + user manuals, support for Windows, Linux and macOS and more.
      The next few updates are focusing on adding support for scripting languages like C#, Python and Lua, further enhancing the rendering fidelity and adding sub-systems for particle and terrain rendering.
      A complete editor based on the framework is also in development, currently available in pre-alpha stage.
      You can find out more information on www.bsframework.io.

      View full story
    • By BearishSun
      bs::framework is a newly released, free and open-source C++ game development framework. It aims to provide a modern C++14 API & codebase, focus on high-end technologies comparable to commercial engine offerings and a highly optimized core capable of running demanding projects. Additionally it aims to offer a clean, simple architecture with lightweight implementations that allow the framework to be easily enhanced with new features and therefore be ready for future growth.
      Some of the currently available features include a physically based renderer based on Vulkan, DirectX and OpenGL, unified shading language, systems for animation, audio, GUI, physics, scripting, heavily multi-threaded core, full API documentation + user manuals, support for Windows, Linux and macOS and more.
      The next few updates are focusing on adding support for scripting languages like C#, Python and Lua, further enhancing the rendering fidelity and adding sub-systems for particle and terrain rendering.
      A complete editor based on the framework is also in development, currently available in pre-alpha stage.
      You can find out more information on www.bsframework.io.
    • By recp
      Hello,
      How can I get center of scene or node or model? What is best way to do this? Scene structure:
      Scene   |   o - Node[s]            |            o - Model[s] // Mesh                       |                       o - Primitive[s] // Sub-Mesh                                    |                                    o local AABB and world AABB I'm using AABB's center as center of primitive and I'm combining all AABB boxes to build an AABB for scene. When I visualized the boxes it seems work as expected. 
      But I need to get center of scene, node or model for apply rotation around center. Because I'm using a trackball for rotating attached node or model. Currently I'm using scene's AABB's center as rotation point (pivot), for single object it is working. After rotation is completed center of primitive remains same which it should be, I think. But if I load a scene which contains multiple models or primitives, after rotation is completed center of scene's AABB is moving (I'm using that as center of scene). Because every time rotation is completed, new AABB is calculated for scene by combining all sub AABB boxes. I think this may be a normal because there is no balance between AABB boxes while rotating. For instance if I use two same CUBE without rotations center of new scene's AABB remains same.
      My solution (it seems work for now):
      I created new center member (vec3) in scene struct:
      scene->center    = vec3(0); scene->primCount = 0; for prim in primitivesInFrustum    scene->center += prim->aabb->center;    scene->primCount++; scene->center = scene->center / scene->primCount Now I'm using this center as center of scene instead of scene->aabb->center and it seems work.
      My question is that what is best way to get center of scene, node or model? How do you get the center for rotation? Any suggestions? Am I doing right? 
      Thanks
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!