Initial project import
This commit is contained in:
1
node_modules/@react-three/drei/materials/BlurPass.cjs.js
generated
vendored
Normal file
1
node_modules/@react-three/drei/materials/BlurPass.cjs.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("./ConvolutionMaterial.cjs.js");require("../helpers/constants.cjs.js");exports.BlurPass=class{constructor({gl:r,resolution:i,width:n=500,height:s=500,minDepthThreshold:o=0,maxDepthThreshold:a=1,depthScale:l=0,depthToBlurRatioBias:u=.25}){this.renderToScreen=!1,this.renderTargetA=new e.WebGLRenderTarget(i,i,{minFilter:e.LinearFilter,magFilter:e.LinearFilter,stencilBuffer:!1,depthBuffer:!1,type:e.HalfFloatType}),this.renderTargetB=this.renderTargetA.clone(),this.convolutionMaterial=new t.ConvolutionMaterial,this.convolutionMaterial.setTexelSize(1/n,1/s),this.convolutionMaterial.setResolution(new e.Vector2(n,s)),this.scene=new e.Scene,this.camera=new e.Camera,this.convolutionMaterial.uniforms.minDepthThreshold.value=o,this.convolutionMaterial.uniforms.maxDepthThreshold.value=a,this.convolutionMaterial.uniforms.depthScale.value=l,this.convolutionMaterial.uniforms.depthToBlurRatioBias.value=u,this.convolutionMaterial.defines.USE_DEPTH=l>0;const h=new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),c=new Float32Array([0,0,2,0,0,2]),d=new e.BufferGeometry;d.setAttribute("position",new e.BufferAttribute(h,3)),d.setAttribute("uv",new e.BufferAttribute(c,2)),this.screen=new e.Mesh(d,this.convolutionMaterial),this.screen.frustumCulled=!1,this.scene.add(this.screen)}render(e,t,r){const i=this.scene,n=this.camera,s=this.renderTargetA,o=this.renderTargetB;let a=this.convolutionMaterial,l=a.uniforms;l.depthBuffer.value=t.depthTexture;const u=a.kernel;let h,c,d,f=t;for(c=0,d=u.length-1;c<d;++c)h=1&c?o:s,l.kernel.value=u[c],l.inputBuffer.value=f.texture,e.setRenderTarget(h),e.render(i,n),f=h;l.kernel.value=u[c],l.inputBuffer.value=f.texture,e.setRenderTarget(this.renderToScreen?null:r),e.render(i,n)}};
|
||||
23
node_modules/@react-three/drei/materials/BlurPass.d.ts
generated
vendored
Normal file
23
node_modules/@react-three/drei/materials/BlurPass.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Mesh, Scene, WebGLRenderTarget, WebGLRenderer, Camera } from 'three';
|
||||
import { ConvolutionMaterial } from './ConvolutionMaterial';
|
||||
export interface BlurPassProps {
|
||||
gl: WebGLRenderer;
|
||||
resolution: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
minDepthThreshold?: number;
|
||||
maxDepthThreshold?: number;
|
||||
depthScale?: number;
|
||||
depthToBlurRatioBias?: number;
|
||||
}
|
||||
export declare class BlurPass {
|
||||
readonly renderTargetA: WebGLRenderTarget;
|
||||
readonly renderTargetB: WebGLRenderTarget;
|
||||
readonly convolutionMaterial: ConvolutionMaterial;
|
||||
readonly scene: Scene;
|
||||
readonly camera: Camera;
|
||||
readonly screen: Mesh;
|
||||
renderToScreen: boolean;
|
||||
constructor({ gl, resolution, width, height, minDepthThreshold, maxDepthThreshold, depthScale, depthToBlurRatioBias, }: BlurPassProps);
|
||||
render(renderer: any, inputBuffer: any, outputBuffer: any): void;
|
||||
}
|
||||
72
node_modules/@react-three/drei/materials/BlurPass.js
generated
vendored
Normal file
72
node_modules/@react-three/drei/materials/BlurPass.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
import { WebGLRenderTarget, LinearFilter, HalfFloatType, Vector2, Scene, Camera, BufferGeometry, BufferAttribute, Mesh } from 'three';
|
||||
import { ConvolutionMaterial } from './ConvolutionMaterial.js';
|
||||
|
||||
class BlurPass {
|
||||
constructor({
|
||||
gl,
|
||||
resolution,
|
||||
width = 500,
|
||||
height = 500,
|
||||
minDepthThreshold = 0,
|
||||
maxDepthThreshold = 1,
|
||||
depthScale = 0,
|
||||
depthToBlurRatioBias = 0.25
|
||||
}) {
|
||||
this.renderToScreen = false;
|
||||
this.renderTargetA = new WebGLRenderTarget(resolution, resolution, {
|
||||
minFilter: LinearFilter,
|
||||
magFilter: LinearFilter,
|
||||
stencilBuffer: false,
|
||||
depthBuffer: false,
|
||||
type: HalfFloatType
|
||||
});
|
||||
this.renderTargetB = this.renderTargetA.clone();
|
||||
this.convolutionMaterial = new ConvolutionMaterial();
|
||||
this.convolutionMaterial.setTexelSize(1.0 / width, 1.0 / height);
|
||||
this.convolutionMaterial.setResolution(new Vector2(width, height));
|
||||
this.scene = new Scene();
|
||||
this.camera = new Camera();
|
||||
this.convolutionMaterial.uniforms.minDepthThreshold.value = minDepthThreshold;
|
||||
this.convolutionMaterial.uniforms.maxDepthThreshold.value = maxDepthThreshold;
|
||||
this.convolutionMaterial.uniforms.depthScale.value = depthScale;
|
||||
this.convolutionMaterial.uniforms.depthToBlurRatioBias.value = depthToBlurRatioBias;
|
||||
this.convolutionMaterial.defines.USE_DEPTH = depthScale > 0;
|
||||
const vertices = new Float32Array([-1, -1, 0, 3, -1, 0, -1, 3, 0]);
|
||||
const uvs = new Float32Array([0, 0, 2, 0, 0, 2]);
|
||||
const geometry = new BufferGeometry();
|
||||
geometry.setAttribute('position', new BufferAttribute(vertices, 3));
|
||||
geometry.setAttribute('uv', new BufferAttribute(uvs, 2));
|
||||
this.screen = new Mesh(geometry, this.convolutionMaterial);
|
||||
this.screen.frustumCulled = false;
|
||||
this.scene.add(this.screen);
|
||||
}
|
||||
render(renderer, inputBuffer, outputBuffer) {
|
||||
const scene = this.scene;
|
||||
const camera = this.camera;
|
||||
const renderTargetA = this.renderTargetA;
|
||||
const renderTargetB = this.renderTargetB;
|
||||
let material = this.convolutionMaterial;
|
||||
let uniforms = material.uniforms;
|
||||
uniforms.depthBuffer.value = inputBuffer.depthTexture;
|
||||
const kernel = material.kernel;
|
||||
let lastRT = inputBuffer;
|
||||
let destRT;
|
||||
let i, l;
|
||||
// Apply the multi-pass blur.
|
||||
for (i = 0, l = kernel.length - 1; i < l; ++i) {
|
||||
// Alternate between targets.
|
||||
destRT = (i & 1) === 0 ? renderTargetA : renderTargetB;
|
||||
uniforms.kernel.value = kernel[i];
|
||||
uniforms.inputBuffer.value = lastRT.texture;
|
||||
renderer.setRenderTarget(destRT);
|
||||
renderer.render(scene, camera);
|
||||
lastRT = destRT;
|
||||
}
|
||||
uniforms.kernel.value = kernel[i];
|
||||
uniforms.inputBuffer.value = lastRT.texture;
|
||||
renderer.setRenderTarget(this.renderToScreen ? null : outputBuffer);
|
||||
renderer.render(scene, camera);
|
||||
}
|
||||
}
|
||||
|
||||
export { BlurPass };
|
||||
1
node_modules/@react-three/drei/materials/ConvolutionMaterial.cjs.js
generated
vendored
Normal file
1
node_modules/@react-three/drei/materials/ConvolutionMaterial.cjs.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),n=require("../helpers/constants.cjs.js");function r(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}})),n.default=e,Object.freeze(n)}var t=r(e);class i extends t.ShaderMaterial{constructor(e=new t.Vector2){super({uniforms:{inputBuffer:new t.Uniform(null),depthBuffer:new t.Uniform(null),resolution:new t.Uniform(new t.Vector2),texelSize:new t.Uniform(new t.Vector2),halfTexelSize:new t.Uniform(new t.Vector2),kernel:new t.Uniform(0),scale:new t.Uniform(1),cameraNear:new t.Uniform(0),cameraFar:new t.Uniform(1),minDepthThreshold:new t.Uniform(0),maxDepthThreshold:new t.Uniform(1),depthScale:new t.Uniform(0),depthToBlurRatioBias:new t.Uniform(.25)},fragmentShader:`#include <common>\n #include <dithering_pars_fragment> \n uniform sampler2D inputBuffer;\n uniform sampler2D depthBuffer;\n uniform float cameraNear;\n uniform float cameraFar;\n uniform float minDepthThreshold;\n uniform float maxDepthThreshold;\n uniform float depthScale;\n uniform float depthToBlurRatioBias;\n varying vec2 vUv;\n varying vec2 vUv0;\n varying vec2 vUv1;\n varying vec2 vUv2;\n varying vec2 vUv3;\n\n void main() {\n float depthFactor = 0.0;\n \n #ifdef USE_DEPTH\n vec4 depth = texture2D(depthBuffer, vUv);\n depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));\n depthFactor *= depthScale;\n depthFactor = max(0.0, min(1.0, depthFactor + 0.25));\n #endif\n \n vec4 sum = texture2D(inputBuffer, mix(vUv0, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv1, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv2, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv3, vUv, depthFactor));\n gl_FragColor = sum * 0.25 ;\n\n #include <dithering_fragment>\n #include <tonemapping_fragment>\n #include <${n.version>=154?"colorspace_fragment":"encodings_fragment"}>\n }`,vertexShader:"uniform vec2 texelSize;\n uniform vec2 halfTexelSize;\n uniform float kernel;\n uniform float scale;\n varying vec2 vUv;\n varying vec2 vUv0;\n varying vec2 vUv1;\n varying vec2 vUv2;\n varying vec2 vUv3;\n\n void main() {\n vec2 uv = position.xy * 0.5 + 0.5;\n vUv = uv;\n\n vec2 dUv = (texelSize * vec2(kernel) + halfTexelSize) * scale;\n vUv0 = vec2(uv.x - dUv.x, uv.y + dUv.y);\n vUv1 = vec2(uv.x + dUv.x, uv.y + dUv.y);\n vUv2 = vec2(uv.x + dUv.x, uv.y - dUv.y);\n vUv3 = vec2(uv.x - dUv.x, uv.y - dUv.y);\n\n gl_Position = vec4(position.xy, 1.0, 1.0);\n }",blending:t.NoBlending,depthWrite:!1,depthTest:!1}),this.toneMapped=!1,this.setTexelSize(e.x,e.y),this.kernel=new Float32Array([0,1,2,2,3])}setTexelSize(e,n){this.uniforms.texelSize.value.set(e,n),this.uniforms.halfTexelSize.value.set(e,n).multiplyScalar(.5)}setResolution(e){this.uniforms.resolution.value.copy(e)}}exports.ConvolutionMaterial=i;
|
||||
7
node_modules/@react-three/drei/materials/ConvolutionMaterial.d.ts
generated
vendored
Normal file
7
node_modules/@react-three/drei/materials/ConvolutionMaterial.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import * as THREE from 'three';
|
||||
export declare class ConvolutionMaterial extends THREE.ShaderMaterial {
|
||||
readonly kernel: Float32Array;
|
||||
constructor(texelSize?: THREE.Vector2);
|
||||
setTexelSize(x: number, y: number): void;
|
||||
setResolution(resolution: THREE.Vector2): void;
|
||||
}
|
||||
97
node_modules/@react-three/drei/materials/ConvolutionMaterial.js
generated
vendored
Normal file
97
node_modules/@react-three/drei/materials/ConvolutionMaterial.js
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
import * as THREE from 'three';
|
||||
import { version } from '../helpers/constants.js';
|
||||
|
||||
class ConvolutionMaterial extends THREE.ShaderMaterial {
|
||||
constructor(texelSize = new THREE.Vector2()) {
|
||||
super({
|
||||
uniforms: {
|
||||
inputBuffer: new THREE.Uniform(null),
|
||||
depthBuffer: new THREE.Uniform(null),
|
||||
resolution: new THREE.Uniform(new THREE.Vector2()),
|
||||
texelSize: new THREE.Uniform(new THREE.Vector2()),
|
||||
halfTexelSize: new THREE.Uniform(new THREE.Vector2()),
|
||||
kernel: new THREE.Uniform(0.0),
|
||||
scale: new THREE.Uniform(1.0),
|
||||
cameraNear: new THREE.Uniform(0.0),
|
||||
cameraFar: new THREE.Uniform(1.0),
|
||||
minDepthThreshold: new THREE.Uniform(0.0),
|
||||
maxDepthThreshold: new THREE.Uniform(1.0),
|
||||
depthScale: new THREE.Uniform(0.0),
|
||||
depthToBlurRatioBias: new THREE.Uniform(0.25)
|
||||
},
|
||||
fragmentShader: `#include <common>
|
||||
#include <dithering_pars_fragment>
|
||||
uniform sampler2D inputBuffer;
|
||||
uniform sampler2D depthBuffer;
|
||||
uniform float cameraNear;
|
||||
uniform float cameraFar;
|
||||
uniform float minDepthThreshold;
|
||||
uniform float maxDepthThreshold;
|
||||
uniform float depthScale;
|
||||
uniform float depthToBlurRatioBias;
|
||||
varying vec2 vUv;
|
||||
varying vec2 vUv0;
|
||||
varying vec2 vUv1;
|
||||
varying vec2 vUv2;
|
||||
varying vec2 vUv3;
|
||||
|
||||
void main() {
|
||||
float depthFactor = 0.0;
|
||||
|
||||
#ifdef USE_DEPTH
|
||||
vec4 depth = texture2D(depthBuffer, vUv);
|
||||
depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));
|
||||
depthFactor *= depthScale;
|
||||
depthFactor = max(0.0, min(1.0, depthFactor + 0.25));
|
||||
#endif
|
||||
|
||||
vec4 sum = texture2D(inputBuffer, mix(vUv0, vUv, depthFactor));
|
||||
sum += texture2D(inputBuffer, mix(vUv1, vUv, depthFactor));
|
||||
sum += texture2D(inputBuffer, mix(vUv2, vUv, depthFactor));
|
||||
sum += texture2D(inputBuffer, mix(vUv3, vUv, depthFactor));
|
||||
gl_FragColor = sum * 0.25 ;
|
||||
|
||||
#include <dithering_fragment>
|
||||
#include <tonemapping_fragment>
|
||||
#include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
|
||||
}`,
|
||||
vertexShader: `uniform vec2 texelSize;
|
||||
uniform vec2 halfTexelSize;
|
||||
uniform float kernel;
|
||||
uniform float scale;
|
||||
varying vec2 vUv;
|
||||
varying vec2 vUv0;
|
||||
varying vec2 vUv1;
|
||||
varying vec2 vUv2;
|
||||
varying vec2 vUv3;
|
||||
|
||||
void main() {
|
||||
vec2 uv = position.xy * 0.5 + 0.5;
|
||||
vUv = uv;
|
||||
|
||||
vec2 dUv = (texelSize * vec2(kernel) + halfTexelSize) * scale;
|
||||
vUv0 = vec2(uv.x - dUv.x, uv.y + dUv.y);
|
||||
vUv1 = vec2(uv.x + dUv.x, uv.y + dUv.y);
|
||||
vUv2 = vec2(uv.x + dUv.x, uv.y - dUv.y);
|
||||
vUv3 = vec2(uv.x - dUv.x, uv.y - dUv.y);
|
||||
|
||||
gl_Position = vec4(position.xy, 1.0, 1.0);
|
||||
}`,
|
||||
blending: THREE.NoBlending,
|
||||
depthWrite: false,
|
||||
depthTest: false
|
||||
});
|
||||
this.toneMapped = false;
|
||||
this.setTexelSize(texelSize.x, texelSize.y);
|
||||
this.kernel = new Float32Array([0.0, 1.0, 2.0, 2.0, 3.0]);
|
||||
}
|
||||
setTexelSize(x, y) {
|
||||
this.uniforms.texelSize.value.set(x, y);
|
||||
this.uniforms.halfTexelSize.value.set(x, y).multiplyScalar(0.5);
|
||||
}
|
||||
setResolution(resolution) {
|
||||
this.uniforms.resolution.value.copy(resolution);
|
||||
}
|
||||
}
|
||||
|
||||
export { ConvolutionMaterial };
|
||||
1
node_modules/@react-three/drei/materials/DiscardMaterial.cjs.js
generated
vendored
Normal file
1
node_modules/@react-three/drei/materials/DiscardMaterial.cjs.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../core/shaderMaterial.cjs.js");require("three");const r=e.shaderMaterial({},"void main() { }","void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); discard; }");exports.DiscardMaterial=r;
|
||||
3
node_modules/@react-three/drei/materials/DiscardMaterial.d.ts
generated
vendored
Normal file
3
node_modules/@react-three/drei/materials/DiscardMaterial.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export declare const DiscardMaterial: import("@react-three/fiber").ConstructorRepresentation<import("three").ShaderMaterial> & {
|
||||
key: string;
|
||||
};
|
||||
5
node_modules/@react-three/drei/materials/DiscardMaterial.js
generated
vendored
Normal file
5
node_modules/@react-three/drei/materials/DiscardMaterial.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { shaderMaterial } from '../core/shaderMaterial.js';
|
||||
|
||||
const DiscardMaterial = /* @__PURE__ */shaderMaterial({}, 'void main() { }', 'void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); discard; }');
|
||||
|
||||
export { DiscardMaterial };
|
||||
1
node_modules/@react-three/drei/materials/MeshReflectorMaterial.cjs.js
generated
vendored
Normal file
1
node_modules/@react-three/drei/materials/MeshReflectorMaterial.cjs.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
50
node_modules/@react-three/drei/materials/MeshReflectorMaterial.d.ts
generated
vendored
Normal file
50
node_modules/@react-three/drei/materials/MeshReflectorMaterial.d.ts
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Matrix4, MeshStandardMaterial, Texture } from 'three';
|
||||
export declare class MeshReflectorMaterial extends MeshStandardMaterial {
|
||||
private _tDepth;
|
||||
private _distortionMap;
|
||||
private _tDiffuse;
|
||||
private _tDiffuseBlur;
|
||||
private _textureMatrix;
|
||||
private _hasBlur;
|
||||
private _mirror;
|
||||
private _mixBlur;
|
||||
private _blurStrength;
|
||||
private _minDepthThreshold;
|
||||
private _maxDepthThreshold;
|
||||
private _depthScale;
|
||||
private _depthToBlurRatioBias;
|
||||
private _distortion;
|
||||
private _mixContrast;
|
||||
constructor(parameters?: {});
|
||||
onBeforeCompile(shader: any): void;
|
||||
get tDiffuse(): Texture | null;
|
||||
set tDiffuse(v: Texture | null);
|
||||
get tDepth(): Texture | null;
|
||||
set tDepth(v: Texture | null);
|
||||
get distortionMap(): Texture | null;
|
||||
set distortionMap(v: Texture | null);
|
||||
get tDiffuseBlur(): Texture | null;
|
||||
set tDiffuseBlur(v: Texture | null);
|
||||
get textureMatrix(): Matrix4 | null;
|
||||
set textureMatrix(v: Matrix4 | null);
|
||||
get hasBlur(): boolean;
|
||||
set hasBlur(v: boolean);
|
||||
get mirror(): number;
|
||||
set mirror(v: number);
|
||||
get mixBlur(): number;
|
||||
set mixBlur(v: number);
|
||||
get mixStrength(): number;
|
||||
set mixStrength(v: number);
|
||||
get minDepthThreshold(): number;
|
||||
set minDepthThreshold(v: number);
|
||||
get maxDepthThreshold(): number;
|
||||
set maxDepthThreshold(v: number);
|
||||
get depthScale(): number;
|
||||
set depthScale(v: number);
|
||||
get depthToBlurRatioBias(): number;
|
||||
set depthToBlurRatioBias(v: number);
|
||||
get distortion(): number;
|
||||
set distortion(v: number);
|
||||
get mixContrast(): number;
|
||||
set mixContrast(v: number);
|
||||
}
|
||||
256
node_modules/@react-three/drei/materials/MeshReflectorMaterial.js
generated
vendored
Normal file
256
node_modules/@react-three/drei/materials/MeshReflectorMaterial.js
generated
vendored
Normal file
@@ -0,0 +1,256 @@
|
||||
import { MeshStandardMaterial } from 'three';
|
||||
|
||||
class MeshReflectorMaterial extends MeshStandardMaterial {
|
||||
constructor(parameters = {}) {
|
||||
super(parameters);
|
||||
this._tDepth = {
|
||||
value: null
|
||||
};
|
||||
this._distortionMap = {
|
||||
value: null
|
||||
};
|
||||
this._tDiffuse = {
|
||||
value: null
|
||||
};
|
||||
this._tDiffuseBlur = {
|
||||
value: null
|
||||
};
|
||||
this._textureMatrix = {
|
||||
value: null
|
||||
};
|
||||
this._hasBlur = {
|
||||
value: false
|
||||
};
|
||||
this._mirror = {
|
||||
value: 0.0
|
||||
};
|
||||
this._mixBlur = {
|
||||
value: 0.0
|
||||
};
|
||||
this._blurStrength = {
|
||||
value: 0.5
|
||||
};
|
||||
this._minDepthThreshold = {
|
||||
value: 0.9
|
||||
};
|
||||
this._maxDepthThreshold = {
|
||||
value: 1
|
||||
};
|
||||
this._depthScale = {
|
||||
value: 0
|
||||
};
|
||||
this._depthToBlurRatioBias = {
|
||||
value: 0.25
|
||||
};
|
||||
this._distortion = {
|
||||
value: 1
|
||||
};
|
||||
this._mixContrast = {
|
||||
value: 1.0
|
||||
};
|
||||
this.setValues(parameters);
|
||||
}
|
||||
onBeforeCompile(shader) {
|
||||
var _shader$defines;
|
||||
if (!((_shader$defines = shader.defines) != null && _shader$defines.USE_UV)) {
|
||||
shader.defines.USE_UV = '';
|
||||
}
|
||||
shader.uniforms.hasBlur = this._hasBlur;
|
||||
shader.uniforms.tDiffuse = this._tDiffuse;
|
||||
shader.uniforms.tDepth = this._tDepth;
|
||||
shader.uniforms.distortionMap = this._distortionMap;
|
||||
shader.uniforms.tDiffuseBlur = this._tDiffuseBlur;
|
||||
shader.uniforms.textureMatrix = this._textureMatrix;
|
||||
shader.uniforms.mirror = this._mirror;
|
||||
shader.uniforms.mixBlur = this._mixBlur;
|
||||
shader.uniforms.mixStrength = this._blurStrength;
|
||||
shader.uniforms.minDepthThreshold = this._minDepthThreshold;
|
||||
shader.uniforms.maxDepthThreshold = this._maxDepthThreshold;
|
||||
shader.uniforms.depthScale = this._depthScale;
|
||||
shader.uniforms.depthToBlurRatioBias = this._depthToBlurRatioBias;
|
||||
shader.uniforms.distortion = this._distortion;
|
||||
shader.uniforms.mixContrast = this._mixContrast;
|
||||
shader.vertexShader = `
|
||||
uniform mat4 textureMatrix;
|
||||
varying vec4 my_vUv;
|
||||
${shader.vertexShader}`;
|
||||
shader.vertexShader = shader.vertexShader.replace('#include <project_vertex>', `#include <project_vertex>
|
||||
my_vUv = textureMatrix * vec4( position, 1.0 );
|
||||
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );`);
|
||||
shader.fragmentShader = `
|
||||
uniform sampler2D tDiffuse;
|
||||
uniform sampler2D tDiffuseBlur;
|
||||
uniform sampler2D tDepth;
|
||||
uniform sampler2D distortionMap;
|
||||
uniform float distortion;
|
||||
uniform float cameraNear;
|
||||
uniform float cameraFar;
|
||||
uniform bool hasBlur;
|
||||
uniform float mixBlur;
|
||||
uniform float mirror;
|
||||
uniform float mixStrength;
|
||||
uniform float minDepthThreshold;
|
||||
uniform float maxDepthThreshold;
|
||||
uniform float mixContrast;
|
||||
uniform float depthScale;
|
||||
uniform float depthToBlurRatioBias;
|
||||
varying vec4 my_vUv;
|
||||
${shader.fragmentShader}`;
|
||||
shader.fragmentShader = shader.fragmentShader.replace('#include <emissivemap_fragment>', `#include <emissivemap_fragment>
|
||||
|
||||
float distortionFactor = 0.0;
|
||||
#ifdef USE_DISTORTION
|
||||
distortionFactor = texture2D(distortionMap, vUv).r * distortion;
|
||||
#endif
|
||||
|
||||
vec4 new_vUv = my_vUv;
|
||||
new_vUv.x += distortionFactor;
|
||||
new_vUv.y += distortionFactor;
|
||||
|
||||
vec4 base = texture2DProj(tDiffuse, new_vUv);
|
||||
vec4 blur = texture2DProj(tDiffuseBlur, new_vUv);
|
||||
|
||||
vec4 merge = base;
|
||||
|
||||
#ifdef USE_NORMALMAP
|
||||
vec2 normal_uv = vec2(0.0);
|
||||
vec4 normalColor = texture2D(normalMap, vUv * normalScale);
|
||||
vec3 my_normal = normalize( vec3( normalColor.r * 2.0 - 1.0, normalColor.b, normalColor.g * 2.0 - 1.0 ) );
|
||||
vec3 coord = new_vUv.xyz / new_vUv.w;
|
||||
normal_uv = coord.xy + coord.z * my_normal.xz * 0.05;
|
||||
vec4 base_normal = texture2D(tDiffuse, normal_uv);
|
||||
vec4 blur_normal = texture2D(tDiffuseBlur, normal_uv);
|
||||
merge = base_normal;
|
||||
blur = blur_normal;
|
||||
#endif
|
||||
|
||||
float depthFactor = 0.0001;
|
||||
float blurFactor = 0.0;
|
||||
|
||||
#ifdef USE_DEPTH
|
||||
vec4 depth = texture2DProj(tDepth, new_vUv);
|
||||
depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));
|
||||
depthFactor *= depthScale;
|
||||
depthFactor = max(0.0001, min(1.0, depthFactor));
|
||||
|
||||
#ifdef USE_BLUR
|
||||
blur = blur * min(1.0, depthFactor + depthToBlurRatioBias);
|
||||
merge = merge * min(1.0, depthFactor + 0.5);
|
||||
#else
|
||||
merge = merge * depthFactor;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
float reflectorRoughnessFactor = roughness;
|
||||
#ifdef USE_ROUGHNESSMAP
|
||||
vec4 reflectorTexelRoughness = texture2D( roughnessMap, vUv );
|
||||
reflectorRoughnessFactor *= reflectorTexelRoughness.g;
|
||||
#endif
|
||||
|
||||
#ifdef USE_BLUR
|
||||
blurFactor = min(1.0, mixBlur * reflectorRoughnessFactor);
|
||||
merge = mix(merge, blur, blurFactor);
|
||||
#endif
|
||||
|
||||
vec4 newMerge = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
newMerge.r = (merge.r - 0.5) * mixContrast + 0.5;
|
||||
newMerge.g = (merge.g - 0.5) * mixContrast + 0.5;
|
||||
newMerge.b = (merge.b - 0.5) * mixContrast + 0.5;
|
||||
|
||||
diffuseColor.rgb = diffuseColor.rgb * ((1.0 - min(1.0, mirror)) + newMerge.rgb * mixStrength);
|
||||
`);
|
||||
}
|
||||
get tDiffuse() {
|
||||
return this._tDiffuse.value;
|
||||
}
|
||||
set tDiffuse(v) {
|
||||
this._tDiffuse.value = v;
|
||||
}
|
||||
get tDepth() {
|
||||
return this._tDepth.value;
|
||||
}
|
||||
set tDepth(v) {
|
||||
this._tDepth.value = v;
|
||||
}
|
||||
get distortionMap() {
|
||||
return this._distortionMap.value;
|
||||
}
|
||||
set distortionMap(v) {
|
||||
this._distortionMap.value = v;
|
||||
}
|
||||
get tDiffuseBlur() {
|
||||
return this._tDiffuseBlur.value;
|
||||
}
|
||||
set tDiffuseBlur(v) {
|
||||
this._tDiffuseBlur.value = v;
|
||||
}
|
||||
get textureMatrix() {
|
||||
return this._textureMatrix.value;
|
||||
}
|
||||
set textureMatrix(v) {
|
||||
this._textureMatrix.value = v;
|
||||
}
|
||||
get hasBlur() {
|
||||
return this._hasBlur.value;
|
||||
}
|
||||
set hasBlur(v) {
|
||||
this._hasBlur.value = v;
|
||||
}
|
||||
get mirror() {
|
||||
return this._mirror.value;
|
||||
}
|
||||
set mirror(v) {
|
||||
this._mirror.value = v;
|
||||
}
|
||||
get mixBlur() {
|
||||
return this._mixBlur.value;
|
||||
}
|
||||
set mixBlur(v) {
|
||||
this._mixBlur.value = v;
|
||||
}
|
||||
get mixStrength() {
|
||||
return this._blurStrength.value;
|
||||
}
|
||||
set mixStrength(v) {
|
||||
this._blurStrength.value = v;
|
||||
}
|
||||
get minDepthThreshold() {
|
||||
return this._minDepthThreshold.value;
|
||||
}
|
||||
set minDepthThreshold(v) {
|
||||
this._minDepthThreshold.value = v;
|
||||
}
|
||||
get maxDepthThreshold() {
|
||||
return this._maxDepthThreshold.value;
|
||||
}
|
||||
set maxDepthThreshold(v) {
|
||||
this._maxDepthThreshold.value = v;
|
||||
}
|
||||
get depthScale() {
|
||||
return this._depthScale.value;
|
||||
}
|
||||
set depthScale(v) {
|
||||
this._depthScale.value = v;
|
||||
}
|
||||
get depthToBlurRatioBias() {
|
||||
return this._depthToBlurRatioBias.value;
|
||||
}
|
||||
set depthToBlurRatioBias(v) {
|
||||
this._depthToBlurRatioBias.value = v;
|
||||
}
|
||||
get distortion() {
|
||||
return this._distortion.value;
|
||||
}
|
||||
set distortion(v) {
|
||||
this._distortion.value = v;
|
||||
}
|
||||
get mixContrast() {
|
||||
return this._mixContrast.value;
|
||||
}
|
||||
set mixContrast(v) {
|
||||
this._mixContrast.value = v;
|
||||
}
|
||||
}
|
||||
|
||||
export { MeshReflectorMaterial };
|
||||
1
node_modules/@react-three/drei/materials/MeshRefractionMaterial.cjs.js
generated
vendored
Normal file
1
node_modules/@react-three/drei/materials/MeshRefractionMaterial.cjs.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
18
node_modules/@react-three/drei/materials/MeshRefractionMaterial.d.ts
generated
vendored
Normal file
18
node_modules/@react-three/drei/materials/MeshRefractionMaterial.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import * as THREE from 'three';
|
||||
import { MeshBVHUniformStruct } from 'three-mesh-bvh';
|
||||
export declare const MeshRefractionMaterial: import("@react-three/fiber").ConstructorRepresentation<THREE.ShaderMaterial & {
|
||||
envMap: null;
|
||||
bounces: number;
|
||||
ior: number;
|
||||
correctMips: true;
|
||||
aberrationStrength: number;
|
||||
fresnel: number;
|
||||
bvh: MeshBVHUniformStruct;
|
||||
color: THREE.Color;
|
||||
opacity: number;
|
||||
resolution: THREE.Vector2;
|
||||
viewMatrixInverse: THREE.Matrix4;
|
||||
projectionMatrixInverse: THREE.Matrix4;
|
||||
}> & {
|
||||
key: string;
|
||||
};
|
||||
163
node_modules/@react-three/drei/materials/MeshRefractionMaterial.js
generated
vendored
Normal file
163
node_modules/@react-three/drei/materials/MeshRefractionMaterial.js
generated
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
import * as THREE from 'three';
|
||||
import { shaderMaterial } from '../core/shaderMaterial.js';
|
||||
import { shaderStructs, shaderIntersectFunction, MeshBVHUniformStruct } from 'three-mesh-bvh';
|
||||
import { version } from '../helpers/constants.js';
|
||||
|
||||
// Author: N8Programs
|
||||
const MeshRefractionMaterial = /* @__PURE__ */shaderMaterial({
|
||||
envMap: null,
|
||||
bounces: 3,
|
||||
ior: 2.4,
|
||||
correctMips: true,
|
||||
aberrationStrength: 0.01,
|
||||
fresnel: 0,
|
||||
bvh: /* @__PURE__ */new MeshBVHUniformStruct(),
|
||||
color: /* @__PURE__ */new THREE.Color('white'),
|
||||
opacity: 1,
|
||||
resolution: /* @__PURE__ */new THREE.Vector2(),
|
||||
viewMatrixInverse: /* @__PURE__ */new THREE.Matrix4(),
|
||||
projectionMatrixInverse: /* @__PURE__ */new THREE.Matrix4()
|
||||
}, /*glsl*/`
|
||||
uniform mat4 viewMatrixInverse;
|
||||
|
||||
varying vec3 vWorldPosition;
|
||||
varying vec3 vNormal;
|
||||
varying mat4 vModelMatrixInverse;
|
||||
|
||||
#include <color_pars_vertex>
|
||||
|
||||
void main() {
|
||||
#include <color_vertex>
|
||||
|
||||
vec4 transformedNormal = vec4(normal, 0.0);
|
||||
vec4 transformedPosition = vec4(position, 1.0);
|
||||
#ifdef USE_INSTANCING
|
||||
transformedNormal = instanceMatrix * transformedNormal;
|
||||
transformedPosition = instanceMatrix * transformedPosition;
|
||||
#endif
|
||||
|
||||
#ifdef USE_INSTANCING
|
||||
vModelMatrixInverse = inverse(modelMatrix * instanceMatrix);
|
||||
#else
|
||||
vModelMatrixInverse = inverse(modelMatrix);
|
||||
#endif
|
||||
|
||||
vWorldPosition = (modelMatrix * transformedPosition).xyz;
|
||||
vNormal = normalize((viewMatrixInverse * vec4(normalMatrix * transformedNormal.xyz, 0.0)).xyz);
|
||||
gl_Position = projectionMatrix * viewMatrix * modelMatrix * transformedPosition;
|
||||
}`, /*glsl*/`
|
||||
#define ENVMAP_TYPE_CUBE_UV
|
||||
precision highp isampler2D;
|
||||
precision highp usampler2D;
|
||||
varying vec3 vWorldPosition;
|
||||
varying vec3 vNormal;
|
||||
varying mat4 vModelMatrixInverse;
|
||||
|
||||
#include <color_pars_fragment>
|
||||
|
||||
#ifdef ENVMAP_TYPE_CUBEM
|
||||
uniform samplerCube envMap;
|
||||
#else
|
||||
uniform sampler2D envMap;
|
||||
#endif
|
||||
|
||||
uniform float bounces;
|
||||
${shaderStructs}
|
||||
${shaderIntersectFunction}
|
||||
uniform BVH bvh;
|
||||
uniform float ior;
|
||||
uniform bool correctMips;
|
||||
uniform vec2 resolution;
|
||||
uniform float fresnel;
|
||||
uniform mat4 modelMatrix;
|
||||
uniform mat4 projectionMatrixInverse;
|
||||
uniform mat4 viewMatrixInverse;
|
||||
uniform float aberrationStrength;
|
||||
uniform vec3 color;
|
||||
uniform float opacity;
|
||||
|
||||
float fresnelFunc(vec3 viewDirection, vec3 worldNormal) {
|
||||
return pow( 1.0 + dot( viewDirection, worldNormal), 10.0 );
|
||||
}
|
||||
|
||||
vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 normal, float ior, mat4 modelMatrixInverse) {
|
||||
vec3 rayOrigin = ro;
|
||||
vec3 rayDirection = rd;
|
||||
rayDirection = refract(rayDirection, normal, 1.0 / ior);
|
||||
rayOrigin = vWorldPosition + rayDirection * 0.001;
|
||||
rayOrigin = (modelMatrixInverse * vec4(rayOrigin, 1.0)).xyz;
|
||||
rayDirection = normalize((modelMatrixInverse * vec4(rayDirection, 0.0)).xyz);
|
||||
for(float i = 0.0; i < bounces; i++) {
|
||||
uvec4 faceIndices = uvec4( 0u );
|
||||
vec3 faceNormal = vec3( 0.0, 0.0, 1.0 );
|
||||
vec3 barycoord = vec3( 0.0 );
|
||||
float side = 1.0;
|
||||
float dist = 0.0;
|
||||
bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist );
|
||||
vec3 hitPos = rayOrigin + rayDirection * max(dist - 0.001, 0.0);
|
||||
vec3 tempDir = refract(rayDirection, faceNormal, ior);
|
||||
if (length(tempDir) != 0.0) {
|
||||
rayDirection = tempDir;
|
||||
break;
|
||||
}
|
||||
rayDirection = reflect(rayDirection, faceNormal);
|
||||
rayOrigin = hitPos + rayDirection * 0.01;
|
||||
}
|
||||
rayDirection = normalize((modelMatrix * vec4(rayDirection, 0.0)).xyz);
|
||||
return rayDirection;
|
||||
}
|
||||
|
||||
#include <common>
|
||||
#include <cube_uv_reflection_fragment>
|
||||
|
||||
#ifdef ENVMAP_TYPE_CUBEM
|
||||
vec4 textureGradient(samplerCube envMap, vec3 rayDirection, vec3 directionCamPerfect) {
|
||||
return textureGrad(envMap, rayDirection, dFdx(correctMips ? directionCamPerfect: rayDirection), dFdy(correctMips ? directionCamPerfect: rayDirection));
|
||||
}
|
||||
#else
|
||||
vec4 textureGradient(sampler2D envMap, vec3 rayDirection, vec3 directionCamPerfect) {
|
||||
vec2 uvv = equirectUv( rayDirection );
|
||||
vec2 smoothUv = equirectUv( directionCamPerfect );
|
||||
return textureGrad(envMap, uvv, dFdx(correctMips ? smoothUv : uvv), dFdy(correctMips ? smoothUv : uvv));
|
||||
}
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec2 uv = gl_FragCoord.xy / resolution;
|
||||
vec3 directionCamPerfect = (projectionMatrixInverse * vec4(uv * 2.0 - 1.0, 0.0, 1.0)).xyz;
|
||||
directionCamPerfect = (viewMatrixInverse * vec4(directionCamPerfect, 0.0)).xyz;
|
||||
directionCamPerfect = normalize(directionCamPerfect);
|
||||
vec3 normal = vNormal;
|
||||
vec3 rayOrigin = cameraPosition;
|
||||
vec3 rayDirection = normalize(vWorldPosition - cameraPosition);
|
||||
|
||||
vec4 diffuseColor = vec4(color, opacity);
|
||||
#include <color_fragment>
|
||||
|
||||
#ifdef CHROMATIC_ABERRATIONS
|
||||
vec3 rayDirectionG = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);
|
||||
#ifdef FAST_CHROMA
|
||||
vec3 rayDirectionR = normalize(rayDirectionG + 1.0 * vec3(aberrationStrength / 2.0));
|
||||
vec3 rayDirectionB = normalize(rayDirectionG - 1.0 * vec3(aberrationStrength / 2.0));
|
||||
#else
|
||||
vec3 rayDirectionR = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 - aberrationStrength), 1.0), vModelMatrixInverse);
|
||||
vec3 rayDirectionB = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 + aberrationStrength), 1.0), vModelMatrixInverse);
|
||||
#endif
|
||||
float finalColorR = textureGradient(envMap, rayDirectionR, directionCamPerfect).r;
|
||||
float finalColorG = textureGradient(envMap, rayDirectionG, directionCamPerfect).g;
|
||||
float finalColorB = textureGradient(envMap, rayDirectionB, directionCamPerfect).b;
|
||||
diffuseColor.rgb *= vec3(finalColorR, finalColorG, finalColorB);
|
||||
#else
|
||||
rayDirection = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);
|
||||
diffuseColor.rgb *= textureGradient(envMap, rayDirection, directionCamPerfect).rgb;
|
||||
#endif
|
||||
|
||||
vec3 viewDirection = normalize(vWorldPosition - cameraPosition);
|
||||
float nFresnel = fresnelFunc(viewDirection, normal) * fresnel;
|
||||
gl_FragColor = vec4(mix(diffuseColor.rgb, vec3(1.0), nFresnel), diffuseColor.a);
|
||||
|
||||
#include <tonemapping_fragment>
|
||||
#include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
|
||||
}`);
|
||||
|
||||
export { MeshRefractionMaterial };
|
||||
1
node_modules/@react-three/drei/materials/SpotLightMaterial.cjs.js
generated
vendored
Normal file
1
node_modules/@react-three/drei/materials/SpotLightMaterial.cjs.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),n=require("../helpers/constants.cjs.js");function t(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})}})),n.default=e,Object.freeze(n)}var o=t(e);class r extends o.ShaderMaterial{constructor(){super({uniforms:{depth:{value:null},opacity:{value:1},attenuation:{value:2.5},anglePower:{value:12},spotPosition:{value:new o.Vector3(0,0,0)},lightColor:{value:new o.Color("white")},cameraNear:{value:0},cameraFar:{value:1},resolution:{value:new o.Vector2(0,0)}},transparent:!0,depthWrite:!1,vertexShader:"\n varying vec3 vNormal;\n varying float vViewZ;\n varying float vIntensity;\n uniform vec3 spotPosition;\n uniform float attenuation;\n\n #include <common>\n #include <logdepthbuf_pars_vertex>\n\n void main() {\n // compute intensity\n vNormal = normalize(normalMatrix * normal);\n vec4 worldPosition = modelMatrix * vec4(position, 1);\n vec4 viewPosition = viewMatrix * worldPosition;\n vViewZ = viewPosition.z;\n\n vIntensity = 1.0 - saturate(distance(worldPosition.xyz, spotPosition) / attenuation);\n\n gl_Position = projectionMatrix * viewPosition;\n\n #include <logdepthbuf_vertex>\n }\n ",fragmentShader:`\n varying vec3 vNormal;\n varying float vViewZ;\n varying float vIntensity;\n\n uniform vec3 lightColor;\n uniform float anglePower;\n uniform sampler2D depth;\n uniform vec2 resolution;\n uniform float cameraNear;\n uniform float cameraFar;\n uniform float opacity;\n\n #include <packing>\n #include <logdepthbuf_pars_fragment>\n\n float readDepth(sampler2D depthSampler, vec2 uv) {\n float fragCoordZ = texture(depthSampler, uv).r;\n\n // https://github.com/mrdoob/three.js/issues/23072\n #ifdef USE_LOGDEPTHBUF\n float viewZ = 1.0 - exp2(fragCoordZ * log(cameraFar + 1.0) / log(2.0));\n #else\n float viewZ = perspectiveDepthToViewZ(fragCoordZ, cameraNear, cameraFar);\n #endif\n\n return viewZ;\n }\n\n void main() {\n #include <logdepthbuf_fragment>\n\n vec3 normal = vec3(vNormal.x, vNormal.y, abs(vNormal.z));\n float angleIntensity = pow(dot(normal, vec3(0, 0, 1)), anglePower);\n float intensity = vIntensity * angleIntensity;\n\n // fades when z is close to sampled depth, meaning the cone is intersecting existing geometry\n bool isSoft = resolution[0] > 0.0 && resolution[1] > 0.0;\n if (isSoft) {\n vec2 uv = gl_FragCoord.xy / resolution;\n intensity *= smoothstep(0.0, 1.0, vViewZ - readDepth(depth, uv));\n }\n\n gl_FragColor = vec4(lightColor, intensity * opacity);\n\n #include <tonemapping_fragment>\n #include <${n.version>=154?"colorspace_fragment":"encodings_fragment"}>\n }\n `})}}exports.SpotLightMaterial=r;
|
||||
4
node_modules/@react-three/drei/materials/SpotLightMaterial.d.ts
generated
vendored
Normal file
4
node_modules/@react-three/drei/materials/SpotLightMaterial.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import * as THREE from 'three';
|
||||
export declare class SpotLightMaterial extends THREE.ShaderMaterial {
|
||||
constructor();
|
||||
}
|
||||
115
node_modules/@react-three/drei/materials/SpotLightMaterial.js
generated
vendored
Normal file
115
node_modules/@react-three/drei/materials/SpotLightMaterial.js
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
import * as THREE from 'three';
|
||||
import { version } from '../helpers/constants.js';
|
||||
|
||||
class SpotLightMaterial extends THREE.ShaderMaterial {
|
||||
constructor() {
|
||||
super({
|
||||
uniforms: {
|
||||
depth: {
|
||||
value: null
|
||||
},
|
||||
opacity: {
|
||||
value: 1
|
||||
},
|
||||
attenuation: {
|
||||
value: 2.5
|
||||
},
|
||||
anglePower: {
|
||||
value: 12
|
||||
},
|
||||
spotPosition: {
|
||||
value: new THREE.Vector3(0, 0, 0)
|
||||
},
|
||||
lightColor: {
|
||||
value: new THREE.Color('white')
|
||||
},
|
||||
cameraNear: {
|
||||
value: 0
|
||||
},
|
||||
cameraFar: {
|
||||
value: 1
|
||||
},
|
||||
resolution: {
|
||||
value: new THREE.Vector2(0, 0)
|
||||
}
|
||||
},
|
||||
transparent: true,
|
||||
depthWrite: false,
|
||||
vertexShader: /* glsl */`
|
||||
varying vec3 vNormal;
|
||||
varying float vViewZ;
|
||||
varying float vIntensity;
|
||||
uniform vec3 spotPosition;
|
||||
uniform float attenuation;
|
||||
|
||||
#include <common>
|
||||
#include <logdepthbuf_pars_vertex>
|
||||
|
||||
void main() {
|
||||
// compute intensity
|
||||
vNormal = normalize(normalMatrix * normal);
|
||||
vec4 worldPosition = modelMatrix * vec4(position, 1);
|
||||
vec4 viewPosition = viewMatrix * worldPosition;
|
||||
vViewZ = viewPosition.z;
|
||||
|
||||
vIntensity = 1.0 - saturate(distance(worldPosition.xyz, spotPosition) / attenuation);
|
||||
|
||||
gl_Position = projectionMatrix * viewPosition;
|
||||
|
||||
#include <logdepthbuf_vertex>
|
||||
}
|
||||
`,
|
||||
fragmentShader: /* glsl */`
|
||||
varying vec3 vNormal;
|
||||
varying float vViewZ;
|
||||
varying float vIntensity;
|
||||
|
||||
uniform vec3 lightColor;
|
||||
uniform float anglePower;
|
||||
uniform sampler2D depth;
|
||||
uniform vec2 resolution;
|
||||
uniform float cameraNear;
|
||||
uniform float cameraFar;
|
||||
uniform float opacity;
|
||||
|
||||
#include <packing>
|
||||
#include <logdepthbuf_pars_fragment>
|
||||
|
||||
float readDepth(sampler2D depthSampler, vec2 uv) {
|
||||
float fragCoordZ = texture(depthSampler, uv).r;
|
||||
|
||||
// https://github.com/mrdoob/three.js/issues/23072
|
||||
#ifdef USE_LOGDEPTHBUF
|
||||
float viewZ = 1.0 - exp2(fragCoordZ * log(cameraFar + 1.0) / log(2.0));
|
||||
#else
|
||||
float viewZ = perspectiveDepthToViewZ(fragCoordZ, cameraNear, cameraFar);
|
||||
#endif
|
||||
|
||||
return viewZ;
|
||||
}
|
||||
|
||||
void main() {
|
||||
#include <logdepthbuf_fragment>
|
||||
|
||||
vec3 normal = vec3(vNormal.x, vNormal.y, abs(vNormal.z));
|
||||
float angleIntensity = pow(dot(normal, vec3(0, 0, 1)), anglePower);
|
||||
float intensity = vIntensity * angleIntensity;
|
||||
|
||||
// fades when z is close to sampled depth, meaning the cone is intersecting existing geometry
|
||||
bool isSoft = resolution[0] > 0.0 && resolution[1] > 0.0;
|
||||
if (isSoft) {
|
||||
vec2 uv = gl_FragCoord.xy / resolution;
|
||||
intensity *= smoothstep(0.0, 1.0, vViewZ - readDepth(depth, uv));
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(lightColor, intensity * opacity);
|
||||
|
||||
#include <tonemapping_fragment>
|
||||
#include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
|
||||
}
|
||||
`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export { SpotLightMaterial };
|
||||
1
node_modules/@react-three/drei/materials/WireframeMaterial.cjs.js
generated
vendored
Normal file
1
node_modules/@react-three/drei/materials/WireframeMaterial.cjs.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
64
node_modules/@react-three/drei/materials/WireframeMaterial.d.ts
generated
vendored
Normal file
64
node_modules/@react-three/drei/materials/WireframeMaterial.d.ts
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
import * as THREE from 'three';
|
||||
export interface WireframeMaterialProps extends THREE.ShaderMaterialParameters {
|
||||
fillOpacity?: number;
|
||||
fillMix?: number;
|
||||
strokeOpacity?: number;
|
||||
thickness?: number;
|
||||
colorBackfaces?: boolean;
|
||||
dashInvert?: boolean;
|
||||
dash?: boolean;
|
||||
dashRepeats?: number;
|
||||
dashLength?: number;
|
||||
squeeze?: boolean;
|
||||
squeezeMin?: number;
|
||||
squeezeMax?: number;
|
||||
stroke?: THREE.ColorRepresentation;
|
||||
backfaceStroke?: THREE.ColorRepresentation;
|
||||
fill?: THREE.ColorRepresentation;
|
||||
}
|
||||
export declare const WireframeMaterialShaders: {
|
||||
uniforms: {
|
||||
strokeOpacity: number;
|
||||
fillOpacity: number;
|
||||
fillMix: number;
|
||||
thickness: number;
|
||||
colorBackfaces: boolean;
|
||||
dashInvert: boolean;
|
||||
dash: boolean;
|
||||
dashRepeats: number;
|
||||
dashLength: number;
|
||||
squeeze: boolean;
|
||||
squeezeMin: number;
|
||||
squeezeMax: number;
|
||||
stroke: THREE.Color;
|
||||
backfaceStroke: THREE.Color;
|
||||
fill: THREE.Color;
|
||||
};
|
||||
vertex: string;
|
||||
fragment: string;
|
||||
};
|
||||
export declare const WireframeMaterial: import("@react-three/fiber").ConstructorRepresentation<THREE.ShaderMaterial & {
|
||||
strokeOpacity: number;
|
||||
fillOpacity: number;
|
||||
fillMix: number;
|
||||
thickness: number;
|
||||
colorBackfaces: boolean;
|
||||
dashInvert: boolean;
|
||||
dash: boolean;
|
||||
dashRepeats: number;
|
||||
dashLength: number;
|
||||
squeeze: boolean;
|
||||
squeezeMin: number;
|
||||
squeezeMax: number;
|
||||
stroke: THREE.Color;
|
||||
backfaceStroke: THREE.Color;
|
||||
fill: THREE.Color;
|
||||
}> & {
|
||||
key: string;
|
||||
};
|
||||
export declare function setWireframeOverride(material: THREE.Material, uniforms: {
|
||||
[key: string]: THREE.IUniform<any>;
|
||||
}): void;
|
||||
export declare function useWireframeUniforms(uniforms: {
|
||||
[key: string]: THREE.IUniform<any>;
|
||||
}, props: WireframeMaterialProps): void;
|
||||
217
node_modules/@react-three/drei/materials/WireframeMaterial.js
generated
vendored
Normal file
217
node_modules/@react-three/drei/materials/WireframeMaterial.js
generated
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
import * as THREE from 'three';
|
||||
import * as React from 'react';
|
||||
import { shaderMaterial } from '../core/shaderMaterial.js';
|
||||
|
||||
const WireframeMaterialShaders = {
|
||||
uniforms: {
|
||||
strokeOpacity: 1,
|
||||
fillOpacity: 0.25,
|
||||
fillMix: 0,
|
||||
thickness: 0.05,
|
||||
colorBackfaces: false,
|
||||
dashInvert: true,
|
||||
dash: false,
|
||||
dashRepeats: 4,
|
||||
dashLength: 0.5,
|
||||
squeeze: false,
|
||||
squeezeMin: 0.2,
|
||||
squeezeMax: 1,
|
||||
stroke: /* @__PURE__ */new THREE.Color('#ff0000'),
|
||||
backfaceStroke: /* @__PURE__ */new THREE.Color('#0000ff'),
|
||||
fill: /* @__PURE__ */new THREE.Color('#00ff00')
|
||||
},
|
||||
vertex: /* glsl */`
|
||||
attribute vec3 barycentric;
|
||||
|
||||
varying vec3 v_edges_Barycentric;
|
||||
varying vec3 v_edges_Position;
|
||||
|
||||
void initWireframe() {
|
||||
v_edges_Barycentric = barycentric;
|
||||
v_edges_Position = position.xyz;
|
||||
}
|
||||
`,
|
||||
fragment: /* glsl */`
|
||||
#ifndef PI
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#endif
|
||||
|
||||
varying vec3 v_edges_Barycentric;
|
||||
varying vec3 v_edges_Position;
|
||||
|
||||
uniform float strokeOpacity;
|
||||
uniform float fillOpacity;
|
||||
uniform float fillMix;
|
||||
uniform float thickness;
|
||||
uniform bool colorBackfaces;
|
||||
|
||||
// Dash
|
||||
uniform bool dashInvert;
|
||||
uniform bool dash;
|
||||
uniform bool dashOnly;
|
||||
uniform float dashRepeats;
|
||||
uniform float dashLength;
|
||||
|
||||
// Squeeze
|
||||
uniform bool squeeze;
|
||||
uniform float squeezeMin;
|
||||
uniform float squeezeMax;
|
||||
|
||||
// Colors
|
||||
uniform vec3 stroke;
|
||||
uniform vec3 backfaceStroke;
|
||||
uniform vec3 fill;
|
||||
|
||||
// This is like
|
||||
float wireframe_aastep(float threshold, float dist) {
|
||||
float afwidth = fwidth(dist) * 0.5;
|
||||
return smoothstep(threshold - afwidth, threshold + afwidth, dist);
|
||||
}
|
||||
|
||||
float wireframe_map(float value, float min1, float max1, float min2, float max2) {
|
||||
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
|
||||
}
|
||||
|
||||
float getWireframe() {
|
||||
vec3 barycentric = v_edges_Barycentric;
|
||||
|
||||
// Distance from center of each triangle to its edges.
|
||||
float d = min(min(barycentric.x, barycentric.y), barycentric.z);
|
||||
|
||||
// for dashed rendering, we can use this to get the 0 .. 1 value of the line length
|
||||
float positionAlong = max(barycentric.x, barycentric.y);
|
||||
if (barycentric.y < barycentric.x && barycentric.y < barycentric.z) {
|
||||
positionAlong = 1.0 - positionAlong;
|
||||
}
|
||||
|
||||
// the thickness of the stroke
|
||||
float computedThickness = wireframe_map(thickness, 0.0, 1.0, 0.0, 0.34);
|
||||
|
||||
// if we want to shrink the thickness toward the center of the line segment
|
||||
if (squeeze) {
|
||||
computedThickness *= mix(squeezeMin, squeezeMax, (1.0 - sin(positionAlong * PI)));
|
||||
}
|
||||
|
||||
// Create dash pattern
|
||||
if (dash) {
|
||||
// here we offset the stroke position depending on whether it
|
||||
// should overlap or not
|
||||
float offset = 1.0 / dashRepeats * dashLength / 2.0;
|
||||
if (!dashInvert) {
|
||||
offset += 1.0 / dashRepeats / 2.0;
|
||||
}
|
||||
|
||||
// if we should animate the dash or not
|
||||
// if (dashAnimate) {
|
||||
// offset += time * 0.22;
|
||||
// }
|
||||
|
||||
// create the repeating dash pattern
|
||||
float pattern = fract((positionAlong + offset) * dashRepeats);
|
||||
computedThickness *= 1.0 - wireframe_aastep(dashLength, pattern);
|
||||
}
|
||||
|
||||
// compute the anti-aliased stroke edge
|
||||
float edge = 1.0 - wireframe_aastep(computedThickness, d);
|
||||
|
||||
return edge;
|
||||
}
|
||||
`
|
||||
};
|
||||
const WireframeMaterial = /* @__PURE__ */shaderMaterial(WireframeMaterialShaders.uniforms, WireframeMaterialShaders.vertex + /* glsl */`
|
||||
void main() {
|
||||
initWireframe();
|
||||
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
||||
}
|
||||
`, WireframeMaterialShaders.fragment + /* glsl */`
|
||||
void main () {
|
||||
// Compute color
|
||||
|
||||
float edge = getWireframe();
|
||||
vec4 colorStroke = vec4(stroke, edge);
|
||||
|
||||
#ifdef FLIP_SIDED
|
||||
colorStroke.rgb = backfaceStroke;
|
||||
#endif
|
||||
|
||||
vec4 colorFill = vec4(fill, fillOpacity);
|
||||
vec4 outColor = mix(colorFill, colorStroke, edge * strokeOpacity);
|
||||
|
||||
gl_FragColor = outColor;
|
||||
}
|
||||
`);
|
||||
function setWireframeOverride(material, uniforms) {
|
||||
material.onBeforeCompile = shader => {
|
||||
shader.uniforms = {
|
||||
...shader.uniforms,
|
||||
...uniforms
|
||||
};
|
||||
shader.vertexShader = shader.vertexShader.replace('void main() {', `
|
||||
${WireframeMaterialShaders.vertex}
|
||||
void main() {
|
||||
initWireframe();
|
||||
`);
|
||||
shader.fragmentShader = shader.fragmentShader.replace('void main() {', `
|
||||
${WireframeMaterialShaders.fragment}
|
||||
void main() {
|
||||
`);
|
||||
shader.fragmentShader = shader.fragmentShader.replace('#include <color_fragment>', /* glsl */`
|
||||
#include <color_fragment>
|
||||
float edge = getWireframe();
|
||||
vec4 colorStroke = vec4(stroke, edge);
|
||||
#ifdef FLIP_SIDED
|
||||
colorStroke.rgb = backfaceStroke;
|
||||
#endif
|
||||
vec4 colorFill = vec4(mix(diffuseColor.rgb, fill, fillMix), mix(diffuseColor.a, fillOpacity, fillMix));
|
||||
vec4 outColor = mix(colorFill, colorStroke, edge * strokeOpacity);
|
||||
|
||||
diffuseColor.rgb = outColor.rgb;
|
||||
diffuseColor.a *= outColor.a;
|
||||
`);
|
||||
};
|
||||
material.side = THREE.DoubleSide;
|
||||
material.transparent = true;
|
||||
}
|
||||
function useWireframeUniforms(uniforms, props) {
|
||||
React.useEffect(() => {
|
||||
var _props$fillOpacity;
|
||||
return void (uniforms.fillOpacity.value = (_props$fillOpacity = props.fillOpacity) !== null && _props$fillOpacity !== void 0 ? _props$fillOpacity : uniforms.fillOpacity.value);
|
||||
}, [props.fillOpacity]);
|
||||
React.useEffect(() => {
|
||||
var _props$fillMix;
|
||||
return void (uniforms.fillMix.value = (_props$fillMix = props.fillMix) !== null && _props$fillMix !== void 0 ? _props$fillMix : uniforms.fillMix.value);
|
||||
}, [props.fillMix]);
|
||||
React.useEffect(() => {
|
||||
var _props$strokeOpacity;
|
||||
return void (uniforms.strokeOpacity.value = (_props$strokeOpacity = props.strokeOpacity) !== null && _props$strokeOpacity !== void 0 ? _props$strokeOpacity : uniforms.strokeOpacity.value);
|
||||
}, [props.strokeOpacity]);
|
||||
React.useEffect(() => {
|
||||
var _props$thickness;
|
||||
return void (uniforms.thickness.value = (_props$thickness = props.thickness) !== null && _props$thickness !== void 0 ? _props$thickness : uniforms.thickness.value);
|
||||
}, [props.thickness]);
|
||||
React.useEffect(() => void (uniforms.colorBackfaces.value = !!props.colorBackfaces), [props.colorBackfaces]);
|
||||
React.useEffect(() => void (uniforms.dash.value = !!props.dash), [props.dash]);
|
||||
React.useEffect(() => void (uniforms.dashInvert.value = !!props.dashInvert), [props.dashInvert]);
|
||||
React.useEffect(() => {
|
||||
var _props$dashRepeats;
|
||||
return void (uniforms.dashRepeats.value = (_props$dashRepeats = props.dashRepeats) !== null && _props$dashRepeats !== void 0 ? _props$dashRepeats : uniforms.dashRepeats.value);
|
||||
}, [props.dashRepeats]);
|
||||
React.useEffect(() => {
|
||||
var _props$dashLength;
|
||||
return void (uniforms.dashLength.value = (_props$dashLength = props.dashLength) !== null && _props$dashLength !== void 0 ? _props$dashLength : uniforms.dashLength.value);
|
||||
}, [props.dashLength]);
|
||||
React.useEffect(() => void (uniforms.squeeze.value = !!props.squeeze), [props.squeeze]);
|
||||
React.useEffect(() => {
|
||||
var _props$squeezeMin;
|
||||
return void (uniforms.squeezeMin.value = (_props$squeezeMin = props.squeezeMin) !== null && _props$squeezeMin !== void 0 ? _props$squeezeMin : uniforms.squeezeMin.value);
|
||||
}, [props.squeezeMin]);
|
||||
React.useEffect(() => {
|
||||
var _props$squeezeMax;
|
||||
return void (uniforms.squeezeMax.value = (_props$squeezeMax = props.squeezeMax) !== null && _props$squeezeMax !== void 0 ? _props$squeezeMax : uniforms.squeezeMax.value);
|
||||
}, [props.squeezeMax]);
|
||||
React.useEffect(() => void (uniforms.stroke.value = props.stroke ? new THREE.Color(props.stroke) : uniforms.stroke.value), [props.stroke]);
|
||||
React.useEffect(() => void (uniforms.fill.value = props.fill ? new THREE.Color(props.fill) : uniforms.fill.value), [props.fill]);
|
||||
React.useEffect(() => void (uniforms.backfaceStroke.value = props.backfaceStroke ? new THREE.Color(props.backfaceStroke) : uniforms.backfaceStroke.value), [props.backfaceStroke]);
|
||||
}
|
||||
|
||||
export { WireframeMaterial, WireframeMaterialShaders, setWireframeOverride, useWireframeUniforms };
|
||||
Reference in New Issue
Block a user