我试图从这里运行SSDO演示代码,但在花了几个小时寻找解决方案后,遇到了一些问题,这些问题让我更加困惑。尽管如此,现在我几乎可以肯定问题出在GLSL版本上。
注意:
- 演示使用
glew
和glut
- 我的环境是由Parallels Desktop支持的Windows 10 pro上的Microsoft Visual Studio Community 2019;MacBook Pro 2018
第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
替换它会有所帮助,根据本页,这需要不低于1.30的GLSL版本。
第2阶段
所以我在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);
我开始迷路了。
第3阶段
错误消息变成:
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
被in
或out
取代,因为GLSL版本1.30。
这就是标题中的冲突。
我的期望
- 演示是否正确
- 如果可以运行该项目,我该怎么办
由于我是OpenGL的新手,如果有人能下载源代码在他/她自己的电脑上试用并告诉我如何计算,我将不胜感激
否则,如果一些经验丰富的专家能就可能出现的问题或如何解决这个问题给我一些一般性的建议,我也会感激不尽。
- 演示是否正确
否。让我们看看这里的一些细节:
第1阶段
显然我搜索了
texelFetch2D
,但获得的信息非常有限信息然而,根据这些信息,我暂时假设用texelFetch
替换它会有所帮助,因为它需要GLSL版本不低于1.30。
texelFetch2D
在标准GLSL中不存在。它是GL_EXT_gpu_shader4
扩展中引入的一个函数,从未直接进入核心GL功能。从概念上讲,当使用GLSL 130或更高版本时,texelFetch
是正确的替代品。
尽管该着色器可能在某些实现中编译,但它没有任何标准的备份,也不应该被认为是有效的。
有趣的是,在SSBO.frag
中,演示程序正确地请求了该扩展,因此代码应该在支持该扩展的实现上工作:
#version 120 #extension GL_EXT_gpu_shader4 : enable
仅仅切换到#version 130
也不起作用,因为您必须将整个着色器重写为GLSL 130语法,其中许多细节已经更改(例如,varyings
被更通用的in
/out
方案取代)。
阶段2和第3阶段
然后我接受了@flyx的建议,在主函数中添加了版本:
glutInitContextVersion(3, 2); glutInitContextProfile(GLUT_CORE_PROFILE);
那行不通。在核心配置文件OpenGL中,所有不推荐使用的遗留功能都不可用,该教程在很大程度上依赖于这些不推荐使用功能。这将需要一个重大的重写,使这段代码与核心配置文件OpenGL一起工作。
但是:
我的环境是在Windows 10 pro上的Microsoft Visual Studio Community 2019,由Parallels Desktop支持;MacBook Pro 2018。
在Mac方面,OpenGL通常被苹果公司否决,除此之外,MacOS仅支持GL 2.1之前的遗留GL和GL 3.2开始的核心配置文件GL。根据这个相似的知识库条目,将相同的限制转发给windows来宾。MacOS的遗留GL将不支持该演示所依赖的EXT_gpu_shader4
,而更高版本的GL也将包含所需的功能,这将需要核心配置文件,这将使该演示无法使用。
如果可以运行项目,我应该怎么做?
所以基本上:没有机会。
那么,你应该做什么:
- 不要使用依赖于十多年前删除的内容的教程/演示
- 不要在虚拟机中进行OpenGL开发
- 不要在苹果上开发OpenGL,它在那里完全不受欢迎,GL支持在GL 4.1上停止了,现在它已经有十年的历史了