Welcome to mirror list, hosted at ThFree Co, Russian Federation.

eevee_shadow_page_copy_comp.glsl « shaders « eevee « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f0d7bbd0bc9ac9e3ad40bfe33e35d61cfcfe3b77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

/**
 * Virtual shadowmapping: Tile copy.
 *
 * This pass copies the pages rendered in the render target to the page atlas.
 * This might not be the fastest way to blit shadow regions but at least it is fully GPU driven.
 */

/* TODO(fclem): The goal would be to render on the atlas texture and only move pages if
 * they overlap with the rendering. */

#pragma BLENDER_REQUIRE(eevee_shadow_tilemap_lib.glsl)

bool do_corner_pattern(vec2 uv, float corner_ratio)
{
  uv = uv * 2.0 - 1.0;
  return (any(greaterThan(abs(uv), vec2(1.0 - corner_ratio))) &&
          all(greaterThan(abs(uv), vec2(1.0 - corner_ratio * 3.0))));
}

void main()
{
  int page_size = textureSize(render_tx, 0).x / SHADOW_TILEMAP_RES;

  for (int p = 0; p < pages_infos_buf.page_rendered; p++) {
    uvec4 render_tile = unpackUvec4x8(pages_list_buf[p]);

    ivec2 tile_co = ivec2(render_tile.xy);
    ivec2 page_co = ivec2(render_tile.zw);

    /* We dispatch enough group to cover one page. */
    ivec2 page_texel = ivec2(gl_GlobalInvocationID.xy);
    ivec2 in_texel = page_texel + tile_co * page_size;
    ivec2 out_texel = page_texel + page_co * page_size;

    float depth = texelFetch(render_tx, in_texel, 0).r;

#ifdef SHADOW_DEBUG_PAGE_CORNER
    uvec2 page_size = gl_NumWorkGroups.xy * gl_WorkGroupSize.xy;
    vec2 uv = vec2(gl_GlobalInvocationID.xy) / vec2(page_size);
    /* Print corners to check tile layout and validity. */
    if (do_corner_pattern(uv, 0.025)) {
      depth = 0.0;
    }
    else if (do_corner_pattern(uv, 0.035)) {
      depth = 1.0;
    }
#endif

    imageStore(out_atlas_img, out_texel, vec4(depth));
  }
}