2025-01-31 14:55:49 -05:00
|
|
|
shader_type spatial;
|
2025-02-02 00:09:30 -05:00
|
|
|
render_mode world_vertex_coords;
|
2025-01-31 14:55:49 -05:00
|
|
|
|
|
|
|
uniform vec3 color = vec3(0.1, 0.4, 0.8);
|
2025-02-02 00:09:30 -05:00
|
|
|
uniform float reflectiveness = 10.0;
|
2025-01-31 14:55:49 -05:00
|
|
|
uniform float foamHeight = 0.2;
|
|
|
|
uniform sampler2D foamTex;
|
|
|
|
|
|
|
|
const int WAVE_COUNT = 6;
|
|
|
|
uniform float amplitudes[WAVE_COUNT];
|
|
|
|
uniform float waveSpeeds[WAVE_COUNT];
|
|
|
|
uniform float xAmplifiers[WAVE_COUNT];
|
|
|
|
uniform float yAmplifiers[WAVE_COUNT];
|
|
|
|
|
|
|
|
varying float yOffset;
|
|
|
|
|
|
|
|
float calcHeight(float x, float y){
|
|
|
|
float offset = 0.0;
|
|
|
|
for (int i = 0; i < WAVE_COUNT; i++){
|
2025-02-02 00:09:30 -05:00
|
|
|
offset += amplitudes[i] * pow(E, sin((waveSpeeds[i] * TIME) + (xAmplifiers[i] * (x)) + (yAmplifiers[i] * (y))));
|
2025-01-31 14:55:49 -05:00
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vertex() {
|
|
|
|
yOffset = VERTEX.y;
|
2025-02-02 15:40:03 -05:00
|
|
|
vec3 b = vec3(VERTEX.x + 0.001, VERTEX.y + calcHeight(VERTEX.x + 0.001, VERTEX.z), VERTEX.z);
|
|
|
|
vec3 c = vec3(VERTEX.x, VERTEX.y + calcHeight(VERTEX.x, VERTEX.z + 0.001), VERTEX.z + 0.001);
|
2025-02-02 00:09:30 -05:00
|
|
|
VERTEX.y += calcHeight(VERTEX.x, VERTEX.z);
|
2025-02-02 15:40:03 -05:00
|
|
|
NORMAL = normalize(cross(c - VERTEX, b - VERTEX));
|
2025-01-31 14:55:49 -05:00
|
|
|
yOffset += VERTEX.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fragment() {
|
2025-02-02 00:09:30 -05:00
|
|
|
ALBEDO = color * clamp(0.8 + yOffset, 0.2, 2);
|
2025-01-31 14:55:49 -05:00
|
|
|
float strength = yOffset * texture(foamTex, UV).r;
|
|
|
|
if (strength >= foamHeight) ALBEDO = ALBEDO + vec3(1, 1, 1) * (strength + foamHeight);
|
2025-02-02 00:09:30 -05:00
|
|
|
//ALPHA = 0.9;
|
|
|
|
//ALBEDO = (NORMAL + 1.0) / 2.0;
|
2025-01-31 14:55:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//void light() {
|
2025-02-02 00:09:30 -05:00
|
|
|
//DIFFUSE_LIGHT += clamp(dot(NORMAL, LIGHT), 0.0, 1.0) * ATTENUATION * LIGHT_COLOR;
|
|
|
|
//vec3 halfVector = normalize(normalize(VIEW) + normalize(LIGHT));
|
|
|
|
//SPECULAR_LIGHT += clamp(pow(dot(NORMAL, halfVector), reflectiveness), 0.0, 1.0) * LIGHT_COLOR;
|
2025-01-31 14:55:49 -05:00
|
|
|
//}
|