mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Clouds
This commit is contained in:
parent
9d19a2ec63
commit
2237500743
@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Revamped structure of where settings, logs, and game saves are stored so that almost everything is in one place.
|
||||
- Moved hammer leap attack to skillbar
|
||||
- Reworked fire staff
|
||||
- Overhauled cloud shaders to add mist, light attenuation, an approximation of rayleigh scattering, etc.
|
||||
|
||||
### Removed
|
||||
|
||||
|
@ -275,7 +275,7 @@ magically infused items?"#,
|
||||
"hud.map.map_title": "Map",
|
||||
"hud.map.qlog_title": "Quests",
|
||||
|
||||
// Settings
|
||||
// Settings
|
||||
"hud.settings.general": "General",
|
||||
"hud.settings.none": "None",
|
||||
"hud.settings.press_behavior.toggle": "Toggle",
|
||||
@ -328,7 +328,10 @@ magically infused items?"#,
|
||||
"hud.settings.fluid_rendering_mode": "Fluid Rendering Mode",
|
||||
"hud.settings.fluid_rendering_mode.cheap": "Cheap",
|
||||
"hud.settings.fluid_rendering_mode.shiny": "Shiny",
|
||||
"hud.settings.cloud_rendering_mode.regular": "Regular",
|
||||
"hud.settings.cloud_rendering_mode.minimal": "Minimal",
|
||||
"hud.settings.cloud_rendering_mode.low": "Low",
|
||||
"hud.settings.cloud_rendering_mode.medium": "Medium",
|
||||
"hud.settings.cloud_rendering_mode.high": "High",
|
||||
"hud.settings.fullscreen": "Fullscreen",
|
||||
"hud.settings.fullscreen_mode": "Fullscreen Mode",
|
||||
"hud.settings.fullscreen_mode.exclusive": "Exclusive",
|
||||
@ -455,7 +458,7 @@ magically infused items?"#,
|
||||
"gameinput.sneak": "Sneak",
|
||||
"gameinput.swimdown": "Swim downwards",
|
||||
"gameinput.swimup": "Swim upwards",
|
||||
|
||||
|
||||
/// End GameInput section
|
||||
|
||||
|
||||
@ -503,12 +506,12 @@ Protection
|
||||
/// Start Escape Menu Section
|
||||
"esc_menu.logout": "Logout",
|
||||
"esc_menu.quit_game": "Quit Game",
|
||||
/// End Escape Menu Section
|
||||
/// End Escape Menu Section
|
||||
|
||||
},
|
||||
|
||||
|
||||
vector_map: {
|
||||
|
||||
vector_map: {
|
||||
"loading.tips": [
|
||||
"Press 'G' to light your lantern.",
|
||||
"Press 'F1' to see all default keybindings.",
|
||||
@ -519,17 +522,17 @@ Protection
|
||||
"NPCs with the same level can have a different difficulty.",
|
||||
"Keep an eye out for food, chests and other loot spread all around the world!",
|
||||
"Inventory filled with food? Try crafting better food from it!",
|
||||
"Wondering what's there to do? Dungeons are marked with brown spots on the map!",
|
||||
"Wondering what's there to do? Dungeons are marked with brown spots on the map!",
|
||||
"Don't forget to adjust the graphics for your system. Press 'N' to open the settings.",
|
||||
"Playing with others is fun! Press 'O' to see who is online.",
|
||||
"Playing with others is fun! Press 'O' to see who is online.",
|
||||
"An NPC with a skull beneath their healthbar is quite powerful compared to yourself.",
|
||||
"Press 'J' to dance. Party!",
|
||||
"Press 'L-Shift' to open your Glider and conquer the skies.",
|
||||
"Veloren is still in Pre-Alpha. We do our best to improve it every day!",
|
||||
"If you want to join the Dev-Team or just have a chat with us join our Discord-Server.",
|
||||
"If you want to join the Dev-Team or just have a chat with us join our Discord-Server.",
|
||||
"You can toggle showing your amount of health on the healthbar in the settings.",
|
||||
"In order to see your stats click the 'Stats' button in the inventory.",
|
||||
],
|
||||
"In order to see your stats click the 'Stats' button in the inventory.",
|
||||
],
|
||||
"npc.speech.villager_under_attack": [
|
||||
"Help, I'm under attack!",
|
||||
"Help! I'm under attack!",
|
||||
@ -610,6 +613,6 @@ Protection
|
||||
"Please don't do that again.",
|
||||
"Guards, throw this monster in the lake!",
|
||||
"I'll set my tarrasque on you!",
|
||||
],
|
||||
],
|
||||
}
|
||||
)
|
||||
|
@ -107,31 +107,31 @@ vec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 resolution,
|
||||
|
||||
|
||||
void texcoords(vec2 fragCoord, vec2 resolution,
|
||||
out vec2 v_rgbNW, out vec2 v_rgbNE,
|
||||
out vec2 v_rgbSW, out vec2 v_rgbSE,
|
||||
out vec2 v_rgbM) {
|
||||
vec2 inverseVP = 1.0 / resolution.xy;
|
||||
v_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP;
|
||||
v_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP;
|
||||
v_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP;
|
||||
v_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP;
|
||||
v_rgbM = vec2(fragCoord * inverseVP);
|
||||
out vec2 v_rgbNW, out vec2 v_rgbNE,
|
||||
out vec2 v_rgbSW, out vec2 v_rgbSE,
|
||||
out vec2 v_rgbM) {
|
||||
vec2 inverseVP = 1.0 / resolution.xy;
|
||||
v_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP;
|
||||
v_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP;
|
||||
v_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP;
|
||||
v_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP;
|
||||
v_rgbM = vec2(fragCoord * inverseVP);
|
||||
}
|
||||
|
||||
|
||||
vec4 aa_apply(sampler2D tex, vec2 fragCoord, vec2 resolution) {
|
||||
mediump vec2 v_rgbNW;
|
||||
mediump vec2 v_rgbNE;
|
||||
mediump vec2 v_rgbSW;
|
||||
mediump vec2 v_rgbSE;
|
||||
mediump vec2 v_rgbM;
|
||||
mediump vec2 v_rgbNW;
|
||||
mediump vec2 v_rgbNE;
|
||||
mediump vec2 v_rgbSW;
|
||||
mediump vec2 v_rgbSE;
|
||||
mediump vec2 v_rgbM;
|
||||
|
||||
vec2 scaled_fc = fragCoord * FXAA_SCALE;
|
||||
vec2 scaled_res = resolution * FXAA_SCALE;
|
||||
vec2 scaled_fc = fragCoord * FXAA_SCALE;
|
||||
vec2 scaled_res = resolution * FXAA_SCALE;
|
||||
|
||||
//compute the texture coords
|
||||
texcoords(scaled_fc, scaled_res, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);
|
||||
//compute the texture coords
|
||||
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);
|
||||
//compute FXAA
|
||||
return fxaa(tex, scaled_fc, scaled_res, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
uniform sampler2DMS src_color;
|
||||
|
||||
vec4 aa_apply(sampler2DMS tex, vec2 fragCoord, vec2 resolution) {
|
||||
ivec2 texel_coord = ivec2(fragCoord.x, fragCoord.y);
|
||||
ivec2 texel_coord = ivec2(fragCoord.x, fragCoord.y);
|
||||
|
||||
vec4 sample1 = texelFetch(tex, texel_coord, 0);
|
||||
vec4 sample2 = texelFetch(tex, texel_coord, 1);
|
||||
@ -20,11 +20,11 @@ vec4 aa_apply(sampler2DMS tex, vec2 fragCoord, vec2 resolution) {
|
||||
vec4 sample15 = texelFetch(tex, texel_coord, 14);
|
||||
vec4 sample16 = texelFetch(tex, texel_coord, 15);
|
||||
|
||||
// Average Samples
|
||||
vec4 msaa_color = (
|
||||
sample1 + sample2 + sample3 + sample4 + sample5 + sample6 + sample7 + sample8 +
|
||||
sample9 + sample10 + sample11 + sample12 + sample13 + sample14 + sample15 + sample16
|
||||
) / 16.0;
|
||||
// Average Samples
|
||||
vec4 msaa_color = (
|
||||
sample1 + sample2 + sample3 + sample4 + sample5 + sample6 + sample7 + sample8 +
|
||||
sample9 + sample10 + sample11 + sample12 + sample13 + sample14 + sample15 + sample16
|
||||
) / 16.0;
|
||||
|
||||
return msaa_color;
|
||||
return msaa_color;
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
uniform sampler2DMS src_color;
|
||||
|
||||
vec4 aa_apply(sampler2DMS tex, vec2 fragCoord, vec2 resolution) {
|
||||
ivec2 texel_coord = ivec2(fragCoord.x, fragCoord.y);
|
||||
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);
|
||||
|
||||
// Average Samples
|
||||
vec4 msaa_color = (sample1 + sample2 + sample3 + sample4) / 4.0;
|
||||
// Average Samples
|
||||
vec4 msaa_color = (sample1 + sample2 + sample3 + sample4) / 4.0;
|
||||
|
||||
return msaa_color;
|
||||
return msaa_color;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
uniform sampler2DMS src_color;
|
||||
|
||||
vec4 aa_apply(sampler2DMS tex, vec2 fragCoord, vec2 resolution) {
|
||||
ivec2 texel_coord = ivec2(fragCoord.x, fragCoord.y);
|
||||
ivec2 texel_coord = ivec2(fragCoord.x, fragCoord.y);
|
||||
|
||||
vec4 sample1 = texelFetch(tex, texel_coord, 0);
|
||||
vec4 sample2 = texelFetch(tex, texel_coord, 1);
|
||||
@ -12,8 +12,8 @@ vec4 aa_apply(sampler2DMS tex, vec2 fragCoord, vec2 resolution) {
|
||||
vec4 sample7 = texelFetch(tex, texel_coord, 6);
|
||||
vec4 sample8 = texelFetch(tex, texel_coord, 7);
|
||||
|
||||
// Average Samples
|
||||
vec4 msaa_color = (sample1 + sample2 + sample3 + sample4 + sample5 + sample6 + sample7 + sample8) / 8.0;
|
||||
// Average Samples
|
||||
vec4 msaa_color = (sample1 + sample2 + sample3 + sample4 + sample5 + sample6 + sample7 + sample8) / 8.0;
|
||||
|
||||
return msaa_color;
|
||||
return msaa_color;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
uniform sampler2D src_color;
|
||||
|
||||
vec4 aa_apply(sampler2D tex, vec2 fragCoord, vec2 resolution) {
|
||||
return texture(src_color, fragCoord / resolution);
|
||||
return texture(src_color, fragCoord / resolution);
|
||||
}
|
@ -36,7 +36,7 @@ flat in vec3 f_norm;
|
||||
uniform sampler2D t_col_light;
|
||||
|
||||
//struct ShadowLocals {
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 texture_mat;
|
||||
//};
|
||||
//
|
||||
@ -47,23 +47,23 @@ uniform sampler2D t_col_light;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
mat4 model_mat;
|
||||
vec4 highlight_col;
|
||||
mat4 model_mat;
|
||||
vec4 highlight_col;
|
||||
ivec4 atlas_offs;
|
||||
vec3 model_pos;
|
||||
// bit 0 - is player
|
||||
// bit 1-31 - unused
|
||||
int flags;
|
||||
// bit 0 - is player
|
||||
// bit 1-31 - unused
|
||||
int flags;
|
||||
};
|
||||
|
||||
struct BoneData {
|
||||
mat4 bone_mat;
|
||||
mat4 bone_mat;
|
||||
mat4 normals_mat;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_bones {
|
||||
BoneData bones[16];
|
||||
BoneData bones[16];
|
||||
};
|
||||
|
||||
#include <sky.glsl>
|
||||
@ -86,7 +86,7 @@ void main() {
|
||||
vec4 f_col_light = texelFetch(t_col_light, ivec2(f_uv_pos)/* + uv_delta*//* - f_norm * 0.00001*/, 0);
|
||||
// vec4 f_col_light = texelFetch(t_col_light, ivec2(int(f_uv_pos.x), int(f_uv_pos.y)/* + uv_delta*//* - f_norm * 0.00001*/), 0);
|
||||
vec3 f_col = /*linear_to_srgb*//*srgb_to_linear*/(f_col_light.rgb);
|
||||
// vec3 f_col = vec3(1.0);
|
||||
// vec3 f_col = vec3(1.0);
|
||||
// vec2 texSize = textureSize(t_col_light, 0);
|
||||
float f_ao = texture(t_col_light, (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_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;
|
||||
@ -94,8 +94,8 @@ void main() {
|
||||
// vec3 my_chunk_pos = (vec3((uvec3(f_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0;
|
||||
// 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);
|
||||
// float f_ao = 0;
|
||||
// tgt_color = vec4(vec3(f_ao), 1.0);
|
||||
// tgt_color = vec4(f_col, 1.0);
|
||||
// tgt_color = vec4(vec3(f_ao), 1.0);
|
||||
// tgt_color = vec4(f_col, 1.0);
|
||||
// return;
|
||||
|
||||
// vec3 du = dFdx(f_pos);
|
||||
@ -120,7 +120,7 @@ void main() {
|
||||
/* vec3 sun_dir = get_sun_dir(time_of_day.x);
|
||||
vec3 moon_dir = get_moon_dir(time_of_day.x); */
|
||||
// float sun_light = get_sun_brightness(sun_dir);
|
||||
// float moon_light = get_moon_brightness(moon_dir);
|
||||
// float moon_light = get_moon_brightness(moon_dir);
|
||||
/* float sun_shade_frac = horizon_at(f_pos, sun_dir);
|
||||
float moon_shade_frac = horizon_at(f_pos, moon_dir); */
|
||||
#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP || FLUID_MODE == FLUID_MODE_SHINY)
|
||||
@ -149,7 +149,7 @@ void main() {
|
||||
DirectionalLight sun_info = get_sun_info(sun_dir, point_shadow * sun_shade_frac, /*sun_pos*/f_pos);
|
||||
DirectionalLight moon_info = get_moon_info(moon_dir, point_shadow * moon_shade_frac/*, light_pos*/);
|
||||
|
||||
vec3 surf_color = /*srgb_to_linear*/f_col;
|
||||
vec3 surf_color = /*srgb_to_linear*/f_col;
|
||||
float alpha = 1.0;
|
||||
const float n2 = 1.5;
|
||||
const float R_s2s0 = pow((1.0 - n2) / (1.0 + n2), 2);
|
||||
@ -165,8 +165,8 @@ void main() {
|
||||
vec3 emitted_light, reflected_light;
|
||||
|
||||
// vec3 light_frac = /*vec3(1.0);*//*vec3(max(dot(f_norm, -sun_dir) * 0.5 + 0.5, 0.0));*/light_reflection_factor(f_norm, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha);
|
||||
// vec3 point_light = light_at(f_pos, f_norm);
|
||||
// vec3 light, diffuse_light, ambient_light;
|
||||
// vec3 point_light = light_at(f_pos, f_norm);
|
||||
// vec3 light, diffuse_light, ambient_light;
|
||||
//get_sun_diffuse(f_norm, time_of_day.x, view_dir, k_a * point_shadow * (shade_frac * 0.5 + light_frac * 0.5), k_d * point_shadow * shade_frac, k_s * point_shadow * shade_frac, alpha, emitted_light, reflected_light);
|
||||
float max_light = 0.0;
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, k_d, k_s, alpha, emitted_light, reflected_light);
|
||||
@ -179,44 +179,36 @@ void main() {
|
||||
|
||||
max_light += lights_at(f_pos, f_norm, view_dir, k_a, k_d, k_s, alpha, emitted_light, reflected_light);
|
||||
|
||||
float ao = f_ao * sqrt(f_ao);//0.25 + f_ao * 0.75; ///*pow(f_ao, 0.5)*/f_ao * 0.85 + 0.15;
|
||||
float ao = f_ao * sqrt(f_ao);//0.25 + f_ao * 0.75; ///*pow(f_ao, 0.5)*/f_ao * 0.85 + 0.15;
|
||||
|
||||
reflected_light *= ao;
|
||||
emitted_light *= ao;
|
||||
reflected_light *= ao;
|
||||
emitted_light *= ao;
|
||||
/* reflected_light *= cloud_shadow(f_pos); */
|
||||
/* vec3 point_light = light_at(f_pos, f_norm);
|
||||
emitted_light += point_light;
|
||||
reflected_light += point_light; */
|
||||
// get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, surf_color * f_light * point_shadow, 0.5 * surf_color * f_light * point_shadow, 0.5 * surf_color * f_light * point_shadow, 2.0, emitted_light, reflected_light);
|
||||
|
||||
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||
// diffuse_light *= point_shadow;
|
||||
// ambient_light *= point_shadow;
|
||||
// vec3 point_light = light_at(f_pos, f_norm);
|
||||
// light += point_light;
|
||||
// diffuse_light += point_light;
|
||||
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||
// diffuse_light *= point_shadow;
|
||||
// ambient_light *= point_shadow;
|
||||
// vec3 point_light = light_at(f_pos, f_norm);
|
||||
// light += point_light;
|
||||
// diffuse_light += point_light;
|
||||
// reflected_light += point_light;
|
||||
// vec3 surf_color = illuminate(srgb_to_linear(highlight_col.rgb * f_col), light, diffuse_light, ambient_light);
|
||||
surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light) * highlight_col.rgb;
|
||||
// vec3 surf_color = illuminate(srgb_to_linear(highlight_col.rgb * f_col), light, diffuse_light, ambient_light);
|
||||
surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light) * highlight_col.rgb;
|
||||
|
||||
#if (CLOUD_MODE == CLOUD_MODE_REGULAR)
|
||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||
vec4 clouds;
|
||||
vec3 fog_color = get_sky_color(cam_to_frag/*view_dir*/, time_of_day.x, cam_pos.xyz, f_pos, 0.5, false, clouds);
|
||||
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
vec3 color = surf_color;
|
||||
#endif
|
||||
// if ((flags & 1) == 1 && int(cam_mode) == 1) {
|
||||
// float distance = distance(vec3(cam_pos), focus_pos.xyz) - 2;
|
||||
|
||||
// if ((flags & 1) == 1 && int(cam_mode) == 1) {
|
||||
// float distance = distance(vec3(cam_pos), focus_pos.xyz) - 2;
|
||||
// float opacity = clamp(distance / distance_divider, 0, 1);
|
||||
|
||||
// float opacity = clamp(distance / distance_divider, 0, 1);
|
||||
|
||||
// // if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > opacity) {
|
||||
// // if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > opacity) {
|
||||
// // discard;
|
||||
// // return;
|
||||
// // }
|
||||
// }
|
||||
// // }
|
||||
// }
|
||||
|
||||
tgt_color = vec4(color, 1.0);
|
||||
tgt_color = vec4(surf_color, 1.0);
|
||||
}
|
||||
|
@ -25,28 +25,28 @@ in uint v_ao_bone; */
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
mat4 model_mat;
|
||||
vec4 highlight_col;
|
||||
mat4 model_mat;
|
||||
vec4 highlight_col;
|
||||
ivec4 atlas_offs;
|
||||
vec3 model_pos;
|
||||
// bit 0 - is player
|
||||
// bit 1-31 - unused
|
||||
int flags;
|
||||
// bit 0 - is player
|
||||
// bit 1-31 - unused
|
||||
int flags;
|
||||
};
|
||||
|
||||
struct BoneData {
|
||||
mat4 bone_mat;
|
||||
mat4 bone_mat;
|
||||
mat4 normals_mat;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_bones {
|
||||
// Warning: might not actually be 16 elements long. Don't index out of bounds!
|
||||
BoneData bones[16];
|
||||
// Warning: might not actually be 16 elements long. Don't index out of bounds!
|
||||
BoneData bones[16];
|
||||
};
|
||||
|
||||
//struct ShadowLocals {
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 texture_mat;
|
||||
//};
|
||||
//
|
||||
@ -70,39 +70,39 @@ flat out vec3 f_norm;
|
||||
// #endif
|
||||
|
||||
void main() {
|
||||
// Pre-calculate bone matrix
|
||||
/* uint bone_idx = (v_ao_bone >> 2) & 0x3Fu; */
|
||||
uint bone_idx = (v_pos_norm >> 27) & 0xFu;
|
||||
// Pre-calculate bone matrix
|
||||
/* uint bone_idx = (v_ao_bone >> 2) & 0x3Fu; */
|
||||
uint bone_idx = (v_pos_norm >> 27) & 0xFu;
|
||||
|
||||
mat4 bone_mat = bones[bone_idx].bone_mat;
|
||||
mat4 normals_mat = bones[bone_idx].normals_mat;
|
||||
mat4 combined_mat = /*model_mat * */bone_mat;
|
||||
mat4 bone_mat = bones[bone_idx].bone_mat;
|
||||
mat4 normals_mat = bones[bone_idx].normals_mat;
|
||||
mat4 combined_mat = /*model_mat * */bone_mat;
|
||||
|
||||
vec3 pos = (vec3((uvec3(v_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0;
|
||||
vec3 pos = (vec3((uvec3(v_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0;
|
||||
|
||||
// vec4 bone_pos = bones[bone_idx].bone_mat * vec4(pos, 1);
|
||||
|
||||
f_pos = (
|
||||
f_pos = (
|
||||
combined_mat *
|
||||
vec4(pos, 1.0)
|
||||
).xyz + (model_pos - focus_off.xyz);
|
||||
|
||||
/* 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_col = srgb_to_linear(vec3((uvec3(v_col) >> uvec3(0, 8, 16)) & uvec3(0xFFu)) / 255.0);
|
||||
// f_col = vec3(1.0);
|
||||
// f_col = srgb_to_linear(vec3((uvec3(v_col) >> uvec3(0, 8, 16)) & uvec3(0xFFu)) / 255.0);
|
||||
// f_col = vec3(1.0);
|
||||
|
||||
// f_ao = float(v_ao_bone & 0x3u) / 4.0;
|
||||
// f_ao = float(v_ao_bone & 0x3u) / 4.0;
|
||||
// f_ao = 1.0;
|
||||
/* for (uint i = 0u; i < light_shadow_count.z; ++i) {
|
||||
light_pos[i] = vec3(shadowMats[i].texture_mat * vec4(f_pos, 1.0));
|
||||
} */
|
||||
|
||||
// First 3 normals are negative, next 3 are positive
|
||||
// First 3 normals are negative, next 3 are positive
|
||||
// uint normal_idx = ((v_atlas_pos & 3u) << 1u) | (v_pos_norm >> 31u);
|
||||
// const vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1));
|
||||
// const vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1));
|
||||
// vec3 norm = normals[normal_idx];
|
||||
uint axis_idx = v_atlas_pos & 3u;
|
||||
|
||||
@ -110,11 +110,11 @@ void main() {
|
||||
// norm = normalize(norm);
|
||||
// vec3 norm = norm_mat * vec4(uvec3(1 << axis_idx) & uvec3(0x1u, 0x3u, 0x7u), 1);
|
||||
|
||||
// // Calculate normal here rather than for each pixel in the fragment shader
|
||||
// f_norm = normalize((
|
||||
// combined_mat *
|
||||
// // Calculate normal here rather than for each pixel in the fragment shader
|
||||
// f_norm = normalize((
|
||||
// combined_mat *
|
||||
// vec4(norm, 0)
|
||||
// ).xyz);
|
||||
// ).xyz);
|
||||
f_norm = mix(-norm, norm, v_pos_norm >> 31u);
|
||||
|
||||
// #if (SHADOW_MODE == SHADOW_MODE_MAP)
|
||||
@ -132,10 +132,10 @@ void main() {
|
||||
// f_alt = alt_at(f_pos.xy);
|
||||
// f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
|
||||
|
||||
gl_Position = all_mat/*shadowMats[0].shadowMatrices*/ * vec4(f_pos, 1);
|
||||
gl_Position = all_mat/*shadowMats[0].shadowMatrices*/ * vec4(f_pos, 1);
|
||||
// gl_Position.z = -gl_Position.z / 100.0 / gl_Position.w;
|
||||
// gl_Position.z = -gl_Position.z / 100.0;
|
||||
// gl_Position.z = gl_Position.z / 100.0;
|
||||
// gl_Position.z = -gl_Position.z;
|
||||
// gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
|
||||
// gl_Position.z = -gl_Position.z / 100.0;
|
||||
// gl_Position.z = gl_Position.z / 100.0;
|
||||
// gl_Position.z = -gl_Position.z;
|
||||
// gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
|
||||
}
|
||||
|
@ -186,13 +186,5 @@ void main() {
|
||||
// vec4 color = vec4(surf_color, passthrough * 1.0 / (1.0 + min_refl));// * (1.0 - /*log(1.0 + cam_attenuation)*//*cam_attenuation*/1.0 / (2.0 - log_cam)));
|
||||
vec4 color = mix(vec4(surf_color, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*//*(f_light * point_shadow + point_light)*//*4.0 * reflected_light_point*/min_refl/* * 0.25*/)), passthrough);
|
||||
|
||||
#if (CLOUD_MODE == CLOUD_MODE_REGULAR)
|
||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||
vec4 clouds;
|
||||
vec3 fog_color = get_sky_color(cam_to_frag, time_of_day.x, cam_pos.xyz, f_pos, 0.25, false, clouds);
|
||||
vec4 final_color = mix(mix(color, vec4(fog_color, 0.0), fog_level), vec4(clouds.rgb, 0.0), clouds.a);
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
vec4 final_color = color;
|
||||
#endif
|
||||
tgt_color = final_color;
|
||||
tgt_color = color;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ flat in uint f_pos_norm;
|
||||
// in vec3 light_pos[2];
|
||||
|
||||
//struct ShadowLocals {
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 texture_mat;
|
||||
//};
|
||||
//
|
||||
@ -41,8 +41,8 @@ flat in uint f_pos_norm;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec3 model_offs;
|
||||
float load_time;
|
||||
vec3 model_offs;
|
||||
float load_time;
|
||||
ivec4 atlas_offs;
|
||||
};
|
||||
|
||||
@ -50,56 +50,56 @@ uniform sampler2D t_waves;
|
||||
|
||||
out vec4 tgt_color;
|
||||
|
||||
#include <sky.glsl>
|
||||
#include <cloud.glsl>
|
||||
#include <light.glsl>
|
||||
#include <lod.glsl>
|
||||
|
||||
vec3 warp_normal(vec3 norm, vec3 pos, float time) {
|
||||
return normalize(norm
|
||||
+ smooth_rand(pos * 1.0, time * 1.0) * 0.05
|
||||
+ smooth_rand(pos * 0.25, time * 0.25) * 0.1);
|
||||
return normalize(norm
|
||||
+ smooth_rand(pos * 1.0, time * 1.0) * 0.05
|
||||
+ smooth_rand(pos * 0.25, time * 0.25) * 0.1);
|
||||
}
|
||||
|
||||
float wave_height(vec3 pos) {
|
||||
float timer = tick.x * 0.75;
|
||||
float timer = tick.x * 0.75;
|
||||
|
||||
pos *= 0.5;
|
||||
vec3 big_warp = (
|
||||
texture(t_waves, fract(pos.xy * 0.03 + timer * 0.01)).xyz * 0.5 +
|
||||
texture(t_waves, fract(pos.yx * 0.03 - timer * 0.01)).xyz * 0.5 +
|
||||
vec3(0)
|
||||
);
|
||||
pos *= 0.5;
|
||||
vec3 big_warp = (
|
||||
texture(t_waves, fract(pos.xy * 0.03 + timer * 0.01)).xyz * 0.5 +
|
||||
texture(t_waves, 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 +
|
||||
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 +
|
||||
vec3(0)
|
||||
);
|
||||
|
||||
float height = (
|
||||
(texture(t_noise, pos.xy * 0.03 + big_warp.xy + timer * 0.05).y - 0.5) * 1.0 +
|
||||
(texture(t_noise, pos.yx * 0.03 + big_warp.yx - timer * 0.05).y - 0.5) * 1.0 +
|
||||
(texture(t_waves, pos.xy * 0.1 + warp.xy + timer * 0.1).x - 0.5) * 0.5 +
|
||||
(texture(t_waves, pos.yx * 0.1 + warp.yx - timer * 0.1).x - 0.5) * 0.5 +
|
||||
(texture(t_noise, pos.yx * 0.3 + warp.xy * 0.5 + timer * 0.1).x - 0.5) * 0.2 +
|
||||
(texture(t_noise, pos.yx * 0.3 + warp.yx * 0.5 - timer * 0.1).x - 0.5) * 0.2 +
|
||||
(texture(t_noise, pos.yx * 1.0 + warp.yx * 0.0 - timer * 0.1).x - 0.5) * 0.05 +
|
||||
0.0
|
||||
);
|
||||
float height = (
|
||||
(texture(t_noise, pos.xy * 0.03 + big_warp.xy + timer * 0.05).y - 0.5) * 1.0 +
|
||||
(texture(t_noise, pos.yx * 0.03 + big_warp.yx - timer * 0.05).y - 0.5) * 1.0 +
|
||||
(texture(t_waves, pos.xy * 0.1 + warp.xy + timer * 0.1).x - 0.5) * 0.5 +
|
||||
(texture(t_waves, pos.yx * 0.1 + warp.yx - timer * 0.1).x - 0.5) * 0.5 +
|
||||
(texture(t_noise, pos.yx * 0.3 + warp.xy * 0.5 + timer * 0.1).x - 0.5) * 0.2 +
|
||||
(texture(t_noise, pos.yx * 0.3 + warp.yx * 0.5 - timer * 0.1).x - 0.5) * 0.2 +
|
||||
(texture(t_noise, pos.yx * 1.0 + warp.yx * 0.0 - timer * 0.1).x - 0.5) * 0.05 +
|
||||
0.0
|
||||
);
|
||||
|
||||
return pow(abs(height), 0.5) * sign(height) * 10.5;
|
||||
return pow(abs(height), 0.5) * sign(height) * 15.0;
|
||||
}
|
||||
|
||||
void main() {
|
||||
// First 3 normals are negative, next 3 are positive
|
||||
vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1));
|
||||
// First 3 normals are negative, next 3 are positive
|
||||
vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1));
|
||||
|
||||
// TODO: last 3 bits in v_pos_norm should be a number between 0 and 5, rather than 0-2 and a direction.
|
||||
uint norm_axis = (f_pos_norm >> 30) & 0x3u;
|
||||
// Increase array access by 3 to access positive values
|
||||
uint norm_dir = ((f_pos_norm >> 29) & 0x1u) * 3u;
|
||||
// Use an array to avoid conditional branching
|
||||
vec3 f_norm = normals[norm_axis + norm_dir];
|
||||
// TODO: last 3 bits in v_pos_norm should be a number between 0 and 5, rather than 0-2 and a direction.
|
||||
uint norm_axis = (f_pos_norm >> 30) & 0x3u;
|
||||
// Increase array access by 3 to access positive values
|
||||
uint norm_dir = ((f_pos_norm >> 29) & 0x1u) * 3u;
|
||||
// Use an array to avoid conditional branching
|
||||
vec3 f_norm = normals[norm_axis + norm_dir];
|
||||
|
||||
// vec4 light_pos[2];
|
||||
//#if (SHADOW_MODE == SHADOW_MODE_MAP)
|
||||
@ -111,41 +111,41 @@ void main() {
|
||||
// vec4 sun_pos = vec4(0.0);
|
||||
//#endif
|
||||
|
||||
vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||
vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||
// vec4 vert_pos4 = view_mat * vec4(f_pos, 1.0);
|
||||
// vec3 view_dir = normalize(-vec3(vert_pos4)/* / vert_pos4.w*/);
|
||||
vec3 view_dir = -cam_to_frag;
|
||||
float frag_dist = length(f_pos - cam_pos.xyz);
|
||||
float frag_dist = length(f_pos - cam_pos.xyz);
|
||||
|
||||
vec3 b_norm;
|
||||
if (f_norm.z > 0.0) {
|
||||
b_norm = vec3(1, 0, 0);
|
||||
} else if (f_norm.x > 0.0) {
|
||||
b_norm = vec3(0, 1, 0);
|
||||
} else {
|
||||
b_norm = vec3(0, 0, 1);
|
||||
}
|
||||
vec3 c_norm = cross(f_norm, b_norm);
|
||||
vec3 b_norm;
|
||||
if (f_norm.z > 0.0) {
|
||||
b_norm = vec3(1, 0, 0);
|
||||
} else if (f_norm.x > 0.0) {
|
||||
b_norm = vec3(0, 1, 0);
|
||||
} else {
|
||||
b_norm = vec3(0, 0, 1);
|
||||
}
|
||||
vec3 c_norm = cross(f_norm, b_norm);
|
||||
|
||||
vec3 wave_pos = f_pos + focus_off.xyz;
|
||||
float wave00 = wave_height(wave_pos);
|
||||
float wave10 = wave_height(wave_pos + vec3(0.1, 0, 0));
|
||||
float wave01 = wave_height(wave_pos + vec3(0, 0.1, 0));
|
||||
float wave00 = wave_height(wave_pos);
|
||||
float wave10 = wave_height(wave_pos + vec3(0.1, 0, 0));
|
||||
float wave01 = wave_height(wave_pos + vec3(0, 0.1, 0));
|
||||
|
||||
// Possibility of div by zero when slope = 0,
|
||||
// however this only results in no water surface appearing
|
||||
// and is not likely to occur (could not find any occurrences)
|
||||
float slope = abs(wave00 - wave10) * abs(wave00 - wave01);
|
||||
|
||||
vec3 nmap = vec3(
|
||||
-(wave10 - wave00) / 0.1,
|
||||
-(wave01 - wave00) / 0.1,
|
||||
0.1 / slope
|
||||
);
|
||||
vec3 nmap = vec3(
|
||||
-(wave10 - wave00) / 0.1,
|
||||
-(wave01 - wave00) / 0.1,
|
||||
0.1 / slope
|
||||
);
|
||||
|
||||
nmap = mix(f_norm, normalize(nmap), min(1.0 / pow(frag_dist, 0.75), 1));
|
||||
nmap = mix(f_norm, normalize(nmap), min(1.0 / pow(frag_dist, 0.75), 1));
|
||||
|
||||
vec3 norm = vec3(0, 0, 1) * nmap.z + b_norm * nmap.x + c_norm * nmap.y;
|
||||
vec3 norm = vec3(0, 0, 1) * nmap.z + b_norm * nmap.x + c_norm * nmap.y;
|
||||
// vec3 norm = f_norm;
|
||||
|
||||
vec3 water_color = (1.0 - MU_WATER) * MU_SCATTER;
|
||||
@ -166,18 +166,19 @@ void main() {
|
||||
|
||||
// Water is transparent so both normals are valid.
|
||||
vec3 cam_norm = faceforward(norm, norm, cam_to_frag);
|
||||
vec4 _clouds;
|
||||
vec3 reflect_ray_dir = reflect(cam_to_frag/*-view_dir*/, norm);
|
||||
vec3 refract_ray_dir = refract(cam_to_frag/*-view_dir*/, norm, 1.0 / n2);
|
||||
vec3 reflect_ray_dir = reflect(cam_to_frag/*-view_dir*/, norm);
|
||||
vec3 refract_ray_dir = refract(cam_to_frag/*-view_dir*/, norm, 1.0 / n2);
|
||||
vec3 sun_view_dir = view_dir;///*sign(cam_pos.z - fluid_alt) * view_dir;*/cam_pos.z <= fluid_alt ? -view_dir : view_dir;
|
||||
// vec3 sun_view_dir = cam_pos.z <= fluid_alt ? -view_dir : view_dir;
|
||||
vec3 beam_view_dir = reflect_ray_dir;//cam_pos.z <= fluid_alt ? -refract_ray_dir : reflect_ray_dir;
|
||||
/* vec4 reflect_ray_dir4 = view_mat * vec4(reflect_ray_dir, 1.0);
|
||||
reflect_ray_dir = normalize(vec3(reflect_ray_dir4) / reflect_ray_dir4.w); */
|
||||
// vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||
// vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||
// Squared to account for prior saturation.
|
||||
float f_light = 1.0;// pow(f_light, 1.5);
|
||||
vec3 reflect_color = get_sky_color(/*reflect_ray_dir*/beam_view_dir, time_of_day.x, f_pos, vec3(-100000), 0.25, true, _clouds) * f_light;
|
||||
vec3 reflect_color = get_sky_color(/*reflect_ray_dir*/beam_view_dir, time_of_day.x, f_pos, vec3(-100000), 0.25, true);
|
||||
reflect_color = get_cloud_color(reflect_color, reflect_ray_dir, cam_pos.xyz, time_of_day.x, 100000.0, 1.0);
|
||||
reflect_color *= f_light;
|
||||
// /*const */vec3 water_color = srgb_to_linear(vec3(0.2, 0.5, 1.0));
|
||||
// /*const */vec3 water_color = srgb_to_linear(vec3(0.8, 0.9, 1.0));
|
||||
// NOTE: Linear RGB, attenuation coefficients for water at roughly R, G, B wavelengths.
|
||||
@ -245,14 +246,15 @@ void main() {
|
||||
vec3 k_d = vec3(/*vec3(0.2, 0.9, 0.99)*/1.0);
|
||||
vec3 k_s = vec3(R_s);//2.0 * reflect_color;
|
||||
|
||||
vec3 emitted_light, reflected_light;
|
||||
// vec3 light, diffuse_light, ambient_light;
|
||||
vec3 emitted_light, reflected_light;
|
||||
// vec3 light, diffuse_light, ambient_light;
|
||||
// vec3 light_frac = /*vec3(1.0);*/light_reflection_factor(f_norm/*vec3(0, 0, 1.0)*/, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha);
|
||||
// 0 = 100% reflection, 1 = translucent water
|
||||
float passthrough = /*pow(*/dot(faceforward(norm, norm, cam_to_frag/*view_dir*/), -cam_to_frag/*view_dir*/)/*, 0.5)*/;
|
||||
|
||||
float max_light = 0.0;
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, norm, /*time_of_day.x*/sun_view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, vec3(k_d), /*vec3(f_light * point_shadow)*//*reflect_color*/k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
|
||||
// Apply cloud layer to sky
|
||||
// reflected_light *= /*water_color_direct * */reflect_color * f_light * point_shadow * shade_frac;
|
||||
// emitted_light *= /*water_color_direct*//*ambient_attenuation * */f_light * point_shadow * max(shade_frac, MIN_SHADOW);
|
||||
// max_light *= f_light * point_shadow * shade_frac;
|
||||
@ -275,18 +277,18 @@ void main() {
|
||||
// TODO: See if we can be smarter about this using point light distances.
|
||||
// reflected_light += k_d * (diffuse_light_point/* + f_light * point_shadow * shade_frac*/) + /*water_color_ambient*/specular_light_point;
|
||||
|
||||
/* vec3 point_light = light_at(f_pos, norm);
|
||||
/* vec3 point_light = light_at(f_pos, norm);
|
||||
emitted_light += point_light;
|
||||
reflected_light += point_light; */
|
||||
|
||||
// get_sun_diffuse(norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0);
|
||||
// diffuse_light *= f_light * point_shadow;
|
||||
// ambient_light *= f_light * point_shadow;
|
||||
// vec3 point_light = light_at(f_pos, norm);
|
||||
// light += point_light;
|
||||
// diffuse_light += point_light;
|
||||
// get_sun_diffuse(norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0);
|
||||
// diffuse_light *= f_light * point_shadow;
|
||||
// ambient_light *= f_light * point_shadow;
|
||||
// vec3 point_light = light_at(f_pos, norm);
|
||||
// light += point_light;
|
||||
// diffuse_light += point_light;
|
||||
// reflected_light += point_light;
|
||||
// vec3 surf_color = srgb_to_linear(vec3(0.2, 0.5, 1.0)) * light * diffuse_light * ambient_light;
|
||||
// vec3 surf_color = srgb_to_linear(vec3(0.2, 0.5, 1.0)) * light * diffuse_light * ambient_light;
|
||||
vec3 surf_color = illuminate(max_light, view_dir, water_color * emitted_light/* * log(1.0 - MU_WATER)*/, /*cam_attenuation * *//*water_color * */reflect_color * reflected_light/* * log(1.0 - MU_WATER)*/);
|
||||
|
||||
// passthrough = pow(passthrough, 1.0 / (1.0 + water_depth_to_camera));
|
||||
@ -296,20 +298,20 @@ void main() {
|
||||
; */
|
||||
// passthrough = passthrough * length(cam_attenuation);
|
||||
|
||||
// vec3 reflect_ray_dir = reflect(cam_to_frag, norm);
|
||||
// Hack to prevent the reflection ray dipping below the horizon and creating weird blue spots in the water
|
||||
// reflect_ray_dir.z = max(reflect_ray_dir.z, 0.01);
|
||||
// vec3 reflect_ray_dir = reflect(cam_to_frag, norm);
|
||||
// Hack to prevent the reflection ray dipping below the horizon and creating weird blue spots in the water
|
||||
// reflect_ray_dir.z = max(reflect_ray_dir.z, 0.01);
|
||||
|
||||
// vec4 _clouds;
|
||||
// vec3 reflect_color = get_sky_color(reflect_ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.25, false, _clouds) * f_light;
|
||||
// Tint
|
||||
// reflect_color = mix(reflect_color, surf_color, 0.6);
|
||||
// vec4 _clouds;
|
||||
// vec3 reflect_color = get_sky_color(reflect_ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.25, false, _clouds) * f_light;
|
||||
// Tint
|
||||
// reflect_color = mix(reflect_color, surf_color, 0.6);
|
||||
|
||||
// vec4 color = mix(vec4(reflect_color * 2.0, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(f_light * point_shadow + point_light) * 0.25)), passthrough);
|
||||
// vec4 color = mix(vec4(reflect_color * 2.0, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(/*f_light * point_shadow*/f_light * point_shadow + reflected_light_point/* + point_light*//*reflected_light*/) * 0.25)), passthrough);
|
||||
// vec4 color = mix(vec4(reflect_color * 2.0, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(f_light * point_shadow + point_light) * 0.25)), passthrough);
|
||||
// vec4 color = mix(vec4(reflect_color * 2.0, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(/*f_light * point_shadow*/f_light * point_shadow + reflected_light_point/* + point_light*//*reflected_light*/) * 0.25)), passthrough);
|
||||
// vec4 color = mix(vec4(surf_color, 1.0), vec4(surf_color, 0.0), passthrough);
|
||||
//vec4 color = vec4(surf_color, 1.0);
|
||||
// vec4 color = mix(vec4(reflect_color, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(/*f_light * point_shadow*/reflected_light_point/* + point_light*//*reflected_light*/))), passthrough);
|
||||
// vec4 color = mix(vec4(reflect_color, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(/*f_light * point_shadow*/reflected_light_point/* + point_light*//*reflected_light*/))), passthrough);
|
||||
|
||||
// float log_cam = log(min(cam_attenuation.r, min(cam_attenuation.g, cam_attenuation.b)));
|
||||
float min_refl = min(emitted_light.r, min(emitted_light.g, emitted_light.b));
|
||||
@ -317,19 +319,11 @@ void main() {
|
||||
// vec4 color = vec4(surf_color, mix(1.0, 1.0 / (1.0 + /*0.25 * *//*diffuse_light*/(/*f_light * point_shadow*/reflected_light_point)), passthrough));
|
||||
// vec4 color = vec4(surf_color, mix(1.0, length(cam_attenuation), passthrough));
|
||||
|
||||
/* reflect_color = reflect_color * 0.5 * (diffuse_light + ambient_light);
|
||||
// 0 = 100% reflection, 1 = translucent water
|
||||
float passthrough = dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag);
|
||||
/* reflect_color = reflect_color * 0.5 * (diffuse_light + ambient_light);
|
||||
// 0 = 100% reflection, 1 = translucent water
|
||||
float passthrough = dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag);
|
||||
|
||||
vec4 color = mix(vec4(reflect_color, 1.0), vec4(vec3(0), 1.0 / (1.0 + diffuse_light * 0.25)), passthrough); */
|
||||
vec4 color = mix(vec4(reflect_color, 1.0), vec4(vec3(0), 1.0 / (1.0 + diffuse_light * 0.25)), passthrough); */
|
||||
|
||||
#if (CLOUD_MODE == CLOUD_MODE_REGULAR)
|
||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||
vec4 clouds;
|
||||
vec3 fog_color = get_sky_color(cam_to_frag/*-view_dir*/, time_of_day.x, cam_pos.xyz, f_pos, 0.25, false, clouds);
|
||||
vec4 final_color = mix(mix(color, vec4(fog_color, 0.0), fog_level), vec4(clouds.rgb, 0.0), clouds.a);
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
vec4 final_color = color;
|
||||
#endif
|
||||
tgt_color = final_color;
|
||||
tgt_color = color;
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
vec4 get_cloud_color(vec3 dir, vec3 origin, float time_of_day, float max_dist, float quality) {
|
||||
return vec4(0.0);
|
||||
vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, float time_of_day, float max_dist, float quality) {
|
||||
return surf_color;
|
||||
}
|
||||
|
@ -1,85 +1,152 @@
|
||||
#include <random.glsl>
|
||||
#include <lod.glsl>
|
||||
|
||||
const float CLOUD_THRESHOLD = 0.27;
|
||||
const float CLOUD_SCALE = 5.0;
|
||||
const float CLOUD_DENSITY = 100.0;
|
||||
const float CLOUD_DENSITY = 150.0;
|
||||
|
||||
float vsum(vec3 v) {
|
||||
return v.x + v.y + v.z;
|
||||
vec2 get_cloud_heights(vec2 pos) {
|
||||
const float CLOUD_HALF_WIDTH = 300;
|
||||
const float CLOUD_HEIGHT_VARIATION = 1000.0;
|
||||
float cloud_alt = CLOUD_AVG_ALT + (texture(t_noise, pos.xy * 0.0001).x - 0.5) * CLOUD_HEIGHT_VARIATION;
|
||||
#if (CLOUD_MODE != CLOUD_MODE_MINIMAL)
|
||||
cloud_alt += (texture(t_noise, pos.xy * 0.001).x - 0.5) * 0.1 * CLOUD_HEIGHT_VARIATION;
|
||||
#endif
|
||||
return vec2(cloud_alt, CLOUD_HALF_WIDTH);
|
||||
}
|
||||
|
||||
vec3 get_cloud_heights() {
|
||||
float CLOUD_AVG_HEIGHT = /*1025.0*/view_distance.z + 0.7 * view_distance.w;
|
||||
float CLOUD_HEIGHT_MIN = CLOUD_AVG_HEIGHT - 60.0;
|
||||
float CLOUD_HEIGHT_MAX = CLOUD_AVG_HEIGHT + 60.0;
|
||||
return vec3(CLOUD_AVG_HEIGHT, CLOUD_HEIGHT_MIN, CLOUD_HEIGHT_MAX);
|
||||
// Returns vec4(r, g, b, density)
|
||||
vec3 cloud_at(vec3 pos, float dist) {
|
||||
// Natural attenuation of air (air naturally attenuates light that passes through it)
|
||||
// Simulate the atmosphere thinning above 3000 metres down to nothing at 5000 metres
|
||||
float air = 0.00005 * clamp((3000.0 - pos.z) / 2000, 0, 1);
|
||||
|
||||
// Mist sits close to the ground in valleys (TODO: use base_alt to put it closer to water)
|
||||
float MIST_MIN = 300;
|
||||
const float MIST_FADE_HEIGHT = 250;
|
||||
float mist = 0.00025 * pow(clamp(1.0 - (pos.z - MIST_MIN) / MIST_FADE_HEIGHT, 0.0, 1), 2) / (1.0 + pow(1.0 + dist / 20000.0, 2.0));
|
||||
|
||||
vec3 wind_pos = vec3(pos.xy + wind_offset, pos.z);
|
||||
|
||||
// Clouds
|
||||
float cloud_tendency = cloud_tendency_at(pos.xy);
|
||||
float sun_access = 0.05;
|
||||
float cloud = 0;
|
||||
|
||||
vec2 cloud_attr = get_cloud_heights(wind_pos.xy);
|
||||
float cloud_factor = 0.0;
|
||||
// This is a silly optimisation but it actually nets us a fair few fps by skipping quite a few expensive calcs
|
||||
if (cloud_tendency > 0 || mist > 0.0) {
|
||||
// Turbulence (small variations in clouds/mist)
|
||||
const float turb_speed = -1.0; // Turbulence goes the opposite way
|
||||
vec3 turb_offset = vec3(1, 1, 0) * time_of_day.x * turb_speed;
|
||||
#if (CLOUD_MODE == CLOUD_MODE_MINIMAL)
|
||||
float turb_noise = 0.0;
|
||||
#else
|
||||
float turb_noise = noise_3d((wind_pos + turb_offset) * 0.001) - 0.5;
|
||||
#endif
|
||||
#if (CLOUD_MODE == CLOUD_MODE_MEDIUM || CLOUD_MODE == CLOUD_MODE_HIGH)
|
||||
turb_noise += (noise_3d((wind_pos + turb_offset * 0.3) * 0.004) - 0.5) * 0.25;
|
||||
#endif
|
||||
mist *= (1.0 + turb_noise);
|
||||
|
||||
cloud_factor = 0.25 * (1.0 - pow(min(abs(pos.z - cloud_attr.x) / (cloud_attr.y * pow(max(cloud_tendency * 20.0, 0), 0.5)), 1.0), 2.0));
|
||||
float cloud_flat = min(cloud_tendency, 0.07) * 0.05;
|
||||
cloud_flat *= (1.0 + turb_noise * 7.0 * max(0, 1.0 - cloud_factor * 5));
|
||||
cloud = cloud_flat * pow(cloud_factor, 2) * 20 / (1 + pow(1.0 + dist / 10000.0, 2.0));
|
||||
}
|
||||
|
||||
// What proportion of sunlight is *not* being blocked by nearby cloud? (approximation)
|
||||
sun_access = clamp((pos.z - cloud_attr.x) * 0.002 + 0.35 + mist * 10000, 0.0, 1);
|
||||
|
||||
// Prevent clouds and mist appearing underground (but fade them out gently)
|
||||
float not_underground = clamp(1.0 - (alt_at(pos.xy - focus_off.xy) - (pos.z - focus_off.z)) / 80.0, 0, 1);
|
||||
float vapor_density = (mist + cloud) * not_underground;
|
||||
|
||||
// We track vapor density and air density separately. Why? Because photons will ionize particles in air
|
||||
// leading to rayleigh scattering, but water vapor will not. Tracking these indepedently allows us to
|
||||
// get more correct colours.
|
||||
return vec3(sun_access, vapor_density, air);
|
||||
}
|
||||
|
||||
vec2 cloud_at(vec3 pos) {
|
||||
vec3 max_heights = get_cloud_heights();
|
||||
vec2 scaled_pos = pos.xy / CLOUD_SCALE;
|
||||
|
||||
float tick_offs = 0.0
|
||||
+ texture(t_noise, scaled_pos * 0.0005 - time_of_day.x * 0.00001).x * 0.5
|
||||
+ texture(t_noise, scaled_pos * 0.0015).x * 0.15;
|
||||
|
||||
float value = (
|
||||
0.0
|
||||
+ texture(t_noise, scaled_pos * 0.0003 + tick_offs).x
|
||||
+ texture(t_noise, scaled_pos * 0.0015 - tick_offs * 2.0).x * 0.5
|
||||
) / 3.0;
|
||||
|
||||
value += (0.0
|
||||
+ texture(t_noise, scaled_pos * 0.008 + time_of_day.x * 0.0002).x * 0.25
|
||||
+ texture(t_noise, scaled_pos * 0.02 + tick_offs + time_of_day.x * 0.0002).x * 0.15
|
||||
) * value;
|
||||
|
||||
float density = max((value - CLOUD_THRESHOLD) - abs(pos.z - max_heights.x) / 200.0, 0.0) * CLOUD_DENSITY;
|
||||
|
||||
float SHADE_GRADIENT = 1.5 / (max_heights.x - max_heights.y);
|
||||
float shade = ((pos.z - max_heights.x) / (max_heights.z - max_heights.y)) * 5.0 + 0.3;
|
||||
|
||||
return vec2(shade, density / (1.0 + vsum(abs(pos - cam_pos.xyz)) / 5000));
|
||||
float atan2(in float y, in float x) {
|
||||
bool s = (abs(x) > abs(y));
|
||||
return mix(PI/2.0 - atan(x,y), atan(y,x), s);
|
||||
}
|
||||
|
||||
vec4 get_cloud_color(vec3 dir, vec3 origin, float time_of_day, float max_dist, float quality) {
|
||||
const int ITERS = 12;
|
||||
const float INCR = 1.0 / ITERS;
|
||||
origin = origin + focus_off.xyz;
|
||||
const float DIST_CAP = 50000;
|
||||
#if (CLOUD_MODE == CLOUD_MODE_HIGH)
|
||||
const uint QUALITY = 100u;
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_MEDIUM)
|
||||
const uint QUALITY = 40u;
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_LOW)
|
||||
const uint QUALITY = 20u;
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_MINIMAL)
|
||||
const uint QUALITY = 7u;
|
||||
#endif
|
||||
|
||||
vec3 max_heights = get_cloud_heights();
|
||||
float mind = (max_heights.y - origin.z) / dir.z;
|
||||
float maxd = (max_heights.z - origin.z) / dir.z;
|
||||
const float STEP_SCALE = DIST_CAP / (10.0 * float(QUALITY));
|
||||
|
||||
float start = max(min(mind, maxd), 0.0);
|
||||
float delta = min(abs(mind - maxd), max_dist);
|
||||
|
||||
float fuzz = sin(texture(t_noise, dir.xz * 100000.0 + tick.x).x * 100.0) * INCR * delta * pow(abs(maxd - mind), 0.3) * 2.0;
|
||||
|
||||
float cloud_shade = 1.0;
|
||||
float passthrough = 1.0;
|
||||
if ((mind > 0.0 || maxd > 0.0) && start < max_dist) {
|
||||
float dist = start;
|
||||
for (int i = 0; i < ITERS; i ++) {
|
||||
dist += fuzz * 0.01 * min(pow(dist * 0.005, 2.0), 1.0);
|
||||
|
||||
vec3 pos = origin + dir * min(dist, max_dist);
|
||||
vec2 sample_ = cloud_at(pos);
|
||||
|
||||
float integral = sample_.y * INCR;
|
||||
passthrough *= 1.0 - integral;
|
||||
cloud_shade = mix(cloud_shade, sample_.x, passthrough * integral);
|
||||
dist += INCR * delta;
|
||||
|
||||
if (passthrough < 0.1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float total_density = 1.0 - passthrough / (1.0 + pow(max_dist, 0.5) * 0.0001 + max((0.015 - dir.z) * 0.0001, 0.0) * max_dist);
|
||||
|
||||
total_density = max(total_density - 1.0 / pow(max_dist, 0.25), 0.0); // Hack
|
||||
|
||||
return vec4(vec3(cloud_shade), total_density);
|
||||
float step_to_dist(float step) {
|
||||
return pow(step, 2) * STEP_SCALE;
|
||||
}
|
||||
|
||||
float dist_to_step(float dist) {
|
||||
return pow(dist / STEP_SCALE, 0.5);
|
||||
}
|
||||
|
||||
vec3 get_cloud_color(vec3 surf_color, const vec3 dir, vec3 origin, const float time_of_day, float max_dist, const float quality) {
|
||||
// Limit the marching distance to reduce maximum jumps
|
||||
max_dist = min(max_dist, DIST_CAP);
|
||||
|
||||
origin.xyz += focus_off.xyz;
|
||||
|
||||
float splay = 1.0;
|
||||
// This hack adds a little direction-dependent noise to clouds. It's not correct, but it very cheaply
|
||||
// improves visual quality for low cloud settings
|
||||
#if (CLOUD_MODE == CLOUD_MODE_MINIMAL)
|
||||
splay += (texture(t_noise, vec2(atan2(dir.x, dir.y) * 2 / PI, dir.z) * 1.5 - time_of_day * 0.000025).x - 0.5) * 0.4 / (1.0 + pow(dir.z, 2) * 10);
|
||||
#endif
|
||||
#if (CLOUD_MODE == CLOUD_MODE_MINIMAL || CLOUD_MODE == CLOUD_MODE_LOW)
|
||||
splay += (texture(t_noise, vec2(atan2(dir.x, dir.y) * 2 / PI, dir.z) * 10.0 - time_of_day * 0.00005).x - 0.5) * 0.075 / (1.0 + pow(dir.z, 2) * 10);
|
||||
#endif
|
||||
splay = clamp(splay, 0.5, 1.5);
|
||||
|
||||
// Proportion of sunlight that get scattered back into the camera by clouds
|
||||
float sun_scatter = max(dot(-dir, sun_dir.xyz), 0.5);
|
||||
float moon_scatter = max(dot(-dir, moon_dir.xyz), 0.5);
|
||||
vec3 sky_color = get_sky_color();
|
||||
vec3 directed_scatter =
|
||||
// Sun scatter
|
||||
get_sun_color() * get_sun_brightness() * sun_scatter +
|
||||
// Moon scatter
|
||||
get_moon_color() * get_moon_brightness() * moon_scatter;
|
||||
|
||||
float cdist = max_dist;
|
||||
vec3 last_sample = cloud_at(origin + dir * cdist, cdist);
|
||||
while (cdist > 10) {
|
||||
float ndist = step_to_dist(trunc(dist_to_step(cdist - 10)));
|
||||
vec3 next_sample = cloud_at(origin + dir * ndist * splay, ndist);
|
||||
|
||||
vec3 sample_avg = last_sample;//(last_sample + next_sample) / 2.0;
|
||||
vec2 density_integrals = sample_avg.yz * (cdist - ndist);
|
||||
|
||||
float sun_access = sample_avg.x;
|
||||
float scatter_factor = 1.0 - 1.0 / (1.0 + density_integrals.x);
|
||||
|
||||
surf_color =
|
||||
// Attenuate light passing through the clouds, removing light due to rayleigh scattering (transmission component)
|
||||
surf_color * (1.0 - scatter_factor) - surf_color * density_integrals.y * sky_color +
|
||||
// This is not rayleigh scattering, but it's good enough for our purposes
|
||||
sky_color * density_integrals.y +
|
||||
// Add the directed light light scattered into the camera by the clouds
|
||||
directed_scatter * sun_access * scatter_factor +
|
||||
// Global illumination (uniform scatter from the sky)
|
||||
sky_color * sun_access * scatter_factor;
|
||||
|
||||
cdist = ndist;
|
||||
last_sample = next_sample;
|
||||
}
|
||||
|
||||
return surf_color;
|
||||
}
|
||||
|
@ -10,7 +10,10 @@
|
||||
#define FLUID_MODE_SHINY 1
|
||||
|
||||
#define CLOUD_MODE_NONE 0
|
||||
#define CLOUD_MODE_REGULAR 1
|
||||
#define CLOUD_MODE_MINIMAL 1
|
||||
#define CLOUD_MODE_LOW 2
|
||||
#define CLOUD_MODE_MEDIUM 3
|
||||
#define CLOUD_MODE_HIGH 4
|
||||
|
||||
#define LIGHTING_ALGORITHM_LAMBERTIAN 0
|
||||
#define LIGHTING_ALGORITHM_BLINN_PHONG 1
|
||||
|
@ -1,35 +1,35 @@
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
mat4 all_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_off;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 sun_dir;
|
||||
vec4 moon_dir;
|
||||
vec4 tick;
|
||||
vec4 screen_res;
|
||||
uvec4 light_shadow_count;
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
mat4 all_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_off;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 sun_dir;
|
||||
vec4 moon_dir;
|
||||
vec4 tick;
|
||||
vec4 screen_res;
|
||||
uvec4 light_shadow_count;
|
||||
vec4 shadow_proj_factors;
|
||||
uvec4 medium;
|
||||
ivec4 select_pos;
|
||||
vec4 gamma;
|
||||
float ambiance;
|
||||
// 0 - FirstPerson
|
||||
// 1 - ThirdPerson
|
||||
uint cam_mode;
|
||||
float sprite_render_distance;
|
||||
uvec4 medium;
|
||||
ivec4 select_pos;
|
||||
vec4 gamma;
|
||||
float ambiance;
|
||||
// 0 - FirstPerson
|
||||
// 1 - ThirdPerson
|
||||
uint cam_mode;
|
||||
float sprite_render_distance;
|
||||
};
|
||||
|
||||
// Specifies the pattern used in the player dithering
|
||||
mat4 threshold_matrix = mat4(
|
||||
vec4(1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0),
|
||||
vec4(13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0),
|
||||
vec4(4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0),
|
||||
vec4(16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0)
|
||||
vec4(1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0),
|
||||
vec4(13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0),
|
||||
vec4(4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0),
|
||||
vec4(16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0)
|
||||
);
|
||||
float distance_divider = 2;
|
||||
float shadow_dithering = 0.5;
|
||||
|
@ -2,29 +2,29 @@
|
||||
#include <shadows.glsl>
|
||||
|
||||
struct Light {
|
||||
vec4 light_pos;
|
||||
vec4 light_col;
|
||||
vec4 light_pos;
|
||||
vec4 light_col;
|
||||
// mat4 light_proj;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_lights {
|
||||
Light lights[31];
|
||||
Light lights[31];
|
||||
};
|
||||
|
||||
struct Shadow {
|
||||
vec4 shadow_pos_radius;
|
||||
vec4 shadow_pos_radius;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_shadows {
|
||||
Shadow shadows[24];
|
||||
Shadow shadows[24];
|
||||
};
|
||||
|
||||
float attenuation_strength(vec3 rpos) {
|
||||
// This is not how light attenuation works at all, but it produces visually pleasing and mechanically useful properties
|
||||
float d2 = rpos.x * rpos.x + rpos.y * rpos.y + rpos.z * rpos.z;
|
||||
return max(2.0 / pow(d2 + 10, 0.35) - pow(d2 / 50000.0, 0.8), 0.0);
|
||||
// This is not how light attenuation works at all, but it produces visually pleasing and mechanically useful properties
|
||||
float d2 = rpos.x * rpos.x + rpos.y * rpos.y + rpos.z * rpos.z;
|
||||
return max(2.0 / pow(d2 + 10, 0.35) - pow(d2 / 50000.0, 0.8), 0.0);
|
||||
}
|
||||
|
||||
// // Compute attenuation due to light passing through a substance that fills an area below a horizontal plane
|
||||
@ -59,58 +59,58 @@ float attenuation_strength(vec3 rpos) {
|
||||
// }
|
||||
|
||||
vec3 light_at(vec3 wpos, vec3 wnorm) {
|
||||
const float LIGHT_AMBIANCE = 0.025;
|
||||
const float LIGHT_AMBIANCE = 0.025;
|
||||
|
||||
vec3 light = vec3(0);
|
||||
vec3 light = vec3(0);
|
||||
|
||||
for (uint i = 0u; i < light_shadow_count.x; i ++) {
|
||||
for (uint i = 0u; i < light_shadow_count.x; i ++) {
|
||||
|
||||
// Only access the array once
|
||||
Light L = lights[i];
|
||||
// Only access the array once
|
||||
Light L = lights[i];
|
||||
|
||||
vec3 light_pos = L.light_pos.xyz - focus_off.xyz;
|
||||
vec3 light_pos = L.light_pos.xyz - focus_off.xyz;
|
||||
|
||||
// Pre-calculate difference between light and fragment
|
||||
vec3 difference = light_pos - wpos;
|
||||
// Pre-calculate difference between light and fragment
|
||||
vec3 difference = light_pos - wpos;
|
||||
|
||||
float strength = attenuation_strength(difference);
|
||||
float strength = attenuation_strength(difference);
|
||||
|
||||
// Multiply the vec3 only once
|
||||
vec3 color = srgb_to_linear(L.light_col.rgb) * (strength * L.light_col.a);
|
||||
// Multiply the vec3 only once
|
||||
vec3 color = srgb_to_linear(L.light_col.rgb) * (strength * L.light_col.a);
|
||||
|
||||
light += color * (max(0, max(dot(normalize(difference), wnorm), 0.15)) + LIGHT_AMBIANCE);
|
||||
}
|
||||
return light;
|
||||
light += color * (max(0, max(dot(normalize(difference), wnorm), 0.15)) + LIGHT_AMBIANCE);
|
||||
}
|
||||
return light;
|
||||
}
|
||||
|
||||
float shadow_at(vec3 wpos, vec3 wnorm) {
|
||||
float shadow = 1.0;
|
||||
float shadow = 1.0;
|
||||
|
||||
#if (SHADOW_MODE == SHADOW_MODE_NONE || SHADOW_MODE == SHADOW_MODE_MAP)
|
||||
return shadow;
|
||||
#elif (SHADOW_MODE == SHADOW_MODE_CHEAP)
|
||||
for (uint i = 0u; i < light_shadow_count.y; i ++) {
|
||||
for (uint i = 0u; i < light_shadow_count.y; i ++) {
|
||||
|
||||
// Only access the array once
|
||||
Shadow S = shadows[i];
|
||||
// Only access the array once
|
||||
Shadow S = shadows[i];
|
||||
|
||||
vec3 shadow_pos = S.shadow_pos_radius.xyz - focus_off.xyz;
|
||||
float radius = S.shadow_pos_radius.w;
|
||||
vec3 shadow_pos = S.shadow_pos_radius.xyz - focus_off.xyz;
|
||||
float radius = S.shadow_pos_radius.w;
|
||||
|
||||
vec3 diff = shadow_pos - wpos;
|
||||
if (diff.z >= 0.0) {
|
||||
diff.z = -sign(diff.z) * diff.z * 0.1;
|
||||
}
|
||||
vec3 diff = shadow_pos - wpos;
|
||||
if (diff.z >= 0.0) {
|
||||
diff.z = -sign(diff.z) * diff.z * 0.1;
|
||||
}
|
||||
|
||||
float shade = max(pow(diff.x * diff.x + diff.y * diff.y + diff.z * diff.z, 0.25) / pow(radius * radius * 0.5, 0.25), 0.5);
|
||||
// float shade = max(pow(dot(diff, diff) / (radius * radius * 0.5), 0.25), 0.5);
|
||||
float shade = max(pow(diff.x * diff.x + diff.y * diff.y + diff.z * diff.z, 0.25) / pow(radius * radius * 0.5, 0.25), 0.5);
|
||||
// float shade = max(pow(dot(diff, diff) / (radius * radius * 0.5), 0.25), 0.5);
|
||||
// float shade = dot(diff, diff) / (radius * radius * 0.5);
|
||||
|
||||
shadow = min(shadow, shade);
|
||||
}
|
||||
shadow = min(shadow, shade);
|
||||
}
|
||||
// NOTE: Squared to compenate for prior saturation.
|
||||
return min(shadow, 1.0);
|
||||
// return min(shadow * shadow, 1.0);
|
||||
return min(shadow, 1.0);
|
||||
// return min(shadow * shadow, 1.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -121,48 +121,48 @@ float shadow_at(vec3 wpos, vec3 wnorm) {
|
||||
// surface_alt is the altitude of the attenuating surface.
|
||||
float lights_at(vec3 wpos, vec3 wnorm, vec3 /*cam_to_frag*/view_dir, vec3 mu, vec3 cam_attenuation, float surface_alt, vec3 k_a, vec3 k_d, vec3 k_s, float alpha, vec3 voxel_norm, float voxel_lighting, inout vec3 emitted_light, inout vec3 reflected_light/*, out float shadow*/) {
|
||||
// return 0.0;
|
||||
// shadow = 0.0;
|
||||
// shadow = 0.0;
|
||||
// vec3 ambient_light = vec3(0.0);
|
||||
vec3 directed_light = vec3(0.0);
|
||||
vec3 max_light = vec3(0.0);
|
||||
|
||||
const float LIGHT_AMBIANCE = 0.0;//0.015625;
|
||||
const float LIGHT_AMBIANCE = 0.0;//0.015625;
|
||||
|
||||
for (uint i = 0u; i < /*light_shadow_count.x*//*0u*/light_shadow_count.x/*32u*/; i ++) {
|
||||
for (uint i = 0u; i < /*light_shadow_count.x*//*0u*/light_shadow_count.x/*32u*/; i ++) {
|
||||
|
||||
// Only access the array once
|
||||
Light L = lights[i];
|
||||
// Only access the array once
|
||||
Light L = lights[i];
|
||||
|
||||
vec3 light_pos = L.light_pos.xyz - focus_off.xyz;
|
||||
vec3 light_pos = L.light_pos.xyz - focus_off.xyz;
|
||||
|
||||
// Pre-calculate difference between light and fragment
|
||||
vec3 difference = light_pos - wpos;
|
||||
// Pre-calculate difference between light and fragment
|
||||
vec3 difference = light_pos - wpos;
|
||||
float distance_2 = dot(difference, difference);
|
||||
|
||||
// float strength = attenuation_strength(difference);// pow(attenuation_strength(difference), 0.6);
|
||||
// float strength = attenuation_strength(difference);// pow(attenuation_strength(difference), 0.6);
|
||||
// NOTE: This normalizes strength to 0.25 at the center of the point source.
|
||||
float strength = 1.0 / (4 + distance_2);
|
||||
|
||||
// Multiply the vec3 only once
|
||||
// Multiply the vec3 only once
|
||||
const float PI = 3.1415926535897932384626433832795;
|
||||
const float PI_2 = 2 * PI;
|
||||
float square_factor = /*2.0 * PI_2 * *//*2.0 * */L.light_col.a;
|
||||
vec3 color = /*srgb_to_linear*/L.light_col.rgb;
|
||||
vec3 color = /*srgb_to_linear*/L.light_col.rgb;
|
||||
|
||||
// // Only access the array once
|
||||
// Shadow S = shadows[i];
|
||||
// // Only access the array once
|
||||
// Shadow S = shadows[i];
|
||||
|
||||
// vec3 shadow_pos = S.shadow_pos_radius.xyz;
|
||||
// float radius = S.shadow_pos_radius.w;
|
||||
// vec3 shadow_pos = S.shadow_pos_radius.xyz;
|
||||
// float radius = S.shadow_pos_radius.w;
|
||||
|
||||
// vec3 diff = shadow_pos - wpos;
|
||||
// if (diff.z >= 0.0) {
|
||||
// diff.z = -sign(diff.z) * diff.z * 0.1;
|
||||
// }
|
||||
// vec3 diff = shadow_pos - wpos;
|
||||
// if (diff.z >= 0.0) {
|
||||
// diff.z = -sign(diff.z) * diff.z * 0.1;
|
||||
// }
|
||||
|
||||
// float shade = max(pow(diff.x * diff.x + diff.y * diff.y + diff.z * diff.z, 0.25) / pow(radius * radius * 0.5, 0.25), /*0.5*/0.0);
|
||||
// float shade = max(pow(diff.x * diff.x + diff.y * diff.y + diff.z * diff.z, 0.25) / pow(radius * radius * 0.5, 0.25), /*0.5*/0.0);
|
||||
|
||||
// shadow = min(shadow, shade);
|
||||
// shadow = min(shadow, shade);
|
||||
|
||||
// Compute reflectance.
|
||||
float light_distance = sqrt(distance_2);
|
||||
@ -210,13 +210,13 @@ float lights_at(vec3 wpos, vec3 wnorm, vec3 /*cam_to_frag*/view_dir, vec3 mu, ve
|
||||
// float both_strength = mix(cam_strength, strength, cam_distance_2 / sqrt(cam_distance_2 + distance_2));
|
||||
max_light += /*max(1.0, cam_strength)*//*min(cam_strength, 1.0)*//*max*//*max(both_strength, 1.0) * *//*cam_strength*/computed_shadow * both_strength * square_factor * square_factor * PI * color;
|
||||
// max_light += /*max(1.0, cam_strength)*//*min(cam_strength, 1.0)*//*max*/max(cam_strength, 1.0/*, strength*//*1.0*/) * square_factor * square_factor * PI * color;
|
||||
// light += color * (max(0, max(dot(normalize(difference), wnorm), 0.15)) + LIGHT_AMBIANCE);
|
||||
// light += color * (max(0, max(dot(normalize(difference), wnorm), 0.15)) + LIGHT_AMBIANCE);
|
||||
// Compute emiittance.
|
||||
// float ambient_sides = clamp(mix(0.15, 0.0, abs(dot(wnorm, light_dir)) * 10000.0), 0.0, 0.15);
|
||||
// float ambient_sides = 0.0;// max(dot(wnorm, light_dir) - 0.15, 0.15);
|
||||
// // float ambient_sides = 0.0;
|
||||
// ambient_light += color * (ambient_sides + LIGHT_AMBIANCE);
|
||||
}
|
||||
}
|
||||
|
||||
// shadow = shadow_at(wpos, wnorm);
|
||||
// float shadow = shadow_at(wpos, wnorm);
|
||||
|
@ -10,14 +10,14 @@ const float MIN_SHADOW = 0.33;
|
||||
vec2 pos_to_uv(sampler2D sampler, vec2 pos) {
|
||||
// Want: (pixel + 0.5) / W
|
||||
vec2 texSize = textureSize(sampler, 0);
|
||||
vec2 uv_pos = (focus_off.xy + pos + 16) / (32.0 * texSize);
|
||||
return vec2(uv_pos.x, /*1.0 - */uv_pos.y);
|
||||
vec2 uv_pos = (focus_off.xy + pos + 16) / (32.0 * texSize);
|
||||
return vec2(uv_pos.x, /*1.0 - */uv_pos.y);
|
||||
}
|
||||
|
||||
vec2 pos_to_tex(vec2 pos) {
|
||||
// Want: (pixel + 0.5)
|
||||
vec2 uv_pos = (focus_off.xy + pos + 16) / 32.0;
|
||||
return vec2(uv_pos.x, uv_pos.y);
|
||||
vec2 uv_pos = (focus_off.xy + pos + 16) / 32.0;
|
||||
return vec2(uv_pos.x, uv_pos.y);
|
||||
}
|
||||
|
||||
// textureBicubic from https://stackoverflow.com/a/42179924
|
||||
@ -74,8 +74,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*/(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 0.0
|
||||
// + pow(texture(t_noise, pos * 0.00005).x * 1.4, 3.0) * 1000.0
|
||||
@ -86,11 +86,11 @@ float alt_at(vec2 pos) {
|
||||
float alt_at_real(vec2 pos) {
|
||||
// Basic idea: only really need the real altitude for an accurate water height estimation, so if we are in the cheap shader take a shortcut.
|
||||
// #if (FLUID_MODE == FLUID_MODE_CHEAP)
|
||||
// return alt_at(pos);
|
||||
// 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, 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;
|
||||
//+ (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
|
||||
@ -200,18 +200,18 @@ vec2 splay(vec2 pos) {
|
||||
float len_2 = dot(pos, pos);
|
||||
float len_pow = len_2 * sqrt(len_2);
|
||||
// float len_pow = pow(len/* * SQRT_2*//* * 0.5*/, 3.0);
|
||||
// vec2 splayed = pos * pow(len * 0.5, 3.0) * SPLAY_MULT;
|
||||
// vec2 splayed = pos * pow(len * 0.5, 3.0) * SPLAY_MULT;
|
||||
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 + 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*/));
|
||||
return splayed;
|
||||
|
||||
// Radial: pos.x = r - view_distance.x from focus_pos, pos.y = θ from cam_pos to focus_pos on xy plane.
|
||||
// const float PI_2 = 3.1415926535897932384626433832795;
|
||||
// float squared = pos.x * pos.x;
|
||||
// // // vec2 splayed2 = pos * vec2(squared * (SPLAY_MULT - view_distance.x), PI);
|
||||
// vec2 splayed2 = pos * vec2(squared * (textureSize(t_alt, 0).x * 32.0 - view_distance.x), PI);
|
||||
// // // vec2 splayed2 = pos * vec2(squared * (SPLAY_MULT - view_distance.x), PI);
|
||||
// vec2 splayed2 = pos * vec2(squared * (textureSize(t_alt, 0).x * 32.0 - view_distance.x), PI);
|
||||
// float r = splayed2.x + view_distance.x;
|
||||
// vec2 theta = vec2(cos(splayed2.y), sin(splayed2.y));
|
||||
// return r * theta;
|
||||
@ -221,34 +221,34 @@ vec2 splay(vec2 pos) {
|
||||
}
|
||||
|
||||
vec3 lod_norm(vec2 f_pos/*vec3 pos*/, vec4 square) {
|
||||
// const float SAMPLE_W = 32;
|
||||
// const float SAMPLE_W = 32;
|
||||
|
||||
// vec2 f_pos = pos.xy;
|
||||
// float altx0 = alt_at_real(f_pos + vec2(-1.0, 0) * SAMPLE_W);
|
||||
// float altx1 = alt_at_real(f_pos + vec2(1.0, 0) * SAMPLE_W);
|
||||
// float alty0 = alt_at_real(f_pos + vec2(0, -1.0) * SAMPLE_W);
|
||||
// float alty1 = alt_at_real(f_pos + vec2(0, 1.0) * SAMPLE_W);
|
||||
float altx0 = alt_at(vec2(square.x, f_pos.y));
|
||||
float altx1 = alt_at(vec2(square.z, f_pos.y));
|
||||
float alty0 = alt_at(vec2(f_pos.x, square.y));
|
||||
float alty1 = alt_at(vec2(f_pos.x, square.w));
|
||||
float slope = abs(altx1 - altx0) + abs(alty0 - alty1);
|
||||
// float altx0 = alt_at_real(f_pos + vec2(-1.0, 0) * SAMPLE_W);
|
||||
// float altx1 = alt_at_real(f_pos + vec2(1.0, 0) * SAMPLE_W);
|
||||
// float alty0 = alt_at_real(f_pos + vec2(0, -1.0) * SAMPLE_W);
|
||||
// float alty1 = alt_at_real(f_pos + vec2(0, 1.0) * SAMPLE_W);
|
||||
float altx0 = alt_at(vec2(square.x, f_pos.y));
|
||||
float altx1 = alt_at(vec2(square.z, f_pos.y));
|
||||
float alty0 = alt_at(vec2(f_pos.x, square.y));
|
||||
float alty1 = alt_at(vec2(f_pos.x, square.w));
|
||||
float slope = abs(altx1 - altx0) + abs(alty0 - alty1);
|
||||
|
||||
// vec3 norm = normalize(cross(
|
||||
// vec3(/*2.0 * SAMPLE_W*/square.z - square.x, 0.0, altx1 - altx0),
|
||||
// vec3(0.0, /*2.0 * SAMPLE_W*/square.w - square.y, alty1 - alty0)
|
||||
// ));
|
||||
vec3 norm = normalize(vec3(
|
||||
(altx0 - altx1) / (square.z - square.x),
|
||||
(alty0 - alty1) / (square.w - square.y),
|
||||
(altx0 - altx1) / (square.z - square.x),
|
||||
(alty0 - alty1) / (square.w - square.y),
|
||||
1.0
|
||||
//(abs(square.w - square.y) + abs(square.z - square.x)) / (slope + 0.00001) // Avoid NaN
|
||||
//(abs(square.w - square.y) + abs(square.z - square.x)) / (slope + 0.00001) // Avoid NaN
|
||||
));
|
||||
/* vec3 norm = normalize(vec3(
|
||||
(altx0 - altx1) / (2.0 * SAMPLE_W),
|
||||
(alty0 - alty1) / (2.0 * SAMPLE_W),
|
||||
(2.0 * SAMPLE_W) / (slope + 0.00001) // Avoid NaN
|
||||
)); */
|
||||
/* vec3 norm = normalize(vec3(
|
||||
(altx0 - altx1) / (2.0 * SAMPLE_W),
|
||||
(alty0 - alty1) / (2.0 * SAMPLE_W),
|
||||
(2.0 * SAMPLE_W) / (slope + 0.00001) // Avoid NaN
|
||||
)); */
|
||||
|
||||
return faceforward(norm, vec3(0.0, 0.0, -1.0)/*pos - cam_pos.xyz*/, norm);
|
||||
}
|
||||
@ -261,29 +261,29 @@ vec3 lod_norm(vec2 f_pos/*vec3 pos*/) {
|
||||
|
||||
|
||||
vec3 lod_pos(vec2 pos, vec2 focus_pos) {
|
||||
// Remove spiking by "pushing" vertices towards local optima
|
||||
// Remove spiking by "pushing" vertices towards local optima
|
||||
vec2 delta = splay(pos);
|
||||
vec2 hpos = focus_pos + delta;
|
||||
vec2 nhpos = hpos;
|
||||
vec2 nhpos = hpos;
|
||||
// vec2 lod_shift = splay(abs(pos) - 1.0 / view_distance.y);
|
||||
float shift = 15.0;// min(lod_shift.x, lod_shift.y) * 0.5;
|
||||
for (int i = 0; i < 3; i ++) {
|
||||
for (int i = 0; i < 3; i ++) {
|
||||
// vec4 square = focus_pos.xy + vec4(splay(pos - vec2(1.0, 1.0), splay(pos + vec2(1.0, 1.0))));
|
||||
nhpos -= lod_norm(hpos).xy * shift;
|
||||
}
|
||||
hpos = hpos + normalize(nhpos - hpos + 0.001) * min(length(nhpos - hpos), 32);
|
||||
nhpos -= lod_norm(hpos).xy * shift;
|
||||
}
|
||||
hpos = hpos + normalize(nhpos - hpos + 0.001) * min(length(nhpos - hpos), 32);
|
||||
|
||||
return vec3(hpos, alt_at_real(hpos));
|
||||
return vec3(hpos, alt_at_real(hpos));
|
||||
}
|
||||
|
||||
#ifdef HAS_LOD_FULL_INFO
|
||||
uniform sampler2D t_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)
|
||||
;//+ (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;
|
||||
//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)
|
||||
;//+ (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
|
||||
|
@ -1,50 +1,97 @@
|
||||
uniform sampler2D t_noise;
|
||||
|
||||
float hash(vec4 p) {
|
||||
p = fract(p * 0.3183099 + 0.1) - fract(p + 23.22121);
|
||||
p *= 17.0;
|
||||
p = fract(p * 0.3183099 + 0.1) - fract(p + 23.22121);
|
||||
p *= 17.0;
|
||||
return (fract(p.x * p.y * p.z * p.w * (p.x + p.y + p.z + p.w)) - 0.5) * 2.0;
|
||||
}
|
||||
|
||||
#define M1 1597334677U //1719413*929
|
||||
#define M2 3812015801U //140473*2467*11
|
||||
#define M3 2741598923U
|
||||
|
||||
float hash_one(uint q)
|
||||
{
|
||||
uint n = ((M3 * q) ^ M2) * M1;
|
||||
|
||||
return float(n) * (1.0/float(0xffffffffU));
|
||||
}
|
||||
|
||||
float hash_fast(uvec3 q)
|
||||
{
|
||||
q *= uvec3(M1, M2, M3);
|
||||
|
||||
uint n = (q.x ^ q.y ^ q.z) * M1;
|
||||
|
||||
return float(n) * (1.0/float(0xffffffffU));
|
||||
}
|
||||
|
||||
// 3D, but using shifted 2D textures
|
||||
float noise_3d(vec3 pos) {
|
||||
pos.z *= 15.0;
|
||||
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));
|
||||
}
|
||||
|
||||
// 3D version of `snoise`
|
||||
float snoise3(in vec3 x) {
|
||||
uvec3 p = uvec3(floor(x) + 10000.0);
|
||||
vec3 f = fract(x);
|
||||
//f = f * f * (3.0 - 2.0 * f);
|
||||
return mix(
|
||||
mix(
|
||||
mix(hash_fast(p + uvec3(0,0,0)), hash_fast(p + uvec3(1,0,0)), f.x),
|
||||
mix(hash_fast(p + uvec3(0,1,0)), hash_fast(p + uvec3(1,1,0)), f.x),
|
||||
f.y),
|
||||
mix(
|
||||
mix(hash_fast(p + uvec3(0,0,1)), hash_fast(p + uvec3(1,0,1)), f.x),
|
||||
mix(hash_fast(p + uvec3(0,1,1)), hash_fast(p + uvec3(1,1,1)), f.x),
|
||||
f.y),
|
||||
f.z);
|
||||
}
|
||||
|
||||
// 4D noise
|
||||
float snoise(in vec4 x) {
|
||||
vec4 p = floor(x);
|
||||
vec4 f = fract(x);
|
||||
f = f * f * (3.0 - 2.0 * f);
|
||||
return mix(
|
||||
mix(
|
||||
mix(
|
||||
mix(hash(p + vec4(0,0,0,0)), hash(p + vec4(1,0,0,0)), f.x),
|
||||
mix(hash(p + vec4(0,1,0,0)), hash(p + vec4(1,1,0,0)), f.x),
|
||||
f.y),
|
||||
mix(
|
||||
mix(hash(p + vec4(0,0,1,0)), hash(p + vec4(1,0,1,0)), f.x),
|
||||
mix(hash(p + vec4(0,1,1,0)), hash(p + vec4(1,1,1,0)), f.x),
|
||||
f.y),
|
||||
f.z),
|
||||
mix(
|
||||
mix(
|
||||
mix(hash(p + vec4(0,0,0,1)), hash(p + vec4(1,0,0,1)), f.x),
|
||||
mix(hash(p + vec4(0,1,0,1)), hash(p + vec4(1,1,0,1)), f.x),
|
||||
f.y),
|
||||
mix(
|
||||
mix(hash(p + vec4(0,0,1,1)), hash(p + vec4(1,0,1,1)), f.x),
|
||||
mix(hash(p + vec4(0,1,1,1)), hash(p + vec4(1,1,1,1)), f.x),
|
||||
f.y),
|
||||
f.z),
|
||||
f.w);
|
||||
mix(
|
||||
mix(
|
||||
mix(hash(p + vec4(0,0,0,0)), hash(p + vec4(1,0,0,0)), f.x),
|
||||
mix(hash(p + vec4(0,1,0,0)), hash(p + vec4(1,1,0,0)), f.x),
|
||||
f.y),
|
||||
mix(
|
||||
mix(hash(p + vec4(0,0,1,0)), hash(p + vec4(1,0,1,0)), f.x),
|
||||
mix(hash(p + vec4(0,1,1,0)), hash(p + vec4(1,1,1,0)), f.x),
|
||||
f.y),
|
||||
f.z),
|
||||
mix(
|
||||
mix(
|
||||
mix(hash(p + vec4(0,0,0,1)), hash(p + vec4(1,0,0,1)), f.x),
|
||||
mix(hash(p + vec4(0,1,0,1)), hash(p + vec4(1,1,0,1)), f.x),
|
||||
f.y),
|
||||
mix(
|
||||
mix(hash(p + vec4(0,0,1,1)), hash(p + vec4(1,0,1,1)), f.x),
|
||||
mix(hash(p + vec4(0,1,1,1)), hash(p + vec4(1,1,1,1)), f.x),
|
||||
f.y),
|
||||
f.z),
|
||||
f.w);
|
||||
}
|
||||
|
||||
vec3 rand_perm_3(vec3 pos) {
|
||||
return abs(sin(pos * vec3(1473.7 * pos.z + 472.3, 8891.1 * pos.x + 723.1, 3813.3 * pos.y + 982.5)));
|
||||
return abs(sin(pos * vec3(1473.7 * pos.z + 472.3, 8891.1 * pos.x + 723.1, 3813.3 * pos.y + 982.5)));
|
||||
}
|
||||
|
||||
vec4 rand_perm_4(vec4 pos) {
|
||||
return sin(473.3 * pos * vec4(317.3 * pos.w + 917.7, 1473.7 * pos.z + 472.3, 8891.1 * pos.x + 723.1, 3813.3 * pos.y + 982.5) / pos.yxwz);
|
||||
return sin(473.3 * pos * vec4(317.3 * pos.w + 917.7, 1473.7 * pos.z + 472.3, 8891.1 * pos.x + 723.1, 3813.3 * pos.y + 982.5) / pos.yxwz);
|
||||
}
|
||||
|
||||
vec3 smooth_rand(vec3 pos, float lerp_axis) {
|
||||
return vec3(snoise(vec4(pos, lerp_axis)), snoise(vec4(pos + 400.0, lerp_axis)), snoise(vec4(pos + 1000.0, lerp_axis)));
|
||||
vec3 r0 = rand_perm_3(vec3(pos.x, pos.y, pos.z) + floor(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);
|
||||
return vec3(snoise(vec4(pos, lerp_axis)), snoise(vec4(pos + 400.0, lerp_axis)), snoise(vec4(pos + 1000.0, lerp_axis)));
|
||||
vec3 r0 = rand_perm_3(vec3(pos.x, pos.y, pos.z) + floor(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);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#if (SHADOW_MODE == SHADOW_MODE_MAP)
|
||||
struct ShadowLocals {
|
||||
mat4 shadowMatrices;
|
||||
mat4 shadowMatrices;
|
||||
mat4 texture_mat;
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include <random.glsl>
|
||||
#include <srgb.glsl>
|
||||
#include <cloud.glsl>
|
||||
#include <srgb.glsl>
|
||||
#include <shadows.glsl>
|
||||
#include <globals.glsl>
|
||||
|
||||
@ -25,7 +23,7 @@ const vec3 SKY_DUSK_TOP = vec3(0.06, 0.1, 0.20);
|
||||
const vec3 SKY_DUSK_MID = vec3(0.35, 0.1, 0.15);
|
||||
const vec3 SKY_DUSK_BOT = vec3(0.0, 0.1, 0.23);
|
||||
const vec3 DUSK_LIGHT = vec3(9.0, 1.5, 0.15);
|
||||
const vec3 SUN_HALO_DUSK = vec3(1.2, 0.15, 0.0);
|
||||
const vec3 SUN_HALO_DUSK = vec3(1.2, 0.25, 0.0);
|
||||
|
||||
const vec3 SKY_NIGHT_TOP = vec3(0.001, 0.001, 0.0025);
|
||||
const vec3 SKY_NIGHT_MID = vec3(0.001, 0.005, 0.02);
|
||||
@ -66,12 +64,35 @@ const float PERSISTENT_AMBIANCE = 1.0 / 32.0;// 1.0 / 80; // 1.0 / 512; // 0.001
|
||||
// return normalize(-vec3(sin(moon_angle_rad), 0.0, cos(moon_angle_rad) - 0.5));
|
||||
//}
|
||||
|
||||
float CLOUD_AVG_ALT = view_distance.z + 0.75 * view_distance.w;
|
||||
|
||||
const float wind_speed = 0.25;
|
||||
vec2 wind_offset = vec2(time_of_day.x * wind_speed);
|
||||
|
||||
float cloud_tendency_at(vec2 pos) {
|
||||
return clamp(texture(t_noise, (pos + wind_offset) * 0.000075).x - 0.5, 0, 1);
|
||||
}
|
||||
|
||||
float cloud_shadow(vec3 pos, vec3 light_dir) {
|
||||
#if (CLOUD_MODE == CLOUD_MODE_NONE || CLOUD_MODE == CLOUD_MODE_MINIMAL)
|
||||
return 1.0;
|
||||
#else
|
||||
vec2 xy_offset = light_dir.xy * ((CLOUD_AVG_ALT - pos.z) / -light_dir.z);
|
||||
|
||||
// Fade out shadow if the sun angle is too steep (simulates a widening penumbra with distance)
|
||||
const vec2 FADE_RANGE = vec2(1500, 10000);
|
||||
float fade = 1.0 - clamp((length(xy_offset) - FADE_RANGE.x) / (FADE_RANGE.y - FADE_RANGE.x), 0, 1);
|
||||
|
||||
return max(0, 1 - fade * cloud_tendency_at(pos.xy + focus_off.xy - xy_offset) * 3.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
float get_sun_brightness(/*vec3 sun_dir*/) {
|
||||
return max(-sun_dir.z + 0.6, 0.0) * 0.9;
|
||||
}
|
||||
|
||||
float get_moon_brightness(/*vec3 moon_dir*/) {
|
||||
return max(-moon_dir.z + 0.6, 0.0) * 0.4;
|
||||
return max(-moon_dir.z + 0.6, 0.0) * 0.1;
|
||||
}
|
||||
|
||||
vec3 get_sun_color(/*vec3 sun_dir*/) {
|
||||
@ -86,6 +107,20 @@ vec3 get_sun_color(/*vec3 sun_dir*/) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Average sky colour (i.e: perfectly scattered light from the sky)
|
||||
vec3 get_sky_color(/*vec3 sun_dir*/) {
|
||||
return mix(
|
||||
mix(
|
||||
(SKY_DUSK_TOP + SKY_DUSK_MID) / 2,
|
||||
(SKY_NIGHT_TOP + SKY_NIGHT_MID) / 2,
|
||||
max(sun_dir.z, 0)
|
||||
),
|
||||
(SKY_DAY_TOP + SKY_DAY_MID) / 2,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
}
|
||||
|
||||
vec3 get_moon_color(/*vec3 moon_dir*/) {
|
||||
return vec3(0.05, 0.05, 0.6);
|
||||
}
|
||||
@ -204,8 +239,8 @@ float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, ve
|
||||
// float sun_shadow = 1.0;
|
||||
// float moon_shadow = 1.0;
|
||||
// #endif
|
||||
float sun_shadow = sun_info.shadow;
|
||||
float moon_shadow = moon_info.shadow;
|
||||
float sun_shadow = sun_info.shadow * cloud_shadow(wpos, sun_dir);
|
||||
float moon_shadow = moon_info.shadow * cloud_shadow(wpos, moon_dir);
|
||||
|
||||
// https://en.m.wikipedia.org/wiki/Diffuse_sky_radiation
|
||||
//
|
||||
@ -356,115 +391,102 @@ float is_star_at(vec3 dir) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float quality, bool with_stars, float refractionIndex, out vec4 clouds) {
|
||||
#if (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
const bool has_clouds = false;
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_REGULAR)
|
||||
const bool has_clouds = true;
|
||||
#endif
|
||||
vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float quality, bool with_features, float refractionIndex) {
|
||||
// Sky color
|
||||
/* vec3 sun_dir = get_sun_dir(time_of_day);
|
||||
vec3 moon_dir = get_moon_dir(time_of_day); */
|
||||
vec3 sun_dir = sun_dir.xyz;
|
||||
vec3 moon_dir = moon_dir.xyz;
|
||||
|
||||
if (with_stars || has_clouds) {
|
||||
// Sky color
|
||||
/* vec3 sun_dir = get_sun_dir(time_of_day);
|
||||
vec3 moon_dir = get_moon_dir(time_of_day); */
|
||||
vec3 sun_dir = sun_dir.xyz;
|
||||
vec3 moon_dir = moon_dir.xyz;
|
||||
// sun_dir = sun_dir.z <= 0 ? refract(sun_dir/*-view_dir*/, vec3(0.0, 0.0, 1.0), refractionIndex) : sun_dir;
|
||||
// moon_dir = moon_dir.z <= 0 ? refract(moon_dir/*-view_dir*/, vec3(0.0, 0.0, 1.0), refractionIndex) : moon_dir;
|
||||
|
||||
// sun_dir = sun_dir.z <= 0 ? refract(sun_dir/*-view_dir*/, vec3(0.0, 0.0, 1.0), refractionIndex) : sun_dir;
|
||||
// moon_dir = moon_dir.z <= 0 ? refract(moon_dir/*-view_dir*/, vec3(0.0, 0.0, 1.0), refractionIndex) : moon_dir;
|
||||
|
||||
// Add white dots for stars. Note these flicker and jump due to FXAA
|
||||
float star = 0.0;
|
||||
if (with_stars) {
|
||||
vec3 star_dir = normalize(sun_dir * dir.z + cross(sun_dir, vec3(0, 1, 0)) * dir.x + vec3(0, 1, 0) * dir.y);
|
||||
star = is_star_at(star_dir);
|
||||
}
|
||||
|
||||
// Sun
|
||||
const vec3 SUN_SURF_COLOR = vec3(1.5, 0.9, 0.35) * 200.0;
|
||||
|
||||
vec3 sun_halo_color = mix(
|
||||
SUN_HALO_DUSK,
|
||||
SUN_HALO_DAY,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sun_halo = pow(max(dot(dir, -sun_dir) + 0.1, 0.0), 8.0) * sun_halo_color;
|
||||
vec3 sun_surf = pow(max(dot(dir, -sun_dir) - 0.001, 0.0), 3000.0) * SUN_SURF_COLOR * SUN_COLOR_FACTOR;
|
||||
vec3 sun_light = (sun_halo + sun_surf) * clamp(dir.z * 10.0, 0, 1);
|
||||
|
||||
// Moon
|
||||
const vec3 MOON_SURF_COLOR = vec3(0.7, 1.0, 1.5) * 500.0;
|
||||
const vec3 MOON_HALO_COLOR = vec3(0.015, 0.015, 0.05);
|
||||
|
||||
vec3 moon_halo = pow(max(dot(dir, -moon_dir) + 0.1, 0.0), 8.0) * MOON_HALO_COLOR;
|
||||
vec3 moon_surf = pow(max(dot(dir, -moon_dir) - 0.001, 0.0), 3000.0) * MOON_SURF_COLOR;
|
||||
vec3 moon_light = clamp(moon_halo + moon_surf, vec3(0), vec3(max(dir.z * 3.0, 0)));
|
||||
|
||||
// Replaced all clamp(sun_dir, 0, 1) with max(sun_dir, 0) because sun_dir is calculated from sin and cos, which are never > 1
|
||||
|
||||
vec3 sky_top = mix(
|
||||
mix(
|
||||
SKY_DUSK_TOP + star / (1.0 + moon_surf * 100.0),
|
||||
SKY_NIGHT_TOP + star / (1.0 + moon_surf * 100.0),
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
),
|
||||
SKY_DAY_TOP,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_mid = mix(
|
||||
mix( SKY_DUSK_MID,
|
||||
SKY_NIGHT_MID,
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
),
|
||||
SKY_DAY_MID,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_bot = mix(
|
||||
mix(
|
||||
SKY_DUSK_BOT,
|
||||
SKY_NIGHT_BOT,
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
),
|
||||
SKY_DAY_BOT,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_color = mix(
|
||||
mix(
|
||||
sky_mid,
|
||||
sky_bot,
|
||||
pow(max(-dir.z, 0), 0.4)
|
||||
),
|
||||
sky_top,
|
||||
max(dir.z, 0)
|
||||
);
|
||||
|
||||
// Approximate distance to fragment
|
||||
float f_dist = distance(origin, f_pos);
|
||||
|
||||
// Clouds
|
||||
#if (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
clouds = vec4(0.0);
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_REGULAR)
|
||||
clouds = get_cloud_color(dir, origin, time_of_day, f_dist, quality);
|
||||
clouds.rgb *= get_sun_brightness(/*sun_dir*/) * (sun_halo * 1.5 + get_sun_color(/*sun_dir*/)) + get_moon_brightness(/*moon_dir*/) * (moon_halo * 80.0 + get_moon_color(/*moon_dir*/) + 0.25);
|
||||
#endif
|
||||
|
||||
if (f_dist > 5000.0) {
|
||||
sky_color += sun_light + moon_light;
|
||||
}
|
||||
return mix(sky_color, clouds.rgb, clouds.a);
|
||||
} else {
|
||||
clouds = vec4(0.0);
|
||||
return vec3(0.0);
|
||||
// Add white dots for stars. Note these flicker and jump due to FXAA
|
||||
float star = 0.0;
|
||||
if (with_features) {
|
||||
vec3 star_dir = normalize(sun_dir * dir.z + cross(sun_dir, vec3(0, 1, 0)) * dir.x + vec3(0, 1, 0) * dir.y);
|
||||
star = is_star_at(star_dir);
|
||||
}
|
||||
|
||||
// Sun
|
||||
const vec3 SUN_SURF_COLOR = vec3(1.5, 0.9, 0.35) * 200.0;
|
||||
|
||||
vec3 sun_halo_color = mix(
|
||||
SUN_HALO_DUSK,
|
||||
SUN_HALO_DAY,
|
||||
max(-sun_dir.z, 0.0)
|
||||
);
|
||||
|
||||
vec3 sun_halo = pow(max(dot(dir, -sun_dir) + 0.1, 0.0), 8.0) * sun_halo_color;
|
||||
vec3 sun_surf = vec3(0);
|
||||
if (with_features) {
|
||||
sun_surf = pow(max(dot(dir, -sun_dir) - 0.001, 0.0), 5000.0) * SUN_SURF_COLOR * SUN_COLOR_FACTOR; // Hack to prevent sun vanishing too early
|
||||
}
|
||||
vec3 sun_light = sun_halo + sun_surf;
|
||||
|
||||
// Moon
|
||||
const vec3 MOON_SURF_COLOR = vec3(0.7, 1.0, 1.5) * 500.0;
|
||||
const vec3 MOON_HALO_COLOR = vec3(0.015, 0.015, 0.05);
|
||||
|
||||
vec3 moon_halo = pow(max(dot(dir, -moon_dir) + 0.1, 0.0), 8.0) * MOON_HALO_COLOR;
|
||||
vec3 moon_surf = vec3(0);
|
||||
if (with_features) {
|
||||
moon_surf = pow(max(dot(dir, -moon_dir) - 0.001, 0.0), 5000.0) * MOON_SURF_COLOR; // Hack to prevent moon vanishing too early
|
||||
}
|
||||
vec3 moon_light = moon_halo + moon_surf;
|
||||
|
||||
// Replaced all clamp(sun_dir, 0, 1) with max(sun_dir, 0) because sun_dir is calculated from sin and cos, which are never > 1
|
||||
|
||||
vec3 sky_top = mix(
|
||||
mix(
|
||||
SKY_DUSK_TOP + star / (1.0 + moon_surf * 100.0),
|
||||
SKY_NIGHT_TOP + star / (1.0 + moon_surf * 100.0),
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
),
|
||||
SKY_DAY_TOP,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_mid = mix(
|
||||
mix( SKY_DUSK_MID,
|
||||
SKY_NIGHT_MID,
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
),
|
||||
SKY_DAY_MID,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_bot = mix(
|
||||
mix(
|
||||
SKY_DUSK_BOT,
|
||||
SKY_NIGHT_BOT,
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
),
|
||||
SKY_DAY_BOT,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_color = mix(
|
||||
mix(
|
||||
sky_mid,
|
||||
sky_bot,
|
||||
pow(max(-dir.z, 0), 0.4)
|
||||
),
|
||||
sky_top,
|
||||
max(dir.z, 0)
|
||||
);
|
||||
|
||||
// Approximate distance to fragment
|
||||
float f_dist = distance(origin, f_pos);
|
||||
|
||||
if (f_dist > 5000.0) {
|
||||
sky_color += sun_light + moon_light;
|
||||
}
|
||||
return sky_color;
|
||||
}
|
||||
|
||||
vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float quality, bool with_stars, out vec4 clouds) {
|
||||
return get_sky_color(dir, time_of_day, origin, f_pos, quality, with_stars, 1.0, clouds);
|
||||
vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float quality, bool with_stars) {
|
||||
return get_sky_color(dir, time_of_day, origin, f_pos, quality, with_stars, 1.0);
|
||||
}
|
||||
|
||||
float fog(vec3 f_pos, vec3 focus_pos, uint medium) {
|
||||
|
@ -38,7 +38,7 @@ in uint v_pos_norm;
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec3 model_offs;
|
||||
float load_time;
|
||||
float load_time;
|
||||
ivec4 atlas_offs;
|
||||
};
|
||||
|
||||
@ -48,13 +48,13 @@ const int EXTRA_NEG_Z = 32768;
|
||||
|
||||
void main() {
|
||||
#if (SHADOW_MODE == SHADOW_MODE_MAP)
|
||||
vec3 f_chunk_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0xFFFFu)) - ivec3(0, 0, EXTRA_NEG_Z));
|
||||
vec3 f_pos = f_chunk_pos + model_offs - focus_off.xyz;
|
||||
// f_pos = v_pos;
|
||||
// vec3 f_pos = f_chunk_pos + model_offs;
|
||||
vec3 f_chunk_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0xFFFFu)) - ivec3(0, 0, EXTRA_NEG_Z));
|
||||
vec3 f_pos = f_chunk_pos + model_offs - focus_off.xyz;
|
||||
// f_pos = v_pos;
|
||||
// vec3 f_pos = f_chunk_pos + model_offs;
|
||||
|
||||
// gl_Position = v_pos + vec4(model_offs, 0.0);
|
||||
gl_Position = /*all_mat * */shadowMats[/*layer_face*/0].shadowMatrices * vec4(f_pos/*, 1.0*/, /*float(((f_pos_norm >> 29) & 0x7u) ^ 0x1)*//*uintBitsToFloat(v_pos_norm)*/1.0);
|
||||
// gl_Position = v_pos + vec4(model_offs, 0.0);
|
||||
gl_Position = /*all_mat * */shadowMats[/*layer_face*/0].shadowMatrices * vec4(f_pos/*, 1.0*/, /*float(((f_pos_norm >> 29) & 0x7u) ^ 0x1)*//*uintBitsToFloat(v_pos_norm)*/1.0);
|
||||
// gl_Position.z = -gl_Position.z;
|
||||
// gl_Position.z = clamp(gl_Position.z, -abs(gl_Position.w), abs(gl_Position.w));
|
||||
// shadowMapCoord = lights[gl_InstanceID].light_pos * gl_Vertex;
|
||||
|
@ -37,38 +37,38 @@ in uint v_atlas_pos;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
mat4 model_mat;
|
||||
vec4 highlight_col;
|
||||
mat4 model_mat;
|
||||
vec4 highlight_col;
|
||||
ivec4 atlas_offs;
|
||||
vec3 model_pos;
|
||||
// bit 0 - is player
|
||||
// bit 1-31 - unused
|
||||
int flags;
|
||||
// bit 0 - is player
|
||||
// bit 1-31 - unused
|
||||
int flags;
|
||||
};
|
||||
|
||||
struct BoneData {
|
||||
mat4 bone_mat;
|
||||
mat4 bone_mat;
|
||||
mat4 normals_mat;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_bones {
|
||||
// Warning: might not actually be 16 elements long. Don't index out of bounds!
|
||||
BoneData bones[16];
|
||||
// Warning: might not actually be 16 elements long. Don't index out of bounds!
|
||||
BoneData bones[16];
|
||||
};
|
||||
|
||||
// out vec4 shadowMapCoord;
|
||||
|
||||
void main() {
|
||||
#if (SHADOW_MODE == SHADOW_MODE_MAP)
|
||||
uint bone_idx = (v_pos_norm >> 27) & 0xFu;
|
||||
vec3 pos = (vec3((uvec3(v_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0;
|
||||
uint bone_idx = (v_pos_norm >> 27) & 0xFu;
|
||||
vec3 pos = (vec3((uvec3(v_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0;
|
||||
|
||||
vec3 f_pos = (
|
||||
vec3 f_pos = (
|
||||
bones[bone_idx].bone_mat *
|
||||
vec4(pos, 1.0)
|
||||
).xyz + (model_pos - focus_off.xyz/* + vec3(0.0, 0.0, 0.0001)*/);
|
||||
|
||||
gl_Position = shadowMats[/*layer_face*/0].shadowMatrices * vec4(f_pos, 1.0);
|
||||
gl_Position = shadowMats[/*layer_face*/0].shadowMatrices * vec4(f_pos, 1.0);
|
||||
#endif
|
||||
}
|
||||
|
@ -31,14 +31,14 @@
|
||||
// #include <light.glsl>
|
||||
|
||||
/* struct Light {
|
||||
vec4 light_pos;
|
||||
vec4 light_col;
|
||||
vec4 light_pos;
|
||||
vec4 light_col;
|
||||
// mat4 light_proj;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_lights {
|
||||
Light lights[31];
|
||||
Light lights[31];
|
||||
}; */
|
||||
|
||||
// Since our output primitive is a triangle strip, we have to render three vertices
|
||||
@ -186,7 +186,7 @@ layout (triangles/*, invocations = 6*/) in;
|
||||
layout (triangle_strip, max_vertices = /*MAX_LAYER_VERTICES_PER_FACE*//*96*/18) out;
|
||||
|
||||
//struct ShadowLocals {
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 texture_mat;
|
||||
//};
|
||||
//
|
||||
|
@ -34,7 +34,7 @@ in uint v_pos_norm;
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec3 model_offs;
|
||||
float load_time;
|
||||
float load_time;
|
||||
ivec4 atlas_offs;
|
||||
};
|
||||
|
||||
@ -43,13 +43,13 @@ uniform u_locals {
|
||||
const int EXTRA_NEG_Z = 32768;
|
||||
|
||||
void main() {
|
||||
vec3 f_chunk_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0xFFFFu)) - ivec3(0, 0, EXTRA_NEG_Z));
|
||||
vec3 f_pos = f_chunk_pos + model_offs - focus_off.xyz;
|
||||
// f_pos = v_pos;
|
||||
// vec3 f_pos = f_chunk_pos + model_offs;
|
||||
vec3 f_chunk_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0xFFFFu)) - ivec3(0, 0, EXTRA_NEG_Z));
|
||||
vec3 f_pos = f_chunk_pos + model_offs - focus_off.xyz;
|
||||
// f_pos = v_pos;
|
||||
// vec3 f_pos = f_chunk_pos + model_offs;
|
||||
|
||||
// gl_Position = v_pos + vec4(model_offs, 0.0);
|
||||
gl_Position = /*all_mat * */vec4(f_pos/*, 1.0*/, /*float(((f_pos_norm >> 29) & 0x7u) ^ 0x1)*//*uintBitsToFloat(v_pos_norm)*/1.0);
|
||||
// gl_Position = v_pos + vec4(model_offs, 0.0);
|
||||
gl_Position = /*all_mat * */vec4(f_pos/*, 1.0*/, /*float(((f_pos_norm >> 29) & 0x7u) ^ 0x1)*//*uintBitsToFloat(v_pos_norm)*/1.0);
|
||||
// shadowMapCoord = lights[gl_InstanceID].light_pos * gl_Vertex;
|
||||
// vec4(v_pos, 0.0, 1.0);
|
||||
}
|
||||
|
@ -446,7 +446,7 @@ void main() {
|
||||
voxel_norm = normalize(mix(voxel_norm, lerpy_norm, clamp(my_norm.z * my_norm.z - (1.0 - DIST), 0, 1) / DIST));
|
||||
|
||||
f_pos.xyz += abs(voxel_norm) * delta_sides;
|
||||
voxel_norm = voxel_norm == vec3(0.0) ? f_norm : voxel_norm;
|
||||
voxel_norm = mix(voxel_norm == vec3(0.0) ? f_norm : voxel_norm, my_norm, clamp((f_orig_len - view_distance.x) / 3500, 0, 1));
|
||||
|
||||
vec3 hash_pos = f_pos + focus_off.xyz;
|
||||
const float A = 0.055;
|
||||
@ -555,7 +555,9 @@ void main() {
|
||||
// vec3 light, diffuse_light, ambient_light;
|
||||
// get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, (0.25 * shade_frac + 0.25 * light_frac) * f_col, 0.5 * shade_frac * f_col, 0.5 * shade_frac * /*vec3(1.0)*/f_col, 2.0, emitted_light, reflected_light);
|
||||
float max_light = 0.0;
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, voxel_norm/*l_norm*/, view_dir, f_pos, vec3(0.0), cam_attenuation, fluid_alt, vec3(1.0)/* * (0.5 * light_frac + vec3(0.5 * shade_frac))*/, vec3(1.0), /*0.5 * shade_frac * *//*vec3(1.0)*//*f_col*/vec3(R_s), alpha, voxel_norm, dist_lerp/*max(distance(focus_pos.xy, f_pos.xyz) - view_distance.x, 0.0) / 1000 < 1.0*/, emitted_light, reflected_light);
|
||||
vec3 k_a = vec3(1.0);
|
||||
vec3 k_d = vec3(1.0);
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, voxel_norm/*l_norm*/, view_dir, f_pos, vec3(0.0), cam_attenuation, fluid_alt, k_a/* * (0.5 * light_frac + vec3(0.5 * shade_frac))*/, k_d, /*0.5 * shade_frac * *//*vec3(1.0)*//*f_col*/vec3(R_s), alpha, voxel_norm, dist_lerp/*max(distance(focus_pos.xy, f_pos.xyz) - view_distance.x, 0.0) / 1000 < 1.0*/, emitted_light, reflected_light);
|
||||
// emitted_light = vec3(1.0);
|
||||
// emitted_light *= max(shade_frac, MIN_SHADOW);
|
||||
// reflected_light *= shade_frac;
|
||||
@ -614,20 +616,10 @@ void main() {
|
||||
// f_col = f_col + (hash(vec4(floor(vec3(focus_pos.xy + splay(v_pos_orig), f_pos.z)) * 3.0 - round(f_norm) * 0.5, 0)) - 0.5) * 0.05; // Small-scale noise
|
||||
vec3 surf_color = /*illuminate(emitted_light, reflected_light)*/illuminate(max_light, view_dir, f_col * emitted_light, f_col * reflected_light);
|
||||
|
||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||
|
||||
#if (CLOUD_MODE == CLOUD_MODE_REGULAR)
|
||||
vec4 clouds;
|
||||
vec3 fog_color = get_sky_color(cam_to_frag/*view_dir*/, time_of_day.x, cam_pos.xyz, f_pos, 1.0, /*true*/false, clouds);
|
||||
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
vec3 color = surf_color;
|
||||
#endif
|
||||
|
||||
// float mist_factor = max(1 - (f_pos.z + (texture(t_noise, f_pos.xy * 0.0005 + time_of_day.x * 0.0003).x - 0.5) * 128.0) / 400.0, 0.0);
|
||||
// //float mist_factor = f_norm.z * 2.0;
|
||||
// color = mix(color, vec3(1.0) * /*diffuse_light*/reflected_light, clamp(mist_factor * 0.00005 * distance(f_pos.xy, focus_pos.xy), 0, 0.3));
|
||||
// color = surf_color;
|
||||
|
||||
tgt_color = vec4(color, 1.0);
|
||||
tgt_color = vec4(surf_color, 1.0);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ in vec2 v_pos;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec4 nul;
|
||||
vec4 nul;
|
||||
};
|
||||
|
||||
out vec3 f_pos;
|
||||
@ -43,16 +43,16 @@ void main() {
|
||||
f_norm = lod_norm(f_pos.xy, f_square);
|
||||
// v_pos_orig = v_pos;
|
||||
|
||||
// f_pos = lod_pos(focus_pos.xy + splay(v_pos) * /*1000000.0*/(1 << 20), square);
|
||||
// f_pos = lod_pos(focus_pos.xy + splay(v_pos) * /*1000000.0*/(1 << 20), square);
|
||||
|
||||
// f_norm = lod_norm(f_pos.xy);
|
||||
// f_norm = lod_norm(f_pos.xy);
|
||||
|
||||
// f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
|
||||
|
||||
pull_down = 1.0 / pow(distance(focus_pos.xy, f_pos.xy) / (view_distance.x * 0.95), 20.0);
|
||||
f_pos.z -= pull_down;
|
||||
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 -= 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);
|
||||
|
||||
// bool faces_fluid = false;// bool((f_pos_norm >> 28) & 0x1u);
|
||||
@ -61,8 +61,8 @@ void main() {
|
||||
// // float surfaceAlt = mix(view_distance.z, floor(max(cam_pos.z, alt_at_real(cam_pos.xy))), medium.x);
|
||||
// // float surfaceAlt = min(floor(f_pos.z), floor(alt_at_real(cam_pos.xy))); // faces_fluid ? max(ceil(f_pos.z), floor(f_alt)) : floor(f_alt);
|
||||
|
||||
// f_pos.z -= max(sign(view_distance.x - distance(focus_pos.xy, f_pos.xy)), 0.0) * (32.0 * view_distance.z / 255 + 32.0 * max(0.0, f_pos.z - cam_pos.z));
|
||||
// f_pos.z -= 0.1 + max(view_distance.x - distance(focus_pos.xy, f_pos.xy), 0.0) * (1.0 + max(1.0, ceil(f_pos.z - focus_pos.z)));
|
||||
// f_pos.z -= max(sign(view_distance.x - distance(focus_pos.xy, f_pos.xy)), 0.0) * (32.0 * view_distance.z / 255 + 32.0 * max(0.0, f_pos.z - cam_pos.z));
|
||||
// f_pos.z -= 0.1 + max(view_distance.x - distance(focus_pos.xy, f_pos.xy), 0.0) * (1.0 + max(1.0, ceil(f_pos.z - focus_pos.z)));
|
||||
|
||||
// vec3 wRayinitial = f_pos; // cam_pos.z < f_pos.z ? f_pos : cam_pos.xyz;
|
||||
// vec3 wRayfinal = cam_pos.xyz; // cam_pos.z < f_pos.z ? cam_pos.xyz : f_pos;
|
||||
@ -88,19 +88,19 @@ void main() {
|
||||
|
||||
// vec3 newRay = (dot(wRayDir3, focus_pos.xyz - cam_pos.xyz) < 0.0 && /*dot(wRayDir, wRayNormal) > 0.0 && *//*surfaceAlt < wRayinitial.z && */wIntersectsSurface && medium.x == 1u) ? wPoint - wRayDir3 * wRayLength * n2 / n1/*wPoint - wRayDir3 * wRayLength * n2 / n1*/ : f_pos;// - (wRayfinal - wPoint) * n2 / n1; // wPoint + n2 * (wRayfinal - wPoint) - n2 / n1 * wRayLength * wRayDir3;
|
||||
|
||||
// newRay.z -= max(view_distance.x - distance(focus_pos.xy, f_pos.xy), 0.0) * (1.0 + max(0.0, f_pos.z - focus_pos.z));
|
||||
// newRay.z -= max(view_distance.x - distance(focus_pos.xy, f_pos.xy), 0.0) * (1.0 + max(0.0, f_pos.z - focus_pos.z));
|
||||
|
||||
|
||||
// f_light = 1.0;
|
||||
// f_light = 1.0;
|
||||
|
||||
gl_Position =
|
||||
/* proj_mat *
|
||||
view_mat * */
|
||||
gl_Position =
|
||||
/* proj_mat *
|
||||
view_mat * */
|
||||
all_mat *
|
||||
vec4(f_pos/*newRay*/, 1);
|
||||
vec4(f_pos/*newRay*/, 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;
|
||||
// gl_Position.z = -gl_Position.z / 100.0;
|
||||
// gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
|
||||
// gl_Position.z = -gl_Position.z / 100.0;
|
||||
// gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ void main() {
|
||||
DirectionalLight sun_info = get_sun_info(sun_dir, point_shadow * sun_shade_frac, f_pos);
|
||||
DirectionalLight moon_info = get_moon_info(moon_dir, point_shadow * moon_shade_frac);
|
||||
|
||||
vec3 surf_color = f_col.rgb;
|
||||
vec3 surf_color = f_col.rgb;
|
||||
float alpha = 1.0;
|
||||
const float n2 = 1.5;
|
||||
const float R_s2s0 = pow((1.0 - n2) / (1.0 + n2), 2);
|
||||
@ -71,20 +71,11 @@ void main() {
|
||||
|
||||
max_light += lights_at(f_pos, f_norm, view_dir, k_a, k_d, k_s, alpha, emitted_light, reflected_light);
|
||||
|
||||
// Allow particles to glow at night
|
||||
// TODO: Not this
|
||||
emitted_light += max(f_col.rgb - 1.0, vec3(0));
|
||||
// Allow particles to glow at night
|
||||
// TODO: Not this
|
||||
emitted_light += max(f_col.rgb - 1.0, vec3(0));
|
||||
|
||||
surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light);
|
||||
surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light);
|
||||
|
||||
#if (CLOUD_MODE == CLOUD_MODE_REGULAR)
|
||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||
vec4 clouds;
|
||||
vec3 fog_color = get_sky_color(cam_to_frag, time_of_day.x, cam_pos.xyz, f_pos, 0.5, false, clouds);
|
||||
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
vec3 color = surf_color;
|
||||
#endif
|
||||
|
||||
tgt_color = vec4(color, f_col.a);
|
||||
tgt_color = vec4(surf_color, f_col.a);
|
||||
}
|
||||
|
@ -58,275 +58,275 @@ const int FIRE_SHOCKWAVE = 16;
|
||||
const float earth_gravity = 9.807;
|
||||
|
||||
struct Attr {
|
||||
vec3 offs;
|
||||
vec3 scale;
|
||||
vec4 col;
|
||||
mat4 rot;
|
||||
vec3 offs;
|
||||
vec3 scale;
|
||||
vec4 col;
|
||||
mat4 rot;
|
||||
};
|
||||
|
||||
float lifetime = tick.x - inst_time;
|
||||
|
||||
vec3 linear_motion(vec3 init_offs, vec3 vel) {
|
||||
return init_offs + vel * lifetime;
|
||||
return init_offs + vel * lifetime;
|
||||
}
|
||||
|
||||
vec3 grav_vel(float grav) {
|
||||
return vec3(0, 0, -grav * lifetime);
|
||||
return vec3(0, 0, -grav * lifetime);
|
||||
}
|
||||
|
||||
float exp_scale(float factor) {
|
||||
return 1 / (1 - lifetime * factor);
|
||||
return 1 / (1 - lifetime * factor);
|
||||
}
|
||||
|
||||
float linear_scale(float factor) {
|
||||
return lifetime * factor;
|
||||
return lifetime * factor;
|
||||
}
|
||||
|
||||
float start_end(float from, float to) {
|
||||
return mix(from, to, lifetime / inst_lifespan);
|
||||
return mix(from, to, lifetime / inst_lifespan);
|
||||
}
|
||||
|
||||
mat4 spin_in_axis(vec3 axis, float angle)
|
||||
{
|
||||
axis = normalize(axis);
|
||||
float s = sin(angle);
|
||||
float c = cos(angle);
|
||||
float oc = 1.0 - c;
|
||||
axis = normalize(axis);
|
||||
float s = sin(angle);
|
||||
float c = cos(angle);
|
||||
float oc = 1.0 - c;
|
||||
|
||||
return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0,
|
||||
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0,
|
||||
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0,
|
||||
0, 0, 0, 1);
|
||||
return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0,
|
||||
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0,
|
||||
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
mat4 identity() {
|
||||
return mat4(
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1
|
||||
);
|
||||
return mat4(
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1
|
||||
);
|
||||
}
|
||||
|
||||
vec3 perp_axis1(vec3 axis) {
|
||||
return normalize(vec3(axis.y + axis.z, -axis.x + axis.z, -axis.x - axis.y));
|
||||
return normalize(vec3(axis.y + axis.z, -axis.x + axis.z, -axis.x - axis.y));
|
||||
}
|
||||
|
||||
vec3 perp_axis2(vec3 axis1, vec3 axis2) {
|
||||
return normalize(vec3(axis1.y * axis2.z - axis1.z * axis2.y, axis1.z * axis2.x - axis1.x * axis2.z, axis1.x * axis2.y - axis1.y * axis2.x));
|
||||
return normalize(vec3(axis1.y * axis2.z - axis1.z * axis2.y, axis1.z * axis2.x - axis1.x * axis2.z, axis1.x * axis2.y - axis1.y * axis2.x));
|
||||
}
|
||||
|
||||
vec3 spiral_motion(vec3 line, float radius, float time_function) {
|
||||
vec3 axis2 = perp_axis1(line);
|
||||
vec3 axis3 = perp_axis2(line, axis2);
|
||||
vec3 axis2 = perp_axis1(line);
|
||||
vec3 axis3 = perp_axis2(line, axis2);
|
||||
|
||||
return line * time_function + vec3(
|
||||
radius * cos(10 * time_function - inst_time) * axis2.x + radius * sin(10 * time_function - inst_time) * axis3.x,
|
||||
radius * cos(10 * time_function - inst_time) * axis2.y + radius * sin(10 * time_function - inst_time) * axis3.y,
|
||||
radius * cos(10 * time_function - inst_time) * axis2.z + radius * sin(10 * time_function - inst_time) * axis3.z);
|
||||
return line * time_function + vec3(
|
||||
radius * cos(10 * time_function - inst_time) * axis2.x + radius * sin(10 * time_function - inst_time) * axis3.x,
|
||||
radius * cos(10 * time_function - inst_time) * axis2.y + radius * sin(10 * time_function - inst_time) * axis3.y,
|
||||
radius * cos(10 * time_function - inst_time) * axis2.z + radius * sin(10 * time_function - inst_time) * axis3.z);
|
||||
}
|
||||
|
||||
void main() {
|
||||
float rand0 = hash(vec4(inst_entropy + 0));
|
||||
float rand1 = hash(vec4(inst_entropy + 1));
|
||||
float rand2 = hash(vec4(inst_entropy + 2));
|
||||
float rand3 = hash(vec4(inst_entropy + 3));
|
||||
float rand4 = hash(vec4(inst_entropy + 4));
|
||||
float rand5 = hash(vec4(inst_entropy + 5));
|
||||
float rand6 = hash(vec4(inst_entropy + 6));
|
||||
float rand7 = hash(vec4(inst_entropy + 7));
|
||||
float rand8 = hash(vec4(inst_entropy + 8));
|
||||
float rand9 = hash(vec4(inst_entropy + 9));
|
||||
float rand0 = hash(vec4(inst_entropy + 0));
|
||||
float rand1 = hash(vec4(inst_entropy + 1));
|
||||
float rand2 = hash(vec4(inst_entropy + 2));
|
||||
float rand3 = hash(vec4(inst_entropy + 3));
|
||||
float rand4 = hash(vec4(inst_entropy + 4));
|
||||
float rand5 = hash(vec4(inst_entropy + 5));
|
||||
float rand6 = hash(vec4(inst_entropy + 6));
|
||||
float rand7 = hash(vec4(inst_entropy + 7));
|
||||
float rand8 = hash(vec4(inst_entropy + 8));
|
||||
float rand9 = hash(vec4(inst_entropy + 9));
|
||||
|
||||
Attr attr;
|
||||
Attr attr;
|
||||
|
||||
if (inst_mode == SMOKE) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand2 * 0.02, rand3 * 0.02, 1.0 + rand4 * 0.1)
|
||||
),
|
||||
vec3(linear_scale(0.5)),
|
||||
vec4(1, 1, 1, start_end(1.0, 0.0)),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 0.5)
|
||||
);
|
||||
} else if (inst_mode == FIRE) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(rand0 * 0.25, rand1 * 0.25, 0.3),
|
||||
vec3(rand2 * 0.1, rand3 * 0.1, 2.0 + rand4 * 1.0)
|
||||
),
|
||||
vec3(1.0),
|
||||
vec4(2, 0.8 + rand5 * 0.3, 0, 1),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3)
|
||||
);
|
||||
} else if (inst_mode == GUN_POWDER_SPARK) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(rand0, rand1, rand3) * 0.3,
|
||||
vec3(rand4, rand5, rand6) * 2.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(1.0),
|
||||
vec4(3.5, 3 + rand7, 0, 1),
|
||||
spin_in_axis(vec3(1,0,0),0)
|
||||
);
|
||||
} else if (inst_mode == SHRAPNEL) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand4, rand5, rand6) * 30.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(2.0 + rand0),
|
||||
vec4(vec3(0.6 + rand7 * 0.4), 1),
|
||||
spin_in_axis(vec3(1,0,0),0)
|
||||
);
|
||||
} else if (inst_mode == FIREWORK_BLUE) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(3.0 + rand0),
|
||||
vec4(0.15, 0.4, 1, 1),
|
||||
identity()
|
||||
);
|
||||
} else if (inst_mode == FIREWORK_GREEN) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(3.0 + rand0),
|
||||
vec4(0, 1, 0, 1),
|
||||
identity()
|
||||
);
|
||||
} else if (inst_mode == FIREWORK_PURPLE) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(3.0 + rand0),
|
||||
vec4(0.7, 0.0, 1.0, 1.0),
|
||||
identity()
|
||||
);
|
||||
} else if (inst_mode == FIREWORK_RED) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(3.0 + rand0),
|
||||
vec4(1, 0, 0, 1),
|
||||
identity()
|
||||
);
|
||||
} else if (inst_mode == FIREWORK_YELLOW) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(3.0 + rand0),
|
||||
vec4(1, 1, 0, 1),
|
||||
identity()
|
||||
);
|
||||
} else if (inst_mode == LEAF) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(0, 0, -2)
|
||||
) + vec3(sin(lifetime), sin(lifetime + 0.7), sin(lifetime * 0.5)) * 2.0,
|
||||
vec3(4),
|
||||
vec4(vec3(0.2 + rand7 * 0.2, 0.2 + (0.5 + rand6 * 0.5) * 0.6, 0), 1),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 5)
|
||||
);
|
||||
} else if (inst_mode == FIREFLY) {
|
||||
float raise = pow(sin(3.1416 * lifetime / inst_lifespan), 0.2);
|
||||
attr = Attr(
|
||||
vec3(0, 0, raise * 5.0) + vec3(
|
||||
sin(lifetime * 1.0 + rand0) + sin(lifetime * 7.0 + rand3) * 0.3,
|
||||
sin(lifetime * 3.0 + rand1) + sin(lifetime * 8.0 + rand4) * 0.3,
|
||||
sin(lifetime * 2.0 + rand2) + sin(lifetime * 9.0 + rand5) * 0.3
|
||||
),
|
||||
vec3(raise),
|
||||
vec4(vec3(5, 5, 1.1), 1),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 5)
|
||||
);
|
||||
} else if (inst_mode == BEE) {
|
||||
float lower = pow(sin(3.1416 * lifetime / inst_lifespan), 0.2);
|
||||
attr = Attr(
|
||||
vec3(0, 0, lower * -0.5) + vec3(
|
||||
sin(lifetime * 2.0 + rand0) + sin(lifetime * 9.0 + rand3) * 0.3,
|
||||
sin(lifetime * 3.0 + rand1) + sin(lifetime * 10.0 + rand4) * 0.3,
|
||||
sin(lifetime * 4.0 + rand2) + sin(lifetime * 11.0 + rand5) * 0.3
|
||||
) * 0.5,
|
||||
vec3(lower),
|
||||
vec4(vec3(1, 0.7, 0), 1),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 5)
|
||||
);
|
||||
} else if (inst_mode == GROUND_SHOCKWAVE) {
|
||||
attr = Attr(
|
||||
vec3(0.0),
|
||||
vec3(11.0, 11.0, (33.0 * rand0 * sin(2.0 * lifetime * 3.14 * 2.0))) / 3,
|
||||
vec4(vec3(0.32 + (rand0 * 0.04), 0.22 + (rand1 * 0.03), 0.05 + (rand2 * 0.01)), 1),
|
||||
spin_in_axis(vec3(1,0,0),0)
|
||||
);
|
||||
} else if (inst_mode == HEALING_BEAM) {
|
||||
attr = Attr(
|
||||
spiral_motion(inst_dir, 0.3 * (floor(2 * rand0 + 0.5) - 0.5) * min(linear_scale(10), 1), lifetime / inst_lifespan),
|
||||
vec3((1.7 - 0.7 * abs(floor(2 * rand0 - 0.5) + 0.5)) * (1.5 + 0.5 * sin(tick.x * 10 - lifetime * 4))),
|
||||
vec4(vec3(0.3, 0.7 + 0.4 * sin(tick.x * 8 - lifetime * 3), 0.3 + 0.1 * sin (tick.x * 2)), 0.3),
|
||||
spin_in_axis(inst_dir, tick.z)
|
||||
);
|
||||
} else if (inst_mode == ENERGY_NATURE) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(rand0 * 1, rand1 * 1, rand2 * 1),
|
||||
vec3(rand3 * 2, rand4 * 2, rand5 * 2)
|
||||
),
|
||||
vec3(0.8),
|
||||
vec4(vec3(0, 1, 0), 1),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3)
|
||||
);
|
||||
} else if (inst_mode == FLAMETHROWER) {
|
||||
attr = Attr(
|
||||
(inst_dir * lifetime / inst_lifespan) + vec3(rand0, rand1, rand2) * (lifetime * 5 + 0.25),
|
||||
vec3(0.6 + rand3 * 0.5 + lifetime / inst_lifespan * 5),
|
||||
vec4(1, 0.6 + rand5 * 0.3 - 0.6 * lifetime / inst_lifespan, 0, 0.8 - 0.6 * lifetime / inst_lifespan),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), lifetime / inst_lifespan * 10 + 3 * rand9)
|
||||
);
|
||||
} else if (inst_mode == FIRE_SHOCKWAVE) {
|
||||
attr = Attr(
|
||||
vec3(rand0, rand1, lifetime * 10 + rand2),
|
||||
vec3(1.6 + rand3 * 1.5 + 10 * (lifetime + inst_lifespan)),
|
||||
vec4(1, 0.6 + rand7 * 0.3 - 5 * inst_lifespan + 2 * lifetime, 0, 0.8 - 3.5 * inst_lifespan),
|
||||
spin_in_axis(vec3(rand3, rand4, rand5), rand6)
|
||||
);
|
||||
} else {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(rand0 * 0.25, rand1 * 0.25, 1.7 + rand5),
|
||||
vec3(rand2 * 0.1, rand3 * 0.1, 1.0 + rand4 * 0.5)
|
||||
),
|
||||
vec3(exp_scale(-0.2)),
|
||||
vec4(1),
|
||||
spin_in_axis(vec3(1,0,0),0)
|
||||
);
|
||||
}
|
||||
if (inst_mode == SMOKE) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand2 * 0.02, rand3 * 0.02, 1.0 + rand4 * 0.1)
|
||||
),
|
||||
vec3(linear_scale(0.5)),
|
||||
vec4(1, 1, 1, start_end(1.0, 0.0)),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 0.5)
|
||||
);
|
||||
} else if (inst_mode == FIRE) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(rand0 * 0.25, rand1 * 0.25, 0.3),
|
||||
vec3(rand2 * 0.1, rand3 * 0.1, 2.0 + rand4 * 1.0)
|
||||
),
|
||||
vec3(1.0),
|
||||
vec4(2, 0.8 + rand5 * 0.3, 0, 1),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3)
|
||||
);
|
||||
} else if (inst_mode == GUN_POWDER_SPARK) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(rand0, rand1, rand3) * 0.3,
|
||||
vec3(rand4, rand5, rand6) * 2.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(1.0),
|
||||
vec4(3.5, 3 + rand7, 0, 1),
|
||||
spin_in_axis(vec3(1,0,0),0)
|
||||
);
|
||||
} else if (inst_mode == SHRAPNEL) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand4, rand5, rand6) * 30.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(2.0 + rand0),
|
||||
vec4(vec3(0.6 + rand7 * 0.4), 1),
|
||||
spin_in_axis(vec3(1,0,0),0)
|
||||
);
|
||||
} else if (inst_mode == FIREWORK_BLUE) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(3.0 + rand0),
|
||||
vec4(0.15, 0.4, 1, 1),
|
||||
identity()
|
||||
);
|
||||
} else if (inst_mode == FIREWORK_GREEN) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(3.0 + rand0),
|
||||
vec4(0, 1, 0, 1),
|
||||
identity()
|
||||
);
|
||||
} else if (inst_mode == FIREWORK_PURPLE) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(3.0 + rand0),
|
||||
vec4(0.7, 0.0, 1.0, 1.0),
|
||||
identity()
|
||||
);
|
||||
} else if (inst_mode == FIREWORK_RED) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(3.0 + rand0),
|
||||
vec4(1, 0, 0, 1),
|
||||
identity()
|
||||
);
|
||||
} else if (inst_mode == FIREWORK_YELLOW) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity)
|
||||
),
|
||||
vec3(3.0 + rand0),
|
||||
vec4(1, 1, 0, 1),
|
||||
identity()
|
||||
);
|
||||
} else if (inst_mode == LEAF) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0),
|
||||
vec3(0, 0, -2)
|
||||
) + vec3(sin(lifetime), sin(lifetime + 0.7), sin(lifetime * 0.5)) * 2.0,
|
||||
vec3(4),
|
||||
vec4(vec3(0.2 + rand7 * 0.2, 0.2 + (0.5 + rand6 * 0.5) * 0.6, 0), 1),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 5)
|
||||
);
|
||||
} else if (inst_mode == FIREFLY) {
|
||||
float raise = pow(sin(3.1416 * lifetime / inst_lifespan), 0.2);
|
||||
attr = Attr(
|
||||
vec3(0, 0, raise * 5.0) + vec3(
|
||||
sin(lifetime * 1.0 + rand0) + sin(lifetime * 7.0 + rand3) * 0.3,
|
||||
sin(lifetime * 3.0 + rand1) + sin(lifetime * 8.0 + rand4) * 0.3,
|
||||
sin(lifetime * 2.0 + rand2) + sin(lifetime * 9.0 + rand5) * 0.3
|
||||
),
|
||||
vec3(raise),
|
||||
vec4(vec3(5, 5, 1.1), 1),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 5)
|
||||
);
|
||||
} else if (inst_mode == BEE) {
|
||||
float lower = pow(sin(3.1416 * lifetime / inst_lifespan), 0.2);
|
||||
attr = Attr(
|
||||
vec3(0, 0, lower * -0.5) + vec3(
|
||||
sin(lifetime * 2.0 + rand0) + sin(lifetime * 9.0 + rand3) * 0.3,
|
||||
sin(lifetime * 3.0 + rand1) + sin(lifetime * 10.0 + rand4) * 0.3,
|
||||
sin(lifetime * 4.0 + rand2) + sin(lifetime * 11.0 + rand5) * 0.3
|
||||
) * 0.5,
|
||||
vec3(lower),
|
||||
vec4(vec3(1, 0.7, 0), 1),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 5)
|
||||
);
|
||||
} else if (inst_mode == GROUND_SHOCKWAVE) {
|
||||
attr = Attr(
|
||||
vec3(0.0),
|
||||
vec3(11.0, 11.0, (33.0 * rand0 * sin(2.0 * lifetime * 3.14 * 2.0))) / 3,
|
||||
vec4(vec3(0.32 + (rand0 * 0.04), 0.22 + (rand1 * 0.03), 0.05 + (rand2 * 0.01)), 1),
|
||||
spin_in_axis(vec3(1,0,0),0)
|
||||
);
|
||||
} else if (inst_mode == HEALING_BEAM) {
|
||||
attr = Attr(
|
||||
spiral_motion(inst_dir, 0.3 * (floor(2 * rand0 + 0.5) - 0.5) * min(linear_scale(10), 1), lifetime / inst_lifespan),
|
||||
vec3((1.7 - 0.7 * abs(floor(2 * rand0 - 0.5) + 0.5)) * (1.5 + 0.5 * sin(tick.x * 10 - lifetime * 4))),
|
||||
vec4(vec3(0.3, 0.7 + 0.4 * sin(tick.x * 8 - lifetime * 3), 0.3 + 0.1 * sin (tick.x * 2)), 0.3),
|
||||
spin_in_axis(inst_dir, tick.z)
|
||||
);
|
||||
} else if (inst_mode == ENERGY_NATURE) {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(rand0 * 1, rand1 * 1, rand2 * 1),
|
||||
vec3(rand3 * 2, rand4 * 2, rand5 * 2)
|
||||
),
|
||||
vec3(0.8),
|
||||
vec4(vec3(0, 1, 0), 1),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3)
|
||||
);
|
||||
} else if (inst_mode == FLAMETHROWER) {
|
||||
attr = Attr(
|
||||
(inst_dir * lifetime / inst_lifespan) + vec3(rand0, rand1, rand2) * (lifetime * 5 + 0.25),
|
||||
vec3(0.6 + rand3 * 0.5 + lifetime / inst_lifespan * 5),
|
||||
vec4(1, 0.6 + rand5 * 0.3 - 0.6 * lifetime / inst_lifespan, 0, 0.8 - 0.6 * lifetime / inst_lifespan),
|
||||
spin_in_axis(vec3(rand6, rand7, rand8), lifetime / inst_lifespan * 10 + 3 * rand9)
|
||||
);
|
||||
} else if (inst_mode == FIRE_SHOCKWAVE) {
|
||||
attr = Attr(
|
||||
vec3(rand0, rand1, lifetime * 10 + rand2),
|
||||
vec3(1.6 + rand3 * 1.5 + 10 * (lifetime + inst_lifespan)),
|
||||
vec4(1, 0.6 + rand7 * 0.3 - 5 * inst_lifespan + 2 * lifetime, 0, 0.8 - 3.5 * inst_lifespan),
|
||||
spin_in_axis(vec3(rand3, rand4, rand5), rand6)
|
||||
);
|
||||
} else {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(rand0 * 0.25, rand1 * 0.25, 1.7 + rand5),
|
||||
vec3(rand2 * 0.1, rand3 * 0.1, 1.0 + rand4 * 0.5)
|
||||
),
|
||||
vec3(exp_scale(-0.2)),
|
||||
vec4(1),
|
||||
spin_in_axis(vec3(1,0,0),0)
|
||||
);
|
||||
}
|
||||
|
||||
f_pos = (inst_pos - focus_off.xyz) + (v_pos * attr.scale * SCALE * mat3(attr.rot) + attr.offs);
|
||||
f_pos = (inst_pos - focus_off.xyz) + (v_pos * attr.scale * SCALE * mat3(attr.rot) + attr.offs);
|
||||
|
||||
// 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));
|
||||
f_norm =
|
||||
// inst_pos *
|
||||
((normals[(v_norm_ao >> 0) & 0x7u]) * attr.rot).xyz;
|
||||
// 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));
|
||||
f_norm =
|
||||
// inst_pos *
|
||||
((normals[(v_norm_ao >> 0) & 0x7u]) * attr.rot).xyz;
|
||||
|
||||
//vec3 col = vec3((uvec3(v_col) >> uvec3(0, 8, 16)) & uvec3(0xFFu)) / 255.0;
|
||||
f_col = vec4(srgb_to_linear(attr.col.rgb), attr.col.a);
|
||||
//vec3 col = vec3((uvec3(v_col) >> uvec3(0, 8, 16)) & uvec3(0xFFu)) / 255.0;
|
||||
f_col = vec4(srgb_to_linear(attr.col.rgb), attr.col.a);
|
||||
|
||||
gl_Position =
|
||||
all_mat *
|
||||
vec4(f_pos, 1);
|
||||
gl_Position =
|
||||
all_mat *
|
||||
vec4(f_pos, 1);
|
||||
}
|
||||
|
@ -23,21 +23,21 @@ in float f_ao;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
mat4 model_mat;
|
||||
vec4 highlight_col;
|
||||
mat4 model_mat;
|
||||
vec4 highlight_col;
|
||||
ivec4 atlas_offs;
|
||||
vec3 model_pos;
|
||||
int flags;
|
||||
int flags;
|
||||
};
|
||||
|
||||
struct BoneData {
|
||||
mat4 bone_mat;
|
||||
mat4 bone_mat;
|
||||
mat4 normals_mat;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_bones {
|
||||
BoneData bones[16];
|
||||
BoneData bones[16];
|
||||
};
|
||||
|
||||
#include <sky.glsl>
|
||||
@ -47,17 +47,17 @@ uniform u_bones {
|
||||
out vec4 tgt_color;
|
||||
|
||||
void main() {
|
||||
// float distance = distance(vec3(cam_pos), focus_pos.xyz) - 2;
|
||||
// float distance = distance(vec3(cam_pos), focus_pos.xyz) - 2;
|
||||
|
||||
// float opacity = clamp(distance / distance_divider, 0, 1);
|
||||
// float opacity = clamp(distance / distance_divider, 0, 1);
|
||||
|
||||
// if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > opacity) {
|
||||
// discard;
|
||||
// }
|
||||
// if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > opacity) {
|
||||
// discard;
|
||||
// }
|
||||
|
||||
// if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > shadow_dithering) {
|
||||
// discard;
|
||||
// }
|
||||
// if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > shadow_dithering) {
|
||||
// discard;
|
||||
// }
|
||||
|
||||
tgt_color = vec4(0.0,0.0,0.0, 1.0);
|
||||
tgt_color = vec4(0.0,0.0,0.0, 1.0);
|
||||
}
|
||||
|
@ -20,12 +20,16 @@
|
||||
// Note: The sampler uniform is declared here because it differs for MSAA
|
||||
#include <anti-aliasing.glsl>
|
||||
#include <srgb.glsl>
|
||||
#include <cloud.glsl>
|
||||
|
||||
uniform sampler2D src_depth;
|
||||
|
||||
in vec2 f_pos;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec4 nul;
|
||||
mat4 proj_mat_inv;
|
||||
mat4 view_mat_inv;
|
||||
};
|
||||
|
||||
out vec4 tgt_color;
|
||||
@ -46,7 +50,7 @@ vec3 hsv2rgb(vec3 c) {
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
vec3 illuminate(float max_light, vec3 view_dir, /*vec3 max_light, */vec3 emitted, vec3 reflected) {
|
||||
vec3 _illuminate(float max_light, vec3 view_dir, /*vec3 max_light, */vec3 emitted, vec3 reflected) {
|
||||
const float NIGHT_EXPOSURE = 10.0;
|
||||
const float DUSK_EXPOSURE = 2.0;//0.8;
|
||||
const float DAY_EXPOSURE = 1.0;//0.7;
|
||||
@ -76,14 +80,14 @@ vec3 illuminate(float max_light, vec3 view_dir, /*vec3 max_light, */vec3 emitted
|
||||
// vec3 T = /*color*//*lum*/color;//normalize(color) * lum / (1.0 + lum);
|
||||
// float alpha = 0.5;//2.0;
|
||||
// float alpha = mix(
|
||||
// mix(
|
||||
// DUSK_EXPOSURE,
|
||||
// NIGHT_EXPOSURE,
|
||||
// max(sun_dir.z, 0)
|
||||
// ),
|
||||
// DAY_EXPOSURE,
|
||||
// max(-sun_dir.z, 0)
|
||||
// );
|
||||
// mix(
|
||||
// DUSK_EXPOSURE,
|
||||
// NIGHT_EXPOSURE,
|
||||
// max(sun_dir.z, 0)
|
||||
// ),
|
||||
// DAY_EXPOSURE,
|
||||
// max(-sun_dir.z, 0)
|
||||
// );
|
||||
float alpha = 1.0;//log(1.0 - lum) / lum;
|
||||
// vec3 now_light = moon_dir.z < 0 ? moon_dir : sun_dir;
|
||||
// float cos_view_light = dot(-now_light, view_dir);
|
||||
@ -119,14 +123,14 @@ vec3 illuminate(float max_light, vec3 view_dir, /*vec3 max_light, */vec3 emitted
|
||||
// const float s = 0.8;
|
||||
float s = 1.0;
|
||||
// float s = mix(
|
||||
// mix(
|
||||
// DUSK_SATURATION,
|
||||
// NIGHT_SATURATION,
|
||||
// max(sun_dir.z, 0)
|
||||
// ),
|
||||
// DAY_SATURATION,
|
||||
// max(-sun_dir.z, 0)
|
||||
// );
|
||||
// mix(
|
||||
// DUSK_SATURATION,
|
||||
// NIGHT_SATURATION,
|
||||
// max(sun_dir.z, 0)
|
||||
// ),
|
||||
// DAY_SATURATION,
|
||||
// max(-sun_dir.z, 0)
|
||||
// );
|
||||
// s = max(s, (max_light) / (1.0 + s));
|
||||
// s = max(s, max_light / (1.0 + max_light));
|
||||
// s = max_light / (1.0 + max_light);
|
||||
@ -141,12 +145,34 @@ vec3 illuminate(float max_light, vec3 view_dir, /*vec3 max_light, */vec3 emitted
|
||||
// return /*srgb_to_linear*/(/*0.5*//*0.125 * */vec3(pow(color.x, gamma), pow(color.y, gamma), pow(color.z, gamma)));
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 uv = (f_pos + 1.0) * 0.5;
|
||||
float depth_at(vec2 uv) {
|
||||
float buf_depth = texture(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;
|
||||
return -view_space.z;
|
||||
}
|
||||
|
||||
/* if (medium.x == 1u) {
|
||||
uv = clamp(uv + vec2(sin(uv.y * 16.0 + tick.x), sin(uv.x * 24.0 + tick.x)) * 0.005, 0, 1);
|
||||
} */
|
||||
vec3 wpos_at(vec2 uv) {
|
||||
float buf_depth = texture(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;
|
||||
view_space /= view_space.w;
|
||||
if (buf_depth == 1.0) {
|
||||
vec3 direction = normalize(view_space.xyz);
|
||||
return direction.xyz * 100000.0 + cam_pos.xyz;
|
||||
} else {
|
||||
return view_space.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 uv = (f_pos + 1.0) * 0.5;
|
||||
|
||||
/* if (medium.x == 1u) {
|
||||
uv = clamp(uv + vec2(sin(uv.y * 16.0 + tick.x), sin(uv.x * 24.0 + tick.x)) * 0.005, 0, 1);
|
||||
} */
|
||||
|
||||
vec2 c_uv = vec2(0.5);//uv;//vec2(0.5);//uv;
|
||||
vec2 delta = /*sqrt*//*sqrt(2.0) / 2.0*//*sqrt(2.0) / 2.0*//*0.5 - */min(uv, 1.0 - uv);//min(uv * (1.0 - uv), 0.25) * 2.0;
|
||||
@ -174,23 +200,47 @@ 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(src_color, uv * screen_res.xy, screen_res.xy);
|
||||
|
||||
// Apply clouds to `aa_color`
|
||||
#if (CLOUD_MODE != CLOUD_MODE_NONE)
|
||||
vec3 wpos = wpos_at(uv);
|
||||
float dist = distance(wpos, cam_pos.xyz);
|
||||
vec3 dir = (wpos - cam_pos.xyz) / dist;
|
||||
|
||||
aa_color.rgb = get_cloud_color(aa_color.rgb, dir, cam_pos.xyz, time_of_day.x, dist, 1.0);
|
||||
#endif
|
||||
|
||||
// aa_color.rgb = (wpos + focus_off.xyz) / vec3(32768, 32768, /*view_distance.w*/2048);
|
||||
// aa_color.rgb = mod((wpos + focus_off.xyz), vec3(32768, 32768, view_distance.w)) / vec3(32768, 32768, view_distance.w);// / vec3(32768, 32768, view_distance.w);
|
||||
// aa_color.rgb = mod((wpos + focus_off.xyz), vec3(32, 32, 16)) / vec3(32, 32, 16);// / vec3(32768, 32768, view_distance.w);
|
||||
// aa_color.rgb = focus_off.xyz / vec3(32768, 32768, view_distance.w);
|
||||
|
||||
/* aa_color.rgb = wpos / 10000.0; */
|
||||
|
||||
/* aa_color.rgb = vec3((texture(src_depth, uv).x - 0.99) * 100.0); */
|
||||
|
||||
/* aa_color.rgb = vec3((dist - 100000) / 300000.0, 1, 1); */
|
||||
|
||||
/* vec3 scatter_color = get_sun_color() * get_sun_brightness() + get_moon_color() * get_moon_brightness(); */
|
||||
|
||||
/* aa_color.rgb += cloud_color.rgb * scatter_color;//mix(aa_color, vec4(cloud_color.rgb * scatter_color, 1), cloud_color.a); */
|
||||
|
||||
// aa_color.rgb = illuminate(1.0 - 1.0 / (1.0 + bright_color), normalize(cam_pos.xyz - focus_pos.xyz), /*vec3 max_light, */vec3(0.0), aa_color.rgb);
|
||||
|
||||
//vec4 hsva_color = vec4(rgb2hsv(fxaa_color.rgb), fxaa_color.a);
|
||||
//hsva_color.y *= 1.45;
|
||||
//hsva_color.z *= 0.85;
|
||||
//hsva_color.z = 1.0 - 1.0 / (1.0 * hsva_color.z + 1.0);
|
||||
//vec4 final_color = vec4(hsv2rgb(hsva_color.rgb), hsva_color.a);
|
||||
//vec4 hsva_color = vec4(rgb2hsv(fxaa_color.rgb), fxaa_color.a);
|
||||
//hsva_color.y *= 1.45;
|
||||
//hsva_color.z *= 0.85;
|
||||
//hsva_color.z = 1.0 - 1.0 / (1.0 * hsva_color.z + 1.0);
|
||||
//vec4 final_color = vec4(hsv2rgb(hsva_color.rgb), hsva_color.a);
|
||||
|
||||
vec4 final_color = pow(aa_color, gamma);
|
||||
vec4 final_color = pow(aa_color, gamma);
|
||||
|
||||
#if (FLUID_MODE == FLUID_MODE_CHEAP)
|
||||
if (medium.x == 1u) {
|
||||
final_color *= vec4(0.2, 0.2, 0.8, 1.0);
|
||||
}
|
||||
if (medium.x == 1u) {
|
||||
final_color *= vec4(0.2, 0.2, 0.8, 1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
tgt_color = vec4(final_color.rgb, 1);
|
||||
tgt_color = vec4(final_color.rgb, 1);
|
||||
}
|
||||
|
@ -20,15 +20,10 @@
|
||||
|
||||
in vec2 v_pos;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec4 nul;
|
||||
};
|
||||
|
||||
out vec2 f_pos;
|
||||
|
||||
void main() {
|
||||
f_pos = v_pos;
|
||||
f_pos = v_pos;
|
||||
|
||||
gl_Position = vec4(v_pos, -1.0, 1.0);
|
||||
gl_Position = vec4(v_pos, -1.0, 1.0);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ in vec3 f_pos;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec4 nul;
|
||||
vec4 nul;
|
||||
};
|
||||
|
||||
out vec4 tgt_color;
|
||||
@ -32,9 +32,8 @@ out vec4 tgt_color;
|
||||
void main() {
|
||||
// tgt_color = vec4(MU_SCATTER, 1.0);
|
||||
// return;
|
||||
vec4 _clouds;
|
||||
|
||||
vec3 cam_dir = normalize(f_pos - cam_pos.xyz);
|
||||
vec3 cam_dir = normalize(f_pos - cam_pos.xyz);
|
||||
|
||||
float cam_alt = alt_at(cam_pos.xy);
|
||||
// float f_alt = alt_at(f_pos.xy);
|
||||
@ -47,17 +46,17 @@ void main() {
|
||||
// vec3 cam_attenuation = vec3(1.0);
|
||||
|
||||
|
||||
/* vec3 world_pos = cam_pos.xyz + cam_dir * 500000.0;
|
||||
tgt_color = vec4(get_sky_color(normalize(f_pos), time_of_day.x, cam_pos.xyz, world_pos, 1.0, true, _clouds), 1.0); */
|
||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||
/* vec3 world_pos = cam_pos.xyz + cam_dir * 500000.0;
|
||||
tgt_color = vec4(get_sky_color(normalize(f_pos), time_of_day.x, cam_pos.xyz, world_pos, 1.0, true, _clouds), 1.0); */
|
||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||
|
||||
float dist = 100000.0;
|
||||
float dist = 100000.0;
|
||||
|
||||
float refractionIndex = medium.x == 1u ? 1.0 / 1.3325 : 1.0;
|
||||
/* if (medium.x == 1u) {
|
||||
dist = UNDERWATER_MIST_DIST;
|
||||
} */
|
||||
vec3 wpos = cam_pos.xyz + /*normalize(f_pos)*/cam_dir * dist;
|
||||
float refractionIndex = medium.x == 1u ? 1.0 / 1.3325 : 1.0;
|
||||
/* if (medium.x == 1u) {
|
||||
dist = UNDERWATER_MIST_DIST;
|
||||
} */
|
||||
vec3 wpos = cam_pos.xyz + /*normalize(f_pos)*/cam_dir * dist;
|
||||
|
||||
tgt_color = vec4(cam_attenuation * get_sky_color(normalize(f_pos), time_of_day.x, cam_pos.xyz, wpos, 1.0, true, refractionIndex, _clouds), 1.0);
|
||||
tgt_color = vec4(cam_attenuation * get_sky_color(normalize(f_pos), time_of_day.x, cam_pos.xyz, wpos, 1.0, true, refractionIndex), 1.0);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ in vec3 v_pos;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec4 nul;
|
||||
vec4 nul;
|
||||
};
|
||||
|
||||
out vec3 f_pos;
|
||||
@ -30,20 +30,20 @@ out vec3 f_pos;
|
||||
void main() {
|
||||
/* vec3 v_pos = v_pos;
|
||||
v_pos.y = -v_pos.y; */
|
||||
f_pos = v_pos;
|
||||
f_pos = v_pos;
|
||||
|
||||
// TODO: Make this position-independent to avoid rounding error jittering
|
||||
gl_Position =
|
||||
/* proj_mat *
|
||||
view_mat * */
|
||||
// TODO: Make this position-independent to avoid rounding error jittering
|
||||
gl_Position =
|
||||
/* proj_mat *
|
||||
view_mat * */
|
||||
all_mat *
|
||||
/* proj_mat *
|
||||
view_mat * */
|
||||
vec4(/*100000 * */v_pos + cam_pos.xyz, 1);
|
||||
// vec4(v_pos * (100000.0/* + 0.5*/) + cam_pos.xyz, 1);
|
||||
vec4(/*100000 * */v_pos + cam_pos.xyz, 1);
|
||||
// vec4(v_pos * (100000.0/* + 0.5*/) + cam_pos.xyz, 1);
|
||||
// gl_Position = vec4(gl_Position.xy, sign(gl_Position.z) * gl_Position.w, gl_Position.w);
|
||||
gl_Position.z = gl_Position.w;
|
||||
// gl_Position.z = gl_Position.w - 0.000001;//0.0;
|
||||
// gl_Position.z = 1.0;
|
||||
// gl_Position.z = -1.0;
|
||||
gl_Position.z = gl_Position.w;
|
||||
// gl_Position.z = gl_Position.w - 0.000001;//0.0;
|
||||
// gl_Position.z = 1.0;
|
||||
// gl_Position.z = -1.0;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ in vec2 f_uv_pos;
|
||||
uniform sampler2D t_col_light;
|
||||
|
||||
//struct ShadowLocals {
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 texture_mat;
|
||||
//};
|
||||
//
|
||||
@ -65,7 +65,7 @@ void main() {
|
||||
// vec4 f_col_light = textureGrad(t_col_light, (f_uv_pos + 0.5) / textureSize(t_col_light, 0), vec2(0.5), vec2(0.5));
|
||||
vec4 f_col_light = texelFetch(t_col_light, ivec2(f_uv_pos)/* + uv_delta*//* - f_norm * 0.00001*/, 0);
|
||||
vec3 f_col = /*linear_to_srgb*//*srgb_to_linear*/(f_col_light.rgb);
|
||||
// vec3 f_col = vec3(1.0);
|
||||
// vec3 f_col = vec3(1.0);
|
||||
// vec2 texSize = textureSize(t_col_light, 0);
|
||||
// float f_ao = f_col_light.a;
|
||||
// float f_ao = f_col_light.a + length(vec2(dFdx(f_col_light.a), dFdy(f_col_light.a)));
|
||||
@ -75,8 +75,8 @@ void main() {
|
||||
|
||||
// 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);
|
||||
// tgt_color = vec4(f_uv_pos / texSize, 0.0, 1.0);
|
||||
// tgt_color = vec4(f_col.rgb, 1.0);
|
||||
// tgt_color = vec4(f_uv_pos / texSize, 0.0, 1.0);
|
||||
// tgt_color = vec4(f_col.rgb, 1.0);
|
||||
// return;
|
||||
// vec4 light_pos[2];
|
||||
//#if (SHADOW_MODE == SHADOW_MODE_MAP)
|
||||
@ -95,7 +95,7 @@ void main() {
|
||||
/* vec3 sun_dir = get_sun_dir(time_of_day.x);
|
||||
vec3 moon_dir = get_moon_dir(time_of_day.x); */
|
||||
// float sun_light = get_sun_brightness(sun_dir);
|
||||
// float moon_light = get_moon_brightness(moon_dir);
|
||||
// float moon_light = get_moon_brightness(moon_dir);
|
||||
|
||||
#if (SHADOW_MODE == SHADOW_MODE_CHEAP || SHADOW_MODE == SHADOW_MODE_MAP || FLUID_MODE == FLUID_MODE_SHINY)
|
||||
float f_alt = alt_at(f_pos.xy);
|
||||
@ -127,7 +127,7 @@ void main() {
|
||||
DirectionalLight sun_info = get_sun_info(sun_dir, point_shadow * sun_shade_frac, /*sun_pos*/f_pos);
|
||||
DirectionalLight moon_info = get_moon_info(moon_dir, point_shadow * moon_shade_frac/*, light_pos*/);
|
||||
|
||||
vec3 surf_color = /*srgb_to_linear*//*linear_to_srgb*/(f_col);
|
||||
vec3 surf_color = /*srgb_to_linear*//*linear_to_srgb*/(f_col);
|
||||
float alpha = 1.0;
|
||||
const float n2 = 1.5;
|
||||
const float R_s2s0 = pow((1.0 - n2) / (1.0 + n2), 2);
|
||||
@ -150,11 +150,11 @@ void main() {
|
||||
light_frac += light_reflection_factor(f_norm, view_dir, vec3(0.0, -1.0, 0.0), vec3(1.0), vec3(1.0), 2.0);
|
||||
light_frac += light_reflection_factor(f_norm, view_dir, vec3(0.0, 1.0, 0.0), vec3(1.0), vec3(1.0), 2.0); */
|
||||
|
||||
// vec3 light, diffuse_light, ambient_light;
|
||||
// vec3 light, diffuse_light, ambient_light;
|
||||
// vec3 emitted_light, reflected_light;
|
||||
// float point_shadow = shadow_at(f_pos,f_norm);
|
||||
// vec3 point_light = light_at(f_pos, f_norm);
|
||||
// vec3 surf_color = srgb_to_linear(vec3(0.2, 0.5, 1.0));
|
||||
// float point_shadow = shadow_at(f_pos,f_norm);
|
||||
// vec3 point_light = light_at(f_pos, f_norm);
|
||||
// vec3 surf_color = srgb_to_linear(vec3(0.2, 0.5, 1.0));
|
||||
// vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||
float max_light = 0.0;
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, /*time_of_day.x, *//*cam_to_frag*/view_dir, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, k_d, k_s, alpha, emitted_light, reflected_light);
|
||||
@ -164,12 +164,12 @@ void main() {
|
||||
// emitted_light *= point_shadow;
|
||||
// reflected_light *= point_shadow;
|
||||
// max_light *= point_shadow;
|
||||
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||
// float point_shadow = shadow_at(f_pos, f_norm);
|
||||
// diffuse_light *= f_light * point_shadow;
|
||||
// ambient_light *= f_light * point_shadow;
|
||||
// light += point_light;
|
||||
// diffuse_light += point_light;
|
||||
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||
// float point_shadow = shadow_at(f_pos, f_norm);
|
||||
// diffuse_light *= f_light * point_shadow;
|
||||
// ambient_light *= f_light * point_shadow;
|
||||
// light += point_light;
|
||||
// diffuse_light += point_light;
|
||||
// reflected_light += point_light;
|
||||
|
||||
max_light += lights_at(f_pos, f_norm, view_dir, k_a, k_d, k_s, alpha, emitted_light, reflected_light);
|
||||
@ -177,23 +177,14 @@ void main() {
|
||||
emitted_light += point_light;
|
||||
reflected_light += point_light; */
|
||||
|
||||
// float ao = /*pow(f_ao, 0.5)*/f_ao * 0.85 + 0.15;
|
||||
// float ao = /*pow(f_ao, 0.5)*/f_ao * 0.85 + 0.15;
|
||||
float ao = f_ao;
|
||||
emitted_light *= ao;
|
||||
reflected_light *= ao;
|
||||
emitted_light *= ao;
|
||||
reflected_light *= ao;
|
||||
|
||||
surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light) * f_light;
|
||||
// vec3 surf_color = illuminate(f_col, light, diffuse_light, ambient_light);
|
||||
surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light) * f_light;
|
||||
// vec3 surf_color = illuminate(f_col, light, diffuse_light, ambient_light);
|
||||
|
||||
#if (CLOUD_MODE == CLOUD_MODE_REGULAR)
|
||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||
vec4 clouds;
|
||||
vec3 fog_color = get_sky_color(cam_to_frag/*view_dir*/, time_of_day.x, cam_pos.xyz, f_pos, 0.5, false, clouds);
|
||||
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
vec3 color = surf_color;
|
||||
#endif
|
||||
|
||||
// tgt_color = vec4(color, 1.0);
|
||||
tgt_color = vec4(color, 1.0 - clamp((distance(focus_pos.xy, f_pos.xy) - (sprite_render_distance - FADE_DIST)) / FADE_DIST, 0, 1));
|
||||
// tgt_color = vec4(color, 1.0);
|
||||
tgt_color = vec4(surf_color, 1.0 - clamp((distance(focus_pos.xy, f_pos.xy) - (sprite_render_distance - FADE_DIST)) / FADE_DIST, 0, 1));
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ uniform sampler2D t_col_light;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec3 model_offs;
|
||||
float load_time;
|
||||
vec3 model_offs;
|
||||
float load_time;
|
||||
ivec4 atlas_offs;
|
||||
};
|
||||
|
||||
@ -64,8 +64,8 @@ void main() {
|
||||
// vec4 f_col_light = textureGrad(t_col_light, f_uv_pos / texSize, 0.25, 0.25);
|
||||
// vec4 f_col_light = texture(t_col_light, (f_uv_pos) / texSize);
|
||||
|
||||
// First 3 normals are negative, next 3 are positive
|
||||
const vec3 normals[8] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1), vec3(0,0,0), vec3(0,0,0));
|
||||
// First 3 normals are negative, next 3 are positive
|
||||
const vec3 normals[8] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1), vec3(0,0,0), vec3(0,0,0));
|
||||
|
||||
// uint norm_index = (f_pos_norm >> 29) & 0x7u;
|
||||
// vec2 uv_delta = (norm_index & 0u) == 0u ? vec2(-1.0) : vec2(0);
|
||||
@ -77,7 +77,7 @@ void main() {
|
||||
// float f_light = f_col_light.a;
|
||||
// vec4 f_col_light = texelFetch(t_col_light, ivec2(int(f_uv_pos.x), int(f_uv_pos.y)/* + uv_delta*//* - f_norm * 0.00001*/), 0);
|
||||
vec3 f_col = /*linear_to_srgb*//*srgb_to_linear*/(f_col_light.rgb);
|
||||
// vec3 f_col = vec3(1.0);
|
||||
// vec3 f_col = vec3(1.0);
|
||||
float f_light = texture(t_col_light, (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;
|
||||
// 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;
|
||||
@ -109,9 +109,9 @@ void main() {
|
||||
// tgt_color = vec4(light_shadow_count.x <= 31u ? f_col : vec3(0.0), 1.0);
|
||||
// tgt_color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
// float sum = 0.0;
|
||||
// for (uint i = 0u; i < /* 6 * */light_shadow_count.x; i ++) {
|
||||
// for (uint i = 0u; i < /* 6 * */light_shadow_count.x; i ++) {
|
||||
// // uint i = 1u;
|
||||
// Light L = lights[i/* / 6*/];
|
||||
// Light L = lights[i/* / 6*/];
|
||||
|
||||
// /* vec4 light_col = vec4(
|
||||
// hash(vec4(1.0, 0.0, 0.0, i)),
|
||||
@ -123,10 +123,10 @@ void main() {
|
||||
// float light_strength = L.light_col.a / 255.0;
|
||||
// // float light_strength = 1.0 / light_shadow_count.x;
|
||||
|
||||
// vec3 light_pos = L.light_pos.xyz;
|
||||
// vec3 light_pos = L.light_pos.xyz;
|
||||
|
||||
// // Pre-calculate difference between light and fragment
|
||||
// vec3 fragToLight = f_pos - light_pos;
|
||||
// // Pre-calculate difference between light and fragment
|
||||
// vec3 fragToLight = f_pos - light_pos;
|
||||
|
||||
// // vec3 f_norm = normals[(f_pos_norm >> 29) & 0x7u];
|
||||
|
||||
@ -151,14 +151,14 @@ void main() {
|
||||
// sum += light_strength;
|
||||
// }
|
||||
|
||||
// TODO: last 3 bits in v_pos_norm should be a number between 0 and 5, rather than 0-2 and a direction.
|
||||
// uint norm_axis = (f_pos_norm >> 30) & 0x3u;
|
||||
// // Increase array access by 3 to access positive values
|
||||
// uint norm_dir = ((f_pos_norm >> 29) & 0x1u) * 3u;
|
||||
// Use an array to avoid conditional branching
|
||||
// TODO: last 3 bits in v_pos_norm should be a number between 0 and 5, rather than 0-2 and a direction.
|
||||
// uint norm_axis = (f_pos_norm >> 30) & 0x3u;
|
||||
// // Increase array access by 3 to access positive values
|
||||
// uint norm_dir = ((f_pos_norm >> 29) & 0x1u) * 3u;
|
||||
// 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 f_norm = normals[norm_index];
|
||||
vec3 f_norm = normals[(f_pos_norm >> 29) & 0x7u];
|
||||
// vec3 du = dFdx(f_pos);
|
||||
// vec3 dv = dFdy(f_pos);
|
||||
// vec3 f_norm = normalize(cross(du, dv));
|
||||
@ -205,7 +205,7 @@ void main() {
|
||||
vec3 k_s = vec3(R_s);
|
||||
|
||||
// float sun_light = get_sun_brightness(sun_dir);
|
||||
// float moon_light = get_moon_brightness(moon_dir);
|
||||
// float moon_light = get_moon_brightness(moon_dir);
|
||||
/* float sun_shade_frac = horizon_at(f_pos, sun_dir);
|
||||
float moon_shade_frac = horizon_at(f_pos, moon_dir); */
|
||||
// float f_alt = alt_at(f_pos.xy);
|
||||
@ -264,31 +264,31 @@ void main() {
|
||||
|
||||
// float f_ao = 1.0;
|
||||
|
||||
// float ao = /*pow(f_ao, 0.5)*/f_ao * 0.9 + 0.1;
|
||||
// emitted_light *= ao;
|
||||
// reflected_light *= ao;
|
||||
// float ao = /*pow(f_ao, 0.5)*/f_ao * 0.9 + 0.1;
|
||||
// emitted_light *= ao;
|
||||
// reflected_light *= ao;
|
||||
/* vec3 point_light = light_at(f_pos, f_norm);
|
||||
emitted_light += point_light;
|
||||
reflected_light += point_light; */
|
||||
|
||||
// float point_shadow = shadow_at(f_pos, f_norm);
|
||||
// vec3 point_light = light_at(f_pos, f_norm);
|
||||
// vec3 light, diffuse_light, ambient_light;
|
||||
// float point_shadow = shadow_at(f_pos, f_norm);
|
||||
// vec3 point_light = light_at(f_pos, f_norm);
|
||||
// vec3 light, diffuse_light, ambient_light;
|
||||
|
||||
// get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, k_a * f_light, k_d * f_light, k_s * f_light, alpha, emitted_light, reflected_light);
|
||||
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||
// float point_shadow = shadow_at(f_pos, f_norm);
|
||||
// diffuse_light *= f_light * point_shadow;
|
||||
// ambient_light *= f_light * point_shadow;
|
||||
// vec3 point_light = light_at(f_pos, f_norm);
|
||||
// light += point_light;
|
||||
// diffuse_light += point_light;
|
||||
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||
// float point_shadow = shadow_at(f_pos, f_norm);
|
||||
// diffuse_light *= f_light * point_shadow;
|
||||
// ambient_light *= f_light * point_shadow;
|
||||
// vec3 point_light = light_at(f_pos, f_norm);
|
||||
// light += point_light;
|
||||
// diffuse_light += point_light;
|
||||
// reflected_light += point_light;
|
||||
// reflected_light += light_reflection_factor(norm, cam_to_frag, , vec3 k_d, vec3 k_s, float alpha) {
|
||||
|
||||
// light_reflection_factorplight_reflection_factor
|
||||
|
||||
// vec3 surf_color = illuminate(srgb_to_linear(f_col), light, diffuse_light, ambient_light);
|
||||
// vec3 surf_color = illuminate(srgb_to_linear(f_col), light, diffuse_light, ambient_light);
|
||||
vec3 f_chunk_pos = f_pos - (model_offs - focus_off.xyz);
|
||||
float noise = hash(vec4(floor(f_chunk_pos * 3.0 - f_norm * 0.5), 0));//0.005/* - 0.01*/;
|
||||
|
||||
@ -356,18 +356,9 @@ void main() {
|
||||
// vec3 col = (f_col + noise_delta);
|
||||
vec3 col = noise_delta * noise_delta * W_2;
|
||||
// vec3 col = srgb_to_linear(linear_to_srgb(f_col) + noise * 0.02);
|
||||
// vec3 col = /*srgb_to_linear*/(f_col + noise); // Small-scale noise
|
||||
// vec3 col = /*srgb_to_linear*/(f_col + hash(vec4(floor(f_pos * 3.0 - f_norm * 0.5), 0)) * 0.01); // Small-scale noise
|
||||
// vec3 col = /*srgb_to_linear*/(f_col + noise); // Small-scale noise
|
||||
// vec3 col = /*srgb_to_linear*/(f_col + hash(vec4(floor(f_pos * 3.0 - f_norm * 0.5), 0)) * 0.01); // Small-scale noise
|
||||
vec3 surf_color = illuminate(max_light, view_dir, col * emitted_light, col * reflected_light);
|
||||
|
||||
#if (CLOUD_MODE == CLOUD_MODE_REGULAR)
|
||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||
vec4 clouds;
|
||||
vec3 fog_color = get_sky_color(cam_to_frag/*view_dir*/, time_of_day.x, cam_pos.xyz, f_pos, 1.0, false, clouds);
|
||||
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
vec3 color = surf_color;
|
||||
#endif
|
||||
|
||||
tgt_color = vec4(color, 1.0);
|
||||
tgt_color = vec4(surf_color, 1.0);
|
||||
}
|
||||
|
@ -30,13 +30,13 @@ in uint v_atlas_pos;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec3 model_offs;
|
||||
float load_time;
|
||||
vec3 model_offs;
|
||||
float load_time;
|
||||
ivec4 atlas_offs;
|
||||
};
|
||||
|
||||
//struct ShadowLocals {
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 shadowMatrices;
|
||||
// mat4 texture_mat;
|
||||
//};
|
||||
//
|
||||
@ -69,12 +69,12 @@ const int EXTRA_NEG_Z = 32768;
|
||||
|
||||
void main() {
|
||||
// over it (if this vertex to see if it intersects.
|
||||
// f_chunk_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0xFFFFu)) - ivec3(0, 0, EXTRA_NEG_Z));
|
||||
vec3 f_chunk_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0xFFFFu)) - ivec3(0, 0, EXTRA_NEG_Z));
|
||||
f_pos = f_chunk_pos + model_offs - focus_off.xyz;
|
||||
// f_chunk_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0xFFFFu)) - ivec3(0, 0, EXTRA_NEG_Z));
|
||||
vec3 f_chunk_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0xFFFFu)) - ivec3(0, 0, EXTRA_NEG_Z));
|
||||
f_pos = f_chunk_pos + model_offs - focus_off.xyz;
|
||||
|
||||
// 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));
|
||||
// f_pos.z -= min(32.0, 25.0 * pow(distance(focus_pos.xy, f_pos.xy) / view_distance.x, 20.0));
|
||||
|
||||
// vec3 light_col = vec3(
|
||||
// hash(floor(vec4(f_chunk_pos.x, 0, 0, 0))),
|
||||
@ -82,12 +82,12 @@ void main() {
|
||||
// hash(floor(vec4(0, 0, f_chunk_pos.z, 2)))
|
||||
// );
|
||||
|
||||
// f_col = light_col;// f_col = vec3((uvec3(v_col_light) >> uvec3(8, 16, 24)) & uvec3(0xFFu)) / 255.0;
|
||||
// f_light = 1.0;//float(v_col_light & 0x3Fu) / 64.0;
|
||||
// f_ao = 1.0;//float((v_col_light >> 6u) & 3u) / 4.0;
|
||||
// f_col = f_col = vec3((uvec3(v_col_light) >> uvec3(8, 16, 24)) & uvec3(0xFFu)) / 255.0;
|
||||
// f_light = float(v_col_light & 0x3Fu) / 64.0;
|
||||
// f_ao = float((v_col_light >> 6u) & 3u) / 4.0;
|
||||
// f_col = light_col;// f_col = vec3((uvec3(v_col_light) >> uvec3(8, 16, 24)) & uvec3(0xFFu)) / 255.0;
|
||||
// f_light = 1.0;//float(v_col_light & 0x3Fu) / 64.0;
|
||||
// f_ao = 1.0;//float((v_col_light >> 6u) & 3u) / 4.0;
|
||||
// f_col = f_col = vec3((uvec3(v_col_light) >> uvec3(8, 16, 24)) & uvec3(0xFFu)) / 255.0;
|
||||
// f_light = float(v_col_light & 0x3Fu) / 64.0;
|
||||
// f_ao = float((v_col_light >> 6u) & 3u) / 4.0;
|
||||
|
||||
// for (uint i = 0u; i < 1u/*light_shadow_count.z*/; ++i) {
|
||||
// light_pos[i] = vec3(shadowMats[i].texture_mat * vec4(f_pos, 1.0));
|
||||
@ -105,7 +105,7 @@ void main() {
|
||||
// #endif
|
||||
|
||||
// #ifdef FLUID_MODE_SHINY
|
||||
f_pos_norm = v_pos_norm;
|
||||
f_pos_norm = v_pos_norm;
|
||||
// #endif
|
||||
|
||||
// Also precalculate shadow texture and estimated terrain altitude.
|
||||
@ -150,22 +150,22 @@ void main() {
|
||||
// vec3 newRay = dot(wRayDir, wRayNormal) < 0.0 && wIntersectsSurface ? wPoint - wRayDir3 * wRayLength * n2 / n1 : f_pos;// - (wRayfinal - wPoint) * n2 / n1; // wPoint + n2 * (wRayfinal - wPoint) - n2 / n1 * wRayLength * wRayDir3;
|
||||
|
||||
#ifdef HAS_SHADOW_MAPS
|
||||
gl_Position =
|
||||
/*all_mat*/shadowMats[0].shadowMatrices/*texture_mat*/ *
|
||||
vec4(f_pos/*newRay*/, 1);
|
||||
gl_Position =
|
||||
/*all_mat*/shadowMats[0].shadowMatrices/*texture_mat*/ *
|
||||
vec4(f_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(f_pos/*newRay*/, 1);
|
||||
#endif
|
||||
// gl_Position.y /= gl_Position.w;
|
||||
// gl_Position.w = 1.0;
|
||||
// gl_Position.z = -gl_Position.z;
|
||||
// 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;
|
||||
// gl_Position.z = gl_Position.z / 100.0;
|
||||
// gl_Position.z = gl_Position.z / 10000.0;
|
||||
// gl_Position.z = -gl_Position.z / 100.0;
|
||||
// gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
|
||||
// gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
|
||||
// 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;
|
||||
// gl_Position.z = gl_Position.z / 100.0;
|
||||
// gl_Position.z = gl_Position.z / 10000.0;
|
||||
// gl_Position.z = -gl_Position.z / 100.0;
|
||||
// gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
|
||||
// gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ flat in uint f_mode;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec4 w_pos;
|
||||
vec4 w_pos;
|
||||
};
|
||||
|
||||
uniform sampler2D u_tex;
|
||||
|
@ -10,7 +10,7 @@ in uint v_mode;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec4 w_pos;
|
||||
vec4 w_pos;
|
||||
};
|
||||
|
||||
uniform sampler2D u_tex;
|
||||
|
@ -2052,12 +2052,27 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.cloud_mode_text, ui);
|
||||
|
||||
let mode_list = [CloudMode::None, CloudMode::Regular];
|
||||
let mode_list = [
|
||||
CloudMode::None,
|
||||
CloudMode::Minimal,
|
||||
CloudMode::Low,
|
||||
CloudMode::Medium,
|
||||
CloudMode::High,
|
||||
];
|
||||
let mode_label_list = [
|
||||
&self.localized_strings.get("common.none"),
|
||||
&self
|
||||
.localized_strings
|
||||
.get("hud.settings.cloud_rendering_mode.regular"),
|
||||
.get("hud.settings.cloud_rendering_mode.minimal"),
|
||||
&self
|
||||
.localized_strings
|
||||
.get("hud.settings.cloud_rendering_mode.low"),
|
||||
&self
|
||||
.localized_strings
|
||||
.get("hud.settings.cloud_rendering_mode.medium"),
|
||||
&self
|
||||
.localized_strings
|
||||
.get("hud.settings.cloud_rendering_mode.high"),
|
||||
];
|
||||
|
||||
// Get which cloud rendering mode is currently active
|
||||
|
@ -137,11 +137,14 @@ pub enum CloudMode {
|
||||
/// *every* fragment shader. For machines that can't optimize the check,
|
||||
/// this is absurdly expensive, so we should look at alternatives in the
|
||||
/// future that player better with the GPU.
|
||||
Regular,
|
||||
Minimal,
|
||||
Low,
|
||||
Medium,
|
||||
High,
|
||||
}
|
||||
|
||||
impl Default for CloudMode {
|
||||
fn default() -> Self { CloudMode::Regular }
|
||||
fn default() -> Self { CloudMode::Medium }
|
||||
}
|
||||
|
||||
/// Fluid modes
|
||||
|
@ -71,7 +71,7 @@ gfx_defines! {
|
||||
light_shadows: gfx::ConstantBuffer<shadow::Locals> = "u_light_shadows",
|
||||
|
||||
tgt_color: gfx::BlendTarget<TgtColorFmt> = ("tgt_color", ColorMask::all(), gfx::preset::blend::ALPHA),
|
||||
tgt_depth_stencil: gfx::DepthTarget<TgtDepthStencilFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
|
||||
tgt_depth_stencil: gfx::DepthTarget<TgtDepthStencilFmt> = gfx::preset::depth::LESS_EQUAL_TEST,
|
||||
// tgt_depth_stencil: gfx::DepthStencilTarget<TgtDepthStencilFmt> = (gfx::preset::depth::LESS_EQUAL_WRITE,Stencil::new(Comparison::Always,0xff,(StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))),
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
use super::{
|
||||
super::{Mesh, Pipeline, Tri, WinColorFmt, WinDepthFmt},
|
||||
super::{Mesh, Pipeline, TgtColorFmt, TgtDepthStencilFmt, Tri, WinColorFmt},
|
||||
Globals,
|
||||
};
|
||||
use gfx::{
|
||||
self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta, gfx_pipeline,
|
||||
gfx_pipeline_inner, gfx_vertex_struct_meta,
|
||||
};
|
||||
use vek::*;
|
||||
|
||||
gfx_defines! {
|
||||
vertex Vertex {
|
||||
@ -13,7 +14,8 @@ gfx_defines! {
|
||||
}
|
||||
|
||||
constant Locals {
|
||||
nul: [f32; 4] = "nul",
|
||||
proj_mat_inv: [[f32; 4]; 4] = "proj_mat_inv",
|
||||
view_mat_inv: [[f32; 4]; 4] = "view_mat_inv",
|
||||
}
|
||||
|
||||
pipeline pipe {
|
||||
@ -22,15 +24,30 @@ gfx_defines! {
|
||||
locals: gfx::ConstantBuffer<Locals> = "u_locals",
|
||||
globals: gfx::ConstantBuffer<Globals> = "u_globals",
|
||||
|
||||
src_sampler: gfx::TextureSampler<<WinColorFmt as gfx::format::Formatted>::View> = "src_color",
|
||||
map: gfx::TextureSampler<[f32; 4]> = "t_map",
|
||||
alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
|
||||
horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon",
|
||||
|
||||
color_sampler: gfx::TextureSampler<<TgtColorFmt as gfx::format::Formatted>::View> = "src_color",
|
||||
depth_sampler: gfx::TextureSampler<<TgtDepthStencilFmt as gfx::format::Formatted>::View> = "src_depth",
|
||||
|
||||
noise: gfx::TextureSampler<f32> = "t_noise",
|
||||
|
||||
tgt_color: gfx::RenderTarget<WinColorFmt> = "tgt_color",
|
||||
tgt_depth: gfx::DepthTarget<WinDepthFmt> = gfx::preset::depth::PASS_TEST,
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Locals {
|
||||
fn default() -> Self { Self::new(Mat4::identity(), Mat4::identity()) }
|
||||
}
|
||||
|
||||
impl Locals {
|
||||
pub fn default() -> Self { Self { nul: [0.0; 4] } }
|
||||
pub fn new(proj_mat_inv: Mat4<f32>, view_mat_inv: Mat4<f32>) -> Self {
|
||||
Self {
|
||||
proj_mat_inv: proj_mat_inv.into_col_arrays(),
|
||||
view_mat_inv: view_mat_inv.into_col_arrays(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PostProcessPipeline;
|
||||
|
@ -83,6 +83,12 @@ pub type TgtColorRes = gfx::handle::ShaderResourceView<
|
||||
<TgtColorFmt as gfx::format::Formatted>::View,
|
||||
>;
|
||||
|
||||
/// A handle to a render depth target as a resource.
|
||||
pub type TgtDepthRes = gfx::handle::ShaderResourceView<
|
||||
gfx_backend::Resources,
|
||||
<TgtDepthStencilFmt as gfx::format::Formatted>::View,
|
||||
>;
|
||||
|
||||
/// A handle to a greedy meshed color-light texture as a resource.
|
||||
pub type ColLightRes = gfx::handle::ShaderResourceView<
|
||||
gfx_backend::Resources,
|
||||
@ -144,6 +150,7 @@ pub struct Renderer {
|
||||
tgt_depth_stencil_view: TgtDepthStencilView,
|
||||
|
||||
tgt_color_res: TgtColorRes,
|
||||
tgt_depth_res: TgtDepthRes,
|
||||
|
||||
sampler: Sampler<gfx_backend::Resources>,
|
||||
|
||||
@ -218,7 +225,7 @@ impl Renderer {
|
||||
&mut shader_reload_indicator,
|
||||
)?;
|
||||
|
||||
let (tgt_color_view, tgt_depth_stencil_view, tgt_color_res) =
|
||||
let (tgt_color_view, tgt_depth_stencil_view, tgt_color_res, tgt_depth_res) =
|
||||
Self::create_rt_views(&mut factory, (dims.0, dims.1), &mode)?;
|
||||
|
||||
let shadow_map = if let (
|
||||
@ -281,6 +288,7 @@ impl Renderer {
|
||||
tgt_depth_stencil_view,
|
||||
|
||||
tgt_color_res,
|
||||
tgt_depth_res,
|
||||
|
||||
sampler,
|
||||
|
||||
@ -355,9 +363,10 @@ impl Renderer {
|
||||
|
||||
// Avoid panics when creating texture with w,h of 0,0.
|
||||
if dims.0 != 0 && dims.1 != 0 {
|
||||
let (tgt_color_view, tgt_depth_stencil_view, tgt_color_res) =
|
||||
let (tgt_color_view, tgt_depth_stencil_view, tgt_color_res, tgt_depth_res) =
|
||||
Self::create_rt_views(&mut self.factory, (dims.0, dims.1), &self.mode)?;
|
||||
self.tgt_color_res = tgt_color_res;
|
||||
self.tgt_depth_res = tgt_depth_res;
|
||||
self.tgt_color_view = tgt_color_view;
|
||||
self.tgt_depth_stencil_view = tgt_depth_stencil_view;
|
||||
if let (Some(shadow_map), ShadowMode::Map(mode)) =
|
||||
@ -394,7 +403,7 @@ impl Renderer {
|
||||
factory: &mut gfx_device_gl::Factory,
|
||||
size: (u16, u16),
|
||||
mode: &RenderMode,
|
||||
) -> Result<(TgtColorView, TgtDepthStencilView, TgtColorRes), RenderError> {
|
||||
) -> Result<(TgtColorView, TgtDepthStencilView, TgtColorRes, TgtDepthRes), RenderError> {
|
||||
let kind = match mode.aa {
|
||||
AaMode::None | AaMode::Fxaa => {
|
||||
gfx::texture::Kind::D2(size.0, size.1, gfx::texture::AaMode::Single)
|
||||
@ -435,14 +444,24 @@ impl Renderer {
|
||||
let tgt_depth_stencil_tex = factory.create_texture(
|
||||
kind,
|
||||
levels,
|
||||
gfx::memory::Bind::DEPTH_STENCIL,
|
||||
gfx::memory::Bind::SHADER_RESOURCE | gfx::memory::Bind::DEPTH_STENCIL,
|
||||
gfx::memory::Usage::Data,
|
||||
Some(depth_stencil_cty),
|
||||
)?;
|
||||
let tgt_depth_res = factory.view_texture_as_shader_resource::<TgtDepthStencilFmt>(
|
||||
&tgt_depth_stencil_tex,
|
||||
(0, levels - 1),
|
||||
gfx::format::Swizzle::new(),
|
||||
)?;
|
||||
let tgt_depth_stencil_view =
|
||||
factory.view_texture_as_depth_stencil_trivial(&tgt_depth_stencil_tex)?;
|
||||
|
||||
Ok((tgt_color_view, tgt_depth_stencil_view, tgt_color_res))
|
||||
Ok((
|
||||
tgt_color_view,
|
||||
tgt_depth_stencil_view,
|
||||
tgt_color_res,
|
||||
tgt_depth_res,
|
||||
))
|
||||
}
|
||||
|
||||
/// Create textures and views for shadow maps.
|
||||
@ -1629,6 +1648,7 @@ impl Renderer {
|
||||
model: &Model<postprocess::PostProcessPipeline>,
|
||||
globals: &Consts<Globals>,
|
||||
locals: &Consts<postprocess::Locals>,
|
||||
lod: &lod_terrain::LodData,
|
||||
) {
|
||||
self.encoder.draw(
|
||||
&gfx::Slice {
|
||||
@ -1643,9 +1663,13 @@ impl Renderer {
|
||||
vbuf: model.vbuf.clone(),
|
||||
locals: locals.buf.clone(),
|
||||
globals: globals.buf.clone(),
|
||||
src_sampler: (self.tgt_color_res.clone(), self.sampler.clone()),
|
||||
map: (lod.map.srv.clone(), lod.map.sampler.clone()),
|
||||
alt: (lod.alt.srv.clone(), lod.alt.sampler.clone()),
|
||||
horizon: (lod.horizon.srv.clone(), lod.horizon.sampler.clone()),
|
||||
color_sampler: (self.tgt_color_res.clone(), self.sampler.clone()),
|
||||
depth_sampler: (self.tgt_depth_res.clone(), self.sampler.clone()),
|
||||
noise: (self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()),
|
||||
tgt_color: self.win_color_view.clone(),
|
||||
tgt_depth: self.win_depth_view.clone(),
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -1715,12 +1739,15 @@ fn create_pipelines(
|
||||
},
|
||||
match mode.cloud {
|
||||
CloudMode::None => "CLOUD_MODE_NONE",
|
||||
CloudMode::Regular => "CLOUD_MODE_REGULAR",
|
||||
CloudMode::Minimal => "CLOUD_MODE_MINIMAL",
|
||||
CloudMode::Low => "CLOUD_MODE_LOW",
|
||||
CloudMode::Medium => "CLOUD_MODE_MEDIUM",
|
||||
CloudMode::High => "CLOUD_MODE_HIGH",
|
||||
},
|
||||
match mode.lighting {
|
||||
LightingMode::Ashikhmin => "LIGHTING_ALGORITHM_ASHIKHMIN",
|
||||
LightingMode::BlinnPhong => "LIGHTING_ALGORITHM_BLINN_PHONG",
|
||||
LightingMode::Lambertian => "CLOUD_MODE_NONE",
|
||||
LightingMode::Lambertian => "LIGHTING_ALGORITHM_LAMBERTIAN",
|
||||
},
|
||||
match mode.shadow {
|
||||
ShadowMode::None => "SHADOW_MODE_NONE",
|
||||
@ -1745,7 +1772,7 @@ fn create_pipelines(
|
||||
let cloud = Glsl::load_watched(
|
||||
&["voxygen.shaders.include.cloud.", match mode.cloud {
|
||||
CloudMode::None => "none",
|
||||
CloudMode::Regular => "regular",
|
||||
_ => "regular",
|
||||
}]
|
||||
.concat(),
|
||||
shader_reload_indicator,
|
||||
|
@ -27,7 +27,9 @@ impl Default for CameraMode {
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Dependents {
|
||||
pub view_mat: Mat4<f32>,
|
||||
pub view_mat_inv: Mat4<f32>,
|
||||
pub proj_mat: Mat4<f32>,
|
||||
pub proj_mat_inv: Mat4<f32>,
|
||||
pub cam_pos: Vec3<f32>,
|
||||
pub cam_dir: Vec3<f32>,
|
||||
}
|
||||
@ -67,7 +69,9 @@ impl Camera {
|
||||
|
||||
dependents: Dependents {
|
||||
view_mat: Mat4::identity(),
|
||||
view_mat_inv: Mat4::identity(),
|
||||
proj_mat: Mat4::identity(),
|
||||
proj_mat_inv: Mat4::identity(),
|
||||
cam_pos: Vec3::zero(),
|
||||
cam_dir: Vec3::unit_y(),
|
||||
},
|
||||
@ -112,9 +116,11 @@ impl Camera {
|
||||
* Mat4::rotation_y(self.ori.x)
|
||||
* Mat4::rotation_3d(PI / 2.0, -Vec4::unit_x())
|
||||
* Mat4::translation_3d(-self.focus.map(|e| e.fract()));
|
||||
self.dependents.view_mat_inv = self.dependents.view_mat.inverted();
|
||||
|
||||
self.dependents.proj_mat =
|
||||
Mat4::perspective_rh_no(self.fov, self.aspect, NEAR_PLANE, FAR_PLANE);
|
||||
self.dependents.proj_mat_inv = self.dependents.proj_mat.inverted();
|
||||
|
||||
// TODO: Make this more efficient.
|
||||
self.dependents.cam_pos = Vec3::from(self.dependents.view_mat.inverted() * Vec4::unit_w());
|
||||
|
@ -523,7 +523,9 @@ impl Scene {
|
||||
self.camera.compute_dependents(&*scene_data.state.terrain());
|
||||
let camera::Dependents {
|
||||
view_mat,
|
||||
view_mat_inv,
|
||||
proj_mat,
|
||||
proj_mat_inv,
|
||||
cam_pos,
|
||||
..
|
||||
} = self.camera.dependents();
|
||||
@ -662,6 +664,12 @@ impl Scene {
|
||||
scene_data.sprite_render_distance as f32 - 20.0,
|
||||
)])
|
||||
.expect("Failed to update global constants");
|
||||
renderer
|
||||
.update_consts(&mut self.postprocess.locals, &[PostProcessLocals::new(
|
||||
proj_mat_inv,
|
||||
view_mat_inv,
|
||||
)])
|
||||
.expect("Failed to update post-process locals");
|
||||
|
||||
// Maintain LoD.
|
||||
self.lod.maintain(renderer);
|
||||
@ -1071,6 +1079,7 @@ impl Scene {
|
||||
&self.postprocess.model,
|
||||
&global.globals,
|
||||
&self.postprocess.locals,
|
||||
self.lod.get_data(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -380,6 +380,7 @@ impl Scene {
|
||||
&self.postprocess.model,
|
||||
&self.data.globals,
|
||||
&self.postprocess.locals,
|
||||
&self.lod,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user