A Scene-Graph based Ray Tracer (3) – Light model, Anti-Aliasing, Ray-tracing

This article will cover all graphical topics that are essential for the ray-tracer.

[Light Model]

I adopt the OpenGL light model (Phong Model):

color = emission(material) + ambient(light)*ambient(material) + SUM[0, light-num.-1]( (1 / (k(const)+k(linear)*d+k(quadratic)*d^2) * factor(spot-light) * (ambient(light)*ambient(material) + max(L.N, 0)*diffuse(light)*diffuse(material) + max(S.N, 0)^shininess * specular(light) * specular(material) ) ) )

Don’t forget to clamp the color between 0 and 1.

I also involve the shadow judgment within the light model implementation. When enumerating all lights, the code will judge whether the current ray could reach the light or not.

[Anti-Aliasing]

If we project only one ray for each pixel, there will be aliasing. Jaggies will happen among the pixels as below:

I use the multi-sampling to do anti-aliasing. For each pixel, I have projected 9 rays (3*3) and an average value has been calculated upon the 9 values sampled. Note: the deviation among the rays cannot be too large or the image would be blured obviously. See the anti-aliased image:

It looks more elegent right?

[Ray-tracing]


It is not hard to understand the process. When a ray reaches one opaque object, an reflected ray will be calculated and another ray (from the hit point with the reflected ray) will be projected again. It is a recursive process, which will stop when no objects are hit or max tracing depth has been reached. The color from reflected ray will be combined with local color of the hit object.

Here the tracing depth matters. As the first picture above, you cannot see the mirror image on the sphere from the mirror – it is because the tracing depth is only 2. The original ray takes one, and the reflected ray from the mirror takes the other one. But if we increase the tracing depth to 3, you can see the reflected image on the sphere from the mirror, as the second image shown.

[Another scene]

[Future Work]

* Transparent objects implemented. (refraction)

* Texture enabled. Then the scene will be much better.
* Using GPU… It is too slow for rendering the scene with many objects and lights.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值