Ray Tracing(Ray creation and sphere intersection)
Hi,
I am trying to implement a simple ray tracer. I only want to draw spheres. I have a problem with translations. I can correctly draw a sphere which is centered at the origin. But when I translate along any direction, it is projected as an ellipsoid instead of a circle on the screen. I tried generating rays in the viewer coordinate and transforming to the world coordinate. Can anyone help me?
I was actually about to ask this question too, I'm getting the exact same problem. If the sphere is not in the center of the view, it either gets stretched out into an ellipsoid vertically or horizontally, depending on where its translated. I'm guessing it has something to do with perspective that needs to be adjusted but I'm not really sure whats up...help!!? please...
Perspective has nothing to do with anything.
You don't have to apply perspective transformation. Create rays from the eye point to the pixel, you want to color. That's all, it will produce perspective, just like in real life. And I don't understand how you apply transformation to the spheres. You can transform the coordinates of the center. But how do you transform the radius?
R = initial_r*scale_factor. There aren't any orientations in that.
I have a guess that you are learning from tutorials. Someone should write a decent tutorial someday, and a sticky should be made from it.
Post codes too, so we can help instead of guessing.
You don't have to apply perspective transformation. Create rays from the eye point to the pixel, you want to color. That's all, it will produce perspective, just like in real life. And I don't understand how you apply transformation to the spheres. You can transform the coordinates of the center. But how do you transform the radius?
R = initial_r*scale_factor. There aren't any orientations in that.
I have a guess that you are learning from tutorials. Someone should write a decent tutorial someday, and a sticky should be made from it.
Post codes too, so we can help instead of guessing.
First of all, how are you implementing the translation? The best way, in my opinion, is to apply the inverse of the translation to the rays (in case you don't already do it this way). More generally, you multiply the ray with the inverse of the transformation you want to apply to your sphere. This way, you only need a "formula" for checking intersection between an arbitrary ray and the unit sphere.
Also, what's your field of view? If you translate a sphere along the x-axis, it will be rendered as an ellipse, that's just a result of perspective. However, the effect shouldnt be very prominent. I remember I had this problem when I first tried out raytracing and, indeed, there was something wrong with my FOV or something like that.
Also, what's your field of view? If you translate a sphere along the x-axis, it will be rendered as an ellipse, that's just a result of perspective. However, the effect shouldnt be very prominent. I remember I had this problem when I first tried out raytracing and, indeed, there was something wrong with my FOV or something like that.
This is perfectly normal. It's part of the perspective transformation and even your eyes do it. You just don't notice because the objects that are stretched appear towards the edge of your field of view where they appear blurry. If you look at a traditional rasteriser you'll notice that the same stretching occurs.
zurekx and _Sauce_ are right: When using perspective projection, then in general the ray-sphere intersections just at the "seen" silhouette of the sphere are neither all parallel to the projection plane nor in a plane at all. Hence their depth component varies, and hence they show different depth shortenings. The silhouette appears egg-like. If the sphere is centered on the line-of-view, then the hit points actually lie on a plane parallel to the projection plane, and the sphere's silhouette appears as a circle.
You can check whether it is your translation code or not by implementing orthogonal projection as well. The method I've used in those days was (1) generate the ray in camera space, (2) transform the ray into world space, (3) check the ray-object hit by transforming the ray into model space. In model space the sphere is centered on the local origin. This is senseful for the implicitly given sphere surface anyway.
You can check whether it is your translation code or not by implementing orthogonal projection as well. The method I've used in those days was (1) generate the ray in camera space, (2) transform the ray into world space, (3) check the ray-object hit by transforming the ray into model space. In model space the sphere is centered on the local origin. This is senseful for the implicitly given sphere surface anyway.
Quote:Original post by haegarrIn fact, the silhouette should be an ellipse, since the rays sweeping the sphere sweep a cone aswell. And the intersection curve of a cone and a plane is an ellipsis(parabola/hyperbola/2-crossing-lines)
The silhouette appears egg-like.
And for the eye: a sphere always looks like a circle even at the edge of the field of view (or the distortion is negligible).
But, since you have to project the stuff to a screen, it will appear as an ellipse, but if you look at that ellipse from the desired point of view (which you use as the ray origin), it will distort back to a circle due to perspective.
So for the OP, maybe you apply two wide field of view, that's why the unnatural look.
All of the above seem to apply now that I looked at it again. I really should have easily realized pulling back the camera from the screen plane would have suppressed the distortion :/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement