I can not get this shader to return its uniforms.
I have looked everywhere for a possible problem with my shader assembler or bindings. I even rebooted my machine (desktop quad core) thinking maybe the OpenGL driver crapped out.
Here's the code that tries but fails to get the uniform locations:
Private Sub set_deferredLighting_variables()
deferred_cam_position = Gl.glGetUniformLocation(shader_list.deferred_shader, "viewPos")
deferred_light_position = Gl.glGetUniformLocation(shader_list.deferred_shader, "Light_position")
deferred_gcolor = Gl.glGetUniformLocation(shader_list.deferred_shader, "gColor")
deferred_gnormal = Gl.glGetUniformLocation(shader_list.deferred_shader, "gNormal")
deferred_gposition = Gl.glGetUniformLocation(shader_list.deferred_shader, "gPosition")
End Sub
And here is the fragment shader:
#version 330 core
in vec2 TexCoords;
out vec4 FragColor;
uniform sampler2D gPosition;
uniform sampler2D gNormal;
uniform sampler2D gColor;
uniform vec3 Light_position;
uniform vec3 viewPos;
void main()
{
vec3 light_Color = vec3 (1.0, 1.0, 0.9);
// Retrieve data from G-buffer
vec3 FragPos = texture(gPosition, TexCoords).rgb;
vec3 Normal = texture(gNormal, TexCoords).rgb;
vec3 Albedo = texture(gColor, TexCoords).rgb;
float Specular = texture(gNormal, TexCoords).a;
// Then calculate lighting as usual
vec3 lighting = Albedo * 0.1; // hard-coded ambient component
vec3 viewDir = normalize(viewPos - FragPos);
// Diffuse
vec3 lightDir = normalize(Light_position - FragPos);
vec3 diffuse = max(dot(Normal, lightDir), 0.0) * Albedo * light_Color;
FragColor = vec4(lighting + diffuse, 1.0);
}
For the life of me I can't find a reason why the uniforms are not showing up. I have a very very good shader assembler that checks at every stage for the status and any glGetError. If glGetError returns anything but 0, it throws up a message box. My assembler reads and builds the shaders in the folder.. Naming of the shaders is critical. The assembler builds 20+ shaders with no problem including this one.. There are absolutely no errors thrown!
I had this issue once a few months back and rebooting fixed the problem.. I tried that.. No luck. Any help would be fantastic!
Here is the shader assembler code: Not how crazy I am at checking every thing.
Public Function assemble_shader(v As String, g As String, f As String, ByRef shader As Integer, ByRef name As String, ByRef has_geo As Boolean) As Integer
Dim vs(1) As String
Dim gs(1) As String
Dim fs(1) As String
Dim vertexObject As Integer
Dim geoObject As Integer
Dim fragmentObject As Integer
Dim status_code As Integer
Dim info As New StringBuilder
info.Length = 1024
Dim info_l As Integer
If shader > 0 Then
Gl.glUseProgram(0)
Gl.glDeleteProgram(shader)
Gl.glGetProgramiv(shader, Gl.GL_DELETE_STATUS, status_code)
Gl.glFinish()
End If
Dim e = Gl.glGetError
If e <> 0 Then
Dim s = Glu.gluErrorString(e)
Dim ms As String = System.Reflection.MethodBase.GetCurrentMethod().Name
'MsgBox("Function: " + ms + vbCrLf + "Error! " + s, MsgBoxStyle.Exclamation, "OpenGL Issue")
End If
'have a hard time with files remaining open.. hope this fixes it! (yep.. it did)
Using vs_s As New StreamReader(v)
vs(0) = vs_s.ReadToEnd
vs_s.Close()
vs_s.Dispose()
End Using
Using fs_s As New StreamReader(f)
fs(0) = fs_s.ReadToEnd
fs_s.Close()
fs_s.Dispose()
End Using
If has_geo Then
Using gs_s As New StreamReader(g)
gs(0) = gs_s.ReadToEnd
gs_s.Close()
gs_s.Dispose()
End Using
End If
vertexObject = Gl.glCreateShader(Gl.GL_VERTEX_SHADER)
fragmentObject = Gl.glCreateShader(Gl.GL_FRAGMENT_SHADER)
'--------------------------------------------------------------------
shader = Gl.glCreateProgram()
' Compile vertex shader
Gl.glShaderSource(vertexObject, 1, vs, vs(0).Length)
Gl.glCompileShader(vertexObject)
Gl.glGetShaderInfoLog(vertexObject, 8192, info_l, info)
Gl.glGetShaderiv(vertexObject, Gl.GL_COMPILE_STATUS, status_code)
If Not status_code = Gl.GL_TRUE Then
Gl.glDeleteShader(vertexObject)
gl_error(name + "_vertex didn't compile!" + vbCrLf + info.ToString)
'Return
End If
e = Gl.glGetError
If e <> 0 Then
Dim s = Glu.gluErrorString(e)
Dim ms As String = System.Reflection.MethodBase.GetCurrentMethod().Name
MsgBox("Function: " + ms + vbCrLf + "Error! " + s, MsgBoxStyle.Exclamation, "OpenGL Issue")
End If
If has_geo Then
'geo
geoObject = Gl.glCreateShader(Gl.GL_GEOMETRY_SHADER_EXT)
Gl.glShaderSource(geoObject, 1, gs, gs(0).Length)
Gl.glCompileShader(geoObject)
Gl.glGetShaderInfoLog(geoObject, 8192, info_l, info)
Gl.glGetShaderiv(geoObject, Gl.GL_COMPILE_STATUS, status_code)
If Not status_code = Gl.GL_TRUE Then
Gl.glDeleteShader(geoObject)
gl_error(name + "_geo didn't compile!" + vbCrLf + info.ToString)
'Return
End If
e = Gl.glGetError
If e <> 0 Then
Dim s = Glu.gluErrorString(e)
Dim ms As String = System.Reflection.MethodBase.GetCurrentMethod().Name
MsgBox("Function: " + ms + vbCrLf + "Error! " + s, MsgBoxStyle.Exclamation, "OpenGL Issue")
End If
Gl.glProgramParameteriEXT(shader, Gl.GL_GEOMETRY_INPUT_TYPE_EXT, Gl.GL_TRIANGLES)
Gl.glProgramParameteriEXT(shader, Gl.GL_GEOMETRY_OUTPUT_TYPE_EXT, Gl.GL_LINE_STRIP)
If name.Contains("normal") Then
Gl.glProgramParameteriEXT(shader, Gl.GL_GEOMETRY_VERTICES_OUT_EXT, 18)
Else
Gl.glProgramParameteriEXT(shader, Gl.GL_GEOMETRY_VERTICES_OUT_EXT, 4) 'leaf needs 4
End If
e = Gl.glGetError
If e <> 0 Then
Dim s = Glu.gluErrorString(e)
Dim ms As String = System.Reflection.MethodBase.GetCurrentMethod().Name
MsgBox("Function: " + ms + vbCrLf + "Error! " + s, MsgBoxStyle.Exclamation, "OpenGL Issue")
End If
End If
' Compile fragment shader
Gl.glShaderSource(fragmentObject, 1, fs, fs(0).Length)
Gl.glCompileShader(fragmentObject)
Gl.glGetShaderInfoLog(fragmentObject, 8192, info_l, info)
Gl.glGetShaderiv(fragmentObject, Gl.GL_COMPILE_STATUS, status_code)
If Not status_code = Gl.GL_TRUE Then
Gl.glDeleteShader(fragmentObject)
gl_error(name + "_fragment didn't compile!" + vbCrLf + info.ToString)
'Return
End If
e = Gl.glGetError
If e <> 0 Then
Dim s = Glu.gluErrorString(e)
Dim ms As String = System.Reflection.MethodBase.GetCurrentMethod().Name
MsgBox("Function: " + ms + vbCrLf + "Error! " + s, MsgBoxStyle.Exclamation, "OpenGL Issue")
End If
'attach shader objects
Gl.glAttachShader(shader, fragmentObject)
If has_geo Then
Gl.glAttachShader(shader, geoObject)
End If
Gl.glAttachShader(shader, vertexObject)
'link program
Gl.glLinkProgram(shader)
' detach shader objects
Gl.glDetachShader(shader, fragmentObject)
If has_geo Then
Gl.glDetachShader(shader, geoObject)
End If
Gl.glDetachShader(shader, vertexObject)
e = Gl.glGetError
If e <> 0 Then
Dim s = Glu.gluErrorString(e)
Dim ms As String = System.Reflection.MethodBase.GetCurrentMethod().Name
MsgBox("Function: " + ms + vbCrLf + "Error! " + s, MsgBoxStyle.Exclamation, "OpenGL Issue")
End If
Gl.glGetShaderiv(shader, Gl.GL_LINK_STATUS, status_code)
If Not status_code = Gl.GL_TRUE Then
Gl.glDeleteProgram(shader)
gl_error(name + " did not link!" + vbCrLf + info.ToString)
'Return
End If
'delete shader objects
Gl.glDeleteShader(fragmentObject)
Gl.glGetShaderiv(fragmentObject, Gl.GL_DELETE_STATUS, status_code)
If has_geo Then
Gl.glDeleteShader(geoObject)
Gl.glGetShaderiv(geoObject, Gl.GL_DELETE_STATUS, status_code)
End If
Gl.glDeleteShader(vertexObject)
Gl.glGetShaderiv(vertexObject, Gl.GL_DELETE_STATUS, status_code)
e = Gl.glGetError
If e <> 0 Then
'aways throws a error after deletion even though the status shows them as deleted.. ????
Dim s = Glu.gluErrorString(e)
Dim ms As String = System.Reflection.MethodBase.GetCurrentMethod().Name
'MsgBox("Function: " + ms + vbCrLf + "Error! " + s, MsgBoxStyle.Exclamation, "OpenGL Issue")
End If
vs(0) = Nothing
fs(0) = Nothing
If has_geo Then
gs(0) = Nothing
End If
GC.Collect()
GC.WaitForFullGCComplete()
Return shader
End Function