mirror of https://github.com/sotrh/learn-wgpu
migrated gifs
parent
032253fea9
commit
4a772f7ee0
@ -1,35 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout(location=0) in vec2 v_tex_coords;
|
||||
layout(location=1) in vec3 v_normal;
|
||||
layout(location=2) in vec3 v_position;
|
||||
|
||||
layout(location=0) out vec4 f_color;
|
||||
|
||||
layout(set = 0, binding = 0) uniform texture2D t_diffuse;
|
||||
layout(set = 0, binding = 1) uniform sampler s_diffuse;
|
||||
|
||||
layout(set=1, binding=2)
|
||||
uniform Lights {
|
||||
vec3 u_light;
|
||||
};
|
||||
|
||||
const vec3 ambient_color = vec3(0.0, 0.0, 0.0);
|
||||
const vec3 specular_color = vec3(1.0, 1.0, 1.0);
|
||||
|
||||
const float shininess = 32;
|
||||
|
||||
void main() {
|
||||
vec4 diffuse_color = texture(sampler2D(t_diffuse, s_diffuse), v_tex_coords);
|
||||
float diffuse_term = max(dot(normalize(v_normal), normalize(u_light)), 0);
|
||||
|
||||
vec3 camera_dir = normalize(-v_position);
|
||||
|
||||
// This is an aproximation of the actual reflection vector, aka what
|
||||
// angle you have to look at the object to be blinded by the light
|
||||
vec3 half_direction = normalize(normalize(u_light) + camera_dir);
|
||||
float specular_term = pow(max(dot(normalize(v_normal), half_direction), 0.0), shininess);
|
||||
|
||||
f_color = vec4(ambient_color, 1.0) + vec4(specular_term * specular_color, 1.0) + diffuse_term * diffuse_color;
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout(location=0) in vec3 a_position;
|
||||
layout(location=1) in vec2 a_tex_coords;
|
||||
layout(location=2) in vec3 a_normal;
|
||||
|
||||
layout(location=0) out vec2 v_tex_coords;
|
||||
layout(location=1) out vec3 v_normal;
|
||||
layout(location=2) out vec3 v_position;
|
||||
|
||||
layout(set=1, binding=0)
|
||||
uniform Uniforms {
|
||||
mat4 u_view_proj;
|
||||
};
|
||||
|
||||
layout(set=1, binding=1)
|
||||
buffer Instances {
|
||||
mat4 s_models[];
|
||||
};
|
||||
|
||||
void main() {
|
||||
v_tex_coords = a_tex_coords;
|
||||
|
||||
mat4 model = s_models[gl_InstanceIndex];
|
||||
|
||||
// Rotate the normals with respect to the model, ignoring scaling
|
||||
mat3 normal_matrix = mat3(transpose(inverse(mat3(model))));
|
||||
v_normal = normal_matrix * a_normal;
|
||||
|
||||
gl_Position = u_view_proj * model * vec4(a_position, 1.0);
|
||||
|
||||
// Get the position relative to the view for the lighting calc
|
||||
v_position = gl_Position.xyz / gl_Position.w;
|
||||
}
|
Loading…
Reference in New Issue