从点积到浮点 RGB 0->1 的映射强度

mapping intensity from dot product to float RGB 0->1

我正在获取表面法线和光照位置的点积。奇怪的是点积大于 1。这是问题 1。

第二个问题是我想将强度从 0->1 映射到 Float RGB 从 0->1 这是我的代码

    if (the_object->polys[curr_poly].shading == 1)
            {

                // compute the dot product between the light source vector
                // and normal vector to surface

                dp = Dot_Product_3D((vector_3d_ptr)&normal,
                    (vector_3d_ptr)&light_source);

                // test if light ray is reflecting off surface

                if (dp > 0)
                {
                    // now cos 0 = (u.v)/|u||v| or

                    intensity = ambient_light + ( dp / (the_object->polys[curr_poly].normal_length));


                    float r = the_object->polys[curr_poly].color.R*intensity;
                    float g = the_object->polys[curr_poly].color.G*intensity;
                    float b = the_object->polys[curr_poly].color.B*intensity;
                    Color color = Color(r, g, b, 1);
}

我假设您了解什么是标量积,无论如何它们是 |a|*|b|*cos Θ。它们肯定会大于或小于 1,因为 cos Θ 最多为 1,将向量相乘,除非它们是单位向量,否则肯定会得出不同的数字。

此外,要在强度与 RGB 之间进行映射(如果 RGB 在标准的 0-255 范围内),乘以它对你没有多大帮助,你需要在范围之间对其进行归一化,如下所示:

(color / 255) * intensity

您还可以限制值之间的颜色,这样您就不会过度曝光或类似情况。

如果这没有帮助,请进一步澄清问题。 (我还不能发表评论,所以我尽量回答了)。