Gras Shader Problem gelöst

This commit is contained in:
2026-07-15 19:09:49 +02:00
parent 975161e2cc
commit cdaaba3841
2 changed files with 11 additions and 11 deletions

View File

@@ -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;

View File

@@ -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;
}
}