Made shaders compile by adding locations and bindings and splitting textures and samplers out into two things and adding guards for double including shaders

This commit is contained in:
Imbris 2020-11-29 16:38:03 -05:00 committed by Avi Weinstock
parent 73f5c571d5
commit 612e4fe823
43 changed files with 346 additions and 284 deletions

View File

@ -1,5 +1,3 @@
uniform sampler2D src_color;
const float FXAA_SCALE = 1.25;
/**
@ -57,17 +55,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//optimized version for mobile, where dependent
//texture reads can be a bottleneck
vec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 resolution,
vec4 fxaa(texture2D tex, sampler smplr, vec2 fragCoord, vec2 resolution,
vec2 v_rgbNW, vec2 v_rgbNE,
vec2 v_rgbSW, vec2 v_rgbSE,
vec2 v_rgbM) {
vec4 color;
mediump vec2 inverseVP = vec2(1.0 / resolution.x, 1.0 / resolution.y);
vec3 rgbNW = texture(tex, v_rgbNW).xyz;
vec3 rgbNE = texture(tex, v_rgbNE).xyz;
vec3 rgbSW = texture(tex, v_rgbSW).xyz;
vec3 rgbSE = texture(tex, v_rgbSE).xyz;
vec4 texColor = texture(tex, v_rgbM);
vec3 rgbNW = texture(sampler2D(tex, smplr), v_rgbNW).xyz;
vec3 rgbNE = texture(sampler2D(tex, smplr), v_rgbNE).xyz;
vec3 rgbSW = texture(sampler2D(tex, smplr), v_rgbSW).xyz;
vec3 rgbSE = texture(sampler2D(tex, smplr), v_rgbSE).xyz;
vec4 texColor = texture(sampler2D(tex, smplr), v_rgbM);
vec3 rgbM = texColor.xyz;
vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
@ -91,11 +89,11 @@ vec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 resolution,
dir * rcpDirMin)) * inverseVP;
vec3 rgbA = 0.5 * (
texture(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +
texture(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);
texture(sampler2D(tex, smplr), fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +
texture(sampler2D(tex, smplr), fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);
vec3 rgbB = rgbA * 0.5 + 0.25 * (
texture(tex, fragCoord * inverseVP + dir * -0.5).xyz +
texture(tex, fragCoord * inverseVP + dir * 0.5).xyz);
texture(sampler2D(tex, smplr), fragCoord * inverseVP + dir * -0.5).xyz +
texture(sampler2D(tex, smplr), fragCoord * inverseVP + dir * 0.5).xyz);
float lumaB = dot(rgbB, luma);
if ((lumaB < lumaMin) || (lumaB > lumaMax))
@ -119,7 +117,7 @@ void texcoords(vec2 fragCoord, vec2 resolution,
}
vec4 aa_apply(sampler2D tex, vec2 fragCoord, vec2 resolution) {
vec4 aa_apply(texture2D tex, sampler smplr, vec2 fragCoord, vec2 resolution) {
mediump vec2 v_rgbNW;
mediump vec2 v_rgbNE;
mediump vec2 v_rgbSW;
@ -133,5 +131,5 @@ vec4 aa_apply(sampler2D tex, vec2 fragCoord, vec2 resolution) {
texcoords(scaled_fc, scaled_res, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);
//compute FXAA
return fxaa(tex, scaled_fc, scaled_res, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);
return fxaa(tex, smplr, scaled_fc, scaled_res, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);
}

View File

@ -1,24 +1,22 @@
uniform sampler2DMS src_color;
vec4 aa_apply(sampler2DMS tex, vec2 fragCoord, vec2 resolution) {
vec4 aa_apply(texture2D tex, sampler smplr, vec2 fragCoord, vec2 resolution) {
ivec2 texel_coord = ivec2(fragCoord.x, fragCoord.y);
vec4 sample1 = texelFetch(tex, texel_coord, 0);
vec4 sample2 = texelFetch(tex, texel_coord, 1);
vec4 sample3 = texelFetch(tex, texel_coord, 2);
vec4 sample4 = texelFetch(tex, texel_coord, 3);
vec4 sample5 = texelFetch(tex, texel_coord, 4);
vec4 sample6 = texelFetch(tex, texel_coord, 5);
vec4 sample7 = texelFetch(tex, texel_coord, 6);
vec4 sample8 = texelFetch(tex, texel_coord, 7);
vec4 sample9 = texelFetch(tex, texel_coord, 8);
vec4 sample10 = texelFetch(tex, texel_coord, 9);
vec4 sample11 = texelFetch(tex, texel_coord, 10);
vec4 sample12 = texelFetch(tex, texel_coord, 11);
vec4 sample13 = texelFetch(tex, texel_coord, 12);
vec4 sample14 = texelFetch(tex, texel_coord, 13);
vec4 sample15 = texelFetch(tex, texel_coord, 14);
vec4 sample16 = texelFetch(tex, texel_coord, 15);
vec4 sample1 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 0);
vec4 sample2 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 1);
vec4 sample3 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 2);
vec4 sample4 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 3);
vec4 sample5 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 4);
vec4 sample6 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 5);
vec4 sample7 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 6);
vec4 sample8 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 7);
vec4 sample9 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 8);
vec4 sample10 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 9);
vec4 sample11 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 10);
vec4 sample12 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 11);
vec4 sample13 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 12);
vec4 sample14 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 13);
vec4 sample15 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 14);
vec4 sample16 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 15);
// Average Samples
vec4 msaa_color = (
@ -27,4 +25,4 @@ vec4 aa_apply(sampler2DMS tex, vec2 fragCoord, vec2 resolution) {
) / 16.0;
return msaa_color;
}
}

View File

@ -1,15 +1,13 @@
uniform sampler2DMS src_color;
vec4 aa_apply(sampler2DMS tex, vec2 fragCoord, vec2 resolution) {
vec4 aa_apply(texture2D tex, sampler smplr, vec2 fragCoord, vec2 resolution) {
ivec2 texel_coord = ivec2(fragCoord.x, fragCoord.y);
vec4 sample1 = texelFetch(tex, texel_coord, 0);
vec4 sample2 = texelFetch(tex, texel_coord, 1);
vec4 sample3 = texelFetch(tex, texel_coord, 2);
vec4 sample4 = texelFetch(tex, texel_coord, 3);
vec4 sample1 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 0);
vec4 sample2 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 1);
vec4 sample3 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 2);
vec4 sample4 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 3);
// Average Samples
vec4 msaa_color = (sample1 + sample2 + sample3 + sample4) / 4.0;
return msaa_color;
}
}

View File

@ -1,19 +1,17 @@
uniform sampler2DMS src_color;
vec4 aa_apply(sampler2DMS tex, vec2 fragCoord, vec2 resolution) {
vec4 aa_apply(texture2D tex, sampler smplr, vec2 fragCoord, vec2 resolution) {
ivec2 texel_coord = ivec2(fragCoord.x, fragCoord.y);
vec4 sample1 = texelFetch(tex, texel_coord, 0);
vec4 sample2 = texelFetch(tex, texel_coord, 1);
vec4 sample3 = texelFetch(tex, texel_coord, 2);
vec4 sample4 = texelFetch(tex, texel_coord, 3);
vec4 sample5 = texelFetch(tex, texel_coord, 4);
vec4 sample6 = texelFetch(tex, texel_coord, 5);
vec4 sample7 = texelFetch(tex, texel_coord, 6);
vec4 sample8 = texelFetch(tex, texel_coord, 7);
vec4 sample1 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 0);
vec4 sample2 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 1);
vec4 sample3 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 2);
vec4 sample4 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 3);
vec4 sample5 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 4);
vec4 sample6 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 5);
vec4 sample7 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 6);
vec4 sample8 = texelFetch(sampler2DMS(tex, smplr), texel_coord, 7);
// Average Samples
vec4 msaa_color = (sample1 + sample2 + sample3 + sample4 + sample5 + sample6 + sample7 + sample8) / 8.0;
return msaa_color;
}
}

View File

@ -1,5 +1,3 @@
uniform sampler2D src_color;
vec4 aa_apply(sampler2D tex, vec2 fragCoord, vec2 resolution) {
vec4 aa_apply(texture2D tex, sampler smplr, vec2 fragCoord, vec2 resolution) {
return texture(src_color, fragCoord / resolution);
}
}

View File

@ -22,20 +22,28 @@
#include <srgb.glsl>
#include <cloud.glsl>
uniform sampler2D src_depth;
layout(set = 1, binding = 0)
uniform texture2D t_src_color;
layout(set = 1, binding = 1)
uniform sampler s_src_color;
in vec2 f_pos;
layout(set = 1, binding = 2)
uniform texture2D t_src_depth;
layout(set = 1, binding = 3)
uniform sampler s_src_depth;
layout (std140)
layout(location = 0) in vec2 f_pos;
layout (std140, set = 1, binding = 4)
uniform u_locals {
mat4 proj_mat_inv;
mat4 view_mat_inv;
};
out vec4 tgt_color;
layout(location = 0) out vec4 tgt_color;
float depth_at(vec2 uv) {
float buf_depth = texture(src_depth, uv).x;
float buf_depth = texture(sampler2D(t_src_depth, s_src_depth), uv).x;
vec4 clip_space = vec4(uv * 2.0 - 1.0, buf_depth, 1.0);
vec4 view_space = proj_mat_inv * clip_space;
view_space /= view_space.w;
@ -43,7 +51,7 @@ float depth_at(vec2 uv) {
}
vec3 wpos_at(vec2 uv) {
float buf_depth = texture(src_depth, uv).x * 2.0 - 1.0;
float buf_depth = texture(sampler2D(t_src_depth, s_src_depth), uv).x * 2.0 - 1.0;
mat4 inv = view_mat_inv * proj_mat_inv;//inverse(all_mat);
vec4 clip_space = vec4(uv * 2.0 - 1.0, buf_depth, 1.0);
vec4 view_space = inv * clip_space;
@ -59,9 +67,9 @@ vec3 wpos_at(vec2 uv) {
void main() {
vec2 uv = (f_pos + 1.0) * 0.5;
vec4 color = texture(src_color, uv);
vec4 color = texture(sampler2D(t_src_color, s_src_color), uv);
// Apply clouds to `aa_color`
// Apply clouds
#if (CLOUD_MODE != CLOUD_MODE_NONE)
vec3 wpos = wpos_at(uv);
float dist = distance(wpos, cam_pos.xyz);

View File

@ -18,9 +18,9 @@
#include <globals.glsl>
in vec2 v_pos;
layout(location = 0) in vec2 v_pos;
out vec2 f_pos;
layout(location = 0) out vec2 f_pos;
void main() {
f_pos = v_pos;

View File

@ -17,14 +17,16 @@
#define HAS_SHADOW_MAPS
#include <globals.glsl>
#include <light.glsl>
#include <cloud.glsl>
in vec3 f_pos;
layout(location = 0) in vec3 f_pos;
// in float dummy;
// in vec3 f_col;
// in float f_ao;
// flat in uint f_pos_norm;
flat in vec3 f_norm;
/*centroid */in vec2 f_uv_pos;
layout(location = 1) flat in vec3 f_norm;
/*centroid */layout(location = 2) in vec2 f_uv_pos;
// in float f_alt;
// in vec4 f_shadow;
// in vec3 light_pos[2];
@ -35,7 +37,10 @@ flat in vec3 f_norm;
// const vec4 sun_pos = vec4(0.0);
// #endif
uniform sampler2D t_col_light;
layout(set = 1, binding = 2)
uniform texture2D t_col_light;
layout(set = 1, binding = 3)
uniform sampler s_col_light;
//struct ShadowLocals {
// mat4 shadowMatrices;
@ -47,7 +52,7 @@ uniform sampler2D t_col_light;
// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192];
//};
layout (std140)
layout (std140, set = 1, binding = 0)
uniform u_locals {
mat4 model_mat;
vec4 highlight_col;
@ -65,16 +70,12 @@ struct BoneData {
mat4 normals_mat;
};
layout (std140)
layout (std140, set = 1, binding = 1)
uniform u_bones {
BoneData bones[16];
};
#include <cloud.glsl>
#include <light.glsl>
#include <lod.glsl>
out vec4 tgt_color;
layout(location = 0) out vec4 tgt_color;
void main() {
// vec2 texSize = textureSize(t_col_light, 0);
@ -88,8 +89,7 @@ void main() {
float f_ao, f_glow;
uint material = 0xFFu;
vec3 f_col = greedy_extract_col_light_attr(t_col_light, f_uv_pos, f_ao, f_glow, material);
vec3 f_col = greedy_extract_col_light_attr(t_col_light, s_col_light, f_uv_pos, f_ao, f_glow, material);
// float /*f_light*/f_ao = textureProj(t_col_light, vec3(f_uv_pos, texSize)).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0;
// vec3 my_chunk_pos = (vec3((uvec3(f_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0;
@ -131,7 +131,7 @@ void main() {
#endif
#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP)
vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
vec4 f_shadow = textureBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy));
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
#elif (SHADOW_MODE == SHADOW_MODE_NONE)
float sun_shade_frac = 1.0;//horizon_at2(f_shadow, f_alt, f_pos, sun_dir);

View File

@ -17,15 +17,15 @@
#include <globals.glsl>
#include <lod.glsl>
in uint v_pos_norm;
in uint v_atlas_pos;
layout(location = 0) in uint v_pos_norm;
layout(location = 1) in uint v_atlas_pos;
// in vec3 v_norm;
/* in uint v_col;
// out vec3 light_pos[2];
in uint v_ao_bone; */
layout (std140)
layout (std140, set = 1, binding = 0)
uniform u_locals {
mat4 model_mat;
vec4 highlight_col;
@ -43,7 +43,7 @@ struct BoneData {
mat4 normals_mat;
};
layout (std140)
layout (std140, set = 1, binding = 1)
uniform u_bones {
// Warning: might not actually be 16 elements long. Don't index out of bounds!
BoneData bones[16];
@ -59,11 +59,11 @@ uniform u_bones {
// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192];
//};
out vec3 f_pos;
layout(location = 0) out vec3 f_pos;
// flat out uint f_pos_norm;
flat out vec3 f_norm;
layout(location = 1) flat out vec3 f_norm;
// float dummy;
/*centroid */out vec2 f_uv_pos;
/*centroid */layout(location = 2) out vec2 f_uv_pos;
// out vec3 f_col;
// out float f_ao;
// out float f_alt;

View File

@ -21,8 +21,8 @@
#include <globals.glsl>
#include <random.glsl>
in vec3 f_pos;
flat in uint f_pos_norm;
layout(location = 0) in vec3 f_pos;
layout(location = 1) flat in uint f_pos_norm;
// in vec3 f_col;
// in float f_light;
// in vec3 light_pos[2];
@ -37,16 +37,19 @@ flat in uint f_pos_norm;
// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192];
// };
layout (std140)
layout(std140, set = 2, binding = 0)
uniform u_locals {
vec3 model_offs;
float load_time;
ivec4 atlas_offs;
};
uniform sampler2D t_waves;
layout(set = 1, binding = 0)
uniform texture2D t_waves;
layout(set = 1, binding = 1)
uniform sampler s_waves;
out vec4 tgt_color;
layout(location = 0) out vec4 tgt_color;
#include <sky.glsl>
#include <light.glsl>

View File

@ -23,8 +23,8 @@
#include <globals.glsl>
#include <random.glsl>
in vec3 f_pos;
flat in uint f_pos_norm;
layout(location = 0) in vec3 f_pos;
layout(location = 1) flat in uint f_pos_norm;
// in vec3 f_col;
// in float f_light;
// in vec3 light_pos[2];
@ -39,16 +39,19 @@ flat in uint f_pos_norm;
// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192];
//};
layout (std140)
layout(std140, set = 2, binding = 0)
uniform u_locals {
vec3 model_offs;
float load_time;
ivec4 atlas_offs;
};
uniform sampler2D t_waves;
layout(set = 1, binding = 0)
uniform texture2D t_waves;
layout(set = 1, binding = 1)
uniform sampler s_waves;
out vec4 tgt_color;
layout(location = 0) out vec4 tgt_color;
#include <cloud.glsl>
#include <light.glsl>
@ -65,25 +68,25 @@ float wave_height(vec3 pos) {
pos *= 0.5;
vec3 big_warp = (
texture(t_noise, fract(pos.xy * 0.03 + timer * 0.01)).xyz * 0.5 +
texture(t_noise, fract(pos.yx * 0.03 - timer * 0.01)).xyz * 0.5 +
texture(sampler2D(t_noise, s_noise), fract(pos.xy * 0.03 + timer * 0.01)).xyz * 0.5 +
texture(sampler2D(t_noise, s_noise), fract(pos.yx * 0.03 - timer * 0.01)).xyz * 0.5 +
vec3(0)
);
vec3 warp = (
texture(t_noise, fract(pos.yx * 0.1 + timer * 0.02)).xyz * 0.3 +
texture(t_noise, fract(pos.yx * 0.1 - timer * 0.02)).xyz * 0.3 +
texture(sampler2D(t_noise, s_noise), fract(pos.yx * 0.1 + timer * 0.02)).xyz * 0.3 +
texture(sampler2D(t_noise, s_noise), fract(pos.yx * 0.1 - timer * 0.02)).xyz * 0.3 +
vec3(0)
);
float height = (
(texture(t_noise, (pos.xy + pos.z) * 0.03 + big_warp.xy + timer * 0.05).y - 0.5) * 1.0 +
(texture(t_noise, (pos.yx + pos.z) * 0.03 + big_warp.yx - timer * 0.05).y - 0.5) * 1.0 +
(texture(t_noise, (pos.xy + pos.z) * 0.1 + warp.xy + timer * 0.1).x - 0.5) * 0.5 +
(texture(t_noise, (pos.yx + pos.z) * 0.1 + warp.yx - timer * 0.1).x - 0.5) * 0.5 +
(texture(t_noise, (pos.yx + pos.z) * 0.3 + warp.xy * 0.5 + timer * 0.1).x - 0.5) * 0.2 +
(texture(t_noise, (pos.xy + pos.z) * 0.3 + warp.yx * 0.5 - timer * 0.1).x - 0.5) * 0.2 +
(texture(t_noise, (pos.yx + pos.z) * 1.0 + warp.yx * 0.0 - timer * 0.1).x - 0.5) * 0.05 +
(texture(sampler2D(t_noise, s_noise), (pos.xy + pos.z) * 0.03 + big_warp.xy + timer * 0.05).y - 0.5) * 1.0 +
(texture(sampler2D(t_noise, s_noise), (pos.yx + pos.z) * 0.03 + big_warp.yx - timer * 0.05).y - 0.5) * 1.0 +
(texture(sampler2D(t_noise, s_noise), (pos.xy + pos.z) * 0.1 + warp.xy + timer * 0.1).x - 0.5) * 0.5 +
(texture(sampler2D(t_noise, s_noise), (pos.yx + pos.z) * 0.1 + warp.yx - timer * 0.1).x - 0.5) * 0.5 +
(texture(sampler2D(t_noise, s_noise), (pos.yx + pos.z) * 0.3 + warp.xy * 0.5 + timer * 0.1).x - 0.5) * 0.2 +
(texture(sampler2D(t_noise, s_noise), (pos.xy + pos.z) * 0.3 + warp.yx * 0.5 - timer * 0.1).x - 0.5) * 0.2 +
(texture(sampler2D(t_noise, s_noise), (pos.yx + pos.z) * 1.0 + warp.yx * 0.0 - timer * 0.1).x - 0.5) * 0.05 +
0.0
);
@ -191,7 +194,7 @@ void main() {
/* vec3 sun_dir = get_sun_dir(time_of_day.x);
vec3 moon_dir = get_moon_dir(time_of_day.x); */
#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP)
vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
vec4 f_shadow = textureBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy));
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
#elif (SHADOW_MODE == SHADOW_MODE_NONE)
float sun_shade_frac = 1.0;//horizon_at2(f_shadow, f_alt, f_pos, sun_dir);

View File

@ -20,10 +20,10 @@
#include <srgb.glsl>
#include <random.glsl>
in uint v_pos_norm;
layout(location = 0) in uint v_pos_norm;
// in uint v_col_light;
layout (std140)
layout(std140, set = 2, binding = 0)
uniform u_locals {
vec3 model_offs;
float load_time;
@ -40,8 +40,8 @@ uniform u_locals {
// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192];
// };
out vec3 f_pos;
flat out uint f_pos_norm;
layout(location = 0) out vec3 f_pos;
layout(location = 1) flat out uint f_pos_norm;
// out vec3 f_col;
// out float f_light;
// out vec3 light_pos[2];

View File

@ -26,7 +26,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(t_noise, pos.xy / 50000.0).x - 0.5) * 1.5 + 0.5;
mist_min_alt = (texture(sampler2D(t_noise, s_noise), pos.xy / 50000.0).x - 0.5) * 1.5 + 0.5;
#endif
mist_min_alt = view_distance.z * 1.5 * (1.0 + mist_min_alt * 0.5);
const float MIST_FADE_HEIGHT = 500;
@ -193,7 +193,7 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
/* (texture(t_noise, vec2(atan2(dir.x, dir.y) * 2 / PI, dir.z) * 1.0 - time_of_day * 0.00005).x - 0.5) * 0.2 / (1.0 + pow(dir.z, 2) * 10), */
/* (texture(t_noise, vec2(atan2(dir.x, dir.y) * 2 / PI, dir.z) * 1.0 - time_of_day * 0.00005).x - 0.5) * 0.2 / (1.0 + pow(dir.z, 2) * 10) */
/* ) * 1500; */
splay += (texture(t_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 += (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);
#endif
/* const float RAYLEIGH = 0.25; */
@ -215,12 +215,12 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
cdist = step_to_dist(trunc(dist_to_step(cdist - 0.25, quality)), quality);
vec3 emission;
vec4 sample = cloud_at(origin + (dir + dir_diff / ldist) * ldist * splay, cdist, emission);
vec4 sampl = cloud_at(origin + (dir + dir_diff / ldist) * ldist * splay, cdist, emission);
vec2 density_integrals = max(sample.zw, vec2(0)) * (ldist - cdist);
vec2 density_integrals = max(sampl.zw, vec2(0)) * (ldist - cdist);
float sun_access = sample.x;
float moon_access = sample.y;
float sun_access = sampl.x;
float moon_access = sampl.y;
float cloud_scatter_factor = 1.0 - 1.0 / (1.0 + clamp(density_integrals.x, 0, 1));
float global_scatter_factor = 1.0 - 1.0 / (1.0 + clamp(density_integrals.y, 0, 1));

View File

@ -1,5 +1,7 @@
layout (std140)
uniform u_globals {
#ifndef GLOBALS_GLSL
#define GLOBALS_GLSL
layout(std140, set = 0, binding = 0) uniform u_globals {
mat4 view_mat;
mat4 proj_mat;
mat4 all_mat;
@ -33,3 +35,5 @@ mat4 threshold_matrix = mat4(
);
float distance_divider = 2;
float shadow_dithering = 0.5;
#endif

View File

@ -7,7 +7,7 @@ struct Light {
// mat4 light_proj;
};
layout (std140)
layout (std140, set = 0, binding = 3)
uniform u_lights {
Light lights[31];
};
@ -16,7 +16,7 @@ struct Shadow {
vec4 shadow_pos_radius;
};
layout (std140)
layout (std140, set = 0, binding = 4)
uniform u_shadows {
Shadow shadows[24];
};

View File

@ -1,15 +1,20 @@
#ifndef LOD_GLSL
#define LOD_GLSL
#include <random.glsl>
#include <sky.glsl>
#include <srgb.glsl>
uniform sampler2D t_alt;
uniform sampler2D t_horizon;
layout(set = 0, binding = 5) uniform texture2D t_alt;
layout(set = 0, binding = 6) uniform sampler s_alt;
layout(set = 0, binding = 7) uniform texture2D t_horizon;
layout(set = 0, binding = 8) uniform sampler s_horizon;
const float MIN_SHADOW = 0.33;
vec2 pos_to_uv(sampler2D sampler, vec2 pos) {
vec2 pos_to_uv(texture2D tex, sampler s, vec2 pos) {
// Want: (pixel + 0.5) / W
vec2 texSize = textureSize(sampler, 0);
vec2 texSize = textureSize(sampler2D(tex, s), 0);
vec2 uv_pos = (focus_off.xy + pos + 16) / (32.0 * texSize);
return vec2(uv_pos.x, /*1.0 - */uv_pos.y);
}
@ -32,8 +37,8 @@ vec4 cubic(float v) {
}
// NOTE: We assume the sampled coordinates are already in "texture pixels".
vec4 textureBicubic(sampler2D sampler, vec2 texCoords) {
vec2 texSize = textureSize(sampler, 0);
vec4 textureBicubic(texture2D tex, sampler sampl, vec2 texCoords) {
vec2 texSize = textureSize(sampler2D(tex, sampl), 0);
vec2 invTexSize = 1.0 / texSize;
/* texCoords.y = texSize.y - texCoords.y; */
@ -56,10 +61,10 @@ vec4 textureBicubic(sampler2D sampler, vec2 texCoords) {
/* // Correct for map rotaton.
offset.zw = 1.0 - offset.zw; */
vec4 sample0 = texture(sampler, offset.xz);
vec4 sample1 = texture(sampler, offset.yz);
vec4 sample2 = texture(sampler, offset.xw);
vec4 sample3 = texture(sampler, offset.yw);
vec4 sample0 = texture(sampler2D(tex, sampl), offset.xz);
vec4 sample1 = texture(sampler2D(tex, sampl), offset.yz);
vec4 sample2 = texture(sampler2D(tex, sampl), offset.xw);
vec4 sample3 = texture(sampler2D(tex, sampl), offset.yw);
// vec4 sample0 = texelFetch(sampler, offset.xz, 0);
// vec4 sample1 = texelFetch(sampler, offset.yz, 0);
// vec4 sample2 = texelFetch(sampler, offset.xw, 0);
@ -74,8 +79,8 @@ vec4 textureBicubic(sampler2D sampler, vec2 texCoords) {
}
float alt_at(vec2 pos) {
return (/*round*/(texture/*textureBicubic*/(t_alt, pos_to_uv(t_alt, pos)).r * (/*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;
return (/*round*/(texture/*textureBicubic*/(sampler2D(t_alt, s_alt), pos_to_uv(t_alt, s_alt, pos)).r * (/*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;
// return 0.0
// + pow(texture(t_noise, pos * 0.00005).x * 1.4, 3.0) * 1000.0
@ -88,7 +93,7 @@ float alt_at_real(vec2 pos) {
// #if (FLUID_MODE == FLUID_MODE_CHEAP)
// return alt_at(pos);
// #elif (FLUID_MODE == FLUID_MODE_SHINY)
return (/*round*/(textureBicubic(t_alt, pos_to_tex(pos)).r * (/*1300.0*//*1278.7266845703125*/view_distance.w)) + /*140.0*/view_distance.z - focus_off.z);
return (/*round*/(textureBicubic(t_alt, s_alt, pos_to_tex(pos)).r * (/*1300.0*//*1278.7266845703125*/view_distance.w)) + /*140.0*/view_distance.z - focus_off.z);
// #endif
//+ (texture(t_noise, pos * 0.002).x - 0.5) * 64.0;
@ -204,7 +209,7 @@ vec2 splay(vec2 pos) {
const float SQRT_2 = sqrt(2.0) / 2.0;
// /const float CBRT_2 = cbrt(2.0) / 2.0;
// vec2 splayed = pos * (view_distance.x * SQRT_2 + pow(len * 0.5, 3.0) * (SPLAY_MULT - view_distance.x));
vec2 splayed = pos * (view_distance.x * SQRT_2 + len_pow * (textureSize(t_alt, 0) * 32.0/* - view_distance.x*/));
vec2 splayed = pos * (view_distance.x * SQRT_2 + len_pow * (textureSize(sampler2D(t_alt, s_alt), 0) * 32.0/* - view_distance.x*/));
if (abs(pos.x) > 0.99 || abs(pos.y) > 0.99) {
splayed *= 10.0;
}
@ -280,13 +285,18 @@ vec3 lod_pos(vec2 pos, vec2 focus_pos) {
}
#ifdef HAS_LOD_FULL_INFO
uniform sampler2D t_map;
layout(set = 0, binding = 15)
uniform texture2D t_map;
layout(set = 0, binding = 16)
uniform sampler s_map;
vec3 lod_col(vec2 pos) {
//return vec3(0, 0.5, 0);
// return /*linear_to_srgb*/vec3(alt_at(pos), textureBicubic(t_map, pos_to_tex(pos)).gb);
return /*linear_to_srgb*/(textureBicubic(t_map, pos_to_tex(pos)).rgb)
return /*linear_to_srgb*/(textureBicubic(t_map, s_map, pos_to_tex(pos)).rgb)
;//+ (texture(t_noise, pos * 0.04 + texture(t_noise, pos * 0.005).xy * 2.0 + texture(t_noise, pos * 0.06).xy * 0.6).x - 0.5) * 0.1;
//+ (texture(t_noise, pos * 0.04 + texture(t_noise, pos * 0.005).xy * 2.0 + texture(t_noise, pos * 0.06).xy * 0.6).x - 0.5) * 0.1;
}
#endif
#endif

View File

@ -1,4 +1,8 @@
uniform sampler2D t_noise;
#ifndef RANDOM_GLSL
#define RANDOM_GLSL
layout(set = 0, binding = 1) uniform texture2D t_noise;
layout(set = 0, binding = 1) uniform sampler s_noise;
float hash(vec4 p) {
p = fract(p * 0.3183099 + 0.1) - fract(p + 23.22121);
@ -37,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(t_noise, pos.xy + offs0).x, texture(t_noise, pos.xy + offs1).x, fract(pos.z));
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));
}
// 3D version of `snoise`
@ -100,3 +104,4 @@ vec3 smooth_rand(vec3 pos, float lerp_axis) {
vec3 r1 = rand_perm_3(vec3(pos.x, pos.y, pos.z) + floor(lerp_axis + 1.0));
return r0 + (r1 - r0) * fract(lerp_axis);
}
#endif

View File

@ -1,3 +1,6 @@
#ifndef SHADOWS_GLSL
#define SHADOWS_GLSL
#ifdef HAS_SHADOW_MAPS
#if (SHADOW_MODE == SHADOW_MODE_MAP)
@ -6,17 +9,25 @@ struct ShadowLocals {
mat4 texture_mat;
};
layout (std140)
layout (std140, set = 0, binding = 9)
uniform u_light_shadows {
ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192];
};
uniform sampler2DShadow t_directed_shadow_maps;
// Use with sampler2DShadow
layout(set = 0, binding = 13)
uniform texture2D t_directed_shadow_maps;
layout(set = 0, binding = 14)
uniform sampler s_directed_shadow_maps;
// uniform sampler2DArrayShadow t_directed_shadow_maps;
// uniform samplerCubeArrayShadow t_shadow_maps;
// uniform samplerCubeArray t_shadow_maps;
uniform samplerCubeShadow t_point_shadow_maps;
// Use with samplerCubeShadow
layout(set = 0, binding = 11)
uniform textureCube t_point_shadow_maps;
layout(set = 0, binding = 12)
uniform sampler s_point_shadow_maps;
// uniform samplerCube t_shadow_maps;
// uniform sampler2DArray t_directed_shadow_maps;
@ -64,7 +75,7 @@ float ShadowCalculationPoint(uint lightIndex, vec3 fragToLight, vec3 fragNorm, /
{
float currentDepth = VectorToDepth(fragToLight);// + bias;
float visibility = texture(t_point_shadow_maps, vec4(fragToLight, currentDepth));// / (screen_res.w/* - screen_res.z*/)/*1.0 -bias*//*-(currentDepth - bias) / screen_res.w*//*-screen_res.w*/);
float visibility = texture(samplerCubeShadow(t_point_shadow_maps, s_point_shadow_maps), vec4(fragToLight, currentDepth));// / (screen_res.w/* - screen_res.z*/)/*1.0 -bias*//*-(currentDepth - bias) / screen_res.w*//*-screen_res.w*/);
/* if (visibility == 1.0 || visibility == 0.0) {
return visibility;
} */
@ -157,7 +168,7 @@ float ShadowCalculationDirected(in vec3 fragPos)//in vec4 /*light_pos[2]*/sun_po
mat4 texture_mat = shadowMats[0].texture_mat;
vec4 sun_pos = texture_mat * vec4(fragPos, 1.0);
// sun_pos.z -= sun_pos.w * bias;
float visibility = textureProj(t_directed_shadow_maps, sun_pos);
float visibility = textureProj(sampler2DShadow(t_directed_shadow_maps, s_directed_shadow_maps), sun_pos);
/* float visibilityLeft = textureProj(t_directed_shadow_maps, sun_shadow.texture_mat * vec4(fragPos + vec3(0.0, -diskRadius, 0.0), 1.0));
float visibilityRight = textureProj(t_directed_shadow_maps, sun_shadow.texture_mat * vec4(fragPos + vec3(0.0, diskRadius, 0.0), 1.0)); */
// float nearVisibility = textureProj(t_directed_shadow_maps + vec3(0.001, sun_pos));
@ -216,3 +227,5 @@ float ShadowCalculationPoint(uint lightIndex, vec3 fragToLight, vec3 fragNorm, /
return 1.0;
}
#endif
#endif

View File

@ -1,3 +1,6 @@
#ifndef SKY_GLSL
#define SKY_GLSL
#include <random.glsl>
#include <srgb.glsl>
#include <shadows.glsl>
@ -84,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(t_noise, (pos + wind_offset) / 60000.0 / cloud_scale).x - 0.3;
float nz = texture(sampler2D(t_noise, s_nosie), (pos + wind_offset) / 60000.0 / cloud_scale).x - 0.3;
nz = pow(clamp(nz, 0, 1), 3);
return nz;
}
@ -640,3 +643,5 @@ vec3 illuminate(float max_light, vec3 view_dir, /*vec3 max_light, */vec3 emitted
// float sum_col = color.r + color.g + color.b;
// return /*srgb_to_linear*/(/*0.5*//*0.125 * */vec3(pow(color.x, gamma), pow(color.y, gamma), pow(color.z, gamma)));
}
#endif

View File

@ -1,3 +1,5 @@
#ifndef SRGB_GLSL
#define SRGB_GLSL
// Linear RGB, attenuation coefficients for water at roughly R, G, B wavelengths.
// See https://en.wikipedia.org/wiki/Electromagnetic_absorption_by_water
const vec3 MU_WATER = vec3(0.6, 0.04, 0.01);
@ -618,8 +620,8 @@ vec3 compute_attenuation_point(vec3 wpos, vec3 ray_dir, vec3 mu, float surface_a
//}
//#endif
vec3 greedy_extract_col_light_attr(sampler2D t_col_light, vec2 f_uv_pos, out float f_light, out float f_glow, out uint f_attr) {
uvec4 f_col_light = uvec4(texelFetch(t_col_light, ivec2(f_uv_pos), 0) * 255);
vec3 greedy_extract_col_light_attr(texture2D t_col_light, sampler s_col_light, vec2 f_uv_pos, out float f_light, out float f_glow, out uint f_attr) {
uvec4 f_col_light = uvec4(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos), 0) * 255);
vec3 f_col = vec3(
float(((f_col_light.r & 0x7u) << 1u) | (f_col_light.b & 0xF0u)),
float(f_col_light.a),
@ -628,9 +630,9 @@ vec3 greedy_extract_col_light_attr(sampler2D t_col_light, vec2 f_uv_pos, out flo
// TODO: Figure out how to use `texture` and modulation to avoid needing to do manual filtering
vec2 light_00 = vec2(uvec2(f_col_light.rg) >> 3u);
vec2 light_10 = vec2(uvec2(texelFetch(t_col_light, ivec2(f_uv_pos) + ivec2(1, 0), 0).rg * 255.0) >> 3u);
vec2 light_01 = vec2(uvec2(texelFetch(t_col_light, ivec2(f_uv_pos) + ivec2(0, 1), 0).rg * 255.0) >> 3u);
vec2 light_11 = vec2(uvec2(texelFetch(t_col_light, ivec2(f_uv_pos) + ivec2(1, 1), 0).rg * 255.0) >> 3u);
vec2 light_10 = vec2(uvec2(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 0), 0).rg * 255.0) >> 3u);
vec2 light_01 = vec2(uvec2(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(0, 1), 0).rg * 255.0) >> 3u);
vec2 light_11 = vec2(uvec2(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 1), 0).rg * 255.0) >> 3u);
vec2 light_0 = mix(light_00, light_01, fract(f_uv_pos.y));
vec2 light_1 = mix(light_10, light_11, fract(f_uv_pos.y));
vec2 light = mix(light_0, light_1, fract(f_uv_pos.x));
@ -644,7 +646,8 @@ vec3 greedy_extract_col_light_attr(sampler2D t_col_light, vec2 f_uv_pos, out flo
return srgb_to_linear(f_col);
}
vec3 greedy_extract_col_light_glow(sampler2D t_col_light, vec2 f_uv_pos, out float f_light, out float f_glow) {
vec3 greedy_extract_col_light_glow(texture2D t_col_light, sampler s_col_light, vec2 f_uv_pos, out float f_light, out float f_glow) {
uint f_attr;
return greedy_extract_col_light_attr(t_col_light, f_uv_pos, f_light, f_glow, f_attr);
}
#endif

View File

@ -30,12 +30,12 @@
*
* */
in uint v_pos_norm;
layout(location = 1) in uint v_pos_norm;
// in uint v_col_light;
// in vec4 v_pos;
// Light projection matrices.
layout (std140)
layout (std140, set = 1, binding = 0)
uniform u_locals {
vec3 model_offs;
float load_time;

View File

@ -32,12 +32,12 @@
*
* */
in uint v_pos_norm;
in uint v_atlas_pos;
layout(location = 0) in uint v_pos_norm;
layout(location = 1) in uint v_atlas_pos;
// in uint v_col_light;
// in vec4 v_pos;
layout (std140)
layout (std140, set = 1, binding = 0)
uniform u_locals {
mat4 model_mat;
vec4 highlight_col;
@ -55,7 +55,7 @@ struct BoneData {
mat4 normals_mat;
};
layout (std140)
layout (std140, set = 1, binding = 1)
uniform u_bones {
// Warning: might not actually be 16 elements long. Don't index out of bounds!
BoneData bones[16];

View File

@ -26,12 +26,12 @@
*
* */
in uint v_pos_norm;
layout(location = 1) in uint v_pos_norm;
// in uint v_col_light;
// in vec4 v_pos;
// Light projection matrices.
layout (std140)
layout (std140, set = 1, binding = 0)
uniform u_locals {
vec3 model_offs;
float load_time;

View File

@ -23,14 +23,14 @@
#include <cloud.glsl>
#include <lod.glsl>
in vec3 f_pos;
in vec3 f_norm;
in float pull_down;
layout(location = 0) in vec3 f_pos;
layout(location = 1) in vec3 f_norm;
layout(location = 2) in float pull_down;
// in vec2 v_pos_orig;
// in vec4 f_shadow;
// in vec4 f_square;
out vec4 tgt_color;
layout(location = 0) out vec4 tgt_color;
/// const vec4 sun_pos = vec4(0);
// const vec4 light_pos[2] = vec4[](vec4(0), vec4(0)/*, vec3(00), vec3(0), vec3(0), vec3(0)*/);
@ -444,7 +444,7 @@ void main() {
#endif
#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP)
vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
vec4 f_shadow = textureBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy));
float sun_shade_frac = horizon_at2(f_shadow, shadow_alt, f_pos, sun_dir);
// float sun_shade_frac = 1.0;
#elif (SHADOW_MODE == SHADOW_MODE_NONE)

View File

@ -20,16 +20,11 @@
#include <srgb.glsl>
#include <lod.glsl>
in vec2 v_pos;
layout(location = 0) in vec2 v_pos;
layout (std140)
uniform u_locals {
vec4 nul;
};
out vec3 f_pos;
out vec3 f_norm;
out float pull_down;
layout(location = 0) out vec3 f_pos;
layout(location = 1) out vec3 f_norm;
layout(location = 2) out float pull_down;
// out vec2 v_pos_orig;
// out vec4 f_square;
// out vec4 f_shadow;

View File

@ -16,12 +16,12 @@
#include <globals.glsl>
in vec3 f_pos;
flat in vec3 f_norm;
in vec4 f_col;
in float f_reflect;
layout(location = 0) in vec3 f_pos;
layout(location = 1) flat in vec3 f_norm;
layout(location = 2) in vec4 f_col;
layout(location = 3) in float f_reflect;
out vec4 tgt_color;
layout(location = 0) out vec4 tgt_color;
#include <sky.glsl>
#include <light.glsl>
@ -40,7 +40,7 @@ void main() {
#endif
#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP)
vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
vec4 f_shadow = textureBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy));
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
#elif (SHADOW_MODE == SHADOW_MODE_NONE)
float sun_shade_frac = 1.0;

View File

@ -17,22 +17,22 @@
#include <random.glsl>
#include <lod.glsl>
in vec3 v_pos;
layout(location = 0) in vec3 v_pos;
// in uint v_col;
in uint v_norm_ao;
in vec3 inst_pos;
in float inst_time;
in float inst_lifespan;
in float inst_entropy;
in vec3 inst_dir;
in int inst_mode;
layout(location = 1) in uint v_norm_ao;
layout(location = 2) in float inst_time;
layout(location = 3) in float inst_lifespan;
layout(location = 4) in float inst_entropy;
layout(location = 5) in int inst_mode;
layout(location = 6) in vec3 inst_dir;
layout(location = 7) in vec3 inst_pos;
out vec3 f_pos;
flat out vec3 f_norm;
out vec4 f_col;
out float f_ao;
out float f_light;
out float f_reflect;
layout(location = 0) out vec3 f_pos;
layout(location = 1) flat out vec3 f_norm;
layout(location = 2) out vec4 f_col;
//layout(location = x) out float f_ao;
//layout(location = x) out float f_light;
layout(location = 3) out float f_reflect;
const float SCALE = 1.0 / 11.0;

View File

@ -22,17 +22,27 @@
#include <srgb.glsl>
#include <cloud.glsl>
//uniform sampler2D src_depth;
layout(set = 1, binding = 0)
uniform texture2D t_src_color;
layout(set = 1, binding = 1)
uniform sampler s_src_color;
in vec2 f_pos;
// TODO: unused
layout(set = 1, binding = 2)
uniform texture2D t_src_depth;
layout(set = 1, binding = 3)
uniform sampler s_src_depth;
layout (std140)
layout(location = 0) in vec2 f_pos;
layout (std140, set = 1, binding = 4)
uniform u_locals {
mat4 proj_mat_inv;
mat4 view_mat_inv;
};
out vec4 tgt_color;
layout(location = 0) out vec4 tgt_color;
vec3 rgb2hsv(vec3 c) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
@ -202,7 +212,7 @@ void main() {
// float bright_color = (bright_color0 + bright_color1 + bright_color2 + bright_color3 + bright_color4) / 5.0;
vec4 aa_color = aa_apply(src_color, uv * screen_res.xy, screen_res.xy);
vec4 aa_color = aa_apply(t_src_color, s_src_color, uv * screen_res.xy, screen_res.xy);
// Tonemapping
float exposure_offset = 1.0;

View File

@ -18,9 +18,9 @@
#include <globals.glsl>
in vec2 v_pos;
layout(location = 0) in vec2 v_pos;
out vec2 f_pos;
layout(location = 0) out vec2 f_pos;
void main() {
f_pos = v_pos;

View File

@ -16,18 +16,11 @@
#define LIGHTING_DISTRIBUTION LIGHTING_DISTRIBUTION_BECKMANN
#include <globals.glsl>
#include <sky.glsl>
#include <lod.glsl>
#include <lod.glsl> // includes sky, globals
in vec3 f_pos;
layout(location = 0) in vec3 f_pos;
layout (std140)
uniform u_locals {
vec4 nul;
};
out vec4 tgt_color;
layout(location = 0) out vec4 tgt_color;
void main() {
// tgt_color = vec4(MU_SCATTER, 1.0);

View File

@ -18,14 +18,9 @@
#include <globals.glsl>
in vec3 v_pos;
layout(location = 0) in vec3 v_pos;
layout (std140)
uniform u_locals {
vec4 nul;
};
out vec3 f_pos;
layout(location = 0) out vec3 f_pos;
void main() {
/* vec3 v_pos = v_pos;

View File

@ -16,19 +16,22 @@
#include <globals.glsl>
in vec3 f_pos;
flat in vec3 f_norm;
flat in float f_select;
layout(location = 0) in vec3 f_pos;
layout(location = 1) flat in vec3 f_norm;
layout(location = 2) flat in float f_select;
// flat in vec3 f_pos_norm;
in vec2 f_uv_pos;
in vec2 f_inst_light;
layout(location = 3) in vec2 f_uv_pos;
layout(location = 4) in vec2 f_inst_light;
// flat in uint f_atlas_pos;
// in vec3 f_col;
// in float f_ao;
// in float f_light;
// in vec4 light_pos[2];
uniform sampler2D t_col_light;
layout(set = 2, binding = 1)
uniform texture2D t_col_light;
layout(set = 2, binding = 2)
uniform sampler s_col_light;
//struct ShadowLocals {
// mat4 shadowMatrices;
@ -40,7 +43,7 @@ uniform sampler2D t_col_light;
// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192];
//};
out vec4 tgt_color;
layout(location = 0) out vec4 tgt_color;
#include <sky.glsl>
#include <light.glsl>
@ -63,7 +66,7 @@ void main() {
// vec3 f_norm = normalize(cross(du, dv));
float f_ao, f_glow;
vec3 f_col = greedy_extract_col_light_glow(t_col_light, f_uv_pos, f_ao, f_glow);
vec3 f_col = greedy_extract_col_light_glow(t_col_light, s_col_light, f_uv_pos, f_ao, f_glow);
// vec3 my_chunk_pos = f_pos_norm;
// tgt_color = vec4(hash(floor(vec4(my_chunk_pos.x, 0, 0, 0))), hash(floor(vec4(0, my_chunk_pos.y, 0, 1))), hash(floor(vec4(0, 0, my_chunk_pos.z, 2))), 1.0);
@ -97,7 +100,7 @@ void main() {
#endif
#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP)
vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
vec4 f_shadow = textureBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy));
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
// float sun_shade_frac = 1.0;//horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
#elif (SHADOW_MODE == SHADOW_MODE_NONE)

View File

@ -16,17 +16,17 @@
#include <srgb.glsl>
#include <sky.glsl>
in vec3 v_pos;
in uint v_atlas_pos;
layout(location = 0) in vec3 v_pos;
layout(location = 1) in uint v_atlas_pos;
// in uint v_col;
in uint v_norm_ao;
in uint inst_pos_ori;
in vec4 inst_mat0;
in vec4 inst_mat1;
in vec4 inst_mat2;
in vec4 inst_mat3;
in vec4 inst_light;
in float inst_wind_sway;
layout(location = 2) in uint v_norm_ao;
layout(location = 3) in uint inst_pos_ori;
layout(location = 4) in vec4 inst_mat0;
layout(location = 5) in vec4 inst_mat1;
layout(location = 6) in vec4 inst_mat2;
layout(location = 7) in vec4 inst_mat3;
layout(location = 8) in vec4 inst_light;
layout(location = 9) in float inst_wind_sway;
struct SpriteLocals {
mat4 mat;
@ -34,7 +34,7 @@ struct SpriteLocals {
vec4 offs;
};
layout (std140)
layout(std140, set = 2, binding = 0)
uniform u_locals {
mat4 mat;
vec4 wind_sway;
@ -63,21 +63,21 @@ uniform u_locals {
// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192];
//};
layout (std140)
layout (std140, set = 1, binding = 0)
uniform u_terrain_locals {
vec3 model_offs;
float load_time;
ivec4 atlas_offs;
};
out vec3 f_pos;
flat out vec3 f_norm;
flat out float f_select;
layout(location = 0) out vec3 f_pos;
layout(location = 1) flat out vec3 f_norm;
layout(location = 2) flat out float f_select;
// flat out vec3 f_pos_norm;
// out vec3 f_col;
// out float f_ao;
out vec2 f_uv_pos;
out vec2 f_inst_light;
layout(location = 3) out vec2 f_uv_pos;
layout(location = 4) out vec2 f_inst_light;
// flat out uint f_atlas_pos;
// out vec3 light_pos[2];
// out float f_light;

View File

@ -22,12 +22,12 @@
#include <globals.glsl>
#include <random.glsl>
in vec3 f_pos;
layout(location = 0) in vec3 f_pos;
// in float f_ao;
// in vec3 f_chunk_pos;
// #ifdef FLUID_MODE_SHINY
flat in uint f_pos_norm;
flat in float f_load_time;
layout(location = 1) flat in uint f_pos_norm;
layout(location = 2) flat in float f_load_time;
// #else
// const uint f_pos_norm = 0u;
// #endif
@ -35,7 +35,7 @@ flat in float f_load_time;
// in vec4 f_shadow;
// in vec3 f_col;
// in float f_light;
/*centroid */in vec2 f_uv_pos;
/*centroid */layout(location = 3) in vec2 f_uv_pos;
// in vec3 light_pos[2];
// const vec3 light_pos[6] = vec3[](vec3(0), vec3(0), vec3(00), vec3(0), vec3(0), vec3(0));
@ -45,16 +45,19 @@ in vec4 sun_pos;
const vec4 sun_pos = vec4(0.0);
#endif */
uniform sampler2D t_col_light;
layout(set = 1, binding = 1)
uniform texture2D t_col_light;
layout(set = 1, binding = 2)
uniform sampler s_col_light;
layout (std140)
layout (std140, set = 1, binding = 0)
uniform u_locals {
vec3 model_offs;
float load_time;
ivec4 atlas_offs;
};
out vec4 tgt_color;
layout(location = 0) out vec4 tgt_color;
#include <sky.glsl>
#include <light.glsl>
@ -82,7 +85,7 @@ void main() {
// vec4 f_col_light = textureProj(t_col_light, vec3(f_uv_pos + 0.5, textureSize(t_col_light, 0)));//(f_uv_pos/* + 0.5*/) / texSize);
// float f_light = textureProj(t_col_light, vec3(f_uv_pos + 0.5, textureSize(t_col_light, 0))).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0;
float f_light, f_glow;
vec3 f_col = greedy_extract_col_light_glow(t_col_light, f_uv_pos, f_light, f_glow);
vec3 f_col = greedy_extract_col_light_glow(t_col_light, s_col_light, f_uv_pos, f_light, f_glow);
//float f_light = (uint(texture(t_col_light, (f_uv_pos + 0.5) / textureSize(t_col_light, 0)).r * 255.0) & 0x1Fu) / 31.0;
// vec2 texSize = textureSize(t_col_light, 0);
// float f_light = texture(t_col_light, f_uv_pos/* + vec2(atlas_offs.xy)*/).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0;
@ -216,7 +219,7 @@ void main() {
// float f_alt = alt_at(f_pos.xy);
// vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP)
vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
vec4 f_shadow = textureBicubic(t_horizon, s_horizon, pos_to_tex(f_pos.xy));
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
#elif (SHADOW_MODE == SHADOW_MODE_NONE)
float sun_shade_frac = 1.0;//horizon_at2(f_shadow, f_alt, f_pos, sun_dir);

View File

@ -24,11 +24,11 @@
#include <shadows.glsl>
in uint v_pos_norm;
layout(location = 0) in uint v_pos_norm;
// in uint v_col_light;
in uint v_atlas_pos;
layout(location = 1) in uint v_atlas_pos;
layout (std140)
layout (std140, set = 1, binding = 0)
uniform u_locals {
vec3 model_offs;
float load_time;
@ -45,10 +45,10 @@ uniform u_locals {
// ShadowLocals shadowMats[/*MAX_LAYER_FACES*/192];
//};
out vec3 f_pos;
layout(location = 0) out vec3 f_pos;
// #ifdef FLUID_MODE_SHINY
flat out uint f_pos_norm;
flat out float f_load_time;
layout(location = 1) flat out uint f_pos_norm;
layout(location = 2) flat out float f_load_time;
// #if (SHADOW_MODE == SHADOW_MODE_MAP)
// out vec4 sun_pos;
@ -60,7 +60,7 @@ flat out float f_load_time;
// out vec3 f_col;
// out vec3 f_chunk_pos;
// out float f_ao;
/*centroid */out vec2 f_uv_pos;
/*centroid */layout(location = 3) out vec2 f_uv_pos;
// out vec3 light_pos[2];
// out float f_light;

View File

@ -2,27 +2,30 @@
#include <globals.glsl>
in vec2 f_uv;
in vec4 f_color;
flat in uint f_mode;
layout(location = 0) in vec2 f_uv;
layout(location = 1) in vec4 f_color;
layout(location = 2) flat in uint f_mode;
layout (std140)
layout (std140, set = 1, binding = 0)
uniform u_locals {
vec4 w_pos;
};
uniform sampler2D u_tex;
layout(set = 1, binding = 1)
uniform texture2D t_tex;
layout(set = 1, binding = 2)
uniform sampler s_tex;
out vec4 tgt_color;
layout(location = 0) out vec4 tgt_color;
void main() {
// Text
if (f_mode == uint(0)) {
tgt_color = f_color * vec4(1.0, 1.0, 1.0, texture(u_tex, f_uv).a);
tgt_color = f_color * vec4(1.0, 1.0, 1.0, texture(sampler2D(t_tex, s_tex), f_uv).a);
// Image
// HACK: bit 0 is set for both ordinary and north-facing images.
} else if ((f_mode & uint(1)) == uint(1)) {
tgt_color = f_color * texture(u_tex, f_uv);
tgt_color = f_color * texture(sampler2D(t_tex, s_tex), f_uv);
// 2D Geometry
} else if (f_mode == uint(2)) {
tgt_color = f_color;

View File

@ -2,22 +2,25 @@
#include <globals.glsl>
in vec2 v_pos;
in vec2 v_uv;
in vec2 v_center;
in vec4 v_color;
in uint v_mode;
layout(location = 0) in vec2 v_pos;
layout(location = 1) in vec2 v_uv;
layout(location = 2) in vec4 v_color;
layout(location = 3) in vec2 v_center;
layout(location = 4) in uint v_mode;
layout (std140)
layout (std140, set = 1, binding = 0)
uniform u_locals {
vec4 w_pos;
};
uniform sampler2D u_tex;
layout(set = 1, binding = 1)
uniform texture2D t_tex;
layout(set = 1, binding = 2)
uniform sampler s_tex;
out vec2 f_uv;
flat out uint f_mode;
out vec4 f_color;
layout(location = 0) out vec2 f_uv;
layout(location = 1) out vec4 f_color;
layout(location = 2) flat out uint f_mode;
void main() {
f_color = v_color;
@ -36,7 +39,7 @@ void main() {
gl_Position = vec4(v_pos, -1.0, 1.0);
vec2 look_at_dir = normalize(vec2(-view_mat[0][2], -view_mat[1][2]));
// TODO: Consider cleaning up matrix to something more efficient (e.g. a mat3).
vec2 aspect_ratio = textureSize(u_tex, 0).yx;
vec2 aspect_ratio = textureSize(sampler2D(t_tex, s_tex), 0).yx;
mat2 look_at = mat2(look_at_dir.y, look_at_dir.x, -look_at_dir.x, look_at_dir.y);
vec2 v_centered = (v_uv - v_center) / aspect_ratio;
vec2 v_rotated = look_at * v_centered;

View File

@ -72,6 +72,7 @@ impl BoneData {
}
}
// TODO: delete? the one below is being used
fn layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
@ -142,6 +143,7 @@ impl FigureLayout {
},
count: None,
},
// TODO: does this change at the same frequency?
// col lights
wgpu::BindGroupLayoutEntry {
binding: 2,

View File

@ -1,4 +1,4 @@
use super::super::{AaMode, GlobalsLayouts};
use super::super::{AaMode, GlobalsLayouts, TerrainLayout};
use bytemuck::{Pod, Zeroable};
use vek::*;
@ -87,13 +87,18 @@ impl FluidPipeline {
sc_desc: &wgpu::SwapChainDescriptor,
global_layout: &GlobalsLayouts,
layout: &FluidLayout,
terrain_layout: &TerrainLayout,
aa_mode: AaMode,
) -> Self {
let render_pipeline_layout =
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Fluid pipeline layout"),
push_constant_ranges: &[],
bind_group_layouts: &[&global_layout.globals, &layout.waves],
bind_group_layouts: &[
&global_layout.globals,
&layout.waves,
&terrain_layout.locals,
],
});
let samples = match aa_mode {

View File

@ -316,6 +316,7 @@ impl GlobalsLayouts {
count: None,
},
// light shadows
// TODO: should this be a uniform?
wgpu::BindGroupLayoutEntry {
binding: 9,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,

View File

@ -148,6 +148,7 @@ impl Locals {
}
}
// TODO: unused?
fn layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
@ -175,6 +176,7 @@ impl SpriteLayout {
label: None,
entries: &[
// locals
// TODO: different freq
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,

View File

@ -170,6 +170,7 @@ impl TerrainLayout {
count: None,
},
// col lights
// TODO: same frequency?
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,

View File

@ -1866,6 +1866,7 @@ fn create_pipelines(
let mut compiler = Compiler::new().ok_or(RenderError::ErrorInitializingCompiler)?;
let mut options = CompileOptions::new().ok_or(RenderError::ErrorInitializingCompiler)?;
options.set_optimization_level(OptimizationLevel::Performance);
options.set_forced_version_profile(420, shaderc::GlslProfile::Core);
options.set_include_callback(move |name, _, shader_name, _| {
Ok(ResolvedInclude {
resolved_name: name.to_string(),
@ -1950,6 +1951,7 @@ fn create_pipelines(
sc_desc,
&layouts.global,
&layouts.fluid,
&layouts.terrain,
mode.aa,
);