【问题标题】:Is the GLSL version requirement of this SSDO demo self-conflicting?这个 SSDO 演示的 GLSL 版本要求是否自相矛盾?
【发布时间】: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。

这是标题中的冲突。


我的期望

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

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

【问题讨论】:

    标签: c++ opengl glsl shader ssao


    【解决方案1】:
    1. 演示是否正确?

    没有。让我们看看这里的一些细节:

    第一阶段

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

    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/@ 取代例如 987654333@ 方案)。

    第二阶段和第三阶段

    然后我采纳了@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 方面,OpenGL 一般已被 Apple 弃用,除此之外,MacOS 仅支持 GL 2.1 之前的旧版 GL,以及从 GL 3.2 开始的核心配置文件 GL。根据this parallels knowledge base entry,同样的限制转发给windows guest。 MacOS 的旧版 GL 将不支持此演示所依赖的 EXT_gpu_shader4,并且还将包含所需功能的更高 GL 版本将需要核心配置文件,这将导致该演示无法使用。

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

    所以基本上:没有机会。

    那么,你应该怎么做:

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

    【讨论】:

    • 感谢您阻止我将更多时间浪费在一个死胡同的工作上!我想知道您的回答是否暗示,如果我切换到合适的 Windows PC 并对演示进行适度修改(而不是重写所有着色器),一切都会正常工作?
    • 嗯,在 Windows 上的典型 OpenGL 实现中,您将拥有可用的 EXT_gpu_shader4 扩展,并且供应商还支持兼容性配置文件 OpenGL,它允许将 GL 3.2 或更高版本与所有旧版本混合使用cruft,所以让它在那里运行的机会要高得多。带有 nvidia 专有驱动程序的 Linux 也是如此。但它仍然需要一些修复才能假定此代码运行。
    • “如果我切换到合适的 Windows PC”请注意,您可以使用 Boot Camp 在 Mac 上启动 Windows,而无需“PC”。在 Apple Silicon 发布之前,所有 Mac 都可以运行 Windows 并使用具有良好 Windows 驱动程序的非 Apple GPU。
    猜你喜欢
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-13
    相关资源
    最近更新 更多