Initial commit

This commit is contained in:
2021-09-03 12:56:57 -04:00
parent 76d457bcd7
commit 578fcb2bbd
154 changed files with 617096 additions and 2 deletions

View File

@@ -0,0 +1,11 @@
#version 330 core
out vec4 fColor;
in vec2 vTextureCoord;
uniform sampler2D texture_diffuse1;
void main()
{
fColor = texture(texture_diffuse1, vTextureCoord);
}

View File

@@ -0,0 +1,93 @@
#version 330 core
struct Light {
vec3 position;
// Light colors RGB value
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
// Input from Vertex shader
in VS_OUT {
// Frag position, UV coordinates, normals
vec2 textureCoord;
vec3 position;
vec3 normal;
// Tangent positions
vec3 tangentLight;
vec3 tangentView;
vec3 tangentFrag;
Light light;
} vOut;
// Final fragment fColor
out vec4 fColor;
struct Material {
// Strength ranges 0.0f - 1.0f
float ambientStrength;
float diffuseStrength;
float specularStrength;
// 32, 64, 128, 256
float shine;
// Material color values
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
uniform Material uMaterial;
struct Result {
vec3 ambient;
vec3 diffuse;
vec3 specular;
vec3 sum;
};
void SumResult(inout Result result)
{
result.sum = result.ambient + result.diffuse + result.specular;
}
uniform sampler2D texture_diffuse1;
uniform sampler2D texture_specular1;
uniform sampler2D texture_normal1;
void main()
{
Result result;
// Diffuse texture for ambient and diffuse lighting
vec3 diffuseTexture = vec3(texture(texture_diffuse1, vOut.textureCoord));
// Ambient lighting
vec3 ambientLighting = vOut.light.ambient * uMaterial.ambient;
result.ambient = ambientLighting * diffuseTexture;
result.ambient *= uMaterial.ambientStrength;
// Diffuse lighting
vec3 normalTexture = texture(texture_normal1, vOut.textureCoord).rgb;
normalTexture = normalize(normalTexture * 2.0f - 1.0f);
vec3 lightDir = normalize(vOut.tangentLight - vOut.tangentFrag);
float diff = max(dot(lightDir, normalTexture), 0.0f);
vec3 diffuseLighting = vOut.light.diffuse * diff * uMaterial.diffuse;
result.diffuse = diffuseLighting * diffuseTexture;
result.diffuse *= uMaterial.diffuseStrength;
// Specular lighting
vec3 specularTexture = vec3(texture(texture_specular1, vOut.textureCoord));
vec3 viewDir = normalize(vOut.tangentView - vOut.tangentFrag);
vec3 reflectDir = reflect(-lightDir, normalTexture);
vec3 halfDir = normalize(lightDir + viewDir);
float angleAlpha = max(dot(normalTexture, halfDir), 0.0f);
float spec = pow(angleAlpha, uMaterial.shine);
vec3 specLighting = vOut.light.specular * spec;
result.specular = specLighting * specularTexture;
result.specular *= uMaterial.specularStrength;
SumResult(result);
fColor = vec4(result.sum, 1.0f);
}

View File

@@ -0,0 +1,85 @@
#version 330 core
// Input from Vertex shader
in vec2 vTextureCoord;
in vec3 vNormal;
in vec3 vPosition;
// Final fragment fColor
out vec4 fColor;
// Light object and camera position vectors
uniform vec3 uCameraPosition;
struct Light {
vec3 position;
// Light colors RGB value
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
uniform Light uLight;
struct Material {
// Strength ranges 0.0f - 1.0f
float ambientStrength;
float diffuseStrength;
float specularStrength;
// 32, 64, 128, 256
float shine;
// Material color values
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
uniform Material uMaterial;
struct Result {
vec3 ambient;
vec3 diffuse;
vec3 specular;
vec3 sum;
};
void SumResult(inout Result result)
{
result.sum = result.ambient + result.diffuse + result.specular;
}
uniform sampler2D texture_diffuse1;
uniform sampler2D texture_specular1;
void main()
{
Result result;
// Diffuse texture for ambient and diffuse lighting
vec3 diffuseTexture = vec3(texture(texture_diffuse1, vTextureCoord));
// Ambient lighting
vec3 ambientLighting = uLight.ambient * uMaterial.ambient;
result.ambient = ambientLighting * diffuseTexture;
result.ambient *= uMaterial.ambientStrength;
// Diffuse lighting
vec3 norm = normalize(vNormal);
vec3 lightDir = normalize(uLight.position - vPosition);
float diff = max(dot(norm, lightDir), 0.0f);
vec3 diffuseLighting = uLight.diffuse * diff * uMaterial.diffuse;
result.diffuse = diffuseLighting * diffuseTexture;
result.diffuse *= uMaterial.diffuseStrength;
// Specular lighting
vec3 specularTexture = vec3(texture(texture_specular1, vTextureCoord));
vec3 viewDir = normalize(uCameraPosition - vPosition);
vec3 reflectDir = reflect(-lightDir, norm);
float angleAlpha = max(dot(viewDir, reflectDir), 0.0f);
float spec = pow(angleAlpha, uMaterial.shine);
vec3 specLighting = uLight.specular * spec;
result.specular = specLighting * specularTexture;
result.specular *= uMaterial.specularStrength;
SumResult(result);
fColor = vec4(result.sum, 1.0f);
}

View File

@@ -0,0 +1,93 @@
#version 330 core
struct Light {
vec3 position;
// Light colors RGB value
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
// Input from Vertex shader
in VS_OUT {
// Frag position, UV coordinates, normals
vec2 textureCoord;
vec3 position;
vec3 normal;
// Tangent positions
vec3 tangentLight;
vec3 tangentView;
vec3 tangentFrag;
Light light;
} vOut;
// Final fragment fColor
out vec4 fColor;
struct Material {
// Strength ranges 0.0f - 1.0f
float ambientStrength;
float diffuseStrength;
float specularStrength;
// 32, 64, 128, 256
float shine;
// Material color values
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
uniform Material uMaterial;
struct Result {
vec3 ambient;
vec3 diffuse;
vec3 specular;
vec3 sum;
};
void SumResult(inout Result result)
{
result.sum = result.ambient + result.diffuse + result.specular;
}
uniform sampler2D texture_diffuse1;
uniform sampler2D texture_specular1;
uniform sampler2D texture_normal1;
void main()
{
Result result;
// Diffuse texture for ambient and diffuse lighting
vec3 diffuseTexture = vec3(texture(texture_diffuse1, vOut.textureCoord));
// Ambient lighting
vec3 ambientLighting = vOut.light.ambient * uMaterial.ambient;
result.ambient = ambientLighting * diffuseTexture;
result.ambient *= uMaterial.ambientStrength;
// Diffuse lighting
vec3 normalTexture = texture(texture_normal1, vOut.textureCoord).rgb;
normalTexture = normalize(normalTexture * 2.0f - 1.0f);
vec3 lightDir = normalize(vOut.tangentLight - vOut.tangentFrag);
float diff = max(dot(lightDir, normalTexture), 0.0f);
vec3 diffuseLighting = vOut.light.diffuse * diff * uMaterial.diffuse;
result.diffuse = diffuseLighting * diffuseTexture;
result.diffuse *= uMaterial.diffuseStrength;
// Specular lighting
vec3 specularTexture = vec3(texture(texture_specular1, vOut.textureCoord));
vec3 viewDir = normalize(vOut.tangentView - vOut.tangentFrag);
vec3 reflectDir = reflect(-lightDir, normalTexture);
vec3 halfDir = normalize(lightDir + viewDir);
float angleAlpha = max(dot(normalTexture, halfDir), 0.0f);
float spec = pow(angleAlpha, uMaterial.shine);
vec3 specLighting = vOut.light.specular * spec;
result.specular = specLighting * specularTexture;
result.specular *= uMaterial.specularStrength;
SumResult(result);
fColor = vec4(result.sum, 1.0f);
}

View File

@@ -0,0 +1,9 @@
#version 330
in vec4 vColor;
out vec4 fColor;
void main()
{
fColor = vColor;
}

View File

@@ -0,0 +1,94 @@
#version 330
// Color input from Vertex shader
in vec3 vNormal;
in vec3 vPosition;
// Final fragment fColor
out vec4 fColor;
// Light object and camera position vectors
uniform vec3 uCameraPosition;
struct Light {
vec3 position;
// Light colors RGB value
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
uniform Light uLight;
struct Material {
// Strength ranges 0.0f - 1.0f
float ambientStrength;
float diffuseStrength;
float specularStrength;
// 32, 64, 128, 256
float shine;
// Material color values
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
uniform Material uMaterial;
struct Result {
vec3 ambient;
vec3 diffuse;
vec3 specular;
vec3 sum;
};
void SumResult(inout Result result)
{
result.sum = result.ambient + result.diffuse + result.specular;
}
void main()
{
// A struct to store lighting results as we finish calculating them
// Valuse stored here will be applied to the final output of our shader
Result result;
// Ambient lighting
result.ambient = (uLight.ambient * uMaterial.ambient) * uMaterial.ambientStrength;
//
// Diffuse lighting
// Normalize the provided normal vector
// + Creates a vector with length of 1 in the same direction as vNormal
vec3 norm = normalize(vNormal);
// Get a vector from this frag to the lightSoruce
vec3 lightDir = normalize(uLight.position - vPosition);
// As the normal vector approaches an angle looking at lightDir vector
// + If this is negative, the frag is on a surface opposite of the lightSource
float diff = max(dot(norm, lightDir), 0.0f);
result.diffuse = (uLight.diffuse * diff * uMaterial.diffuse) * uMaterial.diffuseStrength;
//
// Specular lighting
// Get a vector from the camera to the fragment as our viewDir
vec3 viewDir = normalize(uCameraPosition - vPosition);
// Since lightDir is already a vector from this frag to the light source
// reflectionDir is the opposite; A vector from the light to the frag
vec3 reflectDir = reflect(-lightDir, norm);
// Use dot product to check if viewDir and reflectDir angles are intersecting
// -1.0f if they are opposite; 1.0 if they are looking at each other directly
// + If this is negative, the lightSource is behind the player; Ignore it
float angleAlpha = max(dot(viewDir, reflectDir), 0.0f);
// As the angleAlpha approaches 1, raise to the power of uMaterial.shine
float spec = pow(angleAlpha, uMaterial.shine);
// Apply specular result to the
result.specular = (uLight.specular * uMaterial.specular * spec) * uMaterial.specularStrength;
//
// Final calculation
SumResult(result);
// Final output
fColor = vec4(result.sum, 1.0f); // Reapply alpha for opacity
}

View File

@@ -0,0 +1,11 @@
#version 330
// Color input from Vertex shader
in vec3 vNormal;
// Final fragment color
out vec4 fColor;
void main()
{
fColor = vec4(abs(vNormal), 1.0f); // Reapply alpha
}

View File

@@ -0,0 +1,19 @@
#version 330
// Color input from Vertex shader
in vec4 vColor;
// Final fragment color
out vec4 fColor;
// Light color RGB value
uniform vec3 uLightColor;
// Strength ranges 0.0f - 1.0f
uniform float uAmbientStrength; // 0.2f
void main()
{
vec3 ambient = uAmbientStrength * uLightColor;
vec3 result = ambient * vec3(vColor); // Strip aColor to vec3 to drop alpha
fColor = vec4(result, 1.0f); // Reapply alpha
}

View File

@@ -0,0 +1,35 @@
#version 330
// Color input from Vertex shader
in vec4 vColor;
in vec3 vNormal;
in vec3 vPosition;
// Final fragment color
out vec4 fColor;
// Light color RGB value
uniform vec3 uLightColor;
// Light object position vector
uniform vec3 uLightPosition;
// Strength ranges 0.0f - 1.0f
uniform float uAmbientStrength; // 0.2f
void main()
{
// Ambient lighting
vec3 ambient = uAmbientStrength * uLightColor;
// Diffuse lighting
vec3 norm = normalize(vNormal);
vec3 lightDir = normalize(uLightPosition - vPosition);
float diff = max(dot(norm, lightDir), 0.0f);
vec3 diffuse = diff * uLightColor;
// Strip vColor to vec3 to drop alpha
vec3 result = (ambient + diffuse) * vec3(vColor);
// Final output
fColor = vec4(result, 1.0f); // Reapply alpha
}

View File

@@ -0,0 +1,9 @@
#version 330
in vec4 vColor;
out vec4 fColor;
void main()
{
fColor = vColor;
}

View File

@@ -0,0 +1,49 @@
#version 330
// Color input from Vertex shader
in vec4 vColor;
in vec3 vNormal;
in vec3 vPosition;
// Final fragment fColor
out vec4 fColor;
// Light color RGB value
uniform vec3 uLightColor;
// Light object and camera position vectors
uniform vec3 uLightPosition;
uniform vec3 uCameraPosition;
// Strength ranges 0.0f - 1.0f
uniform float uAmbientStrength; // 0.2f
uniform float uSpecularStrength; // 0.25f
// 32, 64, 128, 256
uniform int uSpecularShine; // 64
void main()
{
// Ambient lighting
vec3 ambient = uAmbientStrength * uLightColor;
// Diffuse lighting
vec3 norm = normalize(vNormal);
vec3 lightDir = normalize(uLightPosition - vPosition);
float diff = max(dot(norm, lightDir), 0.0f);
vec3 diffuse = diff * uLightColor;
// Specular lighting
vec3 viewDir = normalize(uCameraPosition - vPosition);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), uSpecularShine);
vec3 specular = uSpecularStrength * spec * uLightColor;
//
// Final calculation
// Strip vColor to vec3 to drop alpha
vec3 result = (ambient + diffuse + specular) * vec3(vColor);
// Final output
fColor = vec4(result, 1.0f); // Reapply alpha
}

View File

@@ -0,0 +1,49 @@
#version 330
// Color input from Vertex shader
in vec4 vColor;
in vec3 vNormal;
in vec3 vPosition;
// Final fragment fColor
out vec4 fColor;
// Light color RGB value
uniform vec3 uLightColor;
// Light object and camera position vectors
uniform vec3 uLightPosition;
uniform vec3 uCameraPosition;
// Strength ranges 0.0f - 1.0f
uniform float uAmbientStrength; // 0.2f
uniform float uSpecularStrength; // 0.25f
// 32, 64, 128, 256
uniform int uSpecularShine; // 64
void main()
{
// Ambient lighting
vec3 ambient = uAmbientStrength * uLightColor;
// Diffuse lighting
vec3 norm = normalize(vNormal);
vec3 lightDir = normalize(uLightPosition - vPosition);
float diff = max(dot(norm, lightDir), 0.0f);
vec3 diffuse = diff * uLightColor;
// Specular lighting
vec3 viewDir = normalize(uCameraPosition - vPosition);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), uSpecularShine);
vec3 specular = uSpecularStrength * spec * uLightColor;
//
// Final calculation
// Strip vColor to vec3 to drop alpha
vec3 result = (ambient + specular) * vec3(vColor);
// Final output
fColor = vec4(result, 1.0f); // Reapply alpha
}

View File

@@ -0,0 +1,9 @@
#version 330
in vec4 vColor;
out vec4 fColor;
void main()
{
fColor = vColor;
}

View File

@@ -0,0 +1,12 @@
#version 330
in vec3 vPosition;
uniform samplerCube uTexture;
out vec4 fColor;
void main()
{
vec4 texCol = texture(uTexture, vPosition);
fColor = texCol;
}

View File

@@ -0,0 +1,12 @@
#version 330
in vec2 vTextureCoord;
uniform sampler2D uTexture;
out vec4 fColor;
void main()
{
vec4 texCol = texture(uTexture, vTextureCoord);
fColor = texCol;
}

View File

@@ -0,0 +1,16 @@
#version 330 core
layout (location = 0) in vec3 aPosition;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTextureCoord;
out vec2 vTextureCoord;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
void main()
{
vTextureCoord = aTextureCoord;
gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.0);
}

View File

@@ -0,0 +1,68 @@
#version 330 core
layout (location = 0) in vec3 aPosition;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTextureCoord;
layout (location = 3) in vec3 aTangent;
layout (location = 4) in vec3 aBitangent;
struct Light {
vec3 position;
// Light colors RGB value
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
uniform Light uLight;
out VS_OUT {
vec2 textureCoord;
vec3 position;
vec3 normal;
vec3 tangentLight;
vec3 tangentView;
vec3 tangentFrag;
Light light;
} vOut;
// Model View Projection matrix found by P * V * M
struct MVP {
mat4 model;
mat4 view;
mat4 projection;
// Additional uniform to allow CPU to provide mat3(transpose(inverse(uModel)))
// + Makes a big difference in quality of diffuse shading
// + QMatrix4x4.normalMatrix() returns a mat3 that can be used as a uniform
mat3 normalMatrix;
};
uniform MVP uMVP;
vec4 VertexPosition(in MVP mvp, in vec3 position)
{
return mvp.projection * mvp.view * mvp.model * vec4(position, 1.0f);
}
// Light object and camera position vectors
uniform vec3 uCameraPosition;
void main()
{
// Finx TBN 3x3 matrix values for normals
vec3 T = normalize(vec3(uMVP.model * vec4(aTangent, 0.0)));
vec3 B = normalize(vec3(uMVP.model * vec4(aBitangent, 0.0)));
vec3 N = normalize(vec3(uMVP.model * vec4(aNormal, 0.0)));
mat3 TBN = transpose(mat3(T, B, N));
// Set tangent postiions for fragment shader
vOut.tangentLight = TBN * uLight.position;
vOut.tangentView = TBN * uCameraPosition;
vOut.tangentFrag = TBN * vec3(uMVP.model * vec4(aPosition, 1.0f));
// Set normal, position, and texture coordinate for frag shader
vOut.textureCoord = aTextureCoord;
vOut.normal = uMVP.normalMatrix * aNormal;
vOut.position = vec3(uMVP.model * vec4(aPosition, 1.0f));
vOut.light = uLight;
gl_Position = VertexPosition(uMVP, aPosition);
}

View File

@@ -0,0 +1,34 @@
#version 330 core
layout (location = 0) in vec3 aPosition;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTextureCoord;
out vec2 vTextureCoord;
out vec3 vPosition;
out vec3 vNormal;
// Model View Projection matrix found by P * V * M
struct MVP {
mat4 model;
mat4 view;
mat4 projection;
// Additional uniform to allow CPU to provide mat3(transpose(inverse(uModel)))
// + Makes a big difference in quality of diffuse shading
// + QMatrix4x4.normalMatrix() returns a mat3 that can be used as a uniform
mat3 normalMatrix;
};
vec4 VertexPosition(in MVP mvp, in vec3 position)
{
return mvp.projection * mvp.view * mvp.model * vec4(position, 1.0f);
}
uniform MVP uMVP;
void main()
{
vTextureCoord = aTextureCoord;
vNormal = uMVP.normalMatrix * aNormal;
vPosition = vec3(uMVP.model * vec4(aPosition, 1.0f));
gl_Position = VertexPosition(uMVP, aPosition);
}

View File

@@ -0,0 +1,68 @@
#version 330 core
layout (location = 0) in vec3 aPosition;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTextureCoord;
layout (location = 3) in vec3 aTangent;
layout (location = 4) in vec3 aBitangent;
struct Light {
vec3 position;
// Light colors RGB value
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
uniform Light uLight;
out VS_OUT {
vec2 textureCoord;
vec3 position;
vec3 normal;
vec3 tangentLight;
vec3 tangentView;
vec3 tangentFrag;
Light light;
} vOut;
// Model View Projection matrix found by P * V * M
struct MVP {
mat4 model;
mat4 view;
mat4 projection;
// Additional uniform to allow CPU to provide mat3(transpose(inverse(uModel)))
// + Makes a big difference in quality of diffuse shading
// + QMatrix4x4.normalMatrix() returns a mat3 that can be used as a uniform
mat3 normalMatrix;
};
uniform MVP uMVP;
vec4 VertexPosition(in MVP mvp, in vec3 position)
{
return mvp.projection * mvp.view * mvp.model * vec4(position, 1.0f);
}
// Light object and camera position vectors
uniform vec3 uCameraPosition;
void main()
{
// Finx TBN 3x3 matrix values for normals
vec3 T = normalize(vec3(uMVP.model * vec4(aTangent, 0.0)));
vec3 B = normalize(vec3(uMVP.model * vec4(aBitangent, 0.0)));
vec3 N = normalize(vec3(uMVP.model * vec4(aNormal, 0.0)));
mat3 TBN = transpose(mat3(T, B, N));
// Set tangent postiions for fragment shader
vOut.tangentLight = TBN * uLight.position;
vOut.tangentView = TBN * uCameraPosition;
vOut.tangentFrag = TBN * vec3(uMVP.model * vec4(aPosition, 1.0f));
// Set normal, position, and texture coordinate for frag shader
vOut.textureCoord = aTextureCoord;
vOut.normal = uMVP.normalMatrix * aNormal;
vOut.position = vec3(uMVP.model * vec4(aPosition, 1.0f));
vOut.light = uLight;
gl_Position = VertexPosition(uMVP, aPosition);
}

View File

@@ -0,0 +1,16 @@
#version 330
layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec3 aColor;
out vec4 vColor;
uniform mat4 uModel; // Model
uniform mat4 uView; // View
uniform mat4 uProjection; // Projection
void main()
{
gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.0);
vColor = vec4(aColor, 1.0f);
}

View File

@@ -0,0 +1,38 @@
#version 330
layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec3 aNormal;
out vec3 vPosition;
out vec3 vNormal;
// Model View Projection matrix found by P * V * M
struct MVP {
mat4 model;
mat4 view;
mat4 projection;
// Additional uniform to allow CPU to provide mat3(transpose(inverse(uModel)))
// + Makes a big difference in quality of diffuse shading
// + QMatrix4x4.normalMatrix() returns a mat3 that can be used as a uniform
mat3 normalMatrix;
};
uniform MVP uMVP;
vec4 VertexPosition(in MVP mvp, in vec3 position)
{
return mvp.projection * mvp.view * mvp.model * vec4(position, 1.0f);
}
void main()
{
// Find normals, pass to fragment shader
vNormal = uMVP.normalMatrix * aNormal;
// vNormal = aNormal; // This is possible without the additional uniform
// Or you could find this on the GPU using the uModel matrix
// vNormal = mat3(transpose(inverse(uModel))) * aNormal;
// Set the vertex position to pass to fragment shader using only model matrix
vPosition = vec3(uMVP.model * vec4(aPosition, 1.0f));
// Set vertex gl_Position using MVP matrix
gl_Position = VertexPosition(uMVP, aPosition);
}

View File

@@ -0,0 +1,26 @@
#version 330
layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec3 aNormal;
// Solid color input from application
// Color to output to fragment shader
out vec3 vNormal;
// Model View Projection matrix found by P * V * M
//uniform mat3 uModelInverseTransposed;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
void main()
{
gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.0);
// This isn't a shader we plan to use heavily, it's useful for testing normals
// + We can see what the value of normals are on the object based on color
vNormal = mat3(transpose(inverse(uModel))) * aNormal;
// vNormal = uModelInverseTransposed * aNormal;
// vNormal = aNormal; // This is possible without the additional uniform
// Or you could find this on the GPU using the uModel matrix
}

View File

@@ -0,0 +1,20 @@
#version 330
layout(location = 0) in vec3 aPosition;
//layout(location = 1) in vec3 vNormal;
// Solid color input from application
uniform vec3 uColor;
// Color to output to fragment shader
out vec4 vColor;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
void main()
{
gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.0);
vColor = vec4(uColor, 1.0f);
}

View File

@@ -0,0 +1,30 @@
#version 330
layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec3 aNormal;
// Solid color input from application
uniform vec3 uColor;
// Color to output to fragment shader
out vec4 vColor;
out vec3 vPosition;
out vec3 vNormal;
// Model View Projection matrix found by P * V * M
uniform mat3 uModelInverseTransposed;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
void main()
{
gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.0);
vPosition = vec3(uModel * vec4(aPosition, 1.0f));
vColor = vec4(uColor, 1.0f);
vNormal = uModelInverseTransposed * aNormal;
// vNormal = aNormal; // This is possible without the additional uniform
// Or you could find this on the GPU using the uModel matrix
// vNormal = mat3(transpose(inverse(uModel))) * aNormal;
}

View File

@@ -0,0 +1,17 @@
#version 330
layout(location = 0) in vec3 aPosition;
out vec4 vColor;
uniform vec3 uColor;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
void main()
{
gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.0);
vColor = vec4(uColor, 1.0f);
}

