| 1 |
// Copyright 2016 Activision Publishing, Inc. |
| 2 |
// |
| 3 |
// Permission is hereby granted, free of charge, to any person obtaining |
| 4 |
// a copy of this software and associated documentation files (the "Software"), |
| 5 |
// to deal in the Software without restriction, including without limitation |
| 6 |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 7 |
// and/or sell copies of the Software, and to permit persons to whom the Software |
| 8 |
// is furnished to do so, subject to the following conditions: |
| 9 |
// |
| 10 |
// The above copyright notice and this permission notice shall be included in all |
| 11 |
// copies or substantial portions of the Software. |
| 12 |
// |
| 13 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 |
// SOFTWARE. |
| 20 |
|
| 21 |
/* clang-format off */ |
| 22 |
#[vertex] |
| 23 |
|
| 24 |
#version 450 |
| 25 |
|
| 26 |
#VERSION_DEFINES |
| 27 |
|
| 28 |
#include "../oct_inc.glsl" |
| 29 |
|
| 30 |
layout(push_constant, std430) uniform Params { |
| 31 |
uint size; |
| 32 |
} |
| 33 |
params; |
| 34 |
|
| 35 |
layout(location = 0) out vec2 uv_interp; |
| 36 |
/* clang-format on */ |
| 37 |
|
| 38 |
void main() { |
| 39 |
// old code, ARM driver bug on Mali-GXXx GPUs and Vulkan API 1.3.xxx |
| 40 |
// https://github.com/godotengine/godot/pull/92817#issuecomment-2168625982 |
| 41 |
//vec2 base_arr[3] = vec2[](vec2(-1.0, -1.0), vec2(-1.0, 3.0), vec2(3.0, -1.0)); |
| 42 |
//gl_Position = vec4(base_arr[gl_VertexIndex], 0.0, 1.0); |
| 43 |
//uv_interp = clamp(gl_Position.xy, vec2(0.0, 0.0), vec2(1.0, 1.0)) * 2.0; // saturate(x) * 2.0 |
| 44 |
|
| 45 |
vec2 vertex_base; |
| 46 |
if (gl_VertexIndex == 0) { |
| 47 |
vertex_base = vec2(-1.0, -1.0); |
| 48 |
} else if (gl_VertexIndex == 1) { |
| 49 |
vertex_base = vec2(-1.0, 3.0); |
| 50 |
} else { |
| 51 |
vertex_base = vec2(3.0, -1.0); |
| 52 |
} |
| 53 |
gl_Position = vec4(vertex_base, 0.0, 1.0); |
| 54 |
uv_interp = clamp(vertex_base, vec2(0.0, 0.0), vec2(1.0, 1.0)) * 2.0; // saturate(x) * 2.0 |
| 55 |
} |
| 56 |
|
| 57 |
/* clang-format off */ |
| 58 |
#[fragment] |
| 59 |
|
| 60 |
#version 450 |
| 61 |
|
| 62 |
#VERSION_DEFINES |
| 63 |
|
| 64 |
#include "../oct_inc.glsl" |
| 65 |
|
| 66 |
layout(push_constant, std430) uniform Params { |
| 67 |
uint size; |
| 68 |
} |
| 69 |
params; |
| 70 |
|
| 71 |
layout(set = 0, binding = 0) uniform sampler2D source_octmap; |
| 72 |
|
| 73 |
layout(location = 0) in vec2 uv_interp; |
| 74 |
layout(location = 0) out vec4 frag_color; |
| 75 |
/* clang-format on */ |
| 76 |
|
| 77 |
float calcWeight(float u, float v) { |
| 78 |
float val = u * u + v * v + 1.0; |
| 79 |
return val * sqrt(val); |
| 80 |
} |
| 81 |
|
| 82 |
void main() { |
| 83 |
#ifdef USE_HIGH_QUALITY |
| 84 |
float inv_size = 1.0 / float(params.size); |
| 85 |
float u0 = (uv_interp.x * 2.0f) + (1.0f - 0.75f) * inv_size - 1.0f; |
| 86 |
float u1 = (uv_interp.x * 2.0f) + (1.0f + 0.75f) * inv_size - 1.0f; |
| 87 |
float v0 = (uv_interp.y * 2.0f) + (1.0f - 0.75f) * inv_size - 1.0f; |
| 88 |
float v1 = (uv_interp.y * 2.0f) + (1.0f + 0.75f) * inv_size - 1.0f; |
| 89 |
float weights[4]; |
| 90 |
weights[0] = calcWeight(u0, v0); |
| 91 |
weights[1] = calcWeight(u1, v0); |
| 92 |
weights[2] = calcWeight(u0, v1); |
| 93 |
weights[3] = calcWeight(u1, v1); |
| 94 |
|
| 95 |
const float wsum = 0.5 / (weights[0] + weights[1] + weights[2] + weights[3]); |
| 96 |
for (int i = 0; i < 4; i++) { |
| 97 |
weights[i] = weights[i] * wsum + 0.125; |
| 98 |
} |
| 99 |
|
| 100 |
frag_color = textureLod(source_octmap, vec2(u0, v0) * 0.5f + 0.5f, 0.0) * weights[0]; |
| 101 |
frag_color += textureLod(source_octmap, vec2(u1, v0) * 0.5f + 0.5f, 0.0) * weights[1]; |
| 102 |
frag_color += textureLod(source_octmap, vec2(u0, v1) * 0.5f + 0.5f, 0.0) * weights[2]; |
| 103 |
frag_color += textureLod(source_octmap, vec2(u1, v1) * 0.5f + 0.5f, 0.0) * weights[3]; |
| 104 |
#else |
| 105 |
frag_color = textureLod(source_octmap, uv_interp, 0.0); |
| 106 |
#endif |
| 107 |
} |