From a2fc417be6865065723dd2b846bc28e7e61798cf Mon Sep 17 00:00:00 2001 From: Tom Boullay Date: Thu, 28 May 2026 01:12:21 +0200 Subject: [PATCH] fix(environment): preserve grass blade colors --- src/world/grass/GrassPatch.tsx | 7 ++++++- src/world/grass/grassConfig.ts | 1 + src/world/grass/grassShaders.ts | 5 ++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/world/grass/GrassPatch.tsx b/src/world/grass/GrassPatch.tsx index e1a6c68..2ef1902 100644 --- a/src/world/grass/GrassPatch.tsx +++ b/src/world/grass/GrassPatch.tsx @@ -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, diff --git a/src/world/grass/grassConfig.ts b/src/world/grass/grassConfig.ts index fa6a805..599e09d 100644 --- a/src/world/grass/grassConfig.ts +++ b/src/world/grass/grassConfig.ts @@ -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; diff --git a/src/world/grass/grassShaders.ts b/src/world/grass/grassShaders.ts index dbbb527..3f8b461 100644 --- a/src/world/grass/grassShaders.ts +++ b/src/world/grass/grassShaders.ts @@ -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);