View File

@@ -0,0 +1,35 @@
#version 330
layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec3 aNormal;
// Solid color input from application
uniform vec3 uColor;
// Color to output to fragment shader
out vec4 vColor;
out vec3 vPosition;
out vec3 vNormal;
// Additional uniform to allow CPU to provide mat3(transpose(inverse(uModel)))
// + Makes a big difference in quality of diffuse shading
// + QMatrix4x4.normalMatrix() returns a mat3 that can be used as a uniform
uniform mat3 uModelInverseTransposed;
// Model View Projection matrix found by P * V * M
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
void main()
{
mat4 mvp = uProjection * uView * uModel;
gl_Position = mvp * vec4(aPosition, 1.0);
vPosition = vec3(uModel * vec4(aPosition, 1.0f));
vColor = vec4(uColor, 1.0f);
vNormal = uModelInverseTransposed * aNormal;
// vNormal = aNormal; // This is possible without the additional uniform
// Or you could find this on the GPU using the uModel matrix
// vNormal = mat3(transpose(inverse(uModel))) * aNormal;
}

View File

@@ -0,0 +1,33 @@
#version 330
layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec3 aNormal;
// Solid color input from application
uniform vec3 uColor;
// Color to output to fragment shader
out vec4 vColor;
out vec3 vPosition;
out vec3 vNormal;
// Additional uniform to allow CPU to provide mat3(transpose(inverse(uModel)))
// + Makes a big difference in quality of diffuse shading
// + QMatrix4x4.normalMatrix() returns a mat3 that can be used as a uniform
uniform mat3 uModelInverseTransposed;
// Model View Projection matrix found by P * V * M
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
void main()
{
gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.0);
vPosition = vec3(uModel * vec4(aPosition, 1.0f));
vColor = vec4(uColor, 1.0f);
vNormal = uModelInverseTransposed * aNormal;
// vNormal = aNormal; // This is possible without the additional uniform
// Or you could find this on the GPU using the uModel matrix
// vNormal = mat3(transpose(inverse(uModel))) * aNormal;
}

View File

@@ -0,0 +1,13 @@
#version 330
layout(location = 0) in vec3 aPosition;
out vec4 vColor;
uniform vec3 uColor;
void main()
{
gl_Position = vec4(aPosition, 1.0);
vColor = vec4(uColor, 1.0f);
}

View File

@@ -0,0 +1,15 @@
#version 330
layout(location = 0) in vec3 aPosition;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
out vec3 vPosition;
void main()
{
vPosition = aPosition;
gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.0);
}

View File

@@ -0,0 +1,16 @@
#version 330
layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec2 aTexture;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
out vec2 vTextureCoord;
void main()
{
vTextureCoord = aTexture;
gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.0);
}