Created
October 23, 2025 07:18
-
-
Save tombasche/49395619a28446aef8aaf9eff83a5a66 to your computer and use it in GitHub Desktop.
Gerstner wave shader include
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| float3 GerstnerWave(float3 position, float steepness, float wavelength, float speed, float direction, inout float3 tangent, inout float3 binormal) | |
| { | |
| direction = direction * 2 - 1; | |
| float2 d = normalize(float2(cos(3.14 * direction), sin(3.14 * direction))); | |
| float k = 2 * 3.14 / wavelength; | |
| float f = k * (dot(d, position.xz) - speed * _Time.y); | |
| float a = steepness / k; | |
| tangent += float3( | |
| -d.x * d.x * (steepness * sin(f)), | |
| d.x * (steepness * cos(f)), | |
| -d.x * d.y * (steepness * sin(f)) | |
| ); | |
| binormal += float3( | |
| -d.x * d.y * (steepness * sin(f)), | |
| d.y * (steepness * cos(f)), | |
| -d.y * d.y * (steepness * sin(f)) | |
| ); | |
| return float3( | |
| d.x * (a * cos(f)), | |
| a * sin(f), | |
| d.y * (a * cos(f)) | |
| ); | |
| } | |
| void GerstnerWaves_float(float3 position, float steepness, float wavelength, float speed, float4 directions, out float3 Offset, out float3 normal) | |
| { | |
| Offset = 0; | |
| float3 tangent = float3(1, 0, 0); | |
| float3 binormal = float3(0, 0, 1); | |
| Offset += GerstnerWave(position, steepness, wavelength, speed, directions.x, tangent, binormal); | |
| Offset += GerstnerWave(position, steepness, wavelength, speed, directions.y, tangent, binormal); | |
| Offset += GerstnerWave(position, steepness, wavelength, speed, directions.z, tangent, binormal); | |
| Offset += GerstnerWave(position, steepness, wavelength, speed, directions.w, tangent, binormal); | |
| normal = normalize(cross(binormal, tangent)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment