41 lines
1.3 KiB
Plaintext
41 lines
1.3 KiB
Plaintext
#version 450 core
|
|
layout(local_size_x= 20, local_size_y=1) in;
|
|
layout(rgba8, binding = 5) uniform restrict writeonly image2D img_output;
|
|
layout (std140, binding = 1) uniform LightsBlock
|
|
{
|
|
vec4 posBool[20];
|
|
vec4 colRad[20];
|
|
} ;
|
|
layout (binding = 0) uniform sampler2D posTexture;
|
|
layout (binding = 1) uniform sampler2D normals;
|
|
void main ()
|
|
{
|
|
shared vec3[20] larray;
|
|
uint i = gl_LocalInvocationID.x;
|
|
vec3 lightamount = vec3(0,0,0);
|
|
ivec2 pixel_coords = ivec2(gl_WorkGroupID.xy);
|
|
vec2 tex_coords = vec2((4*pixel_coords.x+4)/800.0, (4*pixel_coords.y+4)/835.0);
|
|
vec3 pos = texture(posTexture,tex_coords).xyz;
|
|
vec3 lightPos = posBool[i].xyz;
|
|
vec4 lumRad = colRad[i];
|
|
vec3 distVec = lightPos - pos;
|
|
float dist = dot (distVec,distVec);
|
|
if (dist > lumRad.a) { }
|
|
else
|
|
{
|
|
float x = 1 - dist / lumRad.a;
|
|
vec3 norm = texture(normals,tex_coords).xyz;
|
|
float y1 = dot(normalize(norm), normalize(distVec));
|
|
float y = float(y1 > 0 ? 0 : 1);
|
|
lightamount = y*x*lumRad.rgb;
|
|
|
|
}
|
|
larray[i] = lightamount;
|
|
if (i == 0)
|
|
{ vec3 inverselight = 1 - lightamount;
|
|
//{ vec3 inverselight = vec3(0,0,0);
|
|
for (uint j=1 ; j < 20; ++j) {inverselight = inverselight * (1 - larray[j]);}
|
|
imageStore(img_output, pixel_coords, vec4(inverselight,1));
|
|
}
|
|
}
|