Debian Codegraph @

src/scene/glsl/generated-pascal/bump_mapping_steep_parallax_shadowing.fs.inc

raw
1 { -*- buffer-read-only: t -*- }
2 { DON'T EDIT -- this file was automatically generated from "source/bump_mapping_steep_parallax_shadowing.fs" }
3 '/* Steep parallax with self-shading bump mapping shader effect.' + LineEnding +
4 ' This is added right after bump_mapping.fs and bump_mapping_parallax.fs.' + LineEnding +
5 ' Included by EnableShaderBumpMapping in ../castlerendererinternalshader.pas unit.' + LineEnding +
6 '*/' + LineEnding +
7 '' + LineEnding +
8 '// avoid redeclaring this when no "separate compilation units" (OpenGLES)' + LineEnding +
9 '#ifndef GL_ES' + LineEnding +
10 'uniform float castle_parallax_bm_scale;' + LineEnding +
11 'uniform sampler2D castle_normal_map;' + LineEnding +
12 'float castle_bm_height;' + LineEnding +
13 'vec2 castle_parallax_tex_coord;' + LineEnding +
14 '#endif' + LineEnding +
15 '' + LineEnding +
16 'varying vec3 castle_light_direction_tangent_space;' + LineEnding +
17 '' + LineEnding +
18 '/* This has to be done after PLUG texture_coord_shift (done from PLUG main_texture_apply),' + LineEnding +
19 ' as we depend that global castle_bm_height/castle_parallax_tex_coord' + LineEnding +
20 ' are already set correctly. */' + LineEnding +
21 'void PLUG_steep_parallax_shadow_apply(inout vec4 fragment_color)' + LineEnding +
22 '{' + LineEnding +
23 ' vec3 light_dir = normalize(castle_light_direction_tangent_space);' + LineEnding +
24 '' + LineEnding +
25 ' /* We basically do the same thing as when we calculate tex_coord' + LineEnding +
26 ' with steep parallax mapping.' + LineEnding +
27 ' Only now we increment height, and we use light_dir instead of' + LineEnding +
28 ' v_to_eye. */' + LineEnding +
29 ' float num_steps = mix(30.0, 10.0, light_dir.z);' + LineEnding +
30 '' + LineEnding +
31 ' float step = 1.0 / num_steps;' + LineEnding +
32 '' + LineEnding +
33 ' vec2 delta = light_dir.xy * castle_parallax_bm_scale / (light_dir.z * num_steps);' + LineEnding +
34 '' + LineEnding +
35 ' /* Do the 1st step always, otherwise initial height = shadow_map_height' + LineEnding +
36 ' and we would be considered in our own shadow. */' + LineEnding +
37 ' float height = castle_bm_height + step;' + LineEnding +
38 ' vec2 shadow_texture_coord = castle_parallax_tex_coord + delta;' + LineEnding +
39 ' float shadow_map_height = texture2D(castle_normal_map, shadow_texture_coord).a;' + LineEnding +
40 '' + LineEnding +
41 ' while (shadow_map_height < height && height < 1.0)' + LineEnding +
42 ' {' + LineEnding +
43 ' height += step;' + LineEnding +
44 ' shadow_texture_coord += delta;' + LineEnding +
45 ' shadow_map_height = texture2D(castle_normal_map, shadow_texture_coord).a;' + LineEnding +
46 ' }' + LineEnding +
47 '' + LineEnding +
48 ' if (shadow_map_height >= height)' + LineEnding +
49 ' {' + LineEnding +
50 ' /* TODO: setting appropriate light contribution to 0 would be more correct.' + LineEnding +
51 ' But for now, this self-shadowing is hacky, always from light source 0,' + LineEnding +
52 ' and after the light calculation is actually done. */' + LineEnding +
53 ' fragment_color.rgb /= 2.0;' + LineEnding +
54 ' }' + LineEnding +
55 '}' + LineEnding +
56 ''