How to compute reflected color?

纵饮孤独 提交于 2019-12-25 00:39:21

问题


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)?


回答1:


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;
}


来源:https://stackoverflow.com/questions/47865353/how-to-compute-reflected-color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!