Hi, I have a small problem with glb, i mean. it displays strangely… after implementing the shader.
import React, { useEffect, useRef } from "react";
import * as THREE from "three";
import { extend } from "@react-three/fiber";
import { shaderMaterial, useGLTF } from "@react-three/drei";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
gsap.registerPlugin(ScrollTrigger);
const beltColor = shaderMaterial(
{ progress: 0 },
`
void main() {
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
`
uniform float progress;
void main() {
gl_FragColor = mix(vec4(1.0, 0.0, 0.0, 1.0), vec4(0.0, 0.0, 1.0, 1.0), progress);
}
`
);
extend({ beltColor });
export default function Model(props) {
const modelRef = useRef();
const { nodes, materials } = useGLTF("bjj_belt.glb");
useEffect(() => {
gsap.to(modelRef.current.rotation, {
scrollTrigger: {
trigger: ".section1",
endTrigger: ".section5",
markers: true,
scrub: 1,
start: "top top",
end: "bottom top",
},
y: (index) => Math.PI * (2 + 0.6 * index),
x: (index) => Math.PI * (2 + 0.6 * index),
z: (index) => Math.PI * (2 + 0.6 * index),
});
// gsap.to(beltColor.uniforms.progress, {
// value: 1,
// scrollTrigger: {
// trigger: ".section1",
// endTrigger: ".section5",
// markers: true,
// scrub: 1,
// start: "top top",
// end: "bottom top",
// },
// });
}, []);
return (
<group {...props} dispose={null}>
<mesh
ref={modelRef} // Assign the ref to the mesh
castShadow
receiveShadow
geometry={nodes.BJJ_BELT.geometry}
material={materials[beltColor]}
position={[0, 0, 3]}
rotation={[0.189, 0, 0]}
/>
</group>
);
}
useGLTF.preload("bjj_belt.glb");
White version - shader.
Black version - standard.
Some ideas?