Debian Codegraph @

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

raw
1 { -*- buffer-read-only: t -*- }
2 { DON'T EDIT -- this file was automatically generated from "source/terrain.fs" }
3 '/* OpenGL shader effect (used to enhance the Castle Game Engine shaders,' + LineEnding +
4 ' see https://castle-engine.io/compositing_shaders.php ),' + LineEnding +
5 ' applied over terrain.' + LineEnding +
6 '' + LineEnding +
7 ' This adjusts terrain color, mixing textures, based on current height. */' + LineEnding +
8 '' + LineEnding +
9 'uniform sampler2D tex_1;' + LineEnding +
10 'uniform sampler2D tex_2;' + LineEnding +
11 'uniform sampler2D tex_3;' + LineEnding +
12 'uniform sampler2D tex_4;' + LineEnding +
13 '' + LineEnding +
14 'uniform vec3 color_1;' + LineEnding +
15 'uniform vec3 color_2;' + LineEnding +
16 'uniform vec3 color_3;' + LineEnding +
17 'uniform vec3 color_4;' + LineEnding +
18 '' + LineEnding +
19 '// These values are packed in vec4, one float per layer' + LineEnding +
20 'uniform vec4 uv_scale;' + LineEnding +
21 'uniform vec4 metallic;' + LineEnding +
22 'uniform vec4 roughness;' + LineEnding +
23 '' + LineEnding +
24 'uniform float height_1;' + LineEnding +
25 'uniform float height_2;' + LineEnding +
26 '' + LineEnding +
27 'uniform float layers_influence;' + LineEnding +
28 'uniform float steep_emphasize;' + LineEnding +
29 '' + LineEnding +
30 'varying vec3 terrain_position;' + LineEnding +
31 'varying vec3 terrain_normal;' + LineEnding +
32 '' + LineEnding +
33 '// avoid redeclaring when no "separate compilation units" available (OpenGLES)' + LineEnding +
34 '#ifndef GL_ES' + LineEnding +
35 'vec4 castle_texture_color_to_linear(const in vec4 srgbIn);' + LineEnding +
36 '#endif' + LineEnding +
37 '' + LineEnding +
38 'void PLUG_main_texture_apply(inout vec4 fragment_color, const in vec3 normal)' + LineEnding +
39 '{' + LineEnding +
40 ' float h = terrain_position.y;' + LineEnding +
41 '' + LineEnding +
42 ' /* We flip terrain_position.z, to map texture more naturally, when viewed from above.' + LineEnding +
43 ' This is consistent with calculating TexCoord for TCastleTerrainData.Height.' + LineEnding +
44 ' We just flip the sign, because the terrain textures always have repeat = true,' + LineEnding +
45 ' so there''s no need to shift the texture in any way.' + LineEnding +
46 ' */' + LineEnding +
47 ' vec2 uv = vec2(terrain_position.x, -terrain_position.z);' + LineEnding +
48 '' + LineEnding +
49 ' /* What does this mean?' + LineEnding +
50 ' normal_slope (normal.y)' + LineEnding +
51 ' = 0 means a vertical face' + LineEnding +
52 ' = 1 means a horizontal face' + LineEnding +
53 ' */' + LineEnding +
54 ' float normal_slope = normalize(terrain_normal).y;' + LineEnding +
55 '' + LineEnding +
56 ' vec3 c1 = color_1 * castle_texture_color_to_linear(texture2D(tex_1, uv * uv_scale.x)).rgb;' + LineEnding +
57 ' vec3 c2 = color_2 * castle_texture_color_to_linear(texture2D(tex_2, uv * uv_scale.y)).rgb;' + LineEnding +
58 ' vec3 c3 = color_3 * castle_texture_color_to_linear(texture2D(tex_3, uv * uv_scale.z)).rgb;' + LineEnding +
59 ' vec3 c4 = color_4 * castle_texture_color_to_linear(texture2D(tex_4, uv * uv_scale.w)).rgb;' + LineEnding +
60 '' + LineEnding +
61 ' float height_mix = smoothstep(height_1, height_2, h);' + LineEnding +
62 ' vec3 flat_color = mix(c1, c3, height_mix);' + LineEnding +
63 ' vec3 steep_color = mix(c2, c4, height_mix);' + LineEnding +
64 ' vec3 modified_color = mix(steep_color, flat_color, pow(normal_slope, steep_emphasize));' + LineEnding +
65 '' + LineEnding +
66 ' fragment_color.rgb = mix(fragment_color.rgb, modified_color, layers_influence);' + LineEnding +
67 '}' + LineEnding +
68 '' + LineEnding +
69 'void PLUG_material_metallic_roughness(inout float metallic_final, inout float roughness_final)' + LineEnding +
70 '{' + LineEnding +
71 ' float h = terrain_position.y;' + LineEnding +
72 ' float normal_slope = normalize(terrain_normal).y;' + LineEnding +
73 ' float height_mix = smoothstep(height_1, height_2, h);' + LineEnding +
74 '' + LineEnding +
75 ' float flat_metallic = mix(metallic.x, metallic.z, height_mix);' + LineEnding +
76 ' float steep_metallic = mix(metallic.y, metallic.w, height_mix);' + LineEnding +
77 ' float modified_metallic = mix(steep_metallic, flat_metallic, pow(normal_slope, steep_emphasize));' + LineEnding +
78 ' metallic_final = mix(metallic_final, modified_metallic, layers_influence);' + LineEnding +
79 '' + LineEnding +
80 ' float flat_roughness = mix(roughness.x, roughness.z, height_mix);' + LineEnding +
81 ' float steep_roughness = mix(roughness.y, roughness.w, height_mix);' + LineEnding +
82 ' float modified_roughness = mix(steep_roughness, flat_roughness, pow(normal_slope, steep_emphasize));' + LineEnding +
83 ' roughness_final = mix(roughness_final, modified_roughness, layers_influence);' + LineEnding +
84 '}' + LineEnding +
85 ''