alistair
2 years ago
13 changed files with 410 additions and 3 deletions
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
#version 330 core |
||||
|
||||
out vec4 LFragment; |
||||
|
||||
in vec2 theTexCoord; |
||||
in vec3 Normal; |
||||
in vec3 FragPos; |
||||
|
||||
//uniform vec3 objectColour; |
||||
//uniform vec3 lightColour; |
||||
uniform int lighting_emit; |
||||
|
||||
//uniform vec3 lightPosition; |
||||
uniform vec3 cameraPosition; |
||||
uniform sampler2D texture_diffuse1; |
||||
|
||||
struct Material { |
||||
sampler2D texture_diffuse1; |
||||
sampler2D texture_diffuse2; |
||||
sampler2D texture_diffuse3; |
||||
sampler2D texture_specular1; |
||||
sampler2D texture_specular2; |
||||
sampler2D texture_specular3; |
||||
vec3 ambient; |
||||
vec3 diffuse; |
||||
vec3 specular; |
||||
float shininess; |
||||
}; |
||||
|
||||
#define DIRECTIONAL_LIGHT 0 |
||||
#define POINT_LIGHT 1 |
||||
#define SPOT_LIGHT 2 |
||||
|
||||
struct Light { |
||||
int type; |
||||
vec3 direction; |
||||
vec3 position; |
||||
float angle_cutoff; |
||||
float outer_angle_cutoff; |
||||
vec3 ambient; |
||||
vec3 diffuse; |
||||
vec3 specular; |
||||
bool attenuate; |
||||
vec3 attenuation; |
||||
}; |
||||
|
||||
#define MAX_LIGHTS 10 |
||||
|
||||
uniform Light lights[MAX_LIGHTS]; |
||||
uniform int num_lights; |
||||
|
||||
uniform Material material; |
||||
// uniform Light light; |
||||
|
||||
void main() |
||||
{ |
||||
|
||||
LFragment = vec4(texture(material.texture_diffuse1, theTexCoord)); |
||||
if (LFragment.a < 0.1) |
||||
discard; |
||||
} |
||||
|
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
#version 330 core |
||||
|
||||
layout (location = 0) in vec3 LVertexPos2D; |
||||
layout (location = 1) in vec3 aNormal; |
||||
layout (location = 2) in vec2 aTexCoords; |
||||
layout (location = 3) in vec3 offset; |
||||
layout (location = 4) in vec3 aTangent; |
||||
layout (location = 5) in mat4 modelInst; |
||||
|
||||
uniform mat4 model; |
||||
uniform mat4 view; |
||||
uniform mat4 projection; |
||||
|
||||
out vec3 Normal; |
||||
out vec3 FragPos; |
||||
out vec3 theTexCoord; |
||||
out mat3 TBN; |
||||
|
||||
void main() |
||||
{ |
||||
vec4 pos = (vec4( LVertexPos2D, 1.0) + vec4(offset, 0)); |
||||
|
||||
vec4 ppos = projection * view * model * pos; |
||||
|
||||
// ps1 jiggle |
||||
vec2 resolution = vec2(100,75); |
||||
vec4 snapped = ppos; |
||||
snapped.xyz = ppos.xyz / ppos.w; |
||||
snapped.xy = floor(resolution * snapped.xy) / resolution; |
||||
snapped.xyz *= ppos.w; |
||||
|
||||
// use gl_Position = ppos; to disable jiggle |
||||
gl_Position = snapped; |
||||
|
||||
theTexCoord = vec3(aTexCoords, 1.0); |
||||
Normal = mat3(transpose(inverse(model))) * aNormal; |
||||
FragPos = vec3((model) * pos); |
||||
|
||||
// calculating TBN |
||||
vec3 T = normalize(vec3(model * vec4(aTangent, 0.0))); |
||||
vec3 N = normalize(vec3(model * vec4(aNormal, 0.0))); |
||||
|
||||
T = normalize(T - dot(T, N) * N); |
||||
vec3 B = cross(N,T); |
||||
|
||||
TBN = mat3(T, B, N); |
||||
|
||||
|
||||
} |
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
#version 330 core |
||||
out vec4 FragColor; |
||||
|
||||
void main() |
||||
{ |
||||
FragColor = vec4(1.0, 1.0, 0.0, 1.0); |
||||
} |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
|
||||
#version 330 core |
||||
layout (triangles) in; |
||||
layout (line_strip, max_vertices = 6) out; |
||||
|
||||
in vec3 Normal[]; |
||||
in vec3 FragPos[]; |
||||
|
||||
const float MAGNITUDE = 0.4; |
||||
|
||||
uniform mat4 projection; |
||||
|
||||
void GenerateLine(int index) |
||||
{ |
||||
gl_Position = projection * FragPos[index]; |
||||
EmitVertex(); |
||||
gl_Position = projection * (FragPos[index] + |
||||
(Normal[index], 0.0) * MAGNITUDE); |
||||
EmitVertex(); |
||||
EndPrimitive(); |
||||
} |
||||
|
||||
void main() |
||||
{ |
||||
GenerateLine(0); // first vertex normal |
||||
GenerateLine(1); // second vertex normal |
||||
GenerateLine(2); // third vertex normal |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
#version 330 core |
||||
out vec4 FragColor; |
||||
|
||||
in vec2 TexCoords; |
||||
|
||||
uniform sampler2D screenTexture; |
||||
|
||||
const float gamma = 2.2; |
||||
uniform float exposure = 0.8; |
||||
|
||||
void main() |
||||
{ |
||||
vec3 hdrcol = texture(screenTexture, TexCoords).rgb; |
||||
vec3 mapped = vec3(1.0) - exp((-hdrcol) * exposure); |
||||
//vec3 mapped = hdrcol / (hdrcol + vec3(1.0)); |
||||
// gamma correction |
||||
mapped = pow(mapped, vec3(1.0 / gamma)); |
||||
|
||||
FragColor = vec4(mapped, 1.0); |
||||
|
||||
} |
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
#version 330 core |
||||
layout (location = 0) in vec2 aPos; |
||||
layout (location = 1) in vec2 aTexCoords; |
||||
|
||||
out vec2 TexCoords; |
||||
|
||||
void main() |
||||
{ |
||||
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0); |
||||
TexCoords = aTexCoords; |
||||
} |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
#version 330 core |
||||
out vec4 FragColor; |
||||
|
||||
in vec3 TexCoords; |
||||
|
||||
uniform samplerCube skybox; |
||||
|
||||
void main() |
||||
{ |
||||
// FragColor = vec4(0.0,0.0,0.0,1.1); |
||||
FragColor = texture(skybox, TexCoords); |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
|
||||
#version 330 core |
||||
layout (location = 0) in vec3 LVertexPos2D; |
||||
layout (location = 1) in vec3 aNormal; |
||||
layout (location = 2) in vec2 aTexCoords; |
||||
layout (location = 4) in vec2 aTangent; |
||||
|
||||
out vec3 TexCoords; |
||||
|
||||
uniform mat4 view; |
||||
uniform mat4 projection; |
||||
|
||||
void main() |
||||
{ |
||||
TexCoords = LVertexPos2D; |
||||
vec4 pos = projection * view * vec4( LVertexPos2D, 1.0); |
||||
gl_Position = pos.xyww; |
||||
} |
@ -0,0 +1,151 @@
@@ -0,0 +1,151 @@
|
||||
#version 330 core |
||||
|
||||
out vec4 LFragment; |
||||
|
||||
in vec3 Normal; |
||||
in vec3 FragPos; |
||||
in mat3 TBN; |
||||
in vec3 theTexCoord; |
||||
|
||||
uniform vec3 cameraPosition; |
||||
uniform samplerCube skybox; |
||||
|
||||
|
||||
float gamma = 2.2; |
||||
|
||||
struct Material { |
||||
sampler2D texture_diffuse1; |
||||
sampler2D texture_diffuse2; |
||||
sampler2D texture_diffuse3; |
||||
float shininess; |
||||
}; |
||||
|
||||
#define DIRECTIONAL_LIGHT 0 |
||||
#define POINT_LIGHT 1 |
||||
#define SPOT_LIGHT 2 |
||||
|
||||
|
||||
struct Light { |
||||
int type; |
||||
vec3 direction; |
||||
vec3 position; |
||||
float angle_cutoff; |
||||
float outer_angle_cutoff; |
||||
vec3 ambient; |
||||
vec3 diffuse; |
||||
vec3 specular; |
||||
bool attenuate; |
||||
vec3 attenuation; |
||||
}; |
||||
|
||||
#define MAX_LIGHTS 10 |
||||
|
||||
uniform Light lights[MAX_LIGHTS]; |
||||
uniform int num_lights; |
||||
|
||||
uniform Material material; |
||||
|
||||
vec4 |
||||
reflection(vec3 norm) |
||||
{ |
||||
vec3 reflectiveness = material.specular * material.shininess / 50; |
||||
vec3 I = normalize(FragPos - cameraPosition); |
||||
vec3 R = reflect(I, norm); |
||||
return texture(skybox, R) * (material.shininess / 90); |
||||
} |
||||
|
||||
float |
||||
spotlight(int i, vec3 lightDir) |
||||
{ |
||||
|
||||
float theta = dot(lightDir, normalize(-lights[i].direction)); |
||||
float epsilon = lights[i].angle_cutoff - lights[i].outer_angle_cutoff; |
||||
float intensity = clamp((theta - lights[i].outer_angle_cutoff)/epsilon, 0.0, 1.0); |
||||
|
||||
return intensity; |
||||
} |
||||
|
||||
float |
||||
attenuation(int i) |
||||
{ |
||||
float dist = length(lights[i].position - FragPos); |
||||
// for no gamma correction |
||||
//float attenuation = 1.0 / (lights[i].attenuation.x + lights[i].attenuation.y * |
||||
//dist + lights[i].attenuation.y * (dist * dist)); |
||||
|
||||
// for gamma correction |
||||
float attenuation = 1.0 / (lights[i].attenuation.x + lights[i].attenuation.y * |
||||
dist + lights[i].attenuation.y * (dist)); |
||||
return attenuation; |
||||
} |
||||
|
||||
vec3 |
||||
specular(int i, vec3 lightDir, vec3 norm) |
||||
{ |
||||
float spec = max(dot(normalize(cameraPosition - FragPos), reflect(-lightDir, norm)), 0.0); |
||||
spec = pow(spec, material.shininess); |
||||
vec3 specular = lights[i].specular * (spec * |
||||
vec3(texture(material.texture_specular1, vec2(theTexCoord)))); |
||||
return specular; |
||||
} |
||||
|
||||
vec3 |
||||
diffuse(int i, vec3 lightDir, vec3 norm) |
||||
{ |
||||
float diff_val = max(dot(norm, lightDir), 0.0); |
||||
vec3 diffuse = lights[i].diffuse * (diff_val * material.diffuse); |
||||
return diffuse; |
||||
} |
||||
|
||||
|
||||
void |
||||
main() |
||||
{ |
||||
vec3 endResult = vec3(0); |
||||
// normal |
||||
vec3 norm; |
||||
norm = texture(material.texture_normal1, vec2(theTexCoord)).rgb; |
||||
norm = norm * 2.0 - 1.0; |
||||
norm = normalize(TBN * norm); |
||||
|
||||
for (int i = 0; i < num_lights; i++) { |
||||
|
||||
vec3 ambient = lights[i].ambient * material.ambient; |
||||
|
||||
|
||||
// diffuse |
||||
vec3 lightDir = vec3(0); |
||||
if (lights[i].type == POINT_LIGHT || lights[i].type == SPOT_LIGHT) { |
||||
lightDir = normalize(lights[i].position - FragPos); |
||||
} else if (lights[i].type == DIRECTIONAL_LIGHT) { |
||||
lightDir = normalize(-lights[i].direction); |
||||
} |
||||
|
||||
vec3 diffuse = diffuse(i, lightDir, norm); |
||||
|
||||
vec3 specular = specular(i, lightDir, norm); |
||||
|
||||
vec3 result = ambient; |
||||
float intensity = 1.0; |
||||
|
||||
if (lights[i].type == SPOT_LIGHT) { |
||||
intensity = spotlight(i, lightDir); |
||||
} |
||||
|
||||
result = ambient + (diffuse + specular) * intensity; |
||||
|
||||
if (lights[i].attenuate) { |
||||
result *= attenuation(i); |
||||
} |
||||
|
||||
endResult += result; |
||||
} |
||||
|
||||
vec4 parta = (vec4(endResult, 1.0)) * texture(material.texture_diffuse1, vec2(theTexCoord)); |
||||
LFragment = parta; |
||||
// gamma correction |
||||
// LFragment.rgb = pow(parta.rgb, vec3(1.0/gamma)); |
||||
// LFragment = vec4(norm, 1); |
||||
|
||||
} |
||||
|
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
#version 330 core |
||||
|
||||
layout (location = 0) in vec3 aVertexPos; |
||||
layout (location = 1) in vec3 aNormal; |
||||
layout (location = 2) in vec2 aTexCoords; |
||||
layout (location = 4) in vec3 aTangent; |
||||
|
||||
uniform mat4 model; |
||||
uniform mat4 view; |
||||
uniform mat4 projection; |
||||
uniform bool skyboxON; |
||||
|
||||
out vec3 Normal; |
||||
out vec3 FragPos; |
||||
out vec3 theTexCoord; |
||||
out mat3 TBN; |
||||
|
||||
void main() |
||||
{ |
||||
gl_Position = projection * view * model * vec4( aVertexPos, 1.0); |
||||
|
||||
|
||||
if (skyboxON) { |
||||
theTexCoord = aVertexPos; |
||||
FragPos = aVertexPos; // vec3(model * vec4(aVertexPos, 1.0)); |
||||
return; |
||||
} |
||||
|
||||
// calculating TBN |
||||
vec3 T = normalize(vec3(model * vec4(aTangent, 0.0))); |
||||
vec3 N = normalize(vec3(model * vec4(aNormal, 0.0))); |
||||
|
||||
T = normalize(T - dot(T, N) * N); |
||||
vec3 B = cross(N,T); |
||||
|
||||
TBN = mat3(T, B, N); |
||||
|
||||
// calculating normal |
||||
theTexCoord = vec3(aTexCoords, 1.0); |
||||
Normal = mat3(transpose(inverse(model))) * aNormal; |
||||
FragPos = vec3(model * vec4(aVertexPos, 1.0)); |
||||
} |
Loading…
Reference in new issue