rename shaders to .glsl

This commit is contained in:
2023-10-09 21:43:40 -04:00
parent d3c9bd875b
commit ff6559e3ad
5 changed files with 4 additions and 105 deletions

View File

@@ -1,57 +0,0 @@
#version 460 core
out vec4 FragColor;
struct Material {
//sampler2D diffuse;
//sampler2D specular;
float shininess;
vec3 color;
};
struct Light {
vec3 position;
vec3 direction;
float largecutoff;
float smallcutoff;
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
in vec3 FragPos;
in vec3 Normal;
uniform vec3 viewPos;
uniform Material material;
uniform Light light;
void main()
{
vec3 lightDir = normalize(light.position - FragPos);
// check if lighting is inside the spotlight cone
float theta = dot(lightDir, normalize(-light.direction));
float co = clamp((theta - light.largecutoff) / (light.smallcutoff - light.largecutoff), 0.0, 1.0);
// diffuse
vec3 norm = normalize(Normal);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = light.diffuse * diff * material.color * co;
// specular
vec3 viewDir = normalize(viewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
vec3 specular = light.specular * spec * material.color * co;
// attenuation
float distance = length(light.position - FragPos);
float atten = 1.0 / (1.0 + 0.1 * distance + 0.01 * (distance * distance));
diffuse *= atten;
specular *= atten;
vec3 result = light.ambient + diffuse + specular;
FragColor = vec4(result, 1.0);
}

View File

@@ -193,11 +193,11 @@ int main()
glEnable(GL_DEPTH_TEST);
int vertex_shader = createShader("vertexshader.txt", GL_VERTEX_SHADER);
int vertex_shader = createShader("vertexshader.glsl", GL_VERTEX_SHADER);
if (vertex_shader < 0) {
return -1;
}
int fragment_shader = createShader("fragmentshader.txt", GL_FRAGMENT_SHADER);
int fragment_shader = createShader("fragmentshader.glsl", GL_FRAGMENT_SHADER);
if (fragment_shader < 0) {
return -1;
}
@@ -314,11 +314,11 @@ int main()
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void *)0);
glEnableVertexAttribArray(0);
int trail_shader = createShader("trailshader.txt", GL_VERTEX_SHADER);
int trail_shader = createShader("trailshader.glsl", GL_VERTEX_SHADER);
if (trail_shader < 0) {
return -1;
}
int trailfrag_shader = createShader("trailfragshader.txt", GL_FRAGMENT_SHADER);
int trailfrag_shader = createShader("trailfragshader.glsl", GL_FRAGMENT_SHADER);
if (trailfrag_shader < 0) {
return -1;
}

View File

@@ -1,11 +0,0 @@
#version 460 core
out vec4 FragColor;
in vec3 FragPos;
uniform vec3 objectcolor;
void main()
{
FragColor = vec4(objectcolor, 1.0);
}

View File

@@ -1,15 +0,0 @@
#version 460 core
layout (location = 0) in vec3 aPos;
out vec3 FragPos;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
FragPos = vec3(model * vec4(aPos, 1.0));
gl_Position = projection * view * vec4(FragPos, 1.0);
}

View File

@@ -1,18 +0,0 @@
#version 460 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
out vec3 FragPos;
out vec3 Normal;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
FragPos = vec3(model * vec4(aPos, 1.0));
Normal = mat3(transpose(inverse(model))) * aNormal;
gl_Position = projection * view * vec4(FragPos, 1.0);
}