0

我尝试从这里运行 SSDO 演示代码,但在我花了数小时寻找解决方案后,遇到了一些让我更加困惑的问题。尽管如此,现在我几乎可以肯定问题出在GLSL 版本上。

注意:

  • 该演示使用glewglut
  • 我的环境是 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.30inout自GLSL 版本取代。

这是标题中的冲突


我的期望

  1. 演示完全正确吗?
  2. 如果可以运行项目,我该怎么办?

由于我是 OpenGL 的新手,如果有人可以下载源代码并在他/她自己的计算机上尝试并告诉我如何解决,我将非常感激。
否则,如果一些经验丰富的专家可以就可能出现的问题或如何解决此问题给我一些一般性建议,我将同样感激。

4

1 回答 1

1
  1. 演示完全正确吗?

不,让我们看看这里的一些细节:

阶段1

显然我搜索了texelFetch2D,但只获得了非常有限的信息。然而根据这个信息,我暂时假设用它替换它texelFetch会有所帮助,这需要一个不低于 1.30 的 GLSL 版本,根据这个页面。

texelFetch2D 在标准 GLSL中不存在。它是GL_EXT_gpu_shader4扩展中引入的功能,从未直接进入核心 GL 功能。从概念上讲,texelFetch是使用 GLSL 130 或更高版本时的正确替换。

尽管这个着色器可能会在某些实现上编译,但它没有任何标准支持,也不应该被认为可以工作。

有趣的是,在 中SSBO.frag,演示正确地请求了该扩展,因此代码应该在支持该扩展的实现上工作:

#version 120
#extension GL_EXT_gpu_shader4 : enable

只是切换到#version 130也不起作用,因为您必须将整个着色器重写为 GLSL 130 语法,其中很多细节都发生了变化(例如varyings,被更通用的in/out方案取代)。

第 2阶段和第 3 阶段

然后我接受了@flyx 的建议,在 main 函数中添加了指定版本:

glutInitContextVersion(3, 2);
glutInitContextProfile(GLUT_CORE_PROFILE);

那是行不通的。在核心配置文件 OpenGL 中,所有不推荐使用的遗留功能都不可用,并且该教程在很大程度上依赖于此类不推荐使用的功能。要使此代码与核心配置文件 OpenGL 一起工作,需要进行重大重写。

然而:

我的环境是 15" MacBook Pro 2018 上的 Parallels Desktop 支持的 Windows 10 pro 上的 Microsoft Visual Studio Community 2019。

在 Mac 方面, Apple通常不推荐使用OpenGL ,除此之外,MacOS 仅支持 GL 2.1 之前的旧版 GL,以及从 GL 3.2 开始的核心配置文件 GL。根据此平行知识库条目,将相同的限制转发给 windows 来宾。MacOS 的旧版 GL 将不支持EXT_gpu_shader4此演示,而更高版本的 GL 也将包含所需的功能将需要核心配置文件,这将导致该演示无法使用。

如果可以运行项目,我该怎么办?

所以基本上:没有机会。

所以,你应该怎么做:

  • 不要使用依赖于十多年前删除的已弃用内容的教程/演示
  • 不要在 VM 中进行 OpenGL 开发
  • 不要在 Apple 上进行 OpenGL 开发,它在那里完全被弃用,并且 GL 支持停止在 GL 4.1 上,现在也有十年的历史了。
于 2020-06-20T13:16:28.783 回答