我尝试从这里运行 SSDO 演示代码,但在我花了数小时寻找解决方案后,遇到了一些让我更加困惑的问题。尽管如此,现在我几乎可以肯定问题出在GLSL 版本上。
注意:
- 该演示使用
glew
和glut
。 - 我的环境是 15" MacBook Pro 2018 上的 Parallels Desktop 支持的 Windows 10 pro 上的 Microsoft Visual Studio Community 2019。
阶段1
在对代码进行任何修改之前,我收到了一堆错误消息:
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
,但只获得了非常有限的信息。然而,根据此信息,我暂时假设将其替换为texelFetch
会有所帮助,这需要GLSL 版本不少于 1.30,根据此页面。
第二阶段
所以我#version 130
在最开始添加了create_direct_light_buffer.frag
,错误信息变成了:
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
错误时,我发现了这篇文章,声称它varying
已被GLSL 版本 1.30in
或out
自GLSL 版本取代。
这是标题中的冲突。
我的期望
- 演示完全正确吗?
- 如果可以运行项目,我该怎么办?
由于我是 OpenGL 的新手,如果有人可以下载源代码并在他/她自己的计算机上尝试并告诉我如何解决,我将非常感激。
否则,如果一些经验丰富的专家可以就可能出现的问题或如何解决此问题给我一些一般性建议,我将同样感激。