@react-three/drei 9.89.1 → 9.89.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/useTexture.cjs.js +1 -1
- package/core/useTexture.d.ts +3 -2
- package/core/useTexture.js +2 -4
- package/core/useVideoTexture.cjs.js +1 -1
- package/core/useVideoTexture.js +6 -1
- package/index.cjs.js +1 -1
- package/materials/SpotLightMaterial.cjs.js +1 -1
- package/materials/SpotLightMaterial.js +69 -61
- package/package.json +1 -1
- package/react-three-drei-0.0.0-semantic-release.tgz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
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;
|
|
@@ -36,70 +36,78 @@ class SpotLightMaterial extends THREE.ShaderMaterial {
|
|
|
36
36
|
transparent: true,
|
|
37
37
|
depthWrite: false,
|
|
38
38
|
vertexShader: /* glsl */`
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
fragmentShader: /* glsl */`
|
|
61
|
-
#include <packing>
|
|
62
|
-
|
|
63
|
-
varying vec3 vNormal;
|
|
64
|
-
varying vec3 vWorldPosition;
|
|
65
|
-
uniform vec3 lightColor;
|
|
66
|
-
uniform vec3 spotPosition;
|
|
67
|
-
uniform float attenuation;
|
|
68
|
-
uniform float anglePower;
|
|
69
|
-
uniform sampler2D depth;
|
|
70
|
-
uniform vec2 resolution;
|
|
71
|
-
uniform float cameraNear;
|
|
72
|
-
uniform float cameraFar;
|
|
73
|
-
varying float vViewZ;
|
|
74
|
-
varying float vIntensity;
|
|
75
|
-
uniform float opacity;
|
|
76
|
-
|
|
77
|
-
float readDepth( sampler2D depthSampler, vec2 coord ) {
|
|
78
|
-
float fragCoordZ = texture2D( depthSampler, coord ).x;
|
|
79
|
-
float viewZ = perspectiveDepthToViewZ(fragCoordZ, cameraNear, cameraFar);
|
|
80
|
-
return viewZ;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
void main() {
|
|
84
|
-
float d = 1.0;
|
|
85
|
-
bool isSoft = resolution[0] > 0.0 && resolution[1] > 0.0;
|
|
86
|
-
if (isSoft) {
|
|
87
|
-
vec2 sUv = gl_FragCoord.xy / resolution;
|
|
88
|
-
d = readDepth(depth, sUv);
|
|
39
|
+
varying vec3 vNormal;
|
|
40
|
+
varying float vViewZ;
|
|
41
|
+
varying float vIntensity;
|
|
42
|
+
uniform vec3 spotPosition;
|
|
43
|
+
uniform float attenuation;
|
|
44
|
+
|
|
45
|
+
#include <common>
|
|
46
|
+
#include <logdepthbuf_pars_vertex>
|
|
47
|
+
|
|
48
|
+
void main() {
|
|
49
|
+
// compute intensity
|
|
50
|
+
vNormal = normalize(normalMatrix * normal);
|
|
51
|
+
vec4 worldPosition = modelMatrix * vec4(position, 1);
|
|
52
|
+
vec4 viewPosition = viewMatrix * worldPosition;
|
|
53
|
+
vViewZ = viewPosition.z;
|
|
54
|
+
|
|
55
|
+
vIntensity = 1.0 - saturate(distance(worldPosition.xyz, spotPosition) / attenuation);
|
|
56
|
+
|
|
57
|
+
gl_Position = projectionMatrix * viewPosition;
|
|
58
|
+
|
|
59
|
+
#include <logdepthbuf_vertex>
|
|
89
60
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
61
|
+
`,
|
|
62
|
+
fragmentShader: /* glsl */`
|
|
63
|
+
varying vec3 vNormal;
|
|
64
|
+
varying float vViewZ;
|
|
65
|
+
varying float vIntensity;
|
|
66
|
+
|
|
67
|
+
uniform vec3 lightColor;
|
|
68
|
+
uniform float anglePower;
|
|
69
|
+
uniform sampler2D depth;
|
|
70
|
+
uniform vec2 resolution;
|
|
71
|
+
uniform float cameraNear;
|
|
72
|
+
uniform float cameraFar;
|
|
73
|
+
uniform float opacity;
|
|
74
|
+
|
|
75
|
+
#include <packing>
|
|
76
|
+
#include <logdepthbuf_pars_fragment>
|
|
77
|
+
|
|
78
|
+
float readDepth(sampler2D depthSampler, vec2 uv) {
|
|
79
|
+
float fragCoordZ = texture(depthSampler, uv).r;
|
|
80
|
+
|
|
81
|
+
// https://github.com/mrdoob/three.js/issues/23072
|
|
82
|
+
#ifdef USE_LOGDEPTHBUF
|
|
83
|
+
float viewZ = 1.0 - exp2(fragCoordZ * log(cameraFar + 1.0) / log(2.0));
|
|
84
|
+
#else
|
|
85
|
+
float viewZ = perspectiveDepthToViewZ(fragCoordZ, cameraNear, cameraFar);
|
|
86
|
+
#endif
|
|
87
|
+
|
|
88
|
+
return viewZ;
|
|
97
89
|
}
|
|
98
|
-
gl_FragColor = vec4(lightColor, intensity * opacity);
|
|
99
90
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
91
|
+
void main() {
|
|
92
|
+
#include <logdepthbuf_fragment>
|
|
93
|
+
|
|
94
|
+
vec3 normal = vec3(vNormal.x, vNormal.y, abs(vNormal.z));
|
|
95
|
+
float angleIntensity = pow(dot(normal, vec3(0, 0, 1)), anglePower);
|
|
96
|
+
float intensity = vIntensity * angleIntensity;
|
|
97
|
+
|
|
98
|
+
// fades when z is close to sampled depth, meaning the cone is intersecting existing geometry
|
|
99
|
+
bool isSoft = resolution[0] > 0.0 && resolution[1] > 0.0;
|
|
100
|
+
if (isSoft) {
|
|
101
|
+
vec2 uv = gl_FragCoord.xy / resolution;
|
|
102
|
+
intensity *= smoothstep(0.0, 1.0, vViewZ - readDepth(depth, uv));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
gl_FragColor = vec4(lightColor, intensity * opacity);
|
|
106
|
+
|
|
107
|
+
#include <tonemapping_fragment>
|
|
108
|
+
#include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
|
|
109
|
+
}
|
|
110
|
+
`
|
|
103
111
|
});
|
|
104
112
|
}
|
|
105
113
|
}
|
package/package.json
CHANGED
|
Binary file
|