繁体   English   中英

这个 SSDO 演示的 GLSL 版本要求是否自相矛盾?

[英]Is the GLSL version requirement of this SSDO demo self-conflicting?

我尝试从这里运行 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 ,根据此页面


第二阶段

所以我在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的 function 以指定版本:

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无关,而且我找不到任何关于它们的问题和解决方案,所以我只是让它们 go。
当我试图找出varying的错误时,我发现了这篇文章,它声称从GLSL 版本 1.30开始, varying被替换为inout

这是标题中的冲突


我的期望

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

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

  1. 演示完全正确吗?

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

阶段1

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

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

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

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

 #version 120 #extension GL_EXT_gpu_shader4: enable

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

第 2阶段和第 3 阶段

然后我接受@flyx的建议,在主function中添加指定版本:

 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。 根据此平行知识库条目,将相同的限制转发给 windows 来宾。 MacOS 的旧版 GL 将不支持此演示所依赖的EXT_gpu_shader4 ,并且还将包含所需功能的更高 GL 版本将需要核心配置文件,这将导致该演示无法使用。

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

所以基本上:没有机会。

所以,你应该怎么做:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM