How to compute reflected color?

2019-08-26 14:17发布

I'm trying to implement a simple physically-accurate raytracer. I have it working in grayscale (so with light intensities) but I'm struggling with colors.

How do I calculate relation between colored (non-white) light and the surface. Say the light color is rgb(1.0,0.9,0.8) and the surface is rgb(0.8,0.9,1.0)?

标签: raytracing
1条回答
不美不萌又怎样
2楼-- · 2019-08-26 14:19

In a very basic manner

Let's assume you've chosen the phong shading model or you've chosen not to do any specific shading.

  1. You need the scene's ambient coefficient (a coefficient that describes the overall intensitiy of the colors in the scene), let's say it's 0.3; And then multiply the object's color by the coefficient.
  2. Then you need to calculate the phong shading model or you just need the color of the object, w/o any special shading models.
  3. Then you need to calculate the color of the next object if your reflection vector hit any, again starting from step 1 (recursive)
  4. Sum all of the results

Code:

Color3 trace(..)
{
    ...
    Color3 ambient = object.color * 0.3;
    Color3 phong = phongModel(..) or object.color;
    Color3 reflection = trace(..);

    return ambient + phong + reflection;
}
查看更多
登录 后发表回答