A Scene-Graph based Ray Tracer (3) – Light model, Anti-Aliasing, Ray-tracing
来源:互联网 发布:淘宝怎么加售后服务 编辑:程序博客网 时间:2024/06/11 05:45
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.
- A Scene-Graph based Ray Tracer (3) – Light model, Anti-Aliasing, Ray-tracing
- A Scene-Graph based Ray Tracer (1) – Intro
- A Scene-Graph based Ray Tracer (2) – MFC, Scene Graph API, Maths
- Ray Tracing
- Ray Tracing
- Example 1 : A Single Sample Ray Tracer
- 【Ray Tracing in One Weekend】(ch6)Ray Tracer 里的反走样
- 我的ray tracer
- My refined Ray-tracer
- 读书笔记:Realistic Ray Tracing
- codeforce C. Ray Tracing
- C. Ray Tracing
- CUDA-Ray Tracing
- Ray Tracing Scenes Collection
- C. Ray Tracing
- 《Ray Tracing in One Weekend》——Chapter 3: Rays, a simple camera, and background
- simple ray tracer的实现
- [笔记]Ray Tracing with Cones
- 战争磨盘四:枪杆子里出政权
- 告别魔兽回忆篇之为你守候
- C#将数据导出到Execl的方法
- 毕业后的5年 决定你未来命运
- 最简单的Ajax入门例程
- A Scene-Graph based Ray Tracer (3) – Light model, Anti-Aliasing, Ray-tracing
- Excel导入Axapta 3.0
- 命名空间std详解
- 立志不随流俗转,用心学到古人难————网上答疑(34)
- 请客与谈判的学问 1
- 20091214-1221周计划
- 20091214日计划
- 网卡与路由速度不兼容,造成打不开网页
- 0-1背包问题(回溯法)