Repository navigation
Conversation
| // Sample both wave directions independently | ||
| let wave_a = sample_directional_wave(p, time, material.wave_dir_a); | ||
| let wave_b = sample_directional_wave(p, time, material.wave_dir_b); | ||
|
|
||
| // Asymmetric smoothstep - old waves fade out faster than new waves fade in | ||
| // This mimics how energy dissipates faster than it builds, looking more natural | ||
| let blend = smoothstep(0.0, 0.85, material.wave_blend); | ||
|
|
||
| // Blend wave patterns - NOT rotating, just fading between independent patterns | ||
| let d = mix(wave_a, wave_b, blend); |
There was a problem hiding this comment.
It would be better to blend the wave directions (A, B) on the CPU instead of here. Also the Rust wave_height code doesn't do the same blending of sampled waves as this, which would cause "boat physics" to be wrong.
Calling sample_directional_wave multiple times increases the cost of the shader, which is a problem for some mobile/lower powered GPUs. That is the reason for the QUALITY_* defs.
There was a problem hiding this comment.
If this blending must be done in the shader, then #ifdef should be used to enable/disable the extra sampling based on the wave_blend value. You can look at how the QUALITY_... defs are done.
| // Sample both wave directions independently | |
| let wave_a = sample_directional_wave(p, time, material.wave_dir_a); | |
| let wave_b = sample_directional_wave(p, time, material.wave_dir_b); | |
| // Asymmetric smoothstep - old waves fade out faster than new waves fade in | |
| // This mimics how energy dissipates faster than it builds, looking more natural | |
| let blend = smoothstep(0.0, 0.85, material.wave_blend); | |
| // Blend wave patterns - NOT rotating, just fading between independent patterns | |
| let d = mix(wave_a, wave_b, blend); | |
| #ifdef BLEND_WAVE_DIRECTION | |
| // Sample both wave directions independently | |
| let wave_a = sample_directional_wave(p, time, material.wave_dir_a); | |
| let wave_b = sample_directional_wave(p, time, material.wave_dir_b); | |
| // Asymmetric smoothstep - old waves fade out faster than new waves fade in | |
| // This mimics how energy dissipates faster than it builds, looking more natural | |
| let blend = smoothstep(0.0, 0.85, material.wave_blend); | |
| // Blend wave patterns - NOT rotating, just fading between independent patterns | |
| let d = mix(wave_a, wave_b, blend); | |
| #else | |
| let d = sample_directional_wave(p, time, material.wave_dir_a); | |
| #endif |
Also could you add an example that showcases wave blending.
There was a problem hiding this comment.
I'm thinking the blending must be done in the shader? Namely because it does a crossfade to make the transition look smooth and natural. Without it, it looks like the whole sea is just rotating in place. And I'm not sure that could be done on the CPU
There was a problem hiding this comment.
I am wonder if the wave_blend should be a vertex attribute, this would allow having a transition region between two different wave directions (currents). As a vertex attribute the GPU would smooth the blend value across the water tile.
| // Snapshot current blended state as "old" direction | ||
| self.dir_a = self.current_blended(); | ||
| self.dir_b = normalized; |
There was a problem hiding this comment.
I noticed that this will cause a "jump" in the water direction when done during an active blend. I had tried to fix it, but then realized that snapshotting the current blend is going reset the water to the direction it was "blending" between, but without the blending. So that causes the water to visually "jump".
There was a problem hiding this comment.
Thank you! I've been trying to figure out where that jump came from... I'll close this PR in favor of yours then
Implements part of #2 - change wave direction. I'm not sure the waves look 100% identical to before, but they're still pretty close to my eyes..
Note that there are two extra commits from #41 since I needed some update code from there so I based it on that PR. So that one should be reviewed + merged prior to this.