提问者:小点点

这个SSDO演示的GLSL版本要求是否自我冲突?


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

注意:

  • 演示使用glewglut
  • 我的环境是Windows 10 pro上的Microsoft Visual Studio Community 2019,15“MacBook pro 2018上的Parallels Desktop支持。

在对代码进行任何修改之前,我得到了一堆错误消息:

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_buffere.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版本。

所以我在create_direct_light_buffere.frag的开头添加了#version130,错误消息变成了:

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_buffere.frag无关,而且我找不到任何有关它们的问题和解决方案,所以我就让它们过去了。
当我试图找出variable错误时,我发现了这篇文章,它声称自GLSL版本1.30以来,variableinout替换。

这就是标题中的冲突。

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

由于我是OpenGL的新手,如果有人能下载源代码在自己的电脑上试用并告诉我如何解决它,我将不胜感激。
如果一些经验丰富的专家能给我一些关于可能出现的错误或如何解决这个问题的一般性建议,我将同样感激。


共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

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

阶段2和阶段3

然后我采纳了@Flyx的建议,在main功能中加入了指定版本的内容:

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

那是行不通的。 在core profile OpenGL中,所有不推荐使用的遗留功能都是不可用的,该教程严重依赖于这些不推荐使用的功能。 它将需要一个重大的重写,使这段代码与核心配置文件OpenGL一起工作。

然而:

我的环境是Windows 10 pro上的Microsoft Visual Studio Community 2019,由15英寸MacBook pro 2018上的Parallels Desktop支持。

在Mac方面,OpenGL被苹果普遍反对,除此之外,MacOS只支持GL2.1之前的遗留GL,以及从GL3.2开始的核心配置文件GL。 根据此parallels知识库条目,相同的限制被转发到windows Guest。 MacOS的遗留GL不支持演示所依赖的ext_gpu_shader4,而更高的GL版本(CIH也将包含所需的功能)将需要核心配置文件,这将使演示无法使用。

如果有可能运行项目,应该怎么做?

所以基本上:没有机会。

所以,你应该做的是:

  • 不要使用教程/演示,因为这些教程/演示依赖于十多年前就被删除的那些不实用的东西
  • 不要在VMS中进行OpenGL开发
  • 不要在苹果上做OpenGL的开发,它在那里被完全否决了,GL的支持停止在GL4.1上,到现在也有十年了。