07/shaders/shader.frag

43 lines
1.3 KiB
GLSL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#version 420 core
in vec2 texCoord;
in float diffuse; // Диффузная составляющая
in float specular; // Зеркальная составляющая
layout(std140, binding = 1) uniform Material
{
vec3 ka;
vec3 kd;
vec3 ks;
float p;
} material_f;
layout(std140, binding = 2) uniform Light
{
vec3 position;
vec3 color;
} light_f;
uniform sampler2D tex_diffuse;
uniform sampler2D tex_ambient;
uniform sampler2D tex_specular;
out vec4 color;
void main()
{
// Диффузная составляющая
float diffuse = max(dot(L_vertex, N), 0.0); // скалярное произведение с отсеканием значений < 0
// Отраженный вектор
vec3 R = normalize(reflect(-L_vertex, N));
// Зеркальная составляющая
float specular = 0;
// Если есть диффузная составляющая, то считаем зеркальную
if (diffuse > 0)
specular = pow(max(dot(Cam_vertex, R), 0.0), p); // скалярное произведение с отсеканием значений < 0 в степени p
color = vec4(ka, 1)*texture(tex_ambient, texCoord) + vec4(light_f.color*kd*diffuse, 1)*texture(tex_diffuse, texCoord) + vec4(light_f.color*ks*specular, 1)*texture(tex_specular, texCoord);
}