Minor example spelling/grammar tweaks & optimizations (#457)

* Removing superfluous Use() calls from SetUniform

Both as good practice and the approach used, these are superfluous and potentially confusing when debugging

* Small Spelling and Grammar adjustments
This commit is contained in:
Toby Lawrance 2021-04-12 20:57:43 +01:00 коммит произвёл GitHub
Родитель 775ead6f1b
Коммит e29d12bf91
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
33 изменённых файлов: 36 добавлений и 67 удалений

2
.github/workflows/build.yml поставляемый
Просмотреть файл

@ -5,6 +5,7 @@ on:
paths: paths:
- 'src/**/*' - 'src/**/*'
- 'build/nuke/*' - 'build/nuke/*'
- 'examples/**/*'
branches: branches:
- 'main' - 'main'
- 'release/*' - 'release/*'
@ -12,6 +13,7 @@ on:
paths: paths:
- 'src/**/*' - 'src/**/*'
- 'build/nuke/*' - 'build/nuke/*'
- 'examples/**/*'
jobs: jobs:
Build: Build:

Просмотреть файл

@ -52,7 +52,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -63,7 +62,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -75,7 +73,7 @@ namespace Tutorial
private uint LoadShader(ShaderType type, string path) private uint LoadShader(ShaderType type, string path)
{ {
//To load a single shader we need to load //To load a single shader we need to:
//1) Load the shader from a file. //1) Load the shader from a file.
//2) Create the handle. //2) Create the handle.
//3) Upload the source to opengl. //3) Upload the source to opengl.

Просмотреть файл

@ -1,7 +1,7 @@
//Specifying the version like in our vertex shader. //Specifying the version like in our vertex shader.
#version 330 core #version 330 core
//The input variables, again prefixed with an f as they are the input variables of our fragment shader. //The input variables, again prefixed with an f as they are the input variables of our fragment shader.
//These have to share name for now even tho there is a way around this later on. //These have to share name for now even though there is a way around this later on.
in vec4 fColor; in vec4 fColor;
//The output of our fragment shader, this just has to be a vec3 or a vec4, containing the color information about //The output of our fragment shader, this just has to be a vec3 or a vec4, containing the color information about

Просмотреть файл

@ -2,20 +2,20 @@
#version 330 core #version 330 core
//These lines specify the location and type of our attributes, //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 //the attributes here are prefixed with a "v" as they are our inputs to the vertex shader
//this isnt strictly necessary tho, but a good habbit. //this isn't strictly necessary though, but a good habit.
layout (location = 0) in vec3 vPos; layout (location = 0) in vec3 vPos;
layout (location = 1) in vec4 vColor; 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 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 its our uniform. //This is prefixed with a u as it's our uniform.
uniform float uBlue; uniform float uBlue;
//This is our output variables, notice that this is prefixed with an f as its the input of our fragment shader. //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; out vec4 fColor;
void main() void main()
{ {
//gl_Position, is a builting variable on all vertex shaders that will specify the position of our vertex. //gl_Position, is a built-in variable on all vertex shaders that will specify the position of our vertex.
gl_Position = vec4(vPos, 1.0); gl_Position = vec4(vPos, 1.0);
//The rest of this code looks like plain old c (almost c#) //The rest of this code looks like plain old c (almost c#)
vec4 color = vec4(vColor.rb / 2, uBlue, vColor.a); //Swizzling and constructors in glsl. vec4 color = vec4(vColor.rb / 2, uBlue, vColor.a); //Swizzling and constructors in glsl.

Просмотреть файл

@ -42,7 +42,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -53,7 +52,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }

Просмотреть файл

@ -17,7 +17,7 @@ namespace Tutorial
//Loading an image using imagesharp. //Loading an image using imagesharp.
Image<Rgba32> img = (Image<Rgba32>) Image.Load(path); Image<Rgba32> img = (Image<Rgba32>) Image.Load(path);
//We need to flip our image as image sharps coordinates has origin (0, 0) in the top-left corner, //We need to flip our image as image sharps coordinates has origin (0, 0) in the top-left corner,
//where as openGL has origin in the bottom-left corner. //whereas openGL has origin in the bottom-left corner.
img.Mutate(x => x.Flip(FlipMode.Vertical)); img.Mutate(x => x.Flip(FlipMode.Vertical));
fixed (void* data = &MemoryMarshal.GetReference(img.GetPixelRowSpan(0))) fixed (void* data = &MemoryMarshal.GetReference(img.GetPixelRowSpan(0)))

Просмотреть файл

@ -72,7 +72,7 @@ namespace Tutorial
Texture = new Texture(Gl, "silk.png"); Texture = new Texture(Gl, "silk.png");
//Unlike in the transformation, because of our abstraction order dosent matter here. //Unlike in the transformation, because of our abstraction, order doesn't matter here.
//Translation. //Translation.
Transforms[0] = new Transform(); Transforms[0] = new Transform();
Transforms[0].Position = new Vector3(0.5f, 0.5f, 0f); Transforms[0].Position = new Vector3(0.5f, 0.5f, 0f);

Просмотреть файл

@ -43,7 +43,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -55,7 +54,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.UniformMatrix4(location, 1, false, (float*) &value); _gl.UniformMatrix4(location, 1, false, (float*) &value);
} }
@ -66,7 +64,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }

Просмотреть файл

@ -6,7 +6,7 @@ namespace Tutorial
{ {
//A transform abstraction. //A transform abstraction.
//For a transform we need to have a position a scale and a rotation, //For a transform we need to have a position a scale and a rotation,
//depending on what application you are creating the type for these may vary. //depending on what application you are creating, the type for these may vary.
//Here we have chosen a vec3 for position, float for scale and quaternion for rotation, //Here we have chosen a vec3 for position, float for scale and quaternion for rotation,
//as that is the most normal to go with. //as that is the most normal to go with.

Просмотреть файл

@ -21,7 +21,7 @@ namespace Tutorial
private static Texture Texture; private static Texture Texture;
private static Shader Shader; private static Shader Shader;
//Setup the cameras location, and relative up and right directions //Setup the camera's location, and relative up and right directions
private static Vector3 CameraPosition = new Vector3(0.0f, 0.0f, 3.0f); private static Vector3 CameraPosition = new Vector3(0.0f, 0.0f, 3.0f);
private static Vector3 CameraTarget = Vector3.Zero; private static Vector3 CameraTarget = Vector3.Zero;
private static Vector3 CameraDirection = Vector3.Normalize(CameraPosition - CameraTarget); private static Vector3 CameraDirection = Vector3.Normalize(CameraPosition - CameraTarget);

Просмотреть файл

@ -43,7 +43,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -55,7 +54,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.UniformMatrix4(location, 1, false, (float*) &value); _gl.UniformMatrix4(location, 1, false, (float*) &value);
} }
@ -66,7 +64,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }

