Initial commit: Minecraft 光追着色器包(从零实现的 path tracing)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// MinecraftPT — Water Waves
|
||||
// Gerstner-style water wave normals with multi-octave detail.
|
||||
|
||||
#ifndef WATER_WAVES_GLSL
|
||||
#define WATER_WAVES_GLSL
|
||||
|
||||
vec3 GetWaveNormal(vec3 worldPos, float lightmap){
|
||||
vec2 pos = worldPos.xz;
|
||||
|
||||
float time = frameTimeCounter * 0.05 * WAVE_SPEED;
|
||||
|
||||
// Multi-octave sine waves
|
||||
float wave1 = sin(pos.x * 0.1 * WAVE_SCALE + time) * cos(pos.y * 0.08 * WAVE_SCALE + time * 0.7);
|
||||
float wave2 = sin(pos.x * 0.2 * WAVE_SCALE + time * 1.3) * cos(pos.y * 0.15 * WAVE_SCALE - time * 0.9);
|
||||
float wave3 = sin((pos.x + pos.y) * 0.35 * WAVE_SCALE + time * 1.7) * 0.5;
|
||||
|
||||
// Height field derivatives for normal
|
||||
float dx = cos(pos.x * 0.1 * WAVE_SCALE + time) * 0.1 * WAVE_SCALE * 0.5 * 0.05
|
||||
+ cos(pos.x * 0.2 * WAVE_SCALE + time * 1.3) * 0.2 * WAVE_SCALE * 0.5 * 0.04;
|
||||
float dz = -sin(pos.x * 0.1 * WAVE_SCALE + time) * sin(pos.y * 0.08 * WAVE_SCALE + time * 0.7) * 0.08 * WAVE_SCALE * 0.5 * 0.05
|
||||
- sin(pos.x * 0.2 * WAVE_SCALE + time * 1.3) * sin(pos.y * 0.15 * WAVE_SCALE - time * 0.9) * 0.15 * WAVE_SCALE * 0.5 * 0.04;
|
||||
|
||||
vec3 normal = normalize(vec3(-dx, 1.0, -dz) * WAVE_NORMAL_STRENGTH + vec3(0.0, 1.0 - WAVE_NORMAL_STRENGTH, 0.0));
|
||||
|
||||
return normal;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user