Skip to content

Commit

Permalink
feat(Texture): support opacity (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
vegancat authored Jan 18, 2025
1 parent b18b3ff commit 1c4f72f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/effects/Texture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { TextureLoader, RepeatWrapping } from 'three'

type TextureProps = ConstructorParameters<typeof TextureEffect>[0] & {
textureSrc: string
/** opacity of provided texture */
opacity?: number
}

export const Texture = forwardRef<TextureEffect, TextureProps>(function Texture(
{ textureSrc, texture, ...props }: TextureProps,
{ textureSrc, texture, opacity = 1, ...props }: TextureProps,
ref: Ref<TextureEffect>
) {
const t = useLoader(TextureLoader, textureSrc)
Expand All @@ -20,5 +22,5 @@ export const Texture = forwardRef<TextureEffect, TextureProps>(function Texture(
t.wrapS = t.wrapT = RepeatWrapping
}, [t])
const effect = useMemo(() => new TextureEffect({ ...props, texture: t || texture }), [props, t, texture])
return <primitive ref={ref} object={effect} dispose={null} />
return <primitive ref={ref} object={effect} blendMode-opacity-value={opacity} dispose={null} />
})

0 comments on commit 1c4f72f

Please sign in to comment.