Просмотреть файл

@ -5,8 +5,8 @@ namespace Tutorial
public class Transform public class Transform
{ {
//A transform abstraction. //A transform abstraction.
//For a transform we need to have a position a scale and a rotation, //For a transform we need to have a position, a scale, and a rotation,
//depending on what application you are creating the type for these may vary. //depending on what application you are creating, the type for these may vary.
//Here we have chosen a vec3 for position, float for scale and quaternion for rotation, //Here we have chosen a vec3 for position, float for scale and quaternion for rotation,
//as that is the most normal to go with. //as that is the most normal to go with.

Просмотреть файл

@ -24,7 +24,7 @@ namespace Tutorial
private static Texture Texture; private static Texture Texture;
private static Shader Shader; private static Shader Shader;
//Setup the cameras location, directions, and movement speed //Setup the camera's location, directions, and movement speed
private static Vector3 CameraPosition = new Vector3(0.0f, 0.0f, 3.0f); private static Vector3 CameraPosition = new Vector3(0.0f, 0.0f, 3.0f);
private static Vector3 CameraFront = new Vector3(0.0f, 0.0f, -1.0f); private static Vector3 CameraFront = new Vector3(0.0f, 0.0f, -1.0f);
private static Vector3 CameraUp = Vector3.UnitY; private static Vector3 CameraUp = Vector3.UnitY;

Просмотреть файл

@ -43,7 +43,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -55,7 +54,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.UniformMatrix4(location, 1, false, (float*) &value); _gl.UniformMatrix4(location, 1, false, (float*) &value);
} }
@ -66,7 +64,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }

