C
C#15mo ago
Uchuu

❔ OpenGL / Silk.NET - uniform not found on shader

// Here we specify the version of our shader.
#version 330 core

// These lines specify the location and type of our attributes,
// the attributes here are prefixed with a "v" as they are our inputs to the vertex shader
// this isn't strictly necessary though, but a good habit.
layout (location = 0) in vec3 vPos;
layout (location = 1) in vec4 vColor;

// This is how we declare a uniform, they can be used in all our shaders and share the same name.
// This is prefixed with a u as it's our uniform.
uniform float uBlue;
uniform float uOffset;

// This is our output variable, notice that this is prefixed with an f as it's the input of our fragment shader.
out vec4 fColor;

void main()
{
// gl_Position, is a built-in variable on all vertex shaders that will specify the position of our vertex.
gl_Position = vec4(uOffset + vPos.x, vPos.y, vPos.z, 1.0);
gl_Position = vec4(vPos, 1.0);

// R G B A
// 1 0 0 1

// The rest of this code looks like plain old C (almost C#)
vec4 color = vec4(vColor.r, vColor.g, uBlue, vColor.a);
fColor = color;
}
// Here we specify the version of our shader.
#version 330 core

// These lines specify the location and type of our attributes,
// the attributes here are prefixed with a "v" as they are our inputs to the vertex shader
// this isn't strictly necessary though, but a good habit.
layout (location = 0) in vec3 vPos;
layout (location = 1) in vec4 vColor;

// This is how we declare a uniform, they can be used in all our shaders and share the same name.
// This is prefixed with a u as it's our uniform.
uniform float uBlue;
uniform float uOffset;

// This is our output variable, notice that this is prefixed with an f as it's the input of our fragment shader.
out vec4 fColor;

void main()
{
// gl_Position, is a built-in variable on all vertex shaders that will specify the position of our vertex.
gl_Position = vec4(uOffset + vPos.x, vPos.y, vPos.z, 1.0);
gl_Position = vec4(vPos, 1.0);

// R G B A
// 1 0 0 1

// The rest of this code looks like plain old C (almost C#)
vec4 color = vec4(vColor.r, vColor.g, uBlue, vColor.a);
fColor = color;
}
public void SetUniform(string name, float value)
{
var location = _gl.GetUniformLocation(_handle, name);
if (location == -1)
{
throw new Exception($"{name} uniform not found on shader.");
}

_gl.Uniform1(location, value);
}
public void SetUniform(string name, float value)
{
var location = _gl.GetUniformLocation(_handle, name);
if (location == -1)
{
throw new Exception($"{name} uniform not found on shader.");
}

_gl.Uniform1(location, value);
}
var value = (float) Math.Sin(DateTime.Now.Millisecond / 1000f * Math.PI);
_shader.SetUniform("uBlue", value);
_shader.SetUniform("uOffset", value);
var value = (float) Math.Sin(DateTime.Now.Millisecond / 1000f * Math.PI);
_shader.SetUniform("uBlue", value);
_shader.SetUniform("uOffset", value);
It seems to work fine for the uBlue shader am I missing something stupid
Unhandled exception. System.Exception: uOffset uniform not found on shader.
at Graphics.Shader.SetUniform(String name, Single value) in C:\Users\mdabr\RiderProjects\2023\Graphics\Graphics\Shader.cs:line 149
Unhandled exception. System.Exception: uOffset uniform not found on shader.
at Graphics.Shader.SetUniform(String name, Single value) in C:\Users\mdabr\RiderProjects\2023\Graphics\Graphics\Shader.cs:line 149
2 Replies
Uchuu
Uchuu15mo ago
Nevermind I am an idiot I just had a duplicate line in the vertex shader
Accord
Accord15mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.