Skip to content

Commit 6e931d2

Browse files
committed
improve lookbook
1 parent 28759d6 commit 6e931d2

File tree

7 files changed

+45
-35
lines changed

7 files changed

+45
-35
lines changed
Loading
Loading
Loading

apps/lookbook/src/components/demos/clouds/CloudSprites.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class CloudSprites {
6363
}
6464
}
6565

66-
frame(state, delta) {
66+
frame(_state, delta) {
6767
this.#animateClouds(delta);
6868
}
6969

@@ -106,17 +106,28 @@ export class CloudSprites {
106106
#createClouds() {
107107
let z = this.zRangeMin;
108108

109+
let cloudIndex;
110+
let frame;
111+
let x;
112+
let y;
113+
114+
const framesPerCloud = 5;
115+
109116
for (let i = 0; i < this.capacity; i++) {
110-
const frame = this.atlas.randomFrame();
117+
cloudIndex = i % framesPerCloud;
118+
119+
if (cloudIndex === 0) {
120+
frame = this.atlas.randomFrame();
121+
x = this.width * 2 * Math.random() - this.width + this.xOffset;
122+
y = this.height * 2 * Math.random() - this.height + this.yOffset;
123+
}
111124

112125
const sprite = this.spritePool.createVO();
113-
sprite.setSize(frame.coords.width, frame.coords.height);
126+
const scale = cloudIndex * (this.gap / framesPerCloud);
127+
sprite.setSize(frame.coords.width * scale, frame.coords.height * scale);
114128
sprite.setFrame(frame);
115-
sprite.setPosition(
116-
this.width * 2 * Math.random() - this.width + this.xOffset,
117-
this.height * 2 * Math.random() - this.height + this.yOffset,
118-
z,
119-
);
129+
130+
sprite.setPosition(x, y, z + scale);
120131

121132
sprite.setColor([1, 1, 1, 1]);
122133

apps/lookbook/src/components/demos/clouds/Clouds.jsx

+11-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
useTextureAtlas,
1111
} from '@spearwolf/twopoint5d-r3f';
1212
import {useEffect, useRef} from 'react';
13-
import {AdditiveBlending, FrontSide} from 'three';
13+
import {FrontSide} from 'three';
1414
import assetsUrl from '../../../demos/utils/assetsUrl.ts';
1515
import {createFrameLoopComponent} from '../../../demos/utils/createFrameLoopComponent.js';
1616
import {CloudSprites} from './CloudSprites.js';
@@ -99,18 +99,17 @@ export const Clouds = ({
9999

100100
return (
101101
<>
102-
<TextureAtlas name="clouds" url={assetsUrl('clouds-2.json')} overrideImageUrl={assetsUrl('clouds-2.png')} anisotrophy />
102+
<TextureAtlas
103+
name="clouds"
104+
url={assetsUrl('clouds-2.json')}
105+
overrideImageUrl={assetsUrl('clouds-2.png')}
106+
anisotrophy
107+
linear
108+
/>
103109

104110
<TexturedSprites>
105111
<TexturedSpritesGeometry capacity={capacity} ref={geometry}></TexturedSpritesGeometry>
106-
<TexturedSpritesMaterial
107-
ref={material}
108-
depthTest={false}
109-
depthWrite={false}
110-
blending={AdditiveBlending}
111-
side={FrontSide}
112-
logShadersToConsole={true}
113-
>
112+
<TexturedSpritesMaterial ref={material} depthTest={false} depthWrite={false} side={FrontSide} logShadersToConsole={true}>
114113
<TextureRef name="clouds" attach="colorMap" />
115114
<ShaderChunks chunks={ShaderLib} />
116115
</TexturedSpritesMaterial>
@@ -127,8 +126,8 @@ Clouds.defaultProps = {
127126
xOffset: 0,
128127
yOffset: 0,
129128
zOffset: 0,
130-
speed: 5,
129+
speed: 50,
131130
fadeInRange: 0.1,
132-
fadeOutRange: 0.2,
131+
fadeOutRange: 0.1,
133132
postAlphaMultiplier: 1.0,
134133
};

apps/lookbook/src/components/demos/clouds/index.jsx

+14-7
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,32 @@ import {Clouds} from './Clouds.jsx';
77

88
export default function DemoOrDie() {
99
const {speed, alpha} = useControls({
10-
speed: {value: 90, min: 0, max: 250, step: 1},
11-
alpha: {value: 0.3, min: 0.01, max: 0.99, step: 0.01},
10+
speed: {value: 100, min: 0, max: 250, step: 1},
11+
alpha: {value: 0.9, min: 0.01, max: 0.99, step: 0.01},
1212
});
1313

1414
return (
1515
<Canvas dpr={[1, 2]} camera={{position: [0, 0, 50]}}>
1616
<Stage2D name="stage1" defaultCamera renderPriority={1}>
17-
<ParallaxProjection plane="xy" origin="bottom left" width={1024} height={768} fit="contain" />
17+
<ParallaxProjection
18+
plane="xy"
19+
origin="bottom left"
20+
width={1024}
21+
height={768}
22+
distanceToProjectionPlane={250}
23+
fit="contain"
24+
/>
1825

1926
<Clouds
20-
capacity={800}
21-
gap={2}
27+
capacity={400}
28+
gap={5}
2229
speed={speed}
2330
width={2500}
2431
height={600}
25-
yOffset={-600}
32+
yOffset={-400}
2633
zOffset={-660}
2734
fadeInRange={0.1}
28-
fadeOutRange={0.1}
35+
fadeOutRange={0.2}
2936
postAlphaMultiplier={alpha}
3037
/>
3138
</Stage2D>

apps/lookbook/src/pages/demos/clouds.astro

+1-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ import {title} from './_clouds.json';
1313
margin: 0;
1414
height: 100vh;
1515
overflow-y: hidden;
16-
background-color: rgb(100, 118, 136);
17-
background: linear-gradient(
18-
rgb(0, 28, 48) 0%,
19-
rgb(0, 28, 48) 30%,
20-
rgb(1, 60, 103) 60%,
21-
rgb(68, 29, 100) 70%,
22-
rgb(143, 7, 98) 100%
23-
);
16+
background-color: rgb(155 178 189);
2417
color: #eee;
2518
}
2619
</style>

0 commit comments

Comments
 (0)