Просмотреть файл

@ -5,8 +5,8 @@ namespace Tutorial
public class Transform public class Transform
{ {
//A transform abstraction. //A transform abstraction.
//For a transform we need to have a position a scale and a rotation, //For a transform we need to have a position, a scale, and a rotation,
//depending on what application you are creating the type for these may vary. //depending on what application you are creating, the type for these may vary.
//Here we have chosen a vec3 for position, float for scale and quaternion for rotation, //Here we have chosen a vec3 for position, float for scale and quaternion for rotation,
//as that is the most normal to go with. //as that is the most normal to go with.

Просмотреть файл

@ -118,7 +118,7 @@ namespace Tutorial
VaoCube.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 3, 0); VaoCube.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 3, 0);
//The lighting shader will give our main cube its colour multiplied by the lights intensity //The lighting shader will give our main cube it's colour multiplied by the lights intensity
LightingShader = new Shader(Gl, "shader.vert", "lighting.frag"); LightingShader = new Shader(Gl, "shader.vert", "lighting.frag");
//The Lamp shader uses a fragment shader that just colours it solid white so that we know it is the light source //The Lamp shader uses a fragment shader that just colours it solid white so that we know it is the light source
LampShader = new Shader(Gl, "shader.vert", "shader.frag"); LampShader = new Shader(Gl, "shader.vert", "shader.frag");

Просмотреть файл

@ -43,7 +43,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -55,7 +54,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.UniformMatrix4(location, 1, false, (float*) &value); _gl.UniformMatrix4(location, 1, false, (float*) &value);
} }
@ -66,7 +64,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -77,7 +74,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform3(location, value.X, value.Y, value.Z); _gl.Uniform3(location, value.X, value.Y, value.Z);
} }

Просмотреть файл

@ -5,8 +5,8 @@ namespace Tutorial
public class Transform public class Transform
{ {
//A transform abstraction. //A transform abstraction.
//For a transform we need to have a position a scale and a rotation, //For a transform we need to have a position, a scale, and a rotation,
//depending on what application you are creating the type for these may vary. //depending on what application you are creating, the type for these may vary.
//Here we have chosen a vec3 for position, float for scale and quaternion for rotation, //Here we have chosen a vec3 for position, float for scale and quaternion for rotation,
//as that is the most normal to go with. //as that is the most normal to go with.

Просмотреть файл

@ -120,7 +120,7 @@ namespace Tutorial
VaoCube.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 6, 0); VaoCube.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 6, 0);
VaoCube.VertexAttributePointer(1, 3, VertexAttribPointerType.Float, 6, 3); VaoCube.VertexAttributePointer(1, 3, VertexAttribPointerType.Float, 6, 3);
//The lighting shader will give our main cube its colour multiplied by the lights intensity //The lighting shader will give our main cube it's colour multiplied by the lights intensity
LightingShader = new Shader(Gl, "shader.vert", "lighting.frag"); LightingShader = new Shader(Gl, "shader.vert", "lighting.frag");
//The Lamp shader uses a fragment shader that just colours it solid white so that we know it is the light source //The Lamp shader uses a fragment shader that just colours it solid white so that we know it is the light source
LampShader = new Shader(Gl, "shader.vert", "shader.frag"); LampShader = new Shader(Gl, "shader.vert", "shader.frag");
@ -135,12 +135,12 @@ namespace Tutorial
if (primaryKeyboard.IsKeyPressed(Key.W)) if (primaryKeyboard.IsKeyPressed(Key.W))
{ {
//Move forwards by adding a movement amount in the Cameras Front direction //Move forwards by adding a movement amount in the Camera's Front direction
Camera.Position += moveSpeed * Camera.Front; Camera.Position += moveSpeed * Camera.Front;
} }
if (primaryKeyboard.IsKeyPressed(Key.S)) if (primaryKeyboard.IsKeyPressed(Key.S))
{ {
//Move backwards by subtracting a movement amount in the Cameras Front direction //Move backwards by subtracting a movement amount in the Camera's Front direction
Camera.Position -= moveSpeed * Camera.Front; Camera.Position -= moveSpeed * Camera.Front;
} }
if (primaryKeyboard.IsKeyPressed(Key.A)) if (primaryKeyboard.IsKeyPressed(Key.A))

