现代 GLSL 中的每像素光照?

发布于 2024-09-24 06:27:56 字数 865 浏览 1 评论 0原文

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

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

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

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

我听说归一化可能发挥作用,但如果我归一化()vertex_normal它是相同的结果。

I'm looking for a proper simple example.

Right now I had something based on a tutorial but I don't see variations in the middle of the triangles. It appears each triangle changes color but only in whole.

out vec3 vertex_normal;         
out vec3 vertex_light_position; 

.. on the vertex shader.

with

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

                            )
                        )
                    );

and on fragment shader:

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

gl_FragColor =  out_Color * diffuse_value

But as I said, each triangle appears to be a solid color (that changes only in whole).

I heard that normalization may play a role but if I normalize() vertex_normal it's same result.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月朦胧 2024-10-01 06:27:56

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

gl_FragColor = vertex_normal

我不确定vertex_light_position是什么,但听起来它应该是正常< /em> 从顶点到光源,不是光源的绝对位置。

编辑:
请参阅 http://www.opengl.org/sdk/docs/tutorials /ClockworkCoders/lighting.php

Check your values for vertex_normal and vertex_light_position. You can do this by making the fragment shader do:

gl_FragColor = vertex_normal

I'm not sure what vertex_light_position is, but it sounds like it should be the normal from the vertex to the light, not the absolute position of the light.

EDIT:
See http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/lighting.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文