I tried to run the SSDO demo code from here but met with several problems that confused me even further after I had spent hours searching for solutions. Nevertheless, now I am almost certain that the problems are with the GLSL version.
Note that:
- The demo uses
glew
andglut
. - My environment is Microsoft Visual Studio Community 2019 on Windows 10 pro supported by Parallels Desktop on a 15" MacBook Pro 2018.
Stage 1
Before any modifications to the code, I got a bunch of error messages:
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
...
And the messages went on similarly for other shaders.
Correspondingly, the error messages shown above were related to 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;
}
Apparently I searched for texelFetch2D
, but garnered only very limited information. Yet based on the information, I tentatively assumed that replacing it with texelFetch
would help, which requires a GLSL version no less than 1.30, according to this page.
Stage 2
So I added #version 130
at the very beginning of create_direct_light_buffer.frag
, and the error messages turned into:
ERROR: 0:1: '' : version '130' is not supported
ERROR: One or more attached shaders not successfully compiled
...
Then I took @flyx's advice, adding to the main
function to specify the version:
glutInitContextVersion(3, 2);
glutInitContextProfile(GLUT_CORE_PROFILE);
I started to get lost.
Stage 3
The error messages turned into:
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
...
These warnings did not seem to pertain to the create_direct_light_buffer.frag
, and moreover I could not find any questions and solutions regarding them, so I just let them go.
When I tried to figure out the varying
error, I found this post, which claimed that varying
was replaced by in
or out
since GLSL version 1.30.
This is the conflict in the title.
My Expectation
- Is the demo correct at all?
- If it is possible to run the project, what should I do?
Since I am new to OpenGL, if someone could download the source code to try on his/her own computer and tell me how to work it out, I would be extremely grateful.
Else if some highly-experienced experts could give me some general advice on what might be wrong or how to solve this issue, I would be equally thankful.