Просмотреть файл

@ -44,7 +44,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -56,7 +55,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.UniformMatrix4(location, 1, false, (float*) &value); _gl.UniformMatrix4(location, 1, false, (float*) &value);
} }
@ -67,7 +65,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -78,7 +75,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform3(location, value.X, value.Y, value.Z); _gl.Uniform3(location, value.X, value.Y, value.Z);
} }

Просмотреть файл

@ -5,8 +5,8 @@ namespace Tutorial
public class Transform public class Transform
{ {
//A transform abstraction. //A transform abstraction.
//For a transform we need to have a position a scale and a rotation, //For a transform we need to have a position, a scale, and a rotation,
//depending on what application you are creating the type for these may vary. //depending on what application you are creating, the type for these may vary.
//Here we have chosen a vec3 for position, float for scale and quaternion for rotation, //Here we have chosen a vec3 for position, float for scale and quaternion for rotation,
//as that is the most normal to go with. //as that is the most normal to go with.

Просмотреть файл

@ -13,7 +13,7 @@ void main()
{ {
//Multiplying our uniform with the vertex position, the multiplication order here does matter. //Multiplying our uniform with the vertex position, the multiplication order here does matter.
gl_Position = uProjection * uView * uModel * vec4(vPos, 1.0); gl_Position = uProjection * uView * uModel * vec4(vPos, 1.0);
//We want to know the fragments position in World space, so we multiply ONLY by uModel and not uView or uProjection //We want to know the fragment's position in World space, so we multiply ONLY by uModel and not uView or uProjection
fPos = vec3(uModel * vec4(vPos, 1.0)); fPos = vec3(uModel * vec4(vPos, 1.0));
//The Normal needs to be in World space too, but needs to account for Scaling of the object //The Normal needs to be in World space too, but needs to account for Scaling of the object
fNormal = mat3(transpose(inverse(uModel))) * vPos; fNormal = mat3(transpose(inverse(uModel))) * vPos;

Просмотреть файл

@ -120,7 +120,7 @@ namespace Tutorial
VaoCube.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 6, 0); VaoCube.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 6, 0);
VaoCube.VertexAttributePointer(1, 3, VertexAttribPointerType.Float, 6, 3); VaoCube.VertexAttributePointer(1, 3, VertexAttribPointerType.Float, 6, 3);
//The lighting shader will give our main cube its colour multiplied by the lights intensity //The lighting shader will give our main cube it's colour multiplied by the light's intensity
LightingShader = new Shader(Gl, "shader.vert", "lighting.frag"); LightingShader = new Shader(Gl, "shader.vert", "lighting.frag");
//The Lamp shader uses a fragment shader that just colours it solid white so that we know it is the light source //The Lamp shader uses a fragment shader that just colours it solid white so that we know it is the light source
LampShader = new Shader(Gl, "shader.vert", "shader.frag"); LampShader = new Shader(Gl, "shader.vert", "shader.frag");

Просмотреть файл

@ -43,7 +43,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -55,7 +54,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.UniformMatrix4(location, 1, false, (float*) &value); _gl.UniformMatrix4(location, 1, false, (float*) &value);
} }
@ -66,7 +64,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -77,7 +74,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform3(location, value.X, value.Y, value.Z); _gl.Uniform3(location, value.X, value.Y, value.Z);
} }

