Skip to content

Commit

Permalink
optimized prism
Browse files Browse the repository at this point in the history
  • Loading branch information
kdiffin committed Sep 29, 2023
1 parent c9baeaf commit 5d5a04c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import GradientPlatform from "../components/GradientPlatform";
import LandingHero from "../components/LandingHero";
import AiInCLI from "../components/AiInCLI";
import Navbar from "../components/Navbar";
import Customize from "../components/Customize";

export default function LandingPage() {
// const isMobile = useMediaQuery("(max-width: 768px)");
Expand All @@ -16,10 +17,9 @@ export default function LandingPage() {
<LandingHero />
<AiInCLI />
<GradientPlatform />
{/*{!isMobile ? <Timeline /> : null}*/}
{/* {!isMobile ? <Timeline /> : null} */}
<Authlite />
<Showcase />
{/* <Customize /> */}
<Footer />
</>
);
Expand Down
16 changes: 10 additions & 6 deletions src/components/interactivePrism/Flare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const Flare = forwardRef(
};

useFrame((state) => {
if (visible) {
ref.current.children.forEach((instance) => {
instance.position.x =
(Math[instance.scale.x > 1 ? "sin" : "cos"](
Expand All @@ -36,23 +37,26 @@ export const Flare = forwardRef(
) *
instance.scale.x) /
5;
});
})};
});




return (
<group ref={fRef} {...props} visible={visible} dispose={null}>
<Instances frames={visible ? Infinity : 1}>
<planeGeometry />
<meshBasicMaterial map={dotTexture} {...config} />
<group ref={ref}>
<Instance scale={0.5} />
<Instance scale={1.25} />
<Instance scale={0.75} />
<Instance scale={1.5} />
<Instance scale={2} position={[0, 0, -0.7]} />
<Instance scale={0.5} />
<Instance scale={0.5} />
<Instance scale={0.5} />
<Instance scale={0.5} position={[0, 0, -0.7]} />
</group>
</Instances>
<mesh scale={1}>
<mesh scale={0.5}>
<planeGeometry />
<meshBasicMaterial map={glowTexture} {...config} opacity={1} />
</mesh>
Expand Down
8 changes: 4 additions & 4 deletions src/components/interactivePrism/Prism.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export function Prism({ onRayOver, onRayOut, onRayMove, ...props }) {
);
return (
<group {...props}>
{/* A low-res, invisible representation of the prism that gets hit by the raycaster */}
{/ A low-res, invisible representation of the prism that gets hit by the raycaster /}
<mesh
visible={false}
scale={1.9}
scale={5.9}
rotation={[Math.PI / 2, Math.PI, 0]}
onRayOver={onRayOver}
onRayOut={onRayOut}
Expand All @@ -25,7 +25,7 @@ export function Prism({ onRayOver, onRayOut, onRayMove, ...props }) {
{/* The visible hi-res prism */}
<mesh
position={[0, 0, 0.6]}
renderOrder={10}
renderOrder={1}
scale={6}
dispose={null}
geometry={nodes.Cone.geometry}
Expand All @@ -43,4 +43,4 @@ export function Prism({ onRayOver, onRayOut, onRayMove, ...props }) {
</mesh>
</group>
);
}
}
15 changes: 9 additions & 6 deletions src/components/interactivePrism/Rainbow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,15 @@ export const Rainbow = forwardRef(
) => {
const material = useRef(null);
const { width, height } = useThree((state) => state.viewport);
// calculate the maximum length the rainbow has to have to reach all screen corners
const length = Math.hypot(width, height) + 2.5; // add 1.5 to due motion of the rainbow
useFrame(
(state, delta) =>
(material.current.time += delta * material.current.speed),
);
const length = Math.hypot(width, height) + 2.5;

useFrame((state, delta) => {
// Only update if material.current.speed is not zero
if (material.current.speed !== 0) {
material.current.time += delta * material.current.speed;
}
});

return (
<mesh ref={fRef} scale={[length, length, 1]} {...props}>
<planeGeometry />
Expand Down
47 changes: 28 additions & 19 deletions src/components/interactivePrism/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export function calculateRefractionAngle(
function Effects() {
const [hasEffects, setHasEffects] = useState(true);

// usePerformanceMonitor({
// onChange: ({ factor }) => {
// if (hasEffects && factor > 0.5) {
// // Decrease the qualityScale of your effects.
// effect.qualityScale = round(0.5 + 0.5 * factor, 1);
// }
// // Handle other conditions for declining or inclining quality
// },
// });
usePerformanceMonitor({
onChange: ({ factor }) => {
if (hasEffects && factor > 0.5) {
// Decrease the qualityScale of your effects.
effect.qualityScale = round(0.5 + 0.5 * factor, 1);
}
// Handle other conditions for declining or inclining quality
},
});

return (
<EffectComposer>{/* Your post-processing effects here */}</EffectComposer>
Expand Down Expand Up @@ -136,15 +136,24 @@ function Scene({ isMobile }: { isMobile: boolean }) {
[0, 0, 0],
);

lerp(
rainbow.current.material,
"emissiveIntensity",
isPrismHit ? 2.5 : 0,
0.1,
);
spot.current.intensity = rainbow.current.material.emissiveIntensity;

lerp(ambient.current, "intensity", 0, 0.25);
// Only update if isPrismHit has changed
if (
rainbow.current.material.emissiveIntensity !==
(isPrismHit ? 2.5 : 0)
) {
lerp(
rainbow.current.material,
"emissiveIntensity",
isPrismHit ? 2.5 : 0,
0.1,
);
spot.current.intensity = rainbow.current.material.emissiveIntensity;
}

// Only update if ambient intensity is not zero
if (ambient.current.intensity !== 0) {
lerp(ambient.current, "intensity", 0, 0.25);
}
});

return (
Expand Down Expand Up @@ -189,4 +198,4 @@ function Scene({ isMobile }: { isMobile: boolean }) {
/>
</>
);
}
}

0 comments on commit 5d5a04c

Please sign in to comment.