4

我正在寻找一个适当的简单示例。

现在我有一些基于教程的东西,但我没有看到三角形中间的变化。看起来每个三角形都会改变颜色,但只是整体改变。

out vec3 vertex_normal;         
out vec3 vertex_light_position; 

..在顶点着色器上。

vertex_normal = normalize(NormalMatrix * in_Normal);

// old gl_NormalMatrix: "transpose of the inverse of the upper
// leftmost 3x3 of gl_ModelViewMatrix"

mat3 NormalMatrix = transpose(
                        inverse(
                            mat3(

                                ModelViewMatrix

                            )
                        )
                    );

在片段着色器上:

float diffuse_value = MAX(dot(vertex_normal, vertex_light_position), 0.0);

gl_FragColor =  out_Color * diffuse_value

但正如我所说,每个三角形似乎都是纯色(仅整体变化)。

我听说规范化可能会起作用,但如果我 normalize() vertex_normal 它是相同的结果。

4

1 回答 1

4

检查vertex_normal和的值vertex_light_position。您可以通过使片段着色器执行以下操作来做到这一点:

gl_FragColor = vertex_normal

我不确定是什么vertex_light_position,但听起来应该是从顶点到灯光的法线,而不是灯光的绝对位置。

编辑:见http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/lighting.php

于 2010-09-17T21:33:28.893 回答