Просмотреть файл

@ -5,8 +5,8 @@ namespace Tutorial
public class Transform public class Transform
{ {
//A transform abstraction. //A transform abstraction.
//For a transform we need to have a position a scale and a rotation, //For a transform we need to have a position, a scale, and a rotation,
//depending on what application you are creating the type for these may vary. //depending on what application you are creating, the type for these may vary.
//Here we have chosen a vec3 for position, float for scale and quaternion for rotation, //Here we have chosen a vec3 for position, float for scale and quaternion for rotation,
//as that is the most normal to go with. //as that is the most normal to go with.

Просмотреть файл

@ -13,7 +13,7 @@ void main()
{ {
//Multiplying our uniform with the vertex position, the multiplication order here does matter. //Multiplying our uniform with the vertex position, the multiplication order here does matter.
gl_Position = uProjection * uView * uModel * vec4(vPos, 1.0); gl_Position = uProjection * uView * uModel * vec4(vPos, 1.0);
//We want to know the fragments position in World space, so we multiply ONLY by uModel and not uView or uProjection //We want to know the fragment's position in World space, so we multiply ONLY by uModel and not uView or uProjection
fPos = vec3(uModel * vec4(vPos, 1.0)); fPos = vec3(uModel * vec4(vPos, 1.0));
//The Normal needs to be in World space too, but needs to account for Scaling of the object //The Normal needs to be in World space too, but needs to account for Scaling of the object
fNormal = mat3(transpose(inverse(uModel))) * vPos; fNormal = mat3(transpose(inverse(uModel))) * vPos;

Просмотреть файл

@ -125,7 +125,7 @@ namespace Tutorial
VaoCube.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 6, 0); VaoCube.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 6, 0);
VaoCube.VertexAttributePointer(1, 3, VertexAttribPointerType.Float, 6, 3); VaoCube.VertexAttributePointer(1, 3, VertexAttribPointerType.Float, 6, 3);
//The lighting shader will give our main cube its colour multiplied by the lights intensity //The lighting shader will give our main cube it's colour multiplied by the light's intensity
LightingShader = new Shader(Gl, "shader.vert", "lighting.frag"); LightingShader = new Shader(Gl, "shader.vert", "lighting.frag");
//The Lamp shader uses a fragment shader that just colours it solid white so that we know it is the light source //The Lamp shader uses a fragment shader that just colours it solid white so that we know it is the light source
LampShader = new Shader(Gl, "shader.vert", "shader.frag"); LampShader = new Shader(Gl, "shader.vert", "shader.frag");

Просмотреть файл

@ -43,7 +43,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -55,7 +54,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.UniformMatrix4(location, 1, false, (float*) &value); _gl.UniformMatrix4(location, 1, false, (float*) &value);
} }
@ -66,7 +64,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -77,7 +74,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform3(location, value.X, value.Y, value.Z); _gl.Uniform3(location, value.X, value.Y, value.Z);
} }

Просмотреть файл

