dipityPix app

Wednesday, October 17, 2007

Ray tree pruning

A time honored way to speed up your glass is to do "ray tree pruning" and you should do it if you aren't already. The way Whitted originally implemented his paper was like this:

color trace(ray r, depth d)
color c
if (r hits scene at point p)
c = direct_light(p)
if (depth < maxdepth)
c += ks*trace(reflected_ray) + kt*trace(refracted_ray)
else
c = background(r)
return c

If you hit glass that will be two branches per recursion level. The first efficiency improvement would be to only send the rays if ks and kt are non-zero. But that would not help you for glass. Instead, you need to kill whole paths down the recursion tree once they are sufficiently attenuated. For example, if kt=0.05, then after 3 transmissions the coefficient is (0.05)^3 and can be ignored. To implement this, you need to change the call to include an attenuation argument:

color trace(ray r, depth d, float atten)

and add

if (depth < maxdepth)
if (atten*ks.max_component() < maxatten)
c += ks*trace(refected_ray, atten*ks.max_component())
if (atten*kt.max_component() < maxatten)
c += kt*trace(refracted_ray, atten*kt.max_component())

You will be amazed at how much faster a scene like Whitted's glass ball is.

7 comments:

Adrian said...

If you're clipping based on attenuation, then why even bother with the depth limit on the recursion?

In my ray tracer, I've replaced the depth limit with an attenuation term rather than adding one. Works as long as you don't have a fluorescent material that "amplifies" the light.

Peter Shirley said...

Hi Adrian.

In real physics I agree, but in a program I think you should plan for a ray to sneak inside an object or to get some floating point error that allows it to internally reflect until your stack overflows. If the viewer chose a viewpoint inside a glass ball I think this would even happen for some viewpoints without a bug! Of course, if you always added some exponential attenuation that might accomplish the same thing as max depth.

Another reason for max_depth-- good for approximate fast renderings.

Thomas said...

the way i'd do glass is to first compute the fresnel coefficients for reflection and refraction, and probabilistically do one based on that.

Michael said...

Using just a single attenuation value is probably not the best way to do this. Imagine a fully red glass (color 1,0,0) in front of a blue glass (color 0,0,1). Always using the max component won´t kill the ray at all while using the max component of the product of the colors will kill the ray instantly.

Eric said...

Yes, this one's a big win. I believe it was first mentioned in:

A Testbed for Realistic Image Synthesis, R. A. Hall, D. P. Greenberg, IEEE Computer Graphics & Applications, 3(), November 1983, pp. 10-20.

(Or it was in Hall's thesis.)

Eric

sexy said...

情趣用品,情趣用品,情趣用品,情趣用品,情趣用品,情趣用品,情趣用品,情趣用品,情趣,情趣,情趣,情趣,情趣,情趣,情趣,情趣,A片,視訊聊天室,聊天室,視訊,視訊聊天室,080苗栗人聊天室,上班族聊天室,成人聊天室,中部人聊天室,一夜情聊天室,情色聊天室,視訊交友網a片,a片


免費A片,AV女優,美女視訊,情色交友,免費AV,色情網站,辣妹視訊,美女交友,色情影片,成人影片,成人網站,A片,H漫,18成人,成人圖片,成人漫畫,情色網,日本A片,免費A片下載,性愛

A片,色情,成人,做愛,情色文學,A片下載,色情遊戲,色情影片,色情聊天室,情色電影,免費視訊,免費視訊聊天,免費視訊聊天室,一葉情貼圖片區,情色,情色視訊,免費成人影片,視訊交友,視訊聊天,視訊聊天室,言情小說,愛情小說,AIO,AV片,A漫,avdvd,聊天室,自拍,情色論壇,視訊美女,AV成人網,色情A片,SEX,成人論壇

情趣用品,A片,免費A片,AV女優,美女視訊,情色交友,色情網站,免費AV,辣妹視訊,美女交友,色情影片,成人網站,H漫,18成人,成人圖片,成人漫畫,成人影片,情色網


情趣用品,A片,免費A片,日本A片,A片下載,線上A片,成人電影,嘟嘟成人網,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,微風成人區,成人文章,成人影城,情色,情色貼圖,色情聊天室,情色視訊,情色文學,色情小說,情色小說,臺灣情色網,色情,情色電影,色情遊戲,嘟嘟情人色網,麗的色遊戲,情色論壇,色情網站,一葉情貼圖片區,做愛,性愛,美女視訊,辣妹視訊,視訊聊天室,視訊交友網,免費視訊聊天,美女交友,做愛影片

av,情趣用品,a片,成人電影,微風成人,嘟嘟成人網,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,成人文章,成人影城,愛情公寓,情色,情色貼圖,色情聊天室,情色視訊,情色文學,色情小說,情色小說,色情,寄情築園小遊戲,情色電影,aio,av女優,AV,免費A片,日本a片,美女視訊,辣妹視訊,聊天室,美女交友,成人光碟

情趣用品.A片,情色,情色貼圖,色情聊天室,情色視訊,情色文學,色情小說,情色小說,色情,寄情築園小遊戲,情色電影,色情遊戲,色情網站,聊天室,ut聊天室,豆豆聊天室,美女視訊,辣妹視訊,視訊聊天室,視訊交友網,免費視訊聊天,免費A片,日本a片,a片下載,線上a片,av女優,av,成人電影,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,成人文章,成人影城,成人網站,自拍,尋夢園聊天室

Entertainment said...

home city trung kính

http://homecitytrungkinh.com.vn/

home city

http://homecitytrungkinh.com.vn/tong-quan-du-an-home-city/

chung cư trung kính

http://homecitytrungkinh.com.vn/mat-bang-can-ho-chung-cu-trung-kinh/

trung kính complex

http://homecitytrungkinh.com.vn/tien-ich-trung-kinh-complex/

5S Online - mùa 3 - Tập 66: Tình cậu duyên anh - Phần 1

5S Online - mùa 3 - Tập 65: Con nuôi sếp tổng - Phần 2

5S Online - mùa 3 - Tập 64: Con nuôi sếp tổng - Phần 1

5S Online - mùa 3 - Tập 63: Cắt đuôi sao cho xuôi - Phần 3

5S Online - mùa 3 - Tập 62: Cắt đuôi sao cho xuôi - Phần 2

5S Online - mùa 3 - Tập 61: Cắt đuôi sao cho xuôi - Phần 1

5S Online - Tập 54: Làm giàu quá khó cần có vận may - Phần 3

5S Online - Tập 53: Làm giàu quá khó cần có vận may - Phần 2

5S Online - Tập 52: Làm giàu quá khó cần có vận may - Phần 1

chung cư t&t riverside

chung cư 440 vĩnh hưng

chung cư t&t riverside 440 vĩnh hưng

bat dong san

bat dong san cho thue

bat dong san ban