2024-04-05 20:29:18 +03:00
|
|
|
shader_type spatial;
|
2024-05-12 18:29:56 +03:00
|
|
|
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx, shadows_disabled;
|
2024-04-05 20:29:18 +03:00
|
|
|
|
|
|
|
uniform vec4 data[100];
|
|
|
|
uniform int data_size: hint_range(0, 100, 1);
|
2024-04-07 15:17:52 +03:00
|
|
|
uniform float alpha: hint_range(0.0, 1.0, 0.1) = 0.3;
|
2024-04-05 20:29:18 +03:00
|
|
|
uniform sampler2D color_gradient;
|
|
|
|
|
2024-04-23 00:47:56 +03:00
|
|
|
uniform float roughness : hint_range(0.0, 1.0) = 0.15;
|
|
|
|
uniform vec4 edge_color : source_color = vec4(0.0, 0.0, 0.0, 1.0);
|
|
|
|
|
2024-04-05 20:29:18 +03:00
|
|
|
varying vec3 color;
|
|
|
|
|
2024-04-07 15:17:52 +03:00
|
|
|
float simple_weight(int index, vec3 world_pos, float p) {
|
|
|
|
return 1.0 / pow(distance(data[index].xyz, world_pos), p);
|
|
|
|
}
|
2024-04-05 20:29:18 +03:00
|
|
|
|
2024-04-07 15:17:52 +03:00
|
|
|
float sphere_weight(int index, vec3 world_pos, float r) {
|
|
|
|
float dist = distance(data[index].xyz, world_pos);
|
|
|
|
return pow(max(0, r - dist) / (r * dist), 2);
|
|
|
|
}
|
2024-04-05 20:29:18 +03:00
|
|
|
|
2024-04-23 00:47:56 +03:00
|
|
|
float SchlickFresnel(float u) {
|
|
|
|
float m = 1.0 - u;
|
|
|
|
float m2 = m * m;
|
|
|
|
return m2 * m2 * m;
|
|
|
|
}
|
|
|
|
|
2024-04-05 20:29:18 +03:00
|
|
|
void vertex() {
|
2024-05-12 18:29:56 +03:00
|
|
|
color = vec3(0.9, 0.9, 0.9);
|
2024-05-22 19:38:28 +03:00
|
|
|
|
2024-04-05 20:29:18 +03:00
|
|
|
if(data_size > 0) {
|
2024-04-10 14:23:17 +03:00
|
|
|
float distances[100];
|
|
|
|
float dist_sum = 0.0;
|
|
|
|
float data_sum = 0.0;
|
2024-05-22 19:38:28 +03:00
|
|
|
|
2024-04-10 14:23:17 +03:00
|
|
|
float closest_dist = -1.0;
|
|
|
|
int closest_index = 0;
|
2024-05-22 19:38:28 +03:00
|
|
|
|
2024-04-10 14:23:17 +03:00
|
|
|
// Calculate Global Coordinates
|
|
|
|
//vec3 world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
|
2024-05-22 19:38:28 +03:00
|
|
|
|
2024-04-10 14:23:17 +03:00
|
|
|
closest_dist = distance(data[0].xyz, VERTEX);
|
2024-05-22 19:38:28 +03:00
|
|
|
|
2024-04-07 15:17:52 +03:00
|
|
|
// Inverse distance weighting using Shepard's method
|
2024-04-05 20:29:18 +03:00
|
|
|
for(int i = 0; i < data_size; i++) {
|
2024-04-10 14:23:17 +03:00
|
|
|
distances[i] = sphere_weight(i, VERTEX, 5.0);
|
2024-04-07 15:17:52 +03:00
|
|
|
dist_sum += distances[i];
|
|
|
|
data_sum += distances[i] * data[i].w;
|
2024-05-22 19:38:28 +03:00
|
|
|
|
2024-04-10 14:23:17 +03:00
|
|
|
float dist = distance(data[i].xyz, VERTEX);
|
2024-05-22 19:38:28 +03:00
|
|
|
|
2024-04-07 15:17:52 +03:00
|
|
|
if(dist < closest_dist) {
|
|
|
|
closest_dist = dist;
|
|
|
|
closest_index = i;
|
|
|
|
}
|
2024-04-05 20:29:18 +03:00
|
|
|
}
|
2024-05-22 19:38:28 +03:00
|
|
|
|
2024-04-07 15:17:52 +03:00
|
|
|
float value = (1.0 / dist_sum) * data_sum;
|
2024-05-22 19:38:28 +03:00
|
|
|
|
2024-04-07 15:17:52 +03:00
|
|
|
if( value > 0.0 || value < 1.0) {
|
|
|
|
color.xyz = texture(color_gradient, vec2(value, 0)).xyz;
|
|
|
|
} else {
|
|
|
|
color.xyz = texture(color_gradient, vec2(data[closest_index].w, 0)).xyz;
|
2024-04-05 20:29:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fragment() {
|
|
|
|
ALBEDO = vec3(color.xyz);
|
2024-05-12 18:29:56 +03:00
|
|
|
//ALPHA = alpha;
|
2024-05-22 19:38:28 +03:00
|
|
|
|
2024-04-23 00:47:56 +03:00
|
|
|
float VdotN = dot(VIEW, NORMAL);
|
|
|
|
float fresnel = clamp(SchlickFresnel(VdotN), 0.0, 1.0);
|
2024-05-22 19:38:28 +03:00
|
|
|
|
2024-04-23 00:47:56 +03:00
|
|
|
// apply glass look
|
2024-05-12 18:29:56 +03:00
|
|
|
//float a = mix(0.001, 1.0, ALPHA);
|
|
|
|
//ALPHA = mix(fresnel * edge_color.a, 1.0, a);
|
|
|
|
//ALBEDO = mix(edge_color.rgb * edge_color.a, ALBEDO, a);
|
2024-04-23 00:47:56 +03:00
|
|
|
ROUGHNESS = roughness;
|
2024-05-12 18:29:56 +03:00
|
|
|
//SPECULAR = 0.5 * inversesqrt(ALPHA);
|
2024-05-24 22:08:27 +03:00
|
|
|
DEPTH = FRAGCOORD.z + 0.0001;
|
2024-04-25 16:40:56 +03:00
|
|
|
}
|