Code cleanup
This commit is contained in:
parent
4d0d96e0af
commit
3c0f3e18cd
3 changed files with 5 additions and 37 deletions
|
|
@ -18,7 +18,6 @@ struct Light {
|
|||
|
||||
layout (binding = 3) uniform UBO
|
||||
{
|
||||
vec4 viewPos;
|
||||
Light lights[NUM_LIGHTS];
|
||||
} ubo;
|
||||
|
||||
|
|
@ -30,40 +29,24 @@ void main()
|
|||
vec3 normal = subpassLoad(samplerNormal).rgb;
|
||||
vec4 albedo = subpassLoad(samplerAlbedo);
|
||||
|
||||
#define ambient 0.15
|
||||
#define ambient 0.05
|
||||
|
||||
// Ambient part
|
||||
vec3 fragcolor = albedo.rgb * ambient;
|
||||
|
||||
for(int i = 0; i < NUM_LIGHTS; ++i)
|
||||
{
|
||||
// Vector to light
|
||||
vec3 L = ubo.lights[i].position.xyz - fragPos;
|
||||
// Distance from light to fragment position
|
||||
float dist = length(L);
|
||||
|
||||
// Viewer to fragment
|
||||
vec3 V = ubo.viewPos.xyz - fragPos;
|
||||
V = normalize(V);
|
||||
|
||||
// Light to fragment
|
||||
L = normalize(L);
|
||||
float atten = ubo.lights[i].radius / (pow(dist, 3.0) + 1.0);
|
||||
|
||||
// Attenuation
|
||||
float atten = ubo.lights[i].radius / (pow(dist, 2.0) + 1.0);
|
||||
|
||||
// Diffuse part
|
||||
vec3 N = normalize(normal);
|
||||
float NdotL = max(0.0, dot(N, L));
|
||||
vec3 diff = ubo.lights[i].color * albedo.rgb * NdotL * atten;
|
||||
|
||||
// Specular part
|
||||
// Specular map values are stored in alpha of albedo mrt
|
||||
vec3 R = reflect(-L, N);
|
||||
float NdotR = max(0.0, dot(R, V));
|
||||
//vec3 spec = ubo.lights[i].color * albedo.a * pow(NdotR, 32.0) * atten;
|
||||
|
||||
fragcolor += diff;// + spec;
|
||||
fragcolor += diff;
|
||||
}
|
||||
|
||||
outColor = vec4(fragcolor, 1.0);
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue