Skip to content

Commit

Permalink
fix: up stdlib, fix mtm, fix ts issues in oc and mc
Browse files Browse the repository at this point in the history
  • Loading branch information
drcmda committed May 31, 2023
1 parent c959e0d commit 549493d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ return (
<a href="https://codesandbox.io/s/hmgdjq"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/hmgdjq/screenshot.png" alt="Demo"/></a>
</p>

An improved THREE.MeshPhysicalMaterial. It acts like a normal PhysicalMaterial in terms of transmission support, thickness, ior, roughness, etc., but has chromatic aberration, noise-based roughness blur, (primitive) anisotropy support, and unlike the original it can "see" other transmissive or transparent objects which leads to improved visuals.
An improved THREE.MeshPhysicalMaterial. It acts like a normal PhysicalMaterial in terms of transmission support, thickness, ior, roughness, etc., but has chromatic aberration, noise-based roughness blur, (primitive) anisotropic blur support, and unlike the original it can "see" other transmissive or transparent objects which leads to improved visuals.

Although it should be faster than MPM keep in mind that it can still be expensive as it causes an additional render pass of the scene. Low samples and low resolution will make it faster. If you use roughness consider using a tiny resolution, for instance 32x32 pixels, it will still look good but perform much faster.

Expand All @@ -1640,7 +1640,7 @@ type MeshTransmissionMaterialProps = JSX.IntrinsicElements['meshPhysicalMaterial
/* Chromatic aberration, default: 0.03 */
chromaticAberration?: number
/* Anisotropy, default: 0.1 */
anisotropy?: number
anisotropicBlur?: number
/* Distortion, default: 0 */
distortion?: number
/* Distortion scale, default: 0.5 */
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"stats.js": "^0.17.0",
"suspend-react": "^0.0.8",
"three-mesh-bvh": "^0.5.23",
"three-stdlib": "^2.22.10",
"three-stdlib": "^2.23.5",
"troika-three-text": "^0.47.1",
"utility-types": "^3.10.0",
"zustand": "^3.5.13"
Expand Down
2 changes: 1 addition & 1 deletion src/core/MapControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const MapControls = React.forwardRef<MapControlsImpl, MapControlsProps>(
const get = useThree((state) => state.get)
const explDomElement = (domElement || events.connected || gl.domElement) as HTMLElement

const explCamera = camera || defaultCamera
const explCamera = (camera || defaultCamera) as THREE.OrthographicCamera | THREE.PerspectiveCamera
const controls = React.useMemo(() => new MapControlsImpl(explCamera), [explCamera])

React.useEffect(() => {
Expand Down
12 changes: 6 additions & 6 deletions src/core/MeshTransmissionMaterial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type MeshTransmissionMaterialType = Omit<
roughness?: number
/* Chromatic aberration, default: 0.03 */
chromaticAberration?: number
/* Anisotropy, default: 0.1 */
anisotropy?: number
/* AnisotropicBlur, default: 0.1 */
anisotropicBlur?: number
/* Distortion, default: 0 */
distortion?: number
/* Distortion scale, default: 0.5 */
Expand Down Expand Up @@ -81,7 +81,7 @@ class MeshTransmissionMaterialImpl extends THREE.MeshPhysicalMaterial {
thicknessMap: Uniform<THREE.Texture | null>
attenuationDistance: Uniform<number>
attenuationColor: Uniform<THREE.Color>
anisotropy: Uniform<number>
anisotropicBlur: Uniform<number>
time: Uniform<number>
distortion: Uniform<number>
distortionScale: Uniform<number>
Expand All @@ -105,7 +105,7 @@ class MeshTransmissionMaterialImpl extends THREE.MeshPhysicalMaterial {
thicknessMap: { value: null },
attenuationDistance: { value: Infinity },
attenuationColor: { value: new THREE.Color('white') },
anisotropy: { value: 0.1 },
anisotropicBlur: { value: 0.1 },
time: { value: 0 },
distortion: { value: 0.0 },
distortionScale: { value: 0.5 },
Expand All @@ -129,7 +129,7 @@ class MeshTransmissionMaterialImpl extends THREE.MeshPhysicalMaterial {
shader.fragmentShader =
/*glsl*/ `
uniform float chromaticAberration;
uniform float anisotropy;
uniform float anisotropicBlur;
uniform float time;
uniform float distortion;
uniform float distortionScale;
Expand Down Expand Up @@ -325,7 +325,7 @@ class MeshTransmissionMaterialImpl extends THREE.MeshPhysicalMaterial {
vec3 transmission = vec3(0.0);
float transmissionR, transmissionB, transmissionG;
float randomCoords = rand();
float thickness_smear = thickness * max(pow(roughnessFactor, 0.33), anisotropy);
float thickness_smear = thickness * max(pow(roughnessFactor, 0.33), anisotropicBlur);
vec3 distortionNormal = vec3(0.0);
vec3 temporalOffset = vec3(time, -time, -time) * temporalDistortion;
if (distortion > 0.0) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/OrbitControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const OrbitControls = React.forwardRef<OrbitControlsImpl, OrbitControlsPr
const set = useThree((state) => state.set)
const get = useThree((state) => state.get)
const performance = useThree((state) => state.performance)
const explCamera = camera || defaultCamera
const explCamera = (camera || defaultCamera) as THREE.OrthographicCamera | THREE.PerspectiveCamera
const explDomElement = (domElement || events.connected || gl.domElement) as HTMLElement
const controls = React.useMemo(() => new OrbitControlsImpl(explCamera), [explCamera])

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10438,10 +10438,10 @@ three-mesh-bvh@^0.5.23:
resolved "https://registry.yarnpkg.com/three-mesh-bvh/-/three-mesh-bvh-0.5.23.tgz#08e5b629144b48b11acbd433519680e457d398ed"
integrity sha512-nyk+MskdyDgECqkxdv57UjazqqhrMi+Al9PxJN6yFtx1CTW4r0eCQ27FtyYKY5gCIWhxjtNfWYDPVy8lzx6LkA==

three-stdlib@^2.22.10:
version "2.22.10"
resolved "https://registry.yarnpkg.com/three-stdlib/-/three-stdlib-2.22.10.tgz#1280f62453361b1b7415164b4407e077e212f72a"
integrity sha512-Brsso1ixk7Zv97bOxKwFWLct8fCEbWr+G9Z2uyRxM/Zc64hyRXohTjcZxjb8MvkI3L4tVpeRURRY3VB6HVUiqQ==
three-stdlib@^2.23.5:
version "2.23.5"
resolved "https://registry.yarnpkg.com/three-stdlib/-/three-stdlib-2.23.5.tgz#8429adbb06feec0fcaf323472e67ec5012055f84"
integrity sha512-wePXmLoA+a6CAWHNAzdB7Z4Dg/VcQveRhWjIBEvEj2dQ/jwnmJWNwtE3wHqZRYo4TUf9SDk+xsvlhZp3Q8LydA==
dependencies:
"@types/draco3d" "^1.4.0"
"@types/offscreencanvas" "^2019.6.4"
Expand Down

1 comment on commit 549493d

@vercel
Copy link

@vercel vercel bot commented on 549493d May 31, 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.