fix(environment): preserve grass blade colors
🔍 Lint / 🪄 Check lint (pull_request) Has been cancelled
🔍 Lint / 🎨 Check format (pull_request) Has been cancelled
🔍 Lint / 🔎 Typecheck (pull_request) Has been cancelled
📊 Quality / 🔒 Security Audit (pull_request) Has been cancelled
📊 Quality / 📋 Dependency Freshness (pull_request) Has been cancelled
📊 Quality / 📦 Bundle Size (pull_request) Has been cancelled
🔍 Lint / 🏗 Build (pull_request) Has been cancelled

This commit is contained in:
Tom Boullay
2026-05-28 01:12:21 +02:00
parent 57498b9bb1
commit a2fc417be6
3 changed files with 9 additions and 4 deletions
+6 -1
View File
@@ -3,7 +3,11 @@ import { useTexture } from "@react-three/drei";
import { useFrame, useThree } from "@react-three/fiber";
import * as THREE from "three";
import { useWind } from "@/hooks/world/useWind";
import { GRASS_COLORS, GRASS_CONFIG } from "@/world/grass/grassConfig";
import {
GRASS_BASE_COLOR,
GRASS_COLORS,
GRASS_CONFIG,
} from "@/world/grass/grassConfig";
import {
grassFragmentShader,
grassVertexShader,
@@ -125,6 +129,7 @@ function createGrassMaterial(
uDiffuseMap: { value: grassTexture },
uHeightMap: { value: terrainSampler.heightTexture },
uPlayerPosition: { value: new THREE.Vector3() },
uBaseBladeColor: { value: new THREE.Color(GRASS_BASE_COLOR) },
uBoundingBoxMin: {
value: new THREE.Vector3(
terrainSampler.bounds.minX,
+1
View File
@@ -33,3 +33,4 @@ export const GRASS_CONFIG = {
} as const;
export const GRASS_COLORS = ["#84C66B", "#67B058", "#A3CA5B"] as const;
export const GRASS_BASE_COLOR = "#1A3A1A" as const;
+2 -3
View File
@@ -7,6 +7,7 @@ export const grassVertexShader = /* glsl */ `
uniform float uTime;
uniform vec3 uPlayerPosition;
uniform vec3 uBaseBladeColor;
uniform sampler2D uHeightMap;
uniform sampler2D uDiffuseMap;
uniform sampler2D uNoiseTexture;
@@ -136,9 +137,7 @@ export const grassVertexShader = /* glsl */ `
float width = smoothstep(0.02, uMaxBladeHeight * 0.85, heightModifier) * uBladeWidth * bladeVisibility;
transformed += aYaw * (width / 2.0) * sideFactor;
vec3 textureColor = texture2D(uDiffuseMap, terrainUv * 10.0).rgb;
vec3 colorNoise = texture2D(uNoiseTexture, terrainUv.yx * vec2(uHeightNoiseFrequency) + (uTime * 0.1)).rgb;
vColor = mix(aBladeColor * 0.55, aBladeColor, tipFactor) * textureColor * mix(vec3(0.75), vec3(1.15), colorNoise);
vColor = mix(uBaseBladeColor, aBladeColor, tipFactor);
float distanceFromCenter = length(origin.xz) / halfPatchSize;
float innerCircleFactor = clamp(smoothstep(0.0, 0.5, distanceFromCenter), 0.0, 1.0);