Skip to content

Commit

Permalink
Merge pull request #691 from bamdadfr/next/bamdad
Browse files Browse the repository at this point in the history
  • Loading branch information
bamdadfr authored Aug 23, 2024
2 parents 2af88d6 + 4ea0757 commit bd5dc2a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 119 deletions.
64 changes: 0 additions & 64 deletions src/app/components/with-time-loop/with-time-loop.tsx

This file was deleted.

45 changes: 45 additions & 0 deletions src/components/texture/plane.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {useFrame} from '@react-three/fiber';
import React, {useMemo} from 'react';
import fragmentShader from 'src/components/texture/texture.fragment.glsl';
import vertexShader from 'src/components/texture/texture.vertex.glsl';
import {ShaderMaterial, Texture} from 'three';

interface Props {
size: number;
texture: Texture;
ratio: number;
}

export function PlaneComponent({size, texture, ratio}: Props) {
const material = useMemo(
() =>
new ShaderMaterial({
uniforms: {
u_texture: {value: texture},
u_ratio: {value: ratio},
u_time: {value: 0},
},
vertexShader,
fragmentShader,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);

useFrame(({clock}) => {
material.uniforms.u_time.value = clock.getElapsedTime();
material.uniforms.u_ratio.value = ratio;
});

return (
<mesh>
<planeGeometry args={[size, size]} />
<shaderMaterial
attach="material"
vertexShader={material.vertexShader}
fragmentShader={material.fragmentShader}
uniforms={material.uniforms}
/>
</mesh>
);
}
52 changes: 4 additions & 48 deletions src/components/texture/texture.component.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,24 @@
import {Canvas, useFrame} from '@react-three/fiber';
import {Canvas} from '@react-three/fiber';
import React, {ReactElement, useMemo} from 'react';
import {p} from 'src/app/shared.styles';
import {PlaneComponent} from 'src/components/texture/plane.component';
import {mapRange} from 'src/utils/map-range/map-range';
import {ShaderMaterial, TextureLoader} from 'three';

import fragmentShader from './texture.shaders.fragment.glsl';
import {TextureLoader} from 'three';

interface Props {
image: string;
dryWet: number;
width: number;
}

const vertexShader = `
varying vec2 v_uv;
void main() {
v_uv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;

function Plane({size, texture, ratio}) {
const material = useMemo(
() =>
new ShaderMaterial({
uniforms: {
u_texture: {value: texture},
u_ratio: {value: ratio},
u_time: {value: 0},
},
vertexShader,
fragmentShader,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);

useFrame(({clock}) => {
material.uniforms.u_time.value = clock.getElapsedTime();
material.uniforms.u_ratio.value = ratio;
});

return (
<mesh>
<planeGeometry args={[size, size]} />
<shaderMaterial
attach="material"
vertexShader={material.vertexShader}
fragmentShader={material.fragmentShader}
uniforms={material.uniforms}
/>
</mesh>
);
}

export function TextureComponent({image, dryWet, width}: Props): ReactElement {
const texture = new TextureLoader().load(image);
const size = useMemo(() => width / 100 - (p / 100) * 2, [width]);
const ratio = 0.005 + mapRange(dryWet, 0.5, 1.5, 1.6, -1.6, true);

return (
<Canvas>
<Plane
<PlaneComponent
size={size}
texture={texture}
ratio={ratio}
Expand Down
6 changes: 6 additions & 0 deletions src/components/texture/texture.vertex.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
varying vec2 v_uv;

void main() {
v_uv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
8 changes: 1 addition & 7 deletions src/modules/player/player.module.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {ResizeObserver} from '@juggle/resize-observer';
import React, {ReactElement, useMemo} from 'react';
import {isDesktop} from 'react-device-detect';
import useMeasure from 'react-use-measure';
import {p} from 'src/app/shared.styles';
import {IndicatorsComponent} from 'src/components/indicators/indicators.component';
import {NativeComponent} from 'src/modules/player/components/artwork/native.component';
import {WebGlComponent} from 'src/modules/player/components/artwork/web-gl.component';

import {PlayPauseButtonComponent} from './components/play-pause-button/play-pause-button.component';
Expand Down Expand Up @@ -36,11 +34,7 @@ export function PlayerModule(): ReactElement {
return (
<>
<ImageContainer ref={ref}>
{isDesktop ? (
<WebGlComponent width={imageWidth} />
) : (
<NativeComponent width={imageWidth} />
)}
<WebGlComponent width={imageWidth} />
</ImageContainer>

<PlayerContainer>
Expand Down

0 comments on commit bd5dc2a

Please sign in to comment.