-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fa94e8
commit 321942f
Showing
6 changed files
with
87 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { extend } from '@react-three/fiber' | ||
import { ShaderMaterial, NormalBlending } from 'three' | ||
import dofVertex from '../shaders/dof-dot/vertex.glsl' | ||
import dofFragment from '../shaders/dof-dot/fragment.glsl' | ||
|
||
class DofPointsMaterial extends ShaderMaterial { | ||
constructor() { | ||
super({ | ||
vertexShader: dofVertex, | ||
fragmentShader: dofFragment, | ||
uniforms: { | ||
positions: { value: null }, | ||
uTime: { value: 0 }, | ||
uFocus: { value: 5.1 }, | ||
uFov: { value: 50 }, | ||
uBlur: { value: 30 } | ||
}, | ||
transparent: true, | ||
blending: NormalBlending, | ||
depthWrite: false | ||
}) | ||
} | ||
} | ||
|
||
extend({ DofPointsMaterial }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { extend } from '@react-three/fiber' | ||
import { Vector4, ShaderMaterial, DataTexture, RGBAFormat, FloatType } from 'three' | ||
import simVertex from '../shaders/sim-dot/vertex.glsl' | ||
import simFragment from '../shaders/sim-dot/fragment.glsl' | ||
|
||
function getPoint(v:Vector4, size:number, data: Float32Array, offset: number): ArrayLike<number> { | ||
v.set(Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1, 0) | ||
if (v.length() > 1) return getPoint(v, size, data, offset) | ||
return v.normalize().multiplyScalar(size).toArray(data, offset) | ||
} | ||
|
||
function getSphere(count:number, size:number, p = new Vector4()) { | ||
const data = new Float32Array(count * 4) | ||
for (let i = 0; i < count * 4; i += 4) getPoint(p, size, data, i) | ||
return data | ||
} | ||
|
||
class SimulationMaterial extends ShaderMaterial { | ||
constructor() { | ||
const positionsTexture = new DataTexture(getSphere(512 * 512, 128), 512, 512, RGBAFormat, FloatType) | ||
positionsTexture.needsUpdate = true | ||
|
||
super({ | ||
vertexShader: simVertex, | ||
fragmentShader: simFragment, | ||
uniforms: { | ||
positions: { value: positionsTexture }, | ||
uTime: { value: 0 }, | ||
uCurlFreq: { value: 0.25 } | ||
} | ||
}) | ||
} | ||
} | ||
|
||
extend({ SimulationMaterial }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters