Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Max_Payne

Raytracing strategy

This topic is 5409 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I currently have my raytracing system set up so that rays can never hit backfaces. This has the advantage that a reflected ray can never have a hit detected at the surface it was reflected from. However, it has the annoying aspect that if I want to do refraction, things wont work. Its a fact, if I define a transparent sphere for example, when a ray is to be refracted through it, it wont find an exiting point in the sphere, because when it goes through the sphere, the exit point would be considered a back face. For a cube, I would have to define 12 faces instead of 6. Of course, there is a "solution" to this problem, in that you can simply forbid intersection tests that happen at a small distance, but then that doesnt work when floating point precision limits are reached, and for very close objects, it gives you no intersection. To overcome this, I have remembered that some people use a raytracing function that takes an origin object parameter. This seems like it would fix the problem for a cube... But for a sphere, it still wouldnt work. There are several possible solutions, but they all seem quite annoying. So I ask another question: What are your favorite ways around this problem?

Looking for a serious game project?
www.xgameproject.com

Share this post


Link to post
Share on other sites
Advertisement
If your objects don''t intersect, then you could just flip the front/back ignore when you enter an object for refraction purposes, so that it will only intersect back faces and not front-faces when tracing the ray through the object, essentially flipping the behavior based on whether the ray is meant to go inside or outside of an object. You could do this only for the "current" object if you do have object intersections, or things like a glass sphere with a metal sphere inside it.

Share this post


Link to post
Share on other sites
Your solution is good. Think about it: How often is there an intersection you''d actually want at such a close distance? By close, it''s a small decimal, probably in the range of .01 (maybe even smaller, you''d have to do some testing), just to account for floating point error and such. Secondly, you only need to do the distance check on the object you just intersected, so other close objects won''t be affeted. Most importantly, any visual artifacts you get from this are going to be extremely rare, so they won''t really affect the image quality.

tj963

Share this post


Link to post
Share on other sites
In response to Assassin''s idea, it''s pretty good. The problem comes if you start overlapping objects, for example for CSG. Also, the same errors you''re tring to avoid could also happen when two objects are lying right beside each other because you enter the other object befroe exiting the current due to inaccuracies. But as I said before, I wouldn''t even worry about it unless it''s actually a problem.

tj963

Share this post


Link to post
Share on other sites
quote:
Original post by Assassin
If your objects don''t intersect, then you could just flip the front/back ignore when you enter an object for refraction purposes, so that it will only intersect back faces and not front-faces when tracing the ray through the object, essentially flipping the behavior based on whether the ray is meant to go inside or outside of an object. You could do this only for the "current" object if you do have object intersections, or things like a glass sphere with a metal sphere inside it.


What I don''t like with that is that rays become less general, every raytracing function, for every object, has to have this option to flip back faces... etc...

quote:
Your solution is good. Think about it: How often is there an intersection you''d actually want at such a close distance? By close, it''s a small decimal, probably in the range of .01 (maybe even smaller, you''d have to do some testing), just to account for floating point error and such. Secondly, you only need to do the distance check on the object you just intersected, so other close objects won''t be affeted. Most importantly, any visual artifacts you get from this are going to be extremely rare, so they won''t really affect the image quality.


I don''t really like that idea, it doesnt work for close view, and .01 with my current scale is 1 centimerer, which is noticeable.



Looking for a serious game project?
www.xgameproject.com

Share this post


Link to post
Share on other sites
For ray,you have to store current refraction index , array with indexes of solid objects it has been entered and what surface it touched last time. Voila.

edit: I mean,you need refraction index if you want to have refractions; you need indexes of solid objects it have been entered if you want to do CSG; and you always need last surface.


...

[edited by - Dmytry on February 26, 2004 5:53:40 PM]

Share this post


Link to post
Share on other sites
work with a relative error instead of an absolute one.




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!