From f09f515db2137042f6d2d968d8023020c264bc18 Mon Sep 17 00:00:00 2001 From: Imbris Date: Thu, 1 Apr 2021 19:33:49 -0400 Subject: [PATCH] Fix dx12 shader issues --- .../shaders/include/cloud/regular.glsl | 8 +++---- assets/voxygen/shaders/include/lod.glsl | 2 +- assets/voxygen/shaders/include/random.glsl | 4 ++-- assets/voxygen/shaders/include/sky.glsl | 2 +- assets/voxygen/shaders/sprite-vert.glsl | 21 ++++++++++++++++--- assets/voxygen/shaders/ui-vert.glsl | 1 + 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/assets/voxygen/shaders/include/cloud/regular.glsl b/assets/voxygen/shaders/include/cloud/regular.glsl index d8c216dd14..5853a636e5 100644 --- a/assets/voxygen/shaders/include/cloud/regular.glsl +++ b/assets/voxygen/shaders/include/cloud/regular.glsl @@ -34,7 +34,7 @@ vec4 cloud_at(vec3 pos, float dist, out vec3 emission) { // Mist sits close to the ground in valleys (TODO: use base_alt to put it closer to water) float mist_min_alt = 0.5; #if (CLOUD_MODE >= CLOUD_MODE_MEDIUM) - mist_min_alt = (texture(sampler2D(t_noise, s_noise), pos.xy / 50000.0).x - 0.5) * 1.5 + 0.5; + mist_min_alt = (textureLod(sampler2D(t_noise, s_noise), pos.xy / 50000.0, 0).x - 0.5) * 1.5 + 0.5; #endif mist_min_alt = view_distance.z * 1.5 * (1.0 + mist_min_alt * 0.5) + alt * 0.5 + 250; const float MIST_FADE_HEIGHT = 1000; @@ -146,9 +146,9 @@ vec4 cloud_at(vec3 pos, float dist, out vec3 emission) { #if (CLOUD_MODE >= CLOUD_MODE_MEDIUM) emission_alt += (noise_3d(vec3(wind_pos.xy * 0.0005 + cloud_tendency * 0.2, emission_alt * 0.0001 + time_of_day.x * 0.001)) - 0.5) * 1000; #endif - float tail = (texture(t_noise, wind_pos.xy * 0.00005).x - 0.5) * 4 + (pos.z - emission_alt) * 0.0001; + float tail = (textureLod(t_noise, wind_pos.xy * 0.00005).x - 0.5, 0) * 4 + (pos.z - emission_alt) * 0.0001; vec3 emission_col = vec3(0.8 + tail * 1.5, 0.5 - tail * 0.2, 0.3 + tail * 0.2); - float emission_nz = max(pow(texture(t_noise, wind_pos.xy * 0.000015).x, 8), 0.01) * 0.25 / (10.0 + abs(pos.z - emission_alt) / 80); + float emission_nz = max(pow(textureLod(t_noise, wind_pos.xy * 0.000015, 0).x, 8), 0.01) * 0.25 / (10.0 + abs(pos.z - emission_alt) / 80); emission = emission_col * emission_nz * emission_strength * max(sun_dir.z, 0) * 500000 / (1000.0 + abs(pos.z - emission_alt) * 0.1); } @@ -196,7 +196,7 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of // improves visual quality for low cloud settings float splay = 1.0; #if (CLOUD_MODE == CLOUD_MODE_MINIMAL) - splay += (texture(sampler2D(t_noise, s_noise), vec2(atan2(dir.x, dir.y) * 2 / PI, dir.z) * 5.0 - time_of_day * 0.00005).x - 0.5) * 0.025 / (1.0 + pow(dir.z, 2) * 10); + splay += (textureLod(sampler2D(t_noise, s_noise), vec2(atan2(dir.x, dir.y) * 2 / PI, dir.z) * 5.0 - time_of_day * 0.00005, 0).x - 0.5) * 0.025 / (1.0 + pow(dir.z, 2) * 10); #endif /* const float RAYLEIGH = 0.25; */ diff --git a/assets/voxygen/shaders/include/lod.glsl b/assets/voxygen/shaders/include/lod.glsl index 5288c1eb1c..74f73849cf 100644 --- a/assets/voxygen/shaders/include/lod.glsl +++ b/assets/voxygen/shaders/include/lod.glsl @@ -127,7 +127,7 @@ vec2 textureBicubic16(texture2D tex, sampler sampl, vec2 texCoords) { } float alt_at(vec2 pos) { - vec4 alt_sample = texture/*textureBicubic16*/(sampler2D(t_alt, s_alt), pos_to_uv(t_alt, s_alt, pos)); + vec4 alt_sample = textureLod/*textureBicubic16*/(sampler2D(t_alt, s_alt), pos_to_uv(t_alt, s_alt, pos), 0); return (/*round*/((alt_sample.r / 256.0 + alt_sample.g) * (/*1300.0*//*1278.7266845703125*/view_distance.w)) + /*140.0*/view_distance.z - focus_off.z); //+ (texture(t_noise, pos * 0.002).x - 0.5) * 64.0; diff --git a/assets/voxygen/shaders/include/random.glsl b/assets/voxygen/shaders/include/random.glsl index 9335449111..2b6347b71c 100644 --- a/assets/voxygen/shaders/include/random.glsl +++ b/assets/voxygen/shaders/include/random.glsl @@ -32,7 +32,7 @@ float hash_fast(uvec3 q) // 2D, but using shifted 2D textures float noise_2d(vec2 pos) { - return texture(sampler2D(t_noise, s_noise), pos).x; + return textureLod(sampler2D(t_noise, s_noise), pos, 0).x; } // 3D, but using shifted 2D textures @@ -41,7 +41,7 @@ float noise_3d(vec3 pos) { uint z = uint(trunc(pos.z)); vec2 offs0 = vec2(hash_one(z), hash_one(z + 73u)); vec2 offs1 = vec2(hash_one(z + 1u), hash_one(z + 1u + 73u)); - return mix(texture(sampler2D(t_noise, s_noise), pos.xy + offs0).x, texture(sampler2D(t_noise, s_noise), pos.xy + offs1).x, fract(pos.z)); + return mix(textureLod(sampler2D(t_noise, s_noise), pos.xy + offs0, 0).x, textureLod(sampler2D(t_noise, s_noise), pos.xy + offs1, 0).x, fract(pos.z)); } // 3D version of `snoise` diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index efc6c5b1eb..1e2461a761 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -87,7 +87,7 @@ vec2 wind_offset = vec2(time_of_day.x * wind_speed); float cloud_scale = view_distance.z / 150.0; float cloud_tendency_at(vec2 pos) { - float nz = texture(sampler2D(t_noise, s_nosie), (pos + wind_offset) / 60000.0 / cloud_scale).x - 0.3; + float nz = textureLod(sampler2D(t_noise, s_nosie), (pos + wind_offset) / 60000.0 / cloud_scale, 0).x - 0.3; nz = pow(clamp(nz, 0, 1), 3); return nz; } diff --git a/assets/voxygen/shaders/sprite-vert.glsl b/assets/voxygen/shaders/sprite-vert.glsl index 5565ffc48f..b04c8ee91c 100644 --- a/assets/voxygen/shaders/sprite-vert.glsl +++ b/assets/voxygen/shaders/sprite-vert.glsl @@ -55,7 +55,7 @@ const float SCALE_FACTOR = pow(SCALE, 1.3) * 0.2; const int EXTRA_NEG_Z = 32768; const int VERT_EXTRA_NEG_Z = 128; -const int VERT_PAGE_SIZE = 256; +const uint VERT_PAGE_SIZE = 256; void main() { // Matrix to transform this sprite instance from model space to chunk space @@ -71,7 +71,8 @@ void main() { f_inst_light = vec2(inst_light, inst_glow); // Index of the vertex data in the 1D vertex texture - int vertex_index = int(gl_VertexIndex % VERT_PAGE_SIZE + inst_vert_page * VERT_PAGE_SIZE); + // TODO: dx12 warning to switch to uint for modulus here (test if it got speedup?) + int vertex_index = int(uint(gl_VertexIndex) % VERT_PAGE_SIZE + inst_vert_page * VERT_PAGE_SIZE); //const int WIDTH = 8192; // TODO: temp //ivec2 tex_coords = ivec2(vertex_index % WIDTH, vertex_index / WIDTH); //uvec2 pos_atlas_pos_norm_ao = texelFetch(usampler2D(t_sprite_verts, s_sprite_verts), tex_coords, 0).xy; @@ -100,7 +101,21 @@ void main() { ) * v_pos.z * model_z_scale * SCALE_FACTOR; // Determine normal - vec3 norm = (inst_mat[(v_pos_norm >> 30u) & 3u].xyz); + // TODO: do changes here effect perf on vulkan + // TODO: dx12 doesn't like dynamic index + // TODO: use mix? + // Shader@0x000001AABD89BEE0(112,43-53): error X4576: Input array signature parameter cannot be indexed dynamically. + //vec3 norm = (inst_mat[(v_pos_norm >> 30u) & 3u].xyz); + uint index = v_pos_norm >> 30u & 3u; + vec3 norm; + if (index == 0) { + norm = (inst_mat[0].xyz); + } else if (index == 1) { + norm = (inst_mat[1].xyz); + } else { + norm = (inst_mat[2].xyz); + } + f_norm = normalize(mix(-norm, norm, v_pos_norm >> 29u & 1u)); // Expand atlas tex coords to floats diff --git a/assets/voxygen/shaders/ui-vert.glsl b/assets/voxygen/shaders/ui-vert.glsl index c1042b7f99..7c25f01fd3 100644 --- a/assets/voxygen/shaders/ui-vert.glsl +++ b/assets/voxygen/shaders/ui-vert.glsl @@ -59,5 +59,6 @@ void main() { f_uv = v_uv; gl_Position = vec4(v_pos, 0.5, 1.0); } + f_mode = v_mode; }