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) vec4(pos, 1.0)
).xyz + (model_pos - focus_off.xyz); ).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_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)); 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 -= 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 -= 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 // Small waves
// f_pos.xy += 0.01; // Avoid z-fighting // f_pos.xy += 0.01; // Avoid z-fighting
// f_pos.x += 0.1 * sin(tick.x / 60 * hash(vec4(f_pos.xyz, 1.0))); // 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 <random.glsl>
#include <lod.glsl> #include <lod.glsl>
@ -15,6 +16,10 @@ float cloud_broad(vec3 pos) {
// Returns vec4(r, g, b, density) // Returns vec4(r, g, b, density)
vec4 cloud_at(vec3 pos, float dist, out vec3 emission, out float not_underground) { 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) // 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 // 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. // it can't be since Veloren's world is flat, not spherical.

View File

@ -51,6 +51,10 @@ void main() {
pull_down = 1.0 / pow(distance(focus_pos.xy, f_pos.xy) / (view_distance.x * 0.95), 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; 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 -= 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); // f_pos.z = mix(-f_pos.z, f_pos.z, view_distance.x <= distance(focus_pos.xy, f_pos.xy) + 32.0);

View File

@ -585,6 +585,10 @@ void main() {
f_pos = start_pos + (v_pos * attr.scale * SCALE * mat3(attr.rot) + attr.offs); 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 // First 3 normals are negative, next 3 are positive
// TODO: Make particle normals match orientation // 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)); 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 // 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)); 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 // Wind sway effect
f_pos += model_wind_sway * vec3( f_pos += model_wind_sway * vec3(
sin(tick.x * 1.5 + f_pos.y * 0.1) * sin(tick.x * 0.35), sin(tick.x * 1.5 + f_pos.y * 0.1) * sin(tick.x * 0.35),

View File

@ -166,14 +166,16 @@ void main() {
// Use an array to avoid conditional branching // Use an array to avoid conditional branching
// uint norm_index = (f_pos_norm >> 29) & 0x7u; // uint norm_index = (f_pos_norm >> 29) & 0x7u;
// vec3 f_norm = normals[norm_index]; // 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 #ifdef EXPERIMENTAL_BRICKLOREN
vec3 pos = f_pos - focus_off.xyz; vec3 pos = f_pos + focus_off.xyz;
vec3 fp = pos * vec3(1.0, 1.0, 3.0); const vec3 bk_sz = vec3(2, 2, 2);
fp.xy += floor(fp.z) * 0.5; 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 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)); vec3 fp = pos * sz;
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 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_norm = normalize(f_norm);
f_col /= 1.0 + length((fp - clamped) * sign(1.0 - f_norm)) * 2; f_col /= 1.0 + length((fp - clamped) * sign(1.0 - f_norm)) * 2;
#endif #endif
@ -284,7 +286,7 @@ void main() {
// TODO: Apply AO after this // TODO: Apply AO after this
vec3 glow = glow_light(f_pos) * (pow(f_glow, 3) * 5 + pow(f_glow, 2.0) * 2); 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); 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 #ifdef EXPERIMENTAL_NONOISE
float noise = 0.0; float noise = 0.0;
#else #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 #endif
//vec3 srgb_to_linear(vec3 srgb) { //vec3 srgb_to_linear(vec3 srgb) {

View File

@ -77,10 +77,16 @@ void main() {
f_load_time = load_time; f_load_time = load_time;
vec3 v_pos = f_pos;
// Terrain 'pop-in' effect // 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)); // 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( // vec3 light_col = vec3(
// hash(floor(vec4(f_chunk_pos.x, 0, 0, 0))), // hash(floor(vec4(f_chunk_pos.x, 0, 0, 0))),
// hash(floor(vec4(0, f_chunk_pos.y, 0, 1))), // hash(floor(vec4(0, f_chunk_pos.y, 0, 1))),
@ -157,10 +163,10 @@ void main() {
#ifdef HAS_SHADOW_MAPS #ifdef HAS_SHADOW_MAPS
gl_Position = gl_Position =
/*all_mat*/shadowMatrices/*texture_mat*/ * /*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)); gl_Position.z = clamp(gl_Position.z, -abs(gl_Position.w), abs(gl_Position.w));
#else #else
gl_Position = all_mat * vec4(f_pos/*newRay*/, 1); gl_Position = all_mat * vec4(v_pos/*newRay*/, 1);
#endif #endif
// gl_Position.y /= gl_Position.w; // gl_Position.y /= gl_Position.w;
// gl_Position.w = 1.0; // gl_Position.w = 1.0;

View File

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