better lighting
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(binding = 0) uniform ObjectUniformData {
|
||||
mat4 view;
|
||||
mat4 projection;
|
||||
float time;
|
||||
vec3 light_position;
|
||||
vec3 camera_position;
|
||||
} ubo;
|
||||
|
||||
layout(binding = 1) uniform sampler2D tex;
|
||||
|
||||
layout(location = 0) in vec2 tex_coords;
|
||||
layout(location = 1) in vec3 normal_cam;
|
||||
layout(location = 2) in vec3 position_cam;
|
||||
layout(location = 3) in vec3 light_direction_cam;
|
||||
layout(location = 1) in vec3 normal_wld;
|
||||
layout(location = 2) in vec3 position_wld;
|
||||
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
void main() {
|
||||
vec3 normal_cam_u = normalize(normal_cam);
|
||||
vec3 light_direction_cam_u = normalize(light_direction_cam);
|
||||
vec3 normal_cam_u = normalize(normal_wld);
|
||||
vec3 light_direction_cam_u = normalize(ubo.light_position - position_wld);
|
||||
|
||||
float ambient_strength = 0.1;
|
||||
vec3 light_color = vec3(1.0, 1.0, 1.0);
|
||||
@@ -21,11 +28,11 @@ void main() {
|
||||
float diffuse_strength = max(0.0, dot(normal_cam_u, light_direction_cam_u));
|
||||
vec3 diffuse_color = diffuse_strength * light_color;
|
||||
|
||||
// float specular_value = 1.0;
|
||||
// vec3 view_direction = normalize(position_cam);
|
||||
// vec3 reflect_direction = reflect(-light_direction_cam_nm, normal_cam_nm);
|
||||
// float specular_strength = pow(max(dot(view_direction, reflect_direction), 0.0), 32);
|
||||
// vec3 specular_color = specular_value * specular_strength * light_color;
|
||||
float specular_value = 1.0;
|
||||
vec3 view_direction = normalize(ubo.camera_position - position_wld);
|
||||
vec3 reflect_direction = reflect(-light_direction_cam_u, normal_cam_u);
|
||||
float specular_strength = pow(max(dot(view_direction, reflect_direction), 0.0), 64);
|
||||
vec3 specular_color = specular_value * specular_strength * light_color;
|
||||
|
||||
out_color = vec4(ambient_color + diffuse_color, 1.0) * texture(tex, tex_coords);
|
||||
out_color = vec4(ambient_color + diffuse_color + specular_color, 1.0) * texture(tex, tex_coords);
|
||||
}
|
||||
Reference in New Issue
Block a user