daily update
This commit is contained in:
43
materials/shaders/fscolors.glsl
Normal file
43
materials/shaders/fscolors.glsl
Normal file
@@ -0,0 +1,43 @@
|
||||
#version 330 core
|
||||
|
||||
struct Material {
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
// 光强控制
|
||||
struct Light {
|
||||
vec3 position;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
};
|
||||
uniform Light light;
|
||||
uniform Material material;
|
||||
out vec4 FragColor;
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform vec3 objectColor;
|
||||
uniform vec3 lightColor;
|
||||
|
||||
void main() {
|
||||
// 环境光
|
||||
vec3 ambient = light.ambient * lightColor * material.ambient;
|
||||
// 漫反射
|
||||
vec3 norm= normalize(Normal);
|
||||
vec3 lightDir = normalize(light.position - FragPos);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = light.diffuse * lightColor * (diff * material.diffuse);
|
||||
|
||||
// 镜面光
|
||||
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 * lightColor * (spec * material.specular);
|
||||
vec3 result = ambient + diffuse + specular;
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
8
materials/shaders/fslightCube.glsl
Normal file
8
materials/shaders/fslightCube.glsl
Normal file
@@ -0,0 +1,8 @@
|
||||
#version 330 core
|
||||
|
||||
uniform vec3 aFragColor;
|
||||
out vec4 FragColor;
|
||||
void main() {
|
||||
FragColor = vec4(aFragColor, 1.0);
|
||||
}
|
||||
|
||||
17
materials/shaders/vscolors.glsl
Normal file
17
materials/shaders/vscolors.glsl
Normal file
@@ -0,0 +1,17 @@
|
||||
#version 330 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 * model * vec4(aPos, 1.0);
|
||||
|
||||
}
|
||||
10
materials/shaders/vslightCube.glsl
Normal file
10
materials/shaders/vslightCube.glsl
Normal file
@@ -0,0 +1,10 @@
|
||||
#version 330 core
|
||||
layout(location = 0) in vec3 aPos;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user