From cdaaba3841200bd93fe657540e1b7bdc7126281b Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 15 Jul 2026 19:09:49 +0200 Subject: [PATCH] =?UTF-8?q?Gras=20Shader=20Problem=20gel=C3=B6st?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/Shaders/GrassVertex.vert | 9 ++++----- .../blight/game/state/GrassVertexRenderState.java | 13 +++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/blight-assets/src/main/resources/Shaders/GrassVertex.vert b/blight-assets/src/main/resources/Shaders/GrassVertex.vert index 73a8227..b3a18d1 100644 --- a/blight-assets/src/main/resources/Shaders/GrassVertex.vert +++ b/blight-assets/src/main/resources/Shaders/GrassVertex.vert @@ -9,7 +9,7 @@ uniform vec2 m_WindDir; // normierter XZ-Windvektor in vec3 inPosition; in vec3 inNormal; in vec4 inColor; -in vec2 inTexCoord; // .x = windFactor (0 = Wurzel, 1 = Spitze) +in vec2 inTexCoord; // .x = windFactor (0=Wurzel, 1=Spitze) .y = randPhase (pro Halm, aus Java gebacken) out vec4 varColor; out vec3 varNormal; @@ -25,12 +25,11 @@ void main() { // Windrichtung (Fallback: Süd) vec2 windN = (dot(m_WindDir, m_WindDir) > 0.001) ? normalize(m_WindDir) : vec2(0.0, 1.0); - // Wellenfront: Position entlang der Windachse → Halme in Windrichtung erreicht der Impuls später + // randPhase in Java aus der Halm-Wurzel gebacken (hash(bx,bz)*2π) → identisch für + // alle Vertices desselben Halms, kein Breitenflackern bei starkem Wind. + float randPhase = inTexCoord.y; float wavePhase = dot(worldXZ, windN); - // Zufälliger Phasenversatz pro Halm (Spatial-Hash → kein synchrones Schwingen) - float randPhase = fract(sin(dot(worldXZ, vec2(127.1, 311.7))) * 43758.5453) * 6.2832; - float sway = sin(t * 2.1 + wavePhase * 0.10 + randPhase) * 0.6 + sin(t * 1.4 + wavePhase * 0.06 + randPhase * 0.73) * 0.4; diff --git a/blight-game/src/main/java/de/blight/game/state/GrassVertexRenderState.java b/blight-game/src/main/java/de/blight/game/state/GrassVertexRenderState.java index cfa1521..69d1e6d 100644 --- a/blight-game/src/main/java/de/blight/game/state/GrassVertexRenderState.java +++ b/blight-game/src/main/java/de/blight/game/state/GrassVertexRenderState.java @@ -419,8 +419,8 @@ public class GrassVertexRenderState extends BaseAppState // ── Mesh-Logik (gespiegelt zu GrassVertexState) ─────────────────────────── - private static void buildTuft(float[] pos, float[] nrm, float[] col, float[] tex, int[] idx, - int vi, int ii, GrassVertexBlade blade) { + private static void buildTuft(float[] pos, float[] nrm, float[] col, float[] tex, + int[] idx, int vi, int ii, GrassVertexBlade blade) { float x = blade.x(), y = blade.y(), z = blade.z(), h = blade.height(); float baseHW = h * WIDTH_FACTOR * 0.5f; float tAngle = (float) (((x * 127.1f + z * 311.7f) % (Math.PI * 2) + Math.PI * 2) % (Math.PI * 2)); @@ -481,8 +481,9 @@ public class GrassVertexRenderState extends BaseAppState int svi = bladeVi + s * 2; float dry = blade.dryness(); - setV(pos, nrm, col, tex, svi, spX - cosA * hw, spY, spZ - sinA * hw, nx, ny, nz, t, dry); - setV(pos, nrm, col, tex, svi+1, spX + cosA * hw, spY, spZ + sinA * hw, nx, ny, nz, t, dry); + float bladePhase = hash(bx, bz) * 6.2832f; + setV(pos, nrm, col, tex, svi, spX - cosA * hw, spY, spZ - sinA * hw, nx, ny, nz, t, bladePhase, dry); + setV(pos, nrm, col, tex, svi+1, spX + cosA * hw, spY, spZ + sinA * hw, nx, ny, nz, t, bladePhase, dry); if (s < SEGMENTS) { int sii = bladeIi + s * 6; @@ -505,7 +506,7 @@ public class GrassVertexRenderState extends BaseAppState private static void setV(float[] pos, float[] nrm, float[] col, float[] tex, int vi, float x, float y, float z, float nx, float ny, float nz, - float wf, float dryness) { + float wf, float bladePhase, float dryness) { int pi = vi * 3; pos[pi] = x; pos[pi+1] = y; pos[pi+2] = z; @@ -538,7 +539,7 @@ public class GrassVertexRenderState extends BaseAppState col[ci] = fr; col[ci+1] = fg; col[ci+2] = fb; col[ci+3] = 1f; int ti = vi * 2; - tex[ti] = wf; tex[ti+1] = 0f; + tex[ti] = wf; tex[ti+1] = bladePhase; } }