Merge branch 'zesterer/experimental-shaders' into 'master'

Fixed minor shader issues, added curved world effect

See merge request veloren/veloren!3112
This commit is contained in:
Joshua Barretto 2022-01-18 17:30:49 +00:00
commit c4706078c4
9 changed files with 56 additions and 15 deletions

View File

@ -95,6 +95,10 @@ void main() {
vec4(pos, 1.0)
).xyz + (model_pos - focus_off.xyz);
#ifdef EXPERIMENTAL_CURVEDWORLD
f_pos.z -= pow(distance(f_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2);
#endif
/* f_pos.z -= 25.0 * pow(distance(focus_pos.xy, f_pos.xy) / view_distance.x, 20.0); */
f_uv_pos = vec2((uvec2(v_atlas_pos) >> uvec2(2, 17)) & uvec2(0x7FFFu, 0x7FFFu));

View File

@ -54,6 +54,12 @@ void main() {
// f_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0));
// f_pos.z -= min(32.0, 25.0 * pow(distance(focus_pos.xy, f_pos.xy) / view_distance.x, 20.0));
f_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0));
#ifdef EXPERIMENTAL_CURVEDWORLD
f_pos.z -= pow(distance(f_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2);
#endif
// Small waves
// f_pos.xy += 0.01; // Avoid z-fighting
// f_pos.x += 0.1 * sin(tick.x / 60 * hash(vec4(f_pos.xyz, 1.0)));

View File

@ -1,3 +1,4 @@
#include <constants.glsl>
#include <random.glsl>
#include <lod.glsl>
@ -15,6 +16,10 @@ float cloud_broad(vec3 pos) {
// Returns vec4(r, g, b, density)
vec4 cloud_at(vec3 pos, float dist, out vec3 emission, out float not_underground) {
#ifdef EXPERIMENTAL_CURVEDWORLD
pos.z += pow(distance(pos.xy, focus_pos.xy + focus_off.xy) * 0.05, 2);
#endif
// Natural attenuation of air (air naturally attenuates light that passes through it)
// Simulate the atmosphere thinning as you get higher. Not physically accurate, but then
// it can't be since Veloren's world is flat, not spherical.

View File

@ -44,13 +44,17 @@ void main() {
// f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
// TODO: disabled because it isn't designed to work with reverse depth
// TODO: disabled because it isn't designed to work with reverse depth
//float dist = distance(focus_pos.xy, f_pos.xy);
//pull_down = 0.2 / pow(dist / (view_distance.x * 0.9), 20.0);
pull_down = 1.0 / pow(distance(focus_pos.xy, f_pos.xy) / (view_distance.x * 0.95), 20.0);
f_pos.z -= pull_down;
#ifdef EXPERIMENTAL_CURVEDWORLD
f_pos.z -= pow(distance(f_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2);
#endif
// f_pos.z -= 100.0 * pow(1.0 + 0.01 / view_distance.x, -pow(distance(focus_pos.xy, f_pos.xy), 2.0));
// f_pos.z = mix(-f_pos.z, f_pos.z, view_distance.x <= distance(focus_pos.xy, f_pos.xy) + 32.0);
@ -98,9 +102,9 @@ void main() {
all_mat *
vec4(f_pos/*newRay*/, 1);
// Pull up the depth to avoid drawing over voxels (biased according to VD)
// TODO: disabled because it isn't designed to work with reverse depth
// TODO: disabled because it isn't designed to work with reverse depth
//gl_Position.z += 0.1 * clamp((view_distance.x * 1.0 - dist) * 0.01, 0, 1);
// gl_Position.z = -gl_Position.z / gl_Position.w;
// gl_Position.z = -gl_Position.z / gl_Position.w;
// gl_Position.z = -gl_Position.z * gl_Position.w;

View File

@ -585,6 +585,10 @@ void main() {
f_pos = start_pos + (v_pos * attr.scale * SCALE * mat3(attr.rot) + attr.offs);
#ifdef EXPERIMENTAL_CURVEDWORLD
f_pos.z -= pow(distance(f_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2);
#endif
// First 3 normals are negative, next 3 are positive
// TODO: Make particle normals match orientation
vec4 normals[6] = vec4[](vec4(-1,0,0,0), vec4(1,0,0,0), vec4(0,-1,0,0), vec4(0,1,0,0), vec4(0,0,-1,0), vec4(0,0,1,0));

View File

@ -85,6 +85,10 @@ void main() {
// Terrain 'pop-in' effect
f_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0));
#ifdef EXPERIMENTAL_CURVEDWORLD
f_pos.z -= pow(distance(f_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2);
#endif
// Wind sway effect
f_pos += model_wind_sway * vec3(
sin(tick.x * 1.5 + f_pos.y * 0.1) * sin(tick.x * 0.35),
@ -117,7 +121,7 @@ void main() {
f_uv_pos = vec2((uvec2(v_atlas_pos) >> uvec2(0, 16)) & uvec2(0xFFFFu, 0xFFFFu));;
// Position of the sprite block in the chunk
// Used solely for highlighting the selected sprite
// Used solely for highlighting the selected sprite
vec3 inst_chunk_pos = vec3(inst_pos_ori & 0x3Fu, (inst_pos_ori >> 6) & 0x3Fu, float((inst_pos_ori >> 12) & 0xFFFFu) - EXTRA_NEG_Z);
// Select glowing
vec3 sprite_pos = inst_chunk_pos + chunk_offs;

View File

@ -166,14 +166,16 @@ void main() {
// Use an array to avoid conditional branching
// uint norm_index = (f_pos_norm >> 29) & 0x7u;
// vec3 f_norm = normals[norm_index];
vec3 f_norm = normals[(f_pos_norm >> 29) & 0x7u];
vec3 face_norm = normals[(f_pos_norm >> 29) & 0x7u];
vec3 f_norm = face_norm;
#ifdef EXPERIMENTAL_BRICKLOREN
vec3 pos = f_pos - focus_off.xyz;
vec3 fp = pos * vec3(1.0, 1.0, 3.0);
fp.xy += floor(fp.z) * 0.5;
vec3 clamped = min(floor(fp.xyz) + vec3(0.92, 0.92, 0.8), max(floor(fp.xyz) + vec3(0.06, 0.06, 0.2), fp.xyz));
f_norm.xyz += (fp.xyz - clamped) * 8.0 * sign(1.0 - f_norm) * max(1.0 - length(f_pos - cam_pos.xyz) / 64.0, 0);
vec3 pos = f_pos + focus_off.xyz;
const vec3 bk_sz = vec3(2, 2, 2);
vec3 sz = vec3(1.0 + mod(floor(pos.z * bk_sz.z + floor(pos.x) + floor(pos.y) - 0.01), 2.0) * (bk_sz.x - 1), 1.0 + mod(floor(pos.z * bk_sz.z + floor(pos.x) + floor(pos.y) + 0.99), 2.0) * (bk_sz.y - 1), bk_sz.z);
vec3 fp = pos * sz;
vec3 clamped = min(floor(fp.xyz) + 1.0 - 0.07 * sz, max(floor(fp.xyz) - 0.07 * sz, fp.xyz));
f_norm.xyz += (fp.xyz - clamped) * 5.0 * sign(1.0 - f_norm) * max(1.0 - length(f_pos - cam_pos.xyz) / 64.0, 0);
f_norm = normalize(f_norm);
f_col /= 1.0 + length((fp - clamped) * sign(1.0 - f_norm)) * 2;
#endif
@ -284,7 +286,7 @@ void main() {
// TODO: Apply AO after this
vec3 glow = glow_light(f_pos) * (pow(f_glow, 3) * 5 + pow(f_glow, 2.0) * 2);
reflected_light += glow;
reflected_light += glow * pow(max(dot(face_norm, f_norm), 0), 2);
max_light += lights_at(f_pos, f_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
@ -319,7 +321,11 @@ void main() {
#ifdef EXPERIMENTAL_NONOISE
float noise = 0.0;
#else
float noise = hash(vec4(floor(f_chunk_pos * 3.0 - f_norm * 0.5), 0));//0.005/* - 0.01*/;
#ifdef EXPERIMENTAL_BRICKLOREN
float noise = hash(vec4(floor(clamped), 0)) * 2 + hash(vec4(floor(clamped * 27 / sz), 0)) * 0.5;
#else
float noise = hash(vec4(floor(f_chunk_pos * 3.0 - f_norm * 0.5), 0));//0.005/* - 0.01*/;
#endif
#endif
//vec3 srgb_to_linear(vec3 srgb) {

View File

@ -77,10 +77,16 @@ void main() {
f_load_time = load_time;
vec3 v_pos = f_pos;
// Terrain 'pop-in' effect
f_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0));
v_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0));
// f_pos.z -= min(32.0, 25.0 * pow(distance(focus_pos.xy, f_pos.xy) / view_distance.x, 20.0));
#ifdef EXPERIMENTAL_CURVEDWORLD
v_pos.z -= pow(distance(v_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2);
#endif
// vec3 light_col = vec3(
// hash(floor(vec4(f_chunk_pos.x, 0, 0, 0))),
// hash(floor(vec4(0, f_chunk_pos.y, 0, 1))),
@ -157,10 +163,10 @@ void main() {
#ifdef HAS_SHADOW_MAPS
gl_Position =
/*all_mat*/shadowMatrices/*texture_mat*/ *
vec4(f_pos/*newRay*/, 1);
vec4(v_pos/*newRay*/, 1);
gl_Position.z = clamp(gl_Position.z, -abs(gl_Position.w), abs(gl_Position.w));
#else
gl_Position = all_mat * vec4(f_pos/*newRay*/, 1);
gl_Position = all_mat * vec4(v_pos/*newRay*/, 1);
#endif
// gl_Position.y /= gl_Position.w;
// gl_Position.w = 1.0;

View File

@ -397,4 +397,6 @@ pub enum ExperimentalShader {
Brickloren,
/// Remove the default procedural noise from terrain.
NoNoise,
/// Simulated a curved world.
CurvedWorld,
}