Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/shaders/shadow_accum_frag.glsl
| Show All 13 Lines | if (laNumLight == 0) { | ||||
| fragColor.r = 0.0; | fragColor.r = 0.0; | ||||
| return; | return; | ||||
| } | } | ||||
| ivec2 texel = ivec2(gl_FragCoord.xy); | ivec2 texel = ivec2(gl_FragCoord.xy); | ||||
| float depth = texelFetch(depthBuffer, texel, 0).r; | float depth = texelFetch(depthBuffer, texel, 0).r; | ||||
| if (depth == 1.0f) { | if (depth == 1.0f) { | ||||
| /* Early exit background does not receive shadows */ | /* Early exit background does not receive shadows */ | ||||
| fragColor.r = 1.0; | fragColor.r = 0.0; | ||||
| return; | return; | ||||
| } | } | ||||
| vec2 texel_size = 1.0 / vec2(textureSize(depthBuffer, 0)).xy; | vec2 texel_size = 1.0 / vec2(textureSize(depthBuffer, 0)).xy; | ||||
| vec2 uvs = saturate(gl_FragCoord.xy * texel_size); | vec2 uvs = saturate(gl_FragCoord.xy * texel_size); | ||||
| vec4 rand = texelfetch_noise_tex(texel); | vec4 rand = texelfetch_noise_tex(texel); | ||||
| float accum_light = 0.0; | float accum_light = 0.0; | ||||
| float tracing_depth = depth; | float tracing_depth = depth; | ||||
| /* Constant bias (due to depth buffer precision) */ | /* Constant bias (due to depth buffer precision) */ | ||||
| /* Magic numbers for 24bits of precision. | /* Magic numbers for 24bits of precision. | ||||
| * From http://terathon.com/gdc07_lengyel.pdf (slide 26) */ | * From http://terathon.com/gdc07_lengyel.pdf (slide 26) */ | ||||
| tracing_depth -= mix(2.4e-7, 4.8e-7, depth); | tracing_depth -= mix(2.4e-7, 4.8e-7, depth); | ||||
| /* Convert to view Z. */ | /* Convert to view Z. */ | ||||
| tracing_depth = get_view_z_from_depth(tracing_depth); | tracing_depth = get_view_z_from_depth(tracing_depth); | ||||
| vec3 viewPosition = get_view_space_from_depth(uvs, depth); | vec3 viewPosition = get_view_space_from_depth(uvs, depth); | ||||
| vec3 worldPosition = transform_point(ViewMatrixInverse, viewPosition); | vec3 worldPosition = transform_point(ViewMatrixInverse, viewPosition); | ||||
| vec3 true_normal = normalize(cross(dFdx(viewPosition), dFdy(viewPosition))); | vec3 true_normal = normalize(cross(dFdx(viewPosition), dFdy(viewPosition))); | ||||
| vec3 N = normal_view_to_world(true_normal); | |||||
| for (int i = 0; i < MAX_LIGHT && i < laNumLight; i++) { | for (int i = 0; i < MAX_LIGHT && i < laNumLight; i++) { | ||||
| LightData ld = lights_data[i]; | LightData ld = lights_data[i]; | ||||
| vec4 l_vector; /* Non-Normalized Light Vector with length in last component. */ | vec4 l_vector; /* Non-Normalized Light Vector with length in last component. */ | ||||
| l_vector.xyz = ld.l_position - worldPosition; | l_vector.xyz = ld.l_position - worldPosition; | ||||
| l_vector.w = length(l_vector.xyz); | l_vector.w = length(l_vector.xyz); | ||||
| float light_input = smoothstep(0.2, -0.2, -dot(N, normalize(l_vector.xyz))); | |||||
fclem: does cycles actually have this fallof? if not just use a step function. | |||||
Done Inline Actionsjbakker: Best result I got with
`float light_input = smoothstep(1.5, -1.5, -dot(N, l_vector.xyz));`… | |||||
Done Inline Actionsl_vector is not normalized. so i'm guessing the 1.5 factors are not correct. fclem: l_vector is not normalized. so i'm guessing the 1.5 factors are not correct. | |||||
| float l_vis = light_shadowing( | float l_vis = light_shadowing( | ||||
| ld, worldPosition, viewPosition, tracing_depth, true_normal, rand.x, true, 1.0); | ld, worldPosition, viewPosition, tracing_depth, true_normal, rand.x, true, light_input); | ||||
| accum_light += l_vis; | accum_light += l_vis; | ||||
| } | } | ||||
| fragColor.r = accum_light / float(laNumLight); | fragColor.r = accum_light / float(laNumLight); | ||||
| } | } | ||||
| No newline at end of file | No newline at end of file | ||||

does cycles actually have this fallof? if not just use a step function.