Skip to content

Commit

Permalink
fix: #242 Frustum has incorrect spelling in softshadows (#243)
Browse files Browse the repository at this point in the history
* fix: suggestion for fixing #242

* refactor: default should be other way round

* chore: update readme with correct spelling
  • Loading branch information
joshuaellis authored Jan 19, 2021
1 parent cb64fb9 commit c76b61b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ Injects [percent closer soft shadows (pcss)](https://threejs.org/examples/?q=pcs
```jsx
softShadows({
frustrum: 3.75, // Frustrum width (default: 3.75) must be a float
frustum: 3.75, // Frustum width (default: 3.75) must be a float
size: 0.005, // World size (default: 0.005) must be a float
near: 9.5, // Near plane (default: 9.5) must be a float
samples: 17, // Samples (default: 17) must be a int
Expand Down
9 changes: 7 additions & 2 deletions src/core/softShadows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ import * as THREE from 'three'

type Props = {
frustrum?: number
frustum?: number
size?: number
near?: number
samples?: number
rings?: number
}

const pcss = ({
frustrum = 3.75,
frustrum,
frustum = 3.75,
size = 0.005,
near = 9.5,
samples = 17,
rings = 11,
}: Props = {}) => `#define LIGHT_WORLD_SIZE ${size}
#define LIGHT_FRUSTUM_WIDTH ${frustrum}
#define LIGHT_FRUSTUM_WIDTH ${frustrum ?? frustum}
#define LIGHT_SIZE_UV (LIGHT_WORLD_SIZE / LIGHT_FRUSTUM_WIDTH)
#define NEAR_PLANE ${near}
Expand Down Expand Up @@ -86,6 +88,9 @@ let deployed = false
export const softShadows = (props?: Props) => {
// Avoid adding the effect twice, which may happen in HMR scenarios
if (!deployed) {
if (props?.frustrum) {
console.warn('You have used an incorrect spelling of frustrum, this will be deprecated in the future')
}
deployed = true
let shader = THREE.ShaderChunk.shadowmap_pars_fragment
shader = shader.replace('#ifdef USE_SHADOWMAP', '#ifdef USE_SHADOWMAP\n' + pcss({ ...props }))
Expand Down

0 comments on commit c76b61b

Please sign in to comment.