Skip to content

Commit

Permalink
fix(types): remove references to Shader type (#1765)
Browse files Browse the repository at this point in the history
  • Loading branch information
Methuselah96 authored Dec 23, 2023
1 parent cc8ea56 commit a82d0d4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/core/MeshDistortMaterial.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { MeshPhysicalMaterial, MeshPhysicalMaterialParameters, Shader } from 'three'
import { IUniform, MeshPhysicalMaterial, MeshPhysicalMaterialParameters } from 'three'
import { useFrame } from '@react-three/fiber'
// eslint-disable-next-line
// @ts-ignore
Expand Down Expand Up @@ -42,7 +42,8 @@ class DistortMaterialImpl extends MeshPhysicalMaterial {
this._radius = { value: 1 }
}

onBeforeCompile(shader: Shader) {
// FIXME Use `THREE.WebGLProgramParametersWithUniforms` type when able to target @types/three@0.160.0
onBeforeCompile(shader: { vertexShader: string; uniforms: { [uniform: string]: IUniform } }) {
shader.uniforms.time = this._time
shader.uniforms.radius = this._radius
shader.uniforms.distort = this._distort
Expand Down
5 changes: 3 additions & 2 deletions src/core/MeshWobbleMaterial.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { MeshStandardMaterial, MeshStandardMaterialParameters, Shader } from 'three'
import { IUniform, MeshStandardMaterial, MeshStandardMaterialParameters } from 'three'
import { useFrame } from '@react-three/fiber'
import { ForwardRefComponent } from '../helpers/ts-utils'

Expand Down Expand Up @@ -37,7 +37,8 @@ class WobbleMaterialImpl extends MeshStandardMaterial {
this._factor = { value: 1 }
}

onBeforeCompile(shader: Shader) {
// FIXME Use `THREE.WebGLProgramParametersWithUniforms` type when able to target @types/three@0.160.0
onBeforeCompile(shader: { vertexShader: string; uniforms: { [uniform: string]: IUniform } }) {
shader.uniforms.time = this._time
shader.uniforms.factor = this._factor

Expand Down
14 changes: 11 additions & 3 deletions src/core/useBoxProjectedEnv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ const getIBLRadiance_patch = /* glsl */ `
#endif
`

function boxProjectedEnvMap(shader: THREE.Shader, envMapPosition: THREE.Vector3, envMapSize: THREE.Vector3) {
// FIXME Replace with `THREE.WebGLProgramParametersWithUniforms` type when able to target @types/three@0.160.0
interface MaterialShader {
vertexShader: string
fragmentShader: string
defines: { [define: string]: string | number | boolean } | undefined
uniforms: { [uniform: string]: THREE.IUniform }
}

function boxProjectedEnvMap(shader: MaterialShader, envMapPosition: THREE.Vector3, envMapSize: THREE.Vector3) {
// defines
;(shader as any).defines.BOX_PROJECTED_ENV_MAP = true
shader.defines!.BOX_PROJECTED_ENV_MAP = true
// uniforms
shader.uniforms.envMapPosition = { value: envMapPosition }
shader.uniforms.envMapSize = { value: envMapSize }
Expand Down Expand Up @@ -89,7 +97,7 @@ export function useBoxProjectedEnv(
const spread = React.useMemo(
() => ({
ref,
onBeforeCompile: (shader: THREE.Shader) => boxProjectedEnvMap(shader, config.position, config.size),
onBeforeCompile: (shader: MaterialShader) => boxProjectedEnvMap(shader, config.position, config.size),
customProgramCacheKey: () => JSON.stringify(config.position.toArray()) + JSON.stringify(config.size.toArray()),
}),
[...config.position.toArray(), ...config.size.toArray()]
Expand Down

1 comment on commit a82d0d4

@vercel
Copy link

@vercel vercel bot commented on a82d0d4 Dec 23, 2023

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.