This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/draw/engines/eevee/shaders/shadow_accum_frag.glsl
Jason Fielder 7c9e128bbf Metal: GLSL Compatibility - explicit mat4_to_mat3 conversion
Explicit constructor for mat3 from a mat4 is not valid and cannot be overloaded.

Adding explicit texture resource type flags for depth textures. This is an explicit requirement for Metal Shading language. This is a temporary compatibility, as this path is already supported in GPU_SHADER_CREATE_INFO under ImageType::DEPTH_2D, though required in shader source for MSL shaders which do not have create info.

Authored by Apple: Michael Parkin-White

Ref T96261

Reviewed By: fclem

Maniphest Tasks: T96261

Differential Revision: https://developer.blender.org/D14418
2022-03-30 19:47:00 +02:00

53 lines
1.3 KiB
GLSL

#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_utiltex_lib.glsl)
#pragma BLENDER_REQUIRE(lights_lib.glsl)
uniform depth2D depthBuffer;
out vec4 fragColor;
void main()
{
if (laNumLight == 0) {
/* Early exit: No lights in scene */
fragColor.r = 1.0;
return;
}
ivec2 texel = ivec2(gl_FragCoord.xy);
float depth = texelFetch(depthBuffer, texel, 0).r;
if (depth == 1.0f) {
/* Early exit background does not receive shadows */
fragColor.r = 1.0;
return;
}
vec2 texel_size = 1.0 / vec2(textureSize(depthBuffer, 0)).xy;
vec2 uvs = saturate(gl_FragCoord.xy * texel_size);
vec4 rand = texelfetch_noise_tex(texel);
float accum_light = 0.0;
vec3 vP = get_view_space_from_depth(uvs, depth);
vec3 P = transform_point(ViewMatrixInverse, vP);
vec3 vNg = safe_normalize(cross(dFdx(vP), dFdy(vP)));
for (int i = 0; i < MAX_LIGHT && i < laNumLight; i++) {
LightData ld = lights_data[i];
vec4 l_vector; /* Non-Normalized Light Vector with length in last component. */
l_vector.xyz = ld.l_position - P;
l_vector.w = length(l_vector.xyz);
float l_vis = light_shadowing(ld, P, 1.0);
l_vis *= light_contact_shadows(ld, P, vP, vNg, rand.x, 1.0);
accum_light += l_vis;
}
fragColor.r = accum_light / float(laNumLight);
}