37 lines
1.4 KiB
GLSL
37 lines
1.4 KiB
GLSL
// MinecraftPT — CausticsTex_CS
|
|
// Generates a caustics normal field texture (pixelData2D) used by water voxels.
|
|
|
|
#include "/Lib/Settings.glsl"
|
|
#include "/Lib/Utilities.glsl"
|
|
|
|
const ivec3 workGroups = ivec3(16, 16, 1);
|
|
layout (local_size_x = 32, local_size_y = 32) in;
|
|
|
|
layout (rg16f) uniform writeonly image2D img_pixelData2D;
|
|
|
|
void main(){
|
|
ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
|
|
vec2 uv = (vec2(texel) + 0.5) / vec2(512.0, 513.0);
|
|
|
|
float time = frameTimeCounter * 0.05;
|
|
|
|
// Analytic caustics field (sum of moving sine waves)
|
|
vec2 coord = uv * 32.0;
|
|
float n1 = sin(coord.x * 2.0 + time * 3.0) * cos(coord.y * 1.7 - time * 2.0);
|
|
float n2 = sin(coord.x * 1.3 - time * 1.5) * cos(coord.y * 2.4 + time * 2.5);
|
|
float n3 = sin((coord.x + coord.y) * 3.1 + time * 4.0) * 0.5;
|
|
|
|
float field = n1 * 0.5 + n2 * 0.3 + n3 * 0.2;
|
|
|
|
// Normal from field gradient
|
|
float eps = 0.01;
|
|
float fx = sin((coord.x + eps) * 2.0 + time * 3.0) * cos(coord.y * 1.7 - time * 2.0);
|
|
float fxx = sin((coord.x - eps) * 2.0 + time * 3.0) * cos(coord.y * 1.7 - time * 2.0);
|
|
float fy = sin(coord.x * 2.0 + time * 3.0) * cos((coord.y + eps) * 1.7 - time * 2.0);
|
|
float fyy = sin(coord.x * 2.0 + time * 3.0) * cos((coord.y - eps) * 1.7 - time * 2.0);
|
|
|
|
vec2 normal = vec2((fx - fxx) * 0.5 / eps, (fy - fyy) * 0.5 / eps) * 0.2;
|
|
normal = tanh(normal);
|
|
|
|
imageStore(img_pixelData2D, texel, vec4(normal * 0.5 + 0.5, 0.0, 0.0));
|
|
} |