【问题标题】:Per Pixel lighting in modern GLSL?现代 GLSL 中的每像素照明?
【发布时间】:2010-09-17 21:25:12
【问题描述】:

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

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

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 结果是一样的。

【问题讨论】:

    标签: opengl graphics opengl-3


    【解决方案1】:

    检查vertex_normalvertex_light_position 的值。您可以通过片段着色器来做到这一点:

    gl_FragColor = vertex_normal

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

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

    【讨论】:

    • 灯光位置基于旧的 gl_LightSource[0].position.xyz。有人告诉我那是一个静态光的位置。 [在我基于它的教程中使用了这种方式]
    • 好的,所以如果vertex_normalvertex_light_position 都是每个像素不变的,那么diffuse_value 将是每个像素不变的,并且你有平坦的阴影。
    • 有道理。那么发生了什么变化?这是简单的教程swiftless.com/tutorials/glsl/5_lighting_perpixel.html
    • 那个教程是错误的。 VS的第8行错了,导致FS的第7行错了。请参阅添加到我的答案中的教程。缺少的是您需要计算 L per-pixel,这是从灯光位置到插值顶点位置的法线。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-06
    相关资源
    最近更新 更多