gveaf
gveaf

Reputation: 1

coloring transparent objects

I have problem with ray tracing. I could not put color of the transparent object to the file. Transparent object is seen as white. What is wrong ? Did I forget something in algorithm ?

Note : I could not upload image to stackoverflow because my reputation.

trace ( ray ) 
   intersect with objects
   for each light 
       if ( object in shadow )
              colour = black
       else
              diffuse 
              specular
   ambient
   color += trace ( reflect_ray )
   if ( object is transparent )
        color += trace ( transparent_ray )

Upvotes: 0

Views: 168

Answers (1)

Peter Alexander
Peter Alexander

Reputation: 54290

You don't want to directly add the transparent ray, you need to blend it.

color = opacity * color + (1 - opacity) * trace( transparent_ray )

opacity defines how opaque the object is. A fully opaque object (opacity = 1) is not at all transparent, so the transparent ray will not affect the color. A fully transparent object (opacity = 0), such as air, or glass (almost) will not be affected by the object's color, so the color of the ray is just the color of the transparent ray.

Upvotes: 1

Related Questions