Debian Codegraph @

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

raw
1 { -*- buffer-read-only: t -*- }
2 { DON'T EDIT -- this file was automatically generated from "source/bump_mapping_parallax.fs" }
3 '/* Parallax bump mapping shader effect.' + LineEnding +
4 ' This is added right after bump_mapping.fs.' + LineEnding +
5 ' Included by EnableShaderBumpMapping in ../castlerendererinternalshader.pas unit.' + LineEnding +
6 '*/' + LineEnding +
7 '' + LineEnding +
8 'uniform float castle_parallax_bm_scale;' + LineEnding +
9 '' + LineEnding +
10 '// declare castle_normal_map, avoiding redeclaring it for GL_ES' + LineEnding +
11 '#ifdef GL_ES' + LineEnding +
12 ' #ifndef castle_normal_map_defined' + LineEnding +
13 ' #define castle_normal_map_defined' + LineEnding +
14 ' uniform sampler2D castle_normal_map;' + LineEnding +
15 ' #endif' + LineEnding +
16 '#else' + LineEnding +
17 ' uniform sampler2D castle_normal_map;' + LineEnding +
18 '#endif' + LineEnding +
19 '' + LineEnding +
20 'varying vec3 castle_vertex_to_eye_in_tangent_space;' + LineEnding +
21 '' + LineEnding +
22 '#ifdef CASTLE_BUMP_MAPPING_PARALLAX_STEEP' + LineEnding +
23 'float castle_bm_height;' + LineEnding +
24 'vec2 castle_parallax_tex_coord;' + LineEnding +
25 '#endif' + LineEnding +
26 '' + LineEnding +
27 'void PLUG_texture_coord_shift(inout vec2 tex_coord)' + LineEnding +
28 '{' + LineEnding +
29 ' // We have to normalize castle_vertex_to_eye_in_tangent_space again, just like normal vectors.' + LineEnding +
30 ' vec3 v_to_eye = normalize(castle_vertex_to_eye_in_tangent_space);' + LineEnding +
31 '' + LineEnding +
32 '#ifndef CASTLE_BUMP_MAPPING_PARALLAX_STEEP' + LineEnding +
33 '' + LineEnding +
34 ' // Classic (not steep) parallax bump mapping' + LineEnding +
35 ' float height = (texture2D(castle_normal_map, tex_coord).a - 1.0/2.0) * castle_parallax_bm_scale;' + LineEnding +
36 ' tex_coord += height * v_to_eye.xy /* / v_to_eye.z*/;' + LineEnding +
37 '' + LineEnding +
38 '#else' + LineEnding +
39 '' + LineEnding +
40 ' // Steep parallax bump mapping' + LineEnding +
41 ' /* At smaller view angles, much more iterations needed, otherwise ugly' + LineEnding +
42 ' aliasing artifacts quickly appear. */' + LineEnding +
43 ' float num_steps = mix(30.0, 10.0, v_to_eye.z);' + LineEnding +
44 '#ifdef CASTLE_BUGGY_BUMP_MAPPING_NUM_STEPS' + LineEnding +
45 ' num_steps = clamp(num_steps, 10.0, 30.0);' + LineEnding +
46 '#endif' + LineEnding +
47 ' float step = 1.0 / num_steps;' + LineEnding +
48 '' + LineEnding +
49 ' /* Should we remove "v_to_eye.z" below, i.e. should we apply' + LineEnding +
50 ' "offset limiting" ? In works about steep parallax mapping,' + LineEnding +
51 ' v_to_eye.z is present, and in sample steep parallax mapping' + LineEnding +
52 ' shader they suggest that it doesn''t really matter.' + LineEnding +
53 ' My tests confirm this, so I leave v_to_eye.z component. */' + LineEnding +
54 '' + LineEnding +
55 ' vec2 delta = -v_to_eye.xy * castle_parallax_bm_scale / (v_to_eye.z * num_steps);' + LineEnding +
56 ' float height = 1.0;' + LineEnding +
57 ' castle_bm_height = texture2D(castle_normal_map, tex_coord).a;' + LineEnding +
58 '' + LineEnding +
59 ' /* TODO: NVidia GeForce FX 5200 fails here with' + LineEnding +
60 '' + LineEnding +
61 ' error C5011: profile does not support "while" statements' + LineEnding +
62 ' and "while" could not be unrolled.' + LineEnding +
63 '' + LineEnding +
64 ' I could workaround this problem (by using' + LineEnding +
65 ' for (int i = 0; i < steep_steps_max; i++)' + LineEnding +
66 ' loop and' + LineEnding +
67 ' if (! (castle_bm_height < height)) break;' + LineEnding +
68 ' , this is possible to unroll). But it turns out that this still' + LineEnding +
69 ' (even with steep_steps_max = 1) works much too slow on this hardware...' + LineEnding +
70 ' */' + LineEnding +
71 '' + LineEnding +
72 ' while (castle_bm_height < height)' + LineEnding +
73 ' {' + LineEnding +
74 ' height -= step;' + LineEnding +
75 ' tex_coord += delta;' + LineEnding +
76 ' castle_bm_height = texture2D(castle_normal_map, tex_coord).a;' + LineEnding +
77 ' }' + LineEnding +
78 '' + LineEnding +
79 ' // Save value for bump_mapping_steep_parallax_shadowing.fs' + LineEnding +
80 ' castle_parallax_tex_coord = tex_coord;' + LineEnding +
81 '' + LineEnding +
82 '#endif' + LineEnding +
83 '}' + LineEnding +
84 ''