Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix grass shader demo build errors #62

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/grass-shader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dev": "vite --host",
"dev3": "e2e-dev $npm_package_name",
"build": "tsc && vite build",
"bbuild2": "tsc && e2e-build $npm_package_name",
"build2": "tsc && e2e-build $npm_package_name",
"preview": "vite preview"
},
"browserslist": [
Expand Down
15 changes: 7 additions & 8 deletions demos/grass-shader/src/Grass.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as THREE from "three"
import React, { useRef, useMemo } from "react"
import SimplexNoise from "simplex-noise"
import { useFrame, useLoader } from "@react-three/fiber"
import { Geometry } from "three/examples/jsm/deprecated/Geometry"
//These have been taken from "Realistic real-time grass rendering" by Eddie Lee, 2010
import bladeDiffuse from "./resources/blade_diffuse.jpg"
import bladeAlpha from "./resources/blade_alpha.jpg"
Expand All @@ -16,17 +15,17 @@ export default function Grass({ options = { bW: 0.12, bH: 1, joints: 5 }, width
const materialRef = useRef()
const [texture, alphaMap] = useLoader(THREE.TextureLoader, [bladeDiffuse, bladeAlpha])
const attributeData = useMemo(() => getAttributeData(instances, width), [instances, width])
const baseGeom = useMemo(() => new THREE.PlaneBufferGeometry(bW, bH, 1, joints).translate(0, bH / 2, 0), [options])
const baseGeom = useMemo(() => new THREE.PlaneGeometry(bW, bH, 1, joints).translate(0, bH / 2, 0), [options])
const groundGeo = useMemo(() => {
const geo = new Geometry().fromBufferGeometry(new THREE.PlaneGeometry(width, width, 32, 32))
geo.verticesNeedUpdate = true
const geo = new THREE.PlaneGeometry(width, width, 32, 32)
geo.attributes.position.needsUpdate = true
geo.lookAt(new THREE.Vector3(0, 1, 0))
for (let i = 0; i < geo.vertices.length; i++) {
const v = geo.vertices[i]
v.y = getYPosition(v.x, v.z)
const positions = geo.attributes.position.array
for (let i = 0; i < positions.length; i+=3) {
positions[i+1] = getYPosition(positions[i], positions[i+2])
}
geo.computeVertexNormals()
return geo.toBufferGeometry()
return geo
}, [width])
useFrame(state => (materialRef.current.uniforms.time.value = state.clock.elapsedTime / 4))
return (
Expand Down
2 changes: 1 addition & 1 deletion demos/grass-shader/src/GrassMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const GrassMaterial = shaderMaterial(
gl_FragColor = col;

#include <tonemapping_fragment>
#include <encodings_fragment>
#include <colorspace_fragment>
}`,
(self) => {
self.side = THREE.DoubleSide
Expand Down