Debian Codegraph @

third_party/spirv-cross/reference/shaders/vert/ocean.vert

raw
1 #version 310 es
2 #ifdef GL_ARB_shader_draw_parameters
3 #extension GL_ARB_shader_draw_parameters : enable
4 #endif
5
6 struct PatchData
7 {
8 vec4 Position;
9 vec4 LODs;
10 };
11
12 layout(binding = 0, std140) uniform Offsets
13 {
14 PatchData Patches[256];
15 } _53;
16
17 layout(binding = 4, std140) uniform GlobalOcean
18 {
19 vec4 OceanScale;
20 vec4 OceanPosition;
21 vec4 InvOceanSize_PatchScale;
22 vec4 NormalTexCoordScale;
23 } _180;
24
25 layout(binding = 0, std140) uniform GlobalVSData
26 {
27 vec4 g_ViewProj_Row0;
28 vec4 g_ViewProj_Row1;
29 vec4 g_ViewProj_Row2;
30 vec4 g_ViewProj_Row3;
31 vec4 g_CamPos;
32 vec4 g_CamRight;
33 vec4 g_CamUp;
34 vec4 g_CamFront;
35 vec4 g_SunDir;
36 vec4 g_SunColor;
37 vec4 g_TimeParams;
38 vec4 g_ResolutionParams;
39 vec4 g_CamAxisRight;
40 vec4 g_FogColor_Distance;
41 vec4 g_ShadowVP_Row0;
42 vec4 g_ShadowVP_Row1;
43 vec4 g_ShadowVP_Row2;
44 vec4 g_ShadowVP_Row3;
45 } _273;
46
47 layout(binding = 1) uniform mediump sampler2D TexLOD;
48 layout(binding = 0) uniform mediump sampler2D TexDisplacement;
49
50 layout(location = 1) in vec4 LODWeights;
51 #ifdef GL_ARB_shader_draw_parameters
52 #define SPIRV_Cross_BaseInstance gl_BaseInstanceARB
53 #else
54 uniform int SPIRV_Cross_BaseInstance;
55 #endif
56 layout(location = 0) in vec4 Position;
57 layout(location = 0) out vec3 EyeVec;
58 layout(location = 1) out vec4 TexCoord;
59
60 vec2 warp_position()
61 {
62 float vlod = dot(LODWeights, _53.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].LODs);
63 vlod = all(equal(LODWeights, vec4(0.0))) ? _53.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].Position.w : vlod;
64 float floor_lod = floor(vlod);
65 float fract_lod = vlod - floor_lod;
66 uint ufloor_lod = uint(floor_lod);
67 uvec4 uPosition = uvec4(Position);
68 uvec2 mask = (uvec2(1u) << uvec2(ufloor_lod, ufloor_lod + 1u)) - uvec2(1u);
69 uint _111;
70 if (uPosition.x < 32u)
71 {
72 _111 = mask.x;
73 }
74 else
75 {
76 _111 = 0u;
77 }
78 uvec4 rounding;
79 rounding.x = _111;
80 uint _122;
81 if (uPosition.y < 32u)
82 {
83 _122 = mask.x;
84 }
85 else
86 {
87 _122 = 0u;
88 }
89 rounding.y = _122;
90 uint _133;
91 if (uPosition.x < 32u)
92 {
93 _133 = mask.y;
94 }
95 else
96 {
97 _133 = 0u;
98 }
99 rounding.z = _133;
100 uint _145;
101 if (uPosition.y < 32u)
102 {
103 _145 = mask.y;
104 }
105 else
106 {
107 _145 = 0u;
108 }
109 rounding.w = _145;
110 vec4 lower_upper_snapped = vec4((uPosition.xyxy + rounding) & (~mask).xxyy);
111 return mix(lower_upper_snapped.xy, lower_upper_snapped.zw, vec2(fract_lod));
112 }
113
114 vec2 lod_factor(vec2 uv)
115 {
116 float level = textureLod(TexLOD, uv, 0.0).x * 7.96875;
117 float floor_level = floor(level);
118 float fract_level = level - floor_level;
119 return vec2(floor_level, fract_level);
120 }
121
122 void main()
123 {
124 vec2 PatchPos = _53.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].Position.xz * _180.InvOceanSize_PatchScale.zw;
125 vec2 WarpedPos = warp_position();
126 vec2 VertexPos = PatchPos + WarpedPos;
127 vec2 NormalizedPos = VertexPos * _180.InvOceanSize_PatchScale.xy;
128 vec2 NormalizedTex = NormalizedPos * _180.NormalTexCoordScale.zw;
129 vec2 param = NormalizedPos;
130 vec2 lod = lod_factor(param);
131 vec2 Offset = (_180.InvOceanSize_PatchScale.xy * exp2(lod.x)) * _180.NormalTexCoordScale.zw;
132 vec3 Displacement = mix(textureLod(TexDisplacement, NormalizedTex + (Offset * 0.5), lod.x).yxz, textureLod(TexDisplacement, NormalizedTex + (Offset * 1.0), lod.x + 1.0).yxz, vec3(lod.y));
133 vec3 WorldPos = vec3(NormalizedPos.x, 0.0, NormalizedPos.y) + Displacement;
134 WorldPos *= _180.OceanScale.xyz;
135 WorldPos += _180.OceanPosition.xyz;
136 EyeVec = WorldPos - _273.g_CamPos.xyz;
137 TexCoord = vec4(NormalizedTex, NormalizedTex * _180.NormalTexCoordScale.xy) + ((_180.InvOceanSize_PatchScale.xyxy * 0.5) * _180.NormalTexCoordScale.zwzw);
138 gl_Position = (((_273.g_ViewProj_Row0 * WorldPos.x) + (_273.g_ViewProj_Row1 * WorldPos.y)) + (_273.g_ViewProj_Row2 * WorldPos.z)) + _273.g_ViewProj_Row3;
139 }
140