GLSL中如何实现phong阴影?
我正在在GLSL中实现Phong着色器进行分配,但是我没有得到相同的镜面反射。我理解它的方式与Gouraud阴影相同,但是您没有在顶点着色器中进行所有计算,而是在片段着色器中进行操作,以便您插入正常的插入器,然后在每个像素上应用Phong模型。作为作业的一部分,我还必须开发Gouraud着色器,并且可以按照预期的方式工作,我认为您只需要将Vertex着色器代码放入片段着色器中,但事实并非如此。
我在顶点着色器中进行的操作是,我只需将顶点位置转换为视图坐标,然后将模型视图矩阵的转置倒置对顶点正常。然后,在片段着色器中,我仅将视图转换到光位置,并使用这些坐标来计算phong模型中所需的向量几乎是正确的,但是缺少一些镜面光。所有参数均已测试,因此我认为这是错误的位置是错误的,但是我不知道为什么我的代码在另一个着色器中执行时无法工作。另外,我知道这不是最有效的方法(预计普通矩阵会更快),我只是想首先让它正常工作。
I am implementing a Phong Shader in GLSL for an assignment, but I don't get the same specular reflection as I should. The way I understood it, it's the same as Gouraud Shading, but instead of doing all the calculations in the vertex shader, you do them in the fragment shader, so that you interpolate the normals and then apply the phong model at each pixel. As part of the assignment I had to develop also the Gouraud shader and that works as supposed and I thought you just needed to put the vertex shader code into the fragment shader, but that doesn't seem to be the case.
What I do in the vertex shader is that I simply transform the vertex position into view coordinates and I apply the transpose inverse of the model view matrix to the vertex normal. Then, in the fragment shader I apply just the view transform to the light position and use these coordinates to calculate the vectors needed in the Phong model The lighting is almost correct, but some specular light is missing. All the parameters have been tested, so I would assume it's the light's position that is wrong, however I have no idea why my code wouldn't work when it does so in the other shader. Also, I know this isn't the most efficient way of doing it (pre-computing the normal matrix would be faster), I'm just trying to first get it to work properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是如何计算光源位置的方式。以下代码
将光视为方向(通过将其标准化,并且因为忽略了视图矩阵的翻译部分),但实际上是一个位置。正确的代码应该是类似的
The problem is the way how the light source position is calculated. The following code
treats light as a direction (by normalizing it and because the translation part of the view matrix is ignored), but it actually is a position. The correct code should be something like