forked from LukasBanana/LLGL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.450core.frag
More file actions
46 lines (34 loc) · 1.17 KB
/
Example.450core.frag
File metadata and controls
46 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// GLSL fragment shader
#version 450 core
layout(std140, binding = 1) uniform Settings
{
mat4 wMatrix;
mat4 vpMatrix;
vec3 lightDir;
float shininess;
vec4 viewPos;
vec4 albedo;
};
layout(location = 0) in vec4 vWorldPos;
layout(location = 1) in vec4 vNormal;
layout(location = 2) in vec2 vTexCoord;
layout(location = 0) out vec4 fColor;
layout(binding = 2) uniform texture2D colorMap;
layout(binding = 3) uniform sampler linearSampler;
void main()
{
// Diffuse lighting
vec3 lightVec = -lightDir.xyz;
vec3 normal = normalize(vNormal.xyz);
float NdotL = mix(0.2, 1.0, max(0.0, dot(normal, lightVec)));
vec3 diffuse = albedo.rgb * NdotL;
// Specular lighting
vec3 viewDir = normalize(viewPos.xyz - vWorldPos.xyz);
vec3 halfVec = normalize(viewDir + lightVec);
float NdotH = dot(normal, halfVec);
vec3 specular = vec3(pow(max(0.0, NdotH), shininess));
// Sample texture
vec4 color = texture(sampler2D(colorMap, linearSampler), vTexCoord);
// Set final output color
fColor = mix(vec4(1), color, albedo.a) * vec4(diffuse + specular, 1.0);
}