@ -13,7 +13,7 @@ void main()
{ {
//Multiplying our uniform with the vertex position, the multiplication order here does matter. //Multiplying our uniform with the vertex position, the multiplication order here does matter.
gl_Position = uProjection * uView * uModel * vec4(vPos, 1.0); gl_Position = uProjection * uView * uModel * vec4(vPos, 1.0);
//We want to know the fragments position in World space, so we multiply ONLY by uModel and not uView or uProjection //We want to know the fragment's position in World space, so we multiply ONLY by uModel and not uView or uProjection
fPos = vec3(uModel * vec4(vPos, 1.0)); fPos = vec3(uModel * vec4(vPos, 1.0));
//The Normal needs to be in World space too, but needs to account for Scaling of the object //The Normal needs to be in World space too, but needs to account for Scaling of the object
fNormal = mat3(transpose(inverse(uModel))) * vPos; fNormal = mat3(transpose(inverse(uModel))) * vPos;

Просмотреть файл

@ -129,7 +129,7 @@ namespace Tutorial
VaoCube.VertexAttributePointer(1, 3, VertexAttribPointerType.Float, 8, 3); VaoCube.VertexAttributePointer(1, 3, VertexAttribPointerType.Float, 8, 3);
VaoCube.VertexAttributePointer(2, 2, VertexAttribPointerType.Float, 8, 6); VaoCube.VertexAttributePointer(2, 2, VertexAttribPointerType.Float, 8, 6);
//The lighting shader will give our main cube its colour multiplied by the lights intensity //The lighting shader will give our main cube it's colour multiplied by the light's intensity
LightingShader = new Shader(Gl, "shader.vert", "lighting.frag"); LightingShader = new Shader(Gl, "shader.vert", "lighting.frag");
//The Lamp shader uses a fragment shader that just colours it solid white so that we know it is the light source //The Lamp shader uses a fragment shader that just colours it solid white so that we know it is the light source
LampShader = new Shader(Gl, "shader.vert", "shader.frag"); LampShader = new Shader(Gl, "shader.vert", "shader.frag");

Просмотреть файл

@ -43,7 +43,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -55,7 +54,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.UniformMatrix4(location, 1, false, (float*) &value); _gl.UniformMatrix4(location, 1, false, (float*) &value);
} }
@ -66,7 +64,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform1(location, value); _gl.Uniform1(location, value);
} }
@ -77,7 +74,6 @@ namespace Tutorial
{ {
throw new Exception($"{name} uniform not found on shader."); throw new Exception($"{name} uniform not found on shader.");
} }
Use();
_gl.Uniform3(location, value.X, value.Y, value.Z); _gl.Uniform3(location, value.X, value.Y, value.Z);
} }

Просмотреть файл

@ -5,8 +5,8 @@ namespace Tutorial
public class Transform public class Transform
{ {
//A transform abstraction. //A transform abstraction.
//For a transform we need to have a position a scale and a rotation, //For a transform we need to have a position, a scale, and a rotation,
//depending on what application you are creating the type for these may vary. //depending on what application you are creating, the type for these may vary.
//Here we have chosen a vec3 for position, float for scale and quaternion for rotation, //Here we have chosen a vec3 for position, float for scale and quaternion for rotation,
//as that is the most normal to go with. //as that is the most normal to go with.

Просмотреть файл

@ -15,7 +15,7 @@ void main()
{ {
//Multiplying our uniform with the vertex position, the multiplication order here does matter. //Multiplying our uniform with the vertex position, the multiplication order here does matter.
gl_Position = uProjection * uView * uModel * vec4(vPos, 1.0); gl_Position = uProjection * uView * uModel * vec4(vPos, 1.0);
//We want to know the fragments position in World space, so we multiply ONLY by uModel and not uView or uProjection //We want to know the fragment's position in World space, so we multiply ONLY by uModel and not uView or uProjection
fPos = vec3(uModel * vec4(vPos, 1.0)); fPos = vec3(uModel * vec4(vPos, 1.0));
//The Normal needs to be in World space too, but needs to account for Scaling of the object //The Normal needs to be in World space too, but needs to account for Scaling of the object
fNormal = mat3(transpose(inverse(uModel))) * vPos; fNormal = mat3(transpose(inverse(uModel))) * vPos;