veloren/assets/voxygen/shaders/terrain-vert.glsl

89 lines
4.0 KiB
Plaintext
Raw Normal View History

2019-01-14 23:13:58 +00:00
#version 330 core
#include <globals.glsl>
2019-08-04 21:07:29 +00:00
#include <srgb.glsl>
2020-04-12 22:29:59 +00:00
#include <lod.glsl>
2019-06-03 21:35:03 +00:00
in uint v_pos_norm;
in uint v_col_light;
2019-01-14 23:13:58 +00:00
layout (std140)
uniform u_locals {
vec3 model_offs;
2019-09-24 15:43:51 +00:00
float load_time;
2019-01-14 23:13:58 +00:00
};
out vec3 f_pos;
out vec3 f_chunk_pos;
2020-01-19 23:59:02 +00:00
flat out uint f_pos_norm;
2020-05-01 20:58:55 +00:00
// out float f_alt;
// out vec4 f_shadow;
2019-01-14 23:13:58 +00:00
out vec3 f_col;
2019-05-31 20:37:11 +00:00
out float f_light;
out float f_ao;
2019-01-14 23:13:58 +00:00
2020-04-28 18:49:03 +00:00
const int EXTRA_NEG_Z = 32768;
2019-01-14 23:13:58 +00:00
void main() {
2020-05-01 20:58:55 +00:00
// over it (if this vertex to see if it intersects.
2020-04-28 18:49:03 +00:00
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;
2020-04-16 01:40:09 +00:00
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));
2019-09-24 15:43:51 +00:00
2020-01-21 12:57:59 +00:00
f_col = vec3((uvec3(v_col_light) >> uvec3(8, 16, 24)) & uvec3(0xFFu)) / 255.0;
2019-01-14 23:13:58 +00:00
f_light = float(v_col_light & 0x3Fu) / 64.0;
f_ao = float((v_col_light >> 6u) & 3u) / 4.0;
2019-05-31 20:37:11 +00:00
2020-01-19 23:59:02 +00:00
f_pos_norm = v_pos_norm;
2020-04-12 22:29:59 +00:00
// Also precalculate shadow texture and estimated terrain altitude.
2020-05-01 20:58:55 +00:00
// f_alt = alt_at(f_pos.xy);
// f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
// IDEA: Cast a ray from the vertex to the camera (if this vertex is above the camera) or from the camera to the vertex (if this
// vertex is below the camera) to see where it intersects the plane of water. All of this only applies if either the terrain
// vertex is in water, or the camera is in water.
//
// If an intersection is found, refract the ray across the barrier using the correct ratio of indices of refraction (1 / N_WATER
// if the vertex is above the camera [ray is going from air to water], N_WATER if the camera is above the vertex
// [ray is going from water to air]).
//
// In order to make sure that terrain and other objects below such an interface are properly renered, we then "un-refract" by
// reversing the refracted vector, and multiplying that by the distance from the object from which we cast the ray to the
// intersectng point, in order to make the object appear to the viewer where it should after refraction.
// bool faces_fluid = bool((f_pos_norm >> 28) & 0x1u);
// // TODO: Measure real water surface altitude here.
// float surfaceAlt = faces_fluid ? max(ceil(f_pos.z), floor(f_alt)) : /*floor(f_alt);*/mix(view_distance.z, min(f_alt, floor(alt_at_real(cam_pos.xy))), medium.x);
// 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;
// vec3 wRayNormal = surfaceAlt < wRayinitial.z ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 0.0, -1.0);
// float n_camera = mix(1.0, 1.3325, medium.x);
// float n_vertex = faces_fluid ? 1.3325 : 1.0;
// float n1 = n_vertex; // cam_pos.z < f_pos.z ? n_vertex : n_camera;
// float n2 = n_camera; // cam_pos.z < f_pos.z ? n_camera : n_vertex;
// float wRayLength0 = length(wRayfinal - wRayinitial);
// vec3 wRayDir = (wRayfinal - wRayinitial) / wRayLength0;
// vec3 wPoint = wRayfinal;
// bool wIntersectsSurface = IntersectRayPlane(wRayinitial, wRayDir, vec3(0.0, 0.0, surfaceAlt), -wRayNormal, wPoint);
// float wRayLength = length(wPoint - wRayinitial);
// wPoint = wRayLength < wRayLength0 ? wPoint : wRayfinal;
// wRayLength = min(wRayLength, wRayLength0); // min(max_length, dot(wRayfinal - wpos, defaultpos - wpos));
// // vec3 wRayDir2 = (wRayfinal - wRayinitial) / wRayLength;
// vec3 wRayDir3 = (dot(wRayDir, wRayNormal) < 0.0 && wIntersectsSurface) ? refract(wRayDir, wRayNormal, n2 / n1) : wRayDir;
// // wPoint -= wRayDir3 * wRayLength * n2 / n1;
// 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;
2020-04-12 22:29:59 +00:00
2019-01-14 23:13:58 +00:00
gl_Position =
2020-01-21 12:57:59 +00:00
all_mat *
2020-05-01 20:58:55 +00:00
vec4(f_pos/*newRay*/, 1);
// gl_Position.z = -gl_Position.z / 100.0;
gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
2019-08-28 18:32:44 +00:00
}