【发布时间】:2020-06-20 12:23:52
【问题描述】:
我尝试从here 运行 SSDO 演示代码,但在我花了数小时寻找解决方案后,遇到了一些让我更加困惑的问题。不过,现在我几乎可以肯定问题出在 GLSL 版本。
注意:
- 演示使用
glew和glut。 - 我的环境是 15 英寸 MacBook Pro 2018 上的 Parallels Desktop 支持的 Windows 10 pro 上的 Microsoft Visual Studio Community 2019。
第一阶段
在对代码进行任何修改之前,我收到了一堆错误消息:
ERROR: 0:15: Invalid call of undeclared identifier 'texelFetch2D'
ERROR: 0:16: Invalid call of undeclared identifier 'texelFetch2D'
ERROR: 0:17: Invalid call of undeclared identifier 'texelFetch2D'
ERROR: 0:19: Use of undeclared identifier 'pixelPosition'
ERROR: 0:20: Use of undeclared identifier 'lightVector'
ERROR: 0:21: Use of undeclared identifier 'lightVector'
ERROR: 0:21: Use of undeclared identifier 'lightDistance'
ERROR: 0:23: Use of undeclared identifier 'pixelNormal'
ERROR: 0:24: Use of undeclared identifier 'pixelNormal'
ERROR: 0:24: Use of undeclared identifier 'pixelNormal'
ERROR: 0:25: Use of undeclared identifier 'lightDir'
ERROR: 0:25: Use of undeclared identifier 'pixelNormal'
ERROR: 0:27: Use of undeclared identifier 'cosAlpha'
ERROR: 0:27: Use of undeclared identifier 'pixelReflectance'
ERROR: 0:32: Use of undeclared identifier 'diffuseColor'
ERROR: One or more attached shaders not successfully compiled
...
其他着色器的消息也类似。
相应地,上面显示的错误消息与create_direct_light_buffer.frag有关:
varying vec4 position;
varying vec3 normal;
uniform vec4 lightPosition;
uniform vec4 lightColor;
uniform sampler2D positionTexture;
uniform sampler2D normalTexture;
uniform sampler2D reflectanceTexture;
void main()
{
vec4 pixelPosition = texelFetch2D(positionTexture, ivec2(gl_FragCoord.xy), 0);
vec4 pixelNormal = texelFetch2D(normalTexture, ivec2(gl_FragCoord.xy), 0);
vec4 pixelReflectance = texelFetch2D(reflectanceTexture, ivec2(gl_FragCoord.xy), 0);
vec3 lightVector = lightPosition.xyz - pixelPosition.xyz; // vector to light source
float lightDistance = length(lightVector); // distance to light source
vec3 lightDir = lightVector / lightDistance; // normalized vector to light source
pixelNormal.w = 0.0;
pixelNormal = normalize(pixelNormal);
float cosAlpha = max(0.0, dot(lightDir.xyz, pixelNormal.xyz));
vec4 diffuseColor = vec4(cosAlpha) * pixelReflectance;
// vec4 ambientColor = vec4(0.2, 0.2, 0.2, 1.0);
// diffuseColor += ambientColor;
gl_FragColor = diffuseColor;
gl_FragColor.a = 1.0;
}
显然我搜索了texelFetch2D,但获得的信息非常有限。然而,根据this page 的说法,根据信息,我暂时假设将其替换为texelFetch 会有所帮助,这需要GLSL 版本不低于1.30。
第二阶段
于是我在create_direct_light_buffer.frag的最开始加了#version 130,错误信息变成了:
ERROR: 0:1: '' : version '130' is not supported
ERROR: One or more attached shaders not successfully compiled
...
然后我采纳@flyx的建议,在main函数中添加指定版本:
glutInitContextVersion(3, 2);
glutInitContextProfile(GLUT_CORE_PROFILE);
我开始迷路了。
第三阶段
错误信息变成:
WARNING: Could not find vertex shader attribute 'PRLGLSL_MultiTexCoord5' to match BindAttributeLocation request.
WARNING: Could not find vertex shader attribute 'PRLGLSL_MultiTexCoord6' to match BindAttributeLocation request.
WARNING: Could not find vertex shader attribute 'PRLGLSL_MultiTexCoord0' to match BindAttributeLocation request.
WARNING: Could not find vertex shader attribute 'PRLGLSL_SecondaryColor' to match BindAttributeLocation request.
WARNING: Could not find vertex shader attribute 'PRLGLSL_MultiTexCoord4' to match BindAttributeLocation request.
WARNING: Could not find vertex shader attribute 'PRLGLSL_MultiTexCoord7' to match BindAttributeLocation request.
WARNING: Could not find vertex shader attribute 'PRLGLSL_FogCoord' to match BindAttributeLocation request.
WARNING: Could not find vertex shader attribute 'PRLGLSL_MultiTexCoord1' to match BindAttributeLocation request.
WARNING: Could not find vertex shader attribute 'PRLGLSL_MultiTexCoord3' to match BindAttributeLocation request.
WARNING: Could not find vertex shader attribute 'PRLGLSL_MultiTexCoord2' to match BindAttributeLocation request.
C
ERROR: 0:2: 'varying' : syntax error: syntax error
ERROR: One or more attached shaders not successfully compiled
...
这些警告似乎与create_direct_light_buffer.frag无关,而且我找不到任何关于它们的问题和解决方案,所以我就放了它们。
当我试图找出varying 错误时,我发现this post,它声称varying 被in 或out 替换,因为GLSL 版本1.30。
这是标题中的冲突。
我的期望
- 演示是否正确?
- 如果可以运行项目,我该怎么办?
由于我是 OpenGL 新手,如果有人可以下载 source code 在他/她自己的计算机上试用并告诉我如何解决,我将非常感激。
否则,如果一些经验丰富的专家可以就可能出现的问题或如何解决此问题给我一些一般性建议,我将同样感激。
【问题讨论】:
标签: c++ opengl glsl shader ssao