Skip to content

Commit

Permalink
docs: Caustics blog post (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeHeckel committed Jan 23, 2024
1 parent e84d928 commit 64aa010
Show file tree
Hide file tree
Showing 14 changed files with 3,363 additions and 387 deletions.
825 changes: 825 additions & 0 deletions content/caustics-in-webgl.mdx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion content/immigrating-to-the-us-my-path.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Immigrating to the US: My path from non-immigrant to permanent resident'
title: 'Immigrating to the US'
subtitle: US immigration explained for American citizens by an immigrant.
date: '2020-06-26T08:00:00.000Z'
updated: '2020-06-29T08:00:00.000Z'
Expand Down
3 changes: 3 additions & 0 deletions core/components/MDX/MDXComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ const RaymarchingSandpack = dynamic(
() => import('./Widgets/Raymarching/Sandpack')
);

const CausticsSandpack = dynamic(() => import('./Widgets/Caustics/Sandpack'));

const customComponents = {
AnimationTypes,
ClipboardAnimationDetails,
Expand Down Expand Up @@ -279,6 +281,7 @@ const customComponents = {
RefractionDispersionSandpack,
RenderTargetsSandpack,
RaymarchingSandpack,
CausticsSandpack,
};

const MDXComponents = {
Expand Down
97 changes: 97 additions & 0 deletions core/components/MDX/Widgets/Caustics/Sandpack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { Box, useTheme } from '@maximeheckel/design-system';
import Sandpack from '@core/components/Code/Sandpack';
import useGPUTier from '@core/hooks/useGPUTier';
import { useInView } from 'react-intersection-observer';
import normalProjection from './normalProjection';
import simpleCaustics from './simpleCaustics';
import beautifulCaustics from './beautifulCaustics';
import causticsPlane from './causticsPlane';
import dynamicCaustics from './dynamicCaustics';

const SceneCSSDark = `
html {
background: #20222B;
}
body {
height: 100%;
margin: 0;
}
canvas {
width: 100vw;
height: 100vh;
}`;

const SceneCSSLight = `
html {
background: #F7F7FB;
}
body {
height: 100%;
margin: 0;
}
canvas {
width: 100vw;
height: 100vh;
}`;

const CausticsSandpack = (props: any) => {
const { scene } = props;
const [ref, inView] = useInView();
const { dark } = useTheme();
const { tier, loading: tierLoading } = useGPUTier();

const autorun = tier > 2;

const SCENES = {
scene1: normalProjection,
scene2: simpleCaustics,
scene3: beautifulCaustics,
scene4: causticsPlane,
scene5: dynamicCaustics,
};

return (
<Box ref={ref}>
{inView && !tierLoading ? (
<Sandpack
autorun={autorun}
template="react"
dependencies={{
'@react-three/drei': '9.70.4',
'@react-three/fiber': '8.11.2',
leva: '0.9.31',
three: '0.149.0',
uuid: '^9.0.0',
}}
files={{
// @ts-ignore
...SCENES[scene],
'/scene.css': {
code: !dark ? SceneCSSLight : SceneCSSDark,
hidden: true,
},
'/sandbox.config.json': {
code: `{ "infiniteLoopProtection" : false }`,
hidden: true,
},
}}
/>
) : (
<Box
css={{
height: '520px',
'@media(max-width: 750px)': {
height: '1060px',
},
}}
/>
)}
</Box>
);
};

export default CausticsSandpack;
Loading

1 comment on commit 64aa010

@vercel
Copy link

@vercel vercel bot commented on 64aa010 Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.