Point light working
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
//*PIXEL*
|
||||
#version 460
|
||||
|
||||
#extension GL_ARB_bindless_texture : require
|
||||
|
||||
const uint DIRECTIONAL_LIGHT = 1;
|
||||
const uint POINT_LIGHT = 2;
|
||||
const uint SPOT_LIGHT = 3;
|
||||
uint INVALID_HYDRA_ID = 4294967295;
|
||||
|
||||
struct MaterialStore
|
||||
{
|
||||
vec4 diffuse_colour;
|
||||
vec4 matalic_rough;
|
||||
uint diffuse_texture_id;
|
||||
uint metallic_rough_texture_id;
|
||||
uint normal_texture_id;
|
||||
uint padding[1];
|
||||
};
|
||||
|
||||
struct PointShadowMapSet
|
||||
{
|
||||
uint entity_id;
|
||||
uint shadow_id;
|
||||
uint shadow_texture_id;
|
||||
uint frame_buffer_id;
|
||||
float near_plane;
|
||||
float far_plane;
|
||||
uint padding[2];
|
||||
mat4 light_space_proj;
|
||||
mat4 light_space_view[6];
|
||||
|
||||
};
|
||||
|
||||
layout(std430, binding = 2) readonly buffer material_buffer
|
||||
{
|
||||
MaterialStore materials[1000];
|
||||
};
|
||||
|
||||
layout(std430, binding = 3) readonly buffer texture_buffer
|
||||
{
|
||||
uvec2 textures[1000];
|
||||
};
|
||||
|
||||
layout (std430, binding = 7) readonly buffer point_shadow_map_sets
|
||||
{
|
||||
PointShadowMapSet point_shadows[];
|
||||
};
|
||||
|
||||
layout (location=0) in GEOM_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
flat uint vsMaterialID;
|
||||
vec4 frag_pos;
|
||||
flat uint shad_idx;
|
||||
flat vec3 light_pos;
|
||||
}geom_out;
|
||||
|
||||
layout (location=0) out vec4 output_colour;
|
||||
|
||||
void main()
|
||||
{
|
||||
MaterialStore mat = materials[geom_out.vsMaterialID];
|
||||
vec4 diffuse_val = mat.diffuse_colour;
|
||||
if(mat.diffuse_texture_id != INVALID_HYDRA_ID)
|
||||
{
|
||||
uvec2 diffuse_handle = textures[mat.diffuse_texture_id];
|
||||
diffuse_val = diffuse_val * texture(sampler2D(diffuse_handle), geom_out.vsUV.xy);
|
||||
}
|
||||
|
||||
if(diffuse_val[3] < 1.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
|
||||
float light_distance = length(geom_out.frag_pos.xyz - geom_out.light_pos);
|
||||
|
||||
// map to [0;1] range by dividing by far_plane
|
||||
light_distance = light_distance / point_shadows[geom_out.shad_idx].far_plane;
|
||||
|
||||
// write this as modified depth
|
||||
gl_FragDepth = light_distance;
|
||||
}
|
||||
Reference in New Issue
Block a user