Directional Shdaows, no alpha
This commit is contained in:
@@ -16,8 +16,8 @@ uint HYDRA_LIGHT_DIRECTIONAL = 1;
|
||||
uint HYDRA_LIGHT_POINT = 2;
|
||||
uint HYDRA_LIGHT_SPOT = 3;
|
||||
|
||||
struct light_structure
|
||||
{
|
||||
struct LightStructure
|
||||
{
|
||||
vec4 ambient;
|
||||
vec4 diffuse;
|
||||
vec4 specular;
|
||||
@@ -29,36 +29,59 @@ struct light_structure
|
||||
float cutoff_outer;
|
||||
uint entity_id;
|
||||
uint light_type;
|
||||
uint shadow_map_id;
|
||||
uint shadow_caster;
|
||||
uint padding0;
|
||||
uint padding1;
|
||||
};
|
||||
|
||||
struct ShadowMapSet
|
||||
{
|
||||
uint entity_id;
|
||||
uint cascade_count;
|
||||
uint shadow_texture_id;
|
||||
uint frame_buffer_id;
|
||||
float near_plane[8];
|
||||
float far_plane[8];
|
||||
mat4 light_space_proj[6];
|
||||
mat4 light_space_view[6];
|
||||
};
|
||||
|
||||
|
||||
layout(binding = 0) uniform uniform_per_frame
|
||||
{
|
||||
{
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
vec3 viewer_pos;
|
||||
vec3 viewer_pos;
|
||||
uint light_count;
|
||||
} ubo_per_frame;
|
||||
|
||||
|
||||
layout(binding = 1) uniform uniform_output_textures
|
||||
{
|
||||
{
|
||||
uint texture_ids[16];
|
||||
};
|
||||
|
||||
layout(std430, binding = 1) readonly buffer PositionsBuffer
|
||||
layout(std430, binding = 1) readonly buffer positions_buffer
|
||||
{
|
||||
mat4 model_matrix[];
|
||||
};
|
||||
|
||||
layout( std430, binding = 3) readonly buffer TextureBuffer {
|
||||
layout( std430, binding = 3) readonly buffer texture_buffer {
|
||||
uvec2 textures[1000];
|
||||
};
|
||||
|
||||
layout (std430, binding = 4) readonly buffer LightBuffer
|
||||
layout (std430, binding = 4) readonly buffer light_buffer
|
||||
{
|
||||
light_structure lights[500];
|
||||
LightStructure lights[500];
|
||||
};
|
||||
|
||||
layout (std430, binding = 5) readonly buffer shadow_map_sets
|
||||
{
|
||||
ShadowMapSet shadows[10];
|
||||
};
|
||||
|
||||
|
||||
layout (location=0) in VS_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
@@ -116,38 +139,38 @@ vec3 CalculatePBR(vec3 normal, vec3 view_pos, vec3 world_pos,vec3 light_dir, vec
|
||||
vec3 N = normalize(normal);
|
||||
vec3 V = normalize(view_pos - world_pos);
|
||||
|
||||
// calculate reflectance at normal incidence; if dia-electric (like plastic) use F0
|
||||
// of 0.04 and if it's a metal, use the albedo color as F0 (metallic workflow)
|
||||
vec3 F0 = vec3(0.04);
|
||||
// calculate reflectance at normal incidence; if dia-electric (like plastic) use F0
|
||||
// of 0.04 and if it's a metal, use the albedo color as F0 (metallic workflow)
|
||||
vec3 F0 = vec3(0.04);
|
||||
F0 = mix(F0, diffuse, metallic);
|
||||
|
||||
|
||||
|
||||
// calculate per-light radiance
|
||||
vec3 L = normalize(light_dir);
|
||||
vec3 H = normalize(V + L);
|
||||
|
||||
// Cook-Torrance BRDF
|
||||
float NDF = DistributionGGX(N, H, roughness);
|
||||
float G = GeometrySmith(N, V, L, roughness);
|
||||
float NDF = DistributionGGX(N, H, roughness);
|
||||
float G = GeometrySmith(N, V, L, roughness);
|
||||
vec3 F = fresnelSchlick(clamp(dot(H, V), 0.0, 1.0), F0);
|
||||
|
||||
vec3 numerator = NDF * G * F;
|
||||
|
||||
vec3 numerator = NDF * G * F;
|
||||
float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.0001; // + 0.0001 to prevent divide by zero
|
||||
vec3 specular = numerator / denominator;
|
||||
|
||||
|
||||
// kS is equal to Fresnel
|
||||
vec3 kS = F;
|
||||
// for energy conservation, the diffuse and specular light can't
|
||||
// be above 1.0 (unless the surface emits light); to preserve this
|
||||
// relationship the diffuse component (kD) should equal 1.0 - kS.
|
||||
vec3 kD = vec3(1.0) - kS;
|
||||
// multiply kD by the inverse metalness such that only non-metals
|
||||
// multiply kD by the inverse metalness such that only non-metals
|
||||
// have diffuse lighting, or a linear blend if partly metal (pure metals
|
||||
// have no diffuse light).
|
||||
kD *= 1.0 - metallic;
|
||||
kD *= 1.0 - metallic;
|
||||
|
||||
// scale light by NdotL
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
|
||||
// add to outgoing radiance Lo
|
||||
vec3 Lo = (kD * diffuse / PI + specular) * radiance * NdotL; // note that we already multiplied the BRDF by the Fresnel (kS) so we won't multiply by kS again
|
||||
@@ -155,88 +178,82 @@ vec3 CalculatePBR(vec3 normal, vec3 view_pos, vec3 world_pos,vec3 light_dir, vec
|
||||
return Lo;
|
||||
}
|
||||
|
||||
vec3 DirectionalShading(vec3 normal,
|
||||
vec3 diffuse,
|
||||
float roughness,
|
||||
float metallic,
|
||||
float light_intensity,
|
||||
vec3 light_dir,
|
||||
vec3 light_pos,
|
||||
vec3 world_pos,
|
||||
vec3 DirectionalShading(vec3 normal,
|
||||
vec3 diffuse,
|
||||
float roughness,
|
||||
float metallic,
|
||||
float light_intensity,
|
||||
vec3 light_dir,
|
||||
vec3 light_pos,
|
||||
vec3 world_pos,
|
||||
vec3 view_pos)
|
||||
{
|
||||
|
||||
float distance = length(light_pos - world_pos);
|
||||
float distance = length(light_pos - world_pos);
|
||||
float attenuation = 1.0;
|
||||
|
||||
|
||||
vec3 radiance = diffuse * attenuation;
|
||||
|
||||
vec3 Lo = CalculatePBR(normal, view_pos, world_pos, light_dir, diffuse, radiance, roughness, metallic);
|
||||
|
||||
return Lo;
|
||||
}
|
||||
|
||||
|
||||
vec3 PointShading(vec3 normal,
|
||||
vec3 diffuse,
|
||||
float roughness,
|
||||
float metallic,
|
||||
float light_intensity,
|
||||
|
||||
vec3 PointShading(vec3 normal,
|
||||
vec3 diffuse,
|
||||
float roughness,
|
||||
float metallic,
|
||||
float light_intensity,
|
||||
vec3 light_pos,
|
||||
float light_constant,
|
||||
float light_linear,
|
||||
float light_quadratic,
|
||||
vec3 world_pos,
|
||||
float light_quadratic,
|
||||
vec3 world_pos,
|
||||
vec3 view_pos)
|
||||
{
|
||||
|
||||
|
||||
float distance = length(light_pos - world_pos);
|
||||
float distance = length(light_pos - world_pos);
|
||||
float attenuation = 1.0;
|
||||
|
||||
attenuation = light_intensity / (light_constant + (light_linear * distance) + (light_quadratic * distance * distance));
|
||||
|
||||
attenuation = light_intensity / (light_constant + (light_linear * distance) + (light_quadratic * distance * distance));
|
||||
vec3 radiance = diffuse * attenuation;
|
||||
vec3 light_dir = normalize(light_pos - world_pos);
|
||||
vec3 Lo = CalculatePBR(normal, view_pos, world_pos, light_dir, diffuse, radiance, roughness, metallic);
|
||||
|
||||
return Lo;
|
||||
}
|
||||
vec3 SpotShading(vec3 normal,
|
||||
vec3 diffuse,
|
||||
float roughness,
|
||||
float metallic,
|
||||
float light_intensity,
|
||||
vec3 light_dir,
|
||||
vec3 SpotShading(vec3 normal,
|
||||
vec3 diffuse,
|
||||
float roughness,
|
||||
float metallic,
|
||||
float light_intensity,
|
||||
vec3 light_dir,
|
||||
vec3 light_pos,
|
||||
float cutoff,
|
||||
float cutoff_outer,
|
||||
float cutoff_outer,
|
||||
float light_constant,
|
||||
float light_linear,
|
||||
float light_quadratic,
|
||||
vec3 world_pos,
|
||||
float light_quadratic,
|
||||
vec3 world_pos,
|
||||
vec3 view_pos)
|
||||
{
|
||||
|
||||
vec3 direction_to_light = normalize(light_pos - world_pos);
|
||||
float theta = dot(direction_to_light, light_dir);
|
||||
float falloff = 0.0f;
|
||||
|
||||
|
||||
|
||||
|
||||
// if(theta > cutoff)
|
||||
// {
|
||||
float epsilon = cutoff - cutoff_outer;
|
||||
falloff = clamp((theta - cutoff_outer) / epsilon, 0.0, 1.0);
|
||||
|
||||
falloff = clamp((theta - cutoff_outer) / epsilon, 0.0, 1.0);
|
||||
|
||||
//}
|
||||
|
||||
float distance = length(light_pos - world_pos);
|
||||
float distance = length(light_pos - world_pos);
|
||||
float attenuation = 1.0;
|
||||
|
||||
attenuation = light_intensity / (light_constant + (light_linear * distance) + (light_quadratic * distance * distance));
|
||||
|
||||
attenuation = light_intensity / (light_constant + (light_linear * distance) + (light_quadratic * distance * distance));
|
||||
vec3 radiance = diffuse * attenuation * falloff;
|
||||
|
||||
|
||||
vec3 Lo = CalculatePBR(normal, view_pos, world_pos, direction_to_light, diffuse, radiance, roughness, metallic);
|
||||
|
||||
return Lo;
|
||||
@@ -251,6 +268,101 @@ mat3 GetRotationOnlyMatrix(mat4 model_mat)
|
||||
return rot_mat;
|
||||
}
|
||||
|
||||
float SimpleSampleShadow(vec4 frag_clip_space, sampler2DArray sampler_shadow_map, uint shadow_trans_idx)
|
||||
{
|
||||
vec3 frag_light_space = frag_clip_space.xyz / frag_clip_space.w;
|
||||
frag_light_space = (frag_light_space * 0.5) + 0.5;
|
||||
|
||||
float shadow_map_depth = texture(sampler_shadow_map, vec3(frag_light_space.xy, shadow_trans_idx)).r;
|
||||
// return frag_light_space.z - shadow_map_depth;
|
||||
// return shadow_map_depth ;
|
||||
if(frag_light_space.z > shadow_map_depth)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
float SampleShadow(vec4 frag_clip_space, sampler2DArray sampler_shadow_map, uint shadow_trans_idx, vec3 normal, vec3 light_dir)
|
||||
{
|
||||
vec3 frag_light_space = frag_clip_space.xyz / frag_clip_space.w;
|
||||
frag_light_space = (frag_light_space * 0.5) + 0.5;
|
||||
|
||||
float shadow_map_depth = texture(sampler_shadow_map, vec3(frag_light_space.xy, shadow_trans_idx)).r;
|
||||
// calculate bias (based on depth map resolution and slope)
|
||||
|
||||
|
||||
float bias = max(0.005 * (1.0 - dot(normal, light_dir)), 0.0001);
|
||||
|
||||
|
||||
// check whether current frag pos is in shadow
|
||||
// float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
|
||||
// PCF
|
||||
float shadow = 0.0;
|
||||
vec2 texel_size = 1.0 / textureSize(sampler_shadow_map, 0).xy;
|
||||
|
||||
for(int x = -1; x <= 1; ++x)
|
||||
{
|
||||
for(int y = -1; y <= 1; ++y)
|
||||
{
|
||||
shadow_map_depth = texture(sampler_shadow_map, vec3(frag_light_space.xy + vec2(x, y) * texel_size, shadow_trans_idx)).r;
|
||||
shadow += frag_light_space.z - bias > shadow_map_depth ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
shadow /= 9.0;
|
||||
|
||||
// keep the shadow at 0.0 when outside the far_plane region of the light's frustum.
|
||||
if(frag_light_space.z > 1.0)
|
||||
shadow = 0.0;
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
float CalculateDirectionalShadow(vec4 world_pos, uint shadow_idx, vec3 normal, vec3 light_dir)
|
||||
{
|
||||
float shadow = 0;
|
||||
//Move the fragment to light space
|
||||
vec4 frag_in_light_space = shadows[shadow_idx].light_space_view[5] * world_pos;
|
||||
//measure the distance of the fragment from the light
|
||||
float frag_distance = length(frag_in_light_space.xyz);
|
||||
|
||||
uint shadow_trans_idx = 0;
|
||||
uint ignore_shadow = 0;
|
||||
|
||||
shadow_idx = 0;
|
||||
//Work out which shadowmap is appropriate for this distance
|
||||
for(uint i = 0; i < 6; i++)
|
||||
{
|
||||
if(frag_distance <= shadows[shadow_idx].far_plane[i])
|
||||
{
|
||||
//record the shadow map level
|
||||
shadow_trans_idx = i;
|
||||
//and indicate that this has a level
|
||||
ignore_shadow = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(ignore_shadow == 1)
|
||||
{
|
||||
|
||||
vec4 translated_pixel = shadows[shadow_idx].light_space_proj[shadow_trans_idx] *
|
||||
shadows[shadow_idx].light_space_view[shadow_trans_idx] *
|
||||
world_pos;
|
||||
|
||||
|
||||
uvec2 shadow_handle = textures[shadows[shadow_idx].shadow_texture_id];
|
||||
|
||||
|
||||
shadow = SampleShadow(translated_pixel, sampler2DArray(shadow_handle), shadow_trans_idx, normal, light_dir );
|
||||
|
||||
}
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
uvec2 diffuse_handle = textures[texture_ids[DIFFUSE_TEXTURE_ID]];
|
||||
@@ -258,86 +370,88 @@ void main()
|
||||
uvec2 metal_rough_handle = textures[texture_ids[METAL_ROUGH_TEXTURE_ID]];
|
||||
uvec2 world_pos_handle = textures[texture_ids[POSITION_TEXTIURE_ID]];
|
||||
vec4 diffuse = texture(sampler2D(diffuse_handle), vs_out.vsUV.xy);
|
||||
|
||||
|
||||
if(diffuse[3] <= 0.1)
|
||||
{
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
vec3 normal = texture(sampler2D(normal_handle), vs_out.vsUV.xy).xyz;
|
||||
vec3 metal_rough = texture(sampler2D(metal_rough_handle), vs_out.vsUV.xy).xyz;
|
||||
vec3 world_pos = texture(sampler2D(world_pos_handle), vs_out.vsUV.xy).xyz;
|
||||
vec3 metal_rough = texture(sampler2D(metal_rough_handle), vs_out.vsUV.xy).xyz;
|
||||
vec3 world_pos = texture(sampler2D(world_pos_handle), vs_out.vsUV.xy).xyz;
|
||||
float rough = metal_rough[1];
|
||||
float metal = metal_rough[2];
|
||||
|
||||
vec3 Lo = vec3(0,0,0);
|
||||
float ao = 1;
|
||||
vec3 ambient = vec3(0.05) * diffuse.xyz * ao;
|
||||
vec3 Lo = ambient;
|
||||
for(int i = 0; i < ubo_per_frame.light_count; i ++)
|
||||
{
|
||||
mat4 model = model_matrix[lights[i].entity_id];
|
||||
mat3 rot_mat = GetRotationOnlyMatrix(model);
|
||||
vec3 light_direction = normalize(rot_mat * vec3(0,0,1));
|
||||
|
||||
|
||||
vec3 light_pos = model[3].xyz;
|
||||
if(lights[i].light_type == HYDRA_LIGHT_DIRECTIONAL)
|
||||
{
|
||||
Lo += DirectionalShading(normal, diffuse.xyz, rough, metal, lights[i].intensity, light_direction, light_pos, world_pos, ubo_per_frame.viewer_pos);
|
||||
if(lights[i].shadow_caster == 1)
|
||||
{
|
||||
float shadow = CalculateDirectionalShadow(vec4(world_pos, 1.0), lights[i].shadow_map_id, normal, light_direction);
|
||||
Lo = Lo * vec3(1-shadow);
|
||||
}
|
||||
}
|
||||
else if(lights[i].light_type == HYDRA_LIGHT_POINT)
|
||||
{
|
||||
|
||||
Lo += PointShading(normal,
|
||||
diffuse.xyz,
|
||||
rough,
|
||||
metal,
|
||||
lights[i].intensity,
|
||||
light_pos,
|
||||
Lo += PointShading(normal,
|
||||
diffuse.xyz,
|
||||
rough,
|
||||
metal,
|
||||
lights[i].intensity,
|
||||
light_pos,
|
||||
lights[i].constant,
|
||||
lights[i].linear,
|
||||
lights[i].quadratic,
|
||||
world_pos,
|
||||
lights[i].linear,
|
||||
lights[i].quadratic,
|
||||
world_pos,
|
||||
ubo_per_frame.viewer_pos);
|
||||
}
|
||||
else if(lights[i].light_type == HYDRA_LIGHT_SPOT)
|
||||
{
|
||||
Lo += SpotShading(normal,
|
||||
diffuse.xyz,
|
||||
rough,
|
||||
metal,
|
||||
lights[i].intensity,
|
||||
Lo += SpotShading(normal,
|
||||
diffuse.xyz,
|
||||
rough,
|
||||
metal,
|
||||
lights[i].intensity,
|
||||
light_direction,
|
||||
light_pos,
|
||||
light_pos,
|
||||
lights[i].cutoff,
|
||||
lights[i].cutoff_outer,
|
||||
lights[i].constant,
|
||||
lights[i].linear,
|
||||
lights[i].quadratic,
|
||||
world_pos,
|
||||
lights[i].linear,
|
||||
lights[i].quadratic,
|
||||
world_pos,
|
||||
ubo_per_frame.viewer_pos);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
float lighting = 0;
|
||||
|
||||
|
||||
|
||||
// ambient lighting (note that the next IBL tutorial will replace
|
||||
// ambient lighting (note that the next IBL tutorial will replace
|
||||
// this ambient lighting with environment lighting).
|
||||
float ao = 1;
|
||||
vec3 ambient = vec3(0.05) * diffuse.xyz * ao;
|
||||
|
||||
|
||||
vec3 output_color = Lo + ambient;
|
||||
vec3 output_color = Lo;
|
||||
|
||||
// HDR tonemapping
|
||||
output_color = output_color / (output_color + vec3(1.0));
|
||||
// gamma correct
|
||||
output_color = pow(output_color, vec3(1.0/2.1));
|
||||
output_color = pow(output_color, vec3(1.0/2.1));
|
||||
|
||||
uFragColor = vec4(output_color, 1.0);
|
||||
// float light = dot(lights[0].light_direction, normal);
|
||||
|
||||
// uFragColor = vec4(diffuse.xyz * light,1);
|
||||
|
||||
|
||||
// uFragColor = vec4(normal, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ layout(binding = 0) uniform uniform_per_frame
|
||||
uint light_count;
|
||||
} ubo_per_frame;
|
||||
|
||||
layout(std430, binding = 1) readonly buffer PositionsBuffer
|
||||
layout(std430, binding = 1) readonly buffer positions_buffer
|
||||
{
|
||||
mat4 model_matrix[];
|
||||
};
|
||||
|
||||
@@ -16,12 +16,12 @@ struct MaterialStore
|
||||
uint padding[1];
|
||||
};
|
||||
|
||||
layout(binding = 2, std430) readonly buffer MaterialBuffer
|
||||
layout(binding = 2, std430) readonly buffer material_buffer
|
||||
{
|
||||
MaterialStore materials[1000];
|
||||
};
|
||||
|
||||
layout( std430, binding = 3) readonly buffer TextureBuffer {
|
||||
layout( std430, binding = 3) readonly buffer texture_buffer {
|
||||
uvec2 textures[1000];
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ layout(binding = 0) uniform uniform_per_frame
|
||||
uint light_count;
|
||||
} ubo_per_frame;
|
||||
|
||||
layout(std430, binding = 1) readonly buffer PositionsBuffer
|
||||
layout(std430, binding = 1) readonly buffer positions_buffer
|
||||
{
|
||||
mat4 model_matrix[];
|
||||
};
|
||||
|
||||
@@ -26,7 +26,6 @@ layout (location=0) in VS_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
vec4 vsWorldPos;
|
||||
vec4 normal;
|
||||
flat uint vsChunkID;
|
||||
flat uint vsMaterialID;
|
||||
}vs_out;
|
||||
|
||||
@@ -1,15 +1,62 @@
|
||||
//*PIXEL*
|
||||
#version 450
|
||||
#version 460
|
||||
|
||||
#extension GL_EXT_scalar_block_layout : enable
|
||||
#extension GL_EXT_nonuniform_qualifier : enable
|
||||
#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];
|
||||
};
|
||||
|
||||
layout(std430, binding = 2) readonly buffer material_buffer
|
||||
{
|
||||
MaterialStore materials[1000];
|
||||
};
|
||||
|
||||
layout(std430, binding = 3) readonly buffer texture_buffer
|
||||
{
|
||||
uvec2 textures[1000];
|
||||
};
|
||||
|
||||
layout (location=0) in GEOM_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
flat uint vsMaterialID;
|
||||
}geom_out;
|
||||
|
||||
layout (location=0) out vec4 output_colour;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
//gl_FragDepth = gl_FragCoord.z;
|
||||
MaterialStore mat = materials[geom_out.vsMaterialID];
|
||||
vec4 diffuse_val = mat.diffuse_colour;
|
||||
|
||||
output_colour = vec4(1,0,0,1);
|
||||
|
||||
// if(mat.diffuse_texture_id != INVALID_HYDRA_ID)
|
||||
// {
|
||||
// output_colour = vec4(0,1,0,1);
|
||||
// uvec2 diffuse_handle = textures[mat.diffuse_texture_id];
|
||||
// diffuse_val = diffuse_val * texture(sampler2D(diffuse_handle), geom_out.vsUV.xy);
|
||||
// output_colour = diffuse_val;
|
||||
// }
|
||||
|
||||
// if(diffuse_val[3] <= 0.4)
|
||||
// {
|
||||
// discard;
|
||||
// }
|
||||
// Calculate the accurate, unclamped distance from the light source
|
||||
// output_colour = diffuse_val;
|
||||
// output_colour = vec4(geom_out.vsUV, 1,1);
|
||||
|
||||
}
|
||||
|
||||
@@ -22,20 +22,40 @@ layout(binding = 0) uniform shadow_per_frame
|
||||
uint shadow_idxs;
|
||||
};
|
||||
|
||||
layout(std430, binding = 5) readonly buffer ShadowMapSets
|
||||
layout(std430, binding = 5) readonly buffer shadow_map_sets
|
||||
{
|
||||
ShadowMapSet shadows[10];
|
||||
};
|
||||
|
||||
|
||||
layout (location=0) in VS_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
flat uint vsMaterialID;
|
||||
}vs_in[];
|
||||
|
||||
layout (location=0) out GEOM_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
flat uint vsMaterialID;
|
||||
}geom_out;
|
||||
|
||||
void main()
|
||||
{
|
||||
{
|
||||
mat4 view = shadows[shadow_idxs].light_space_view[gl_InvocationID];
|
||||
mat4 proj = shadows[shadow_idxs].light_space_proj[gl_InvocationID];
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
gl_Position = shadows[shadow_idxs].light_space_proj[gl_InvocationID] *
|
||||
shadows[shadow_idxs].light_space_view[gl_InvocationID] *
|
||||
gl_in[i].gl_Position;
|
||||
gl_Layer = gl_InvocationID;
|
||||
EmitVertex();
|
||||
vec4 clip_space_pos = proj * view * gl_in[i].gl_Position;
|
||||
|
||||
gl_Position = clip_space_pos;
|
||||
|
||||
geom_out.vsMaterialID = vs_in[gl_InvocationID].vsMaterialID;
|
||||
geom_out.vsUV = vs_in[gl_InvocationID].vsUV;
|
||||
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
//*VERTEX*
|
||||
#version 450
|
||||
#extension GL_EXT_buffer_reference : enable
|
||||
#version 460
|
||||
|
||||
layout(binding = 1) readonly buffer PositionsBuffer
|
||||
|
||||
layout(binding = 1) readonly buffer positions_buffer
|
||||
{
|
||||
mat4 model_matrix[];
|
||||
};
|
||||
@@ -14,10 +14,19 @@ layout (location = 3) in vec3 inNormal; //8 Bytes : 12
|
||||
layout (location = 4) in vec3 inBiTangent;
|
||||
layout (location = 5) in vec3 inTangent;
|
||||
|
||||
layout (location=0) out VS_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
flat uint vsMaterialID;
|
||||
}vs_out;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
{
|
||||
uint chunkid = inChunkID[0];
|
||||
mat4 model = model_matrix[chunkid];
|
||||
gl_Position = model * vec4(inPos, 1.0);
|
||||
vs_out.vsUV = inUV;
|
||||
vs_out.vsMaterialID = inChunkID[1];
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
//*PIXEL*
|
||||
#version 450
|
||||
|
||||
#extension GL_EXT_scalar_block_layout : enable
|
||||
#extension GL_EXT_nonuniform_qualifier : enable
|
||||
#extension GL_ARB_bindless_texture : enable
|
||||
|
||||
const uint DIRECTIONAL_LIGHT = 1;
|
||||
const uint POINT_LIGHT = 2;
|
||||
const uint SPOT_LIGHT = 3;
|
||||
|
||||
layout( std430, binding = 3) readonly buffer texture_buffer {
|
||||
uvec2 textures[1000];
|
||||
};
|
||||
|
||||
layout(binding = 0) uniform uniform_per_frame
|
||||
{
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
uint shadow_texture_id;
|
||||
vec3 padding0;
|
||||
};
|
||||
|
||||
layout (location=0) in VS_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
};
|
||||
|
||||
|
||||
layout (location=0) out vec4 output_colour;
|
||||
|
||||
void main()
|
||||
{
|
||||
uvec2 shadow_handle = textures[shadow_texture_id];
|
||||
float colour = texture(sampler2DArray(shadow_handle), vec3(vsUV, 0)).r;
|
||||
//colour = (1.0 - (1.0 - colour) * 1.4);
|
||||
output_colour = vec4(colour, colour, colour, 1.0);
|
||||
//output_colour = vec4(1,0,0,1);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//*VERTEX*
|
||||
#version 450
|
||||
#extension GL_EXT_buffer_reference : enable
|
||||
|
||||
layout(binding = 1) readonly buffer positions_buffer
|
||||
{
|
||||
mat4 model_matrix[];
|
||||
};
|
||||
|
||||
layout(binding = 0) uniform uniform_per_frame
|
||||
{
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
uint shadow_texture_id;
|
||||
vec3 padding0;
|
||||
};
|
||||
|
||||
|
||||
layout (location = 0) in vec3 inPos; //12 bytes : 0
|
||||
layout (location = 1) in vec2 inUV; //8 Bytes : 12
|
||||
layout (location = 2) in uvec3 inChunkID; //12 Bytes : 20
|
||||
layout (location = 3) in vec3 inNormal; //8 Bytes : 12
|
||||
layout (location = 4) in vec3 inBiTangent;
|
||||
layout (location = 5) in vec3 inTangent;
|
||||
|
||||
layout (location=0) out VS_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
uint chunkid = inChunkID[0];
|
||||
mat4 model = model_matrix[chunkid];
|
||||
gl_Position = proj * view * vec4(inPos, 1.0);
|
||||
vsUV = inUV;
|
||||
}
|
||||
Reference in New Issue
Block a user