|
@@ -5772,7 +5772,7 @@
|
|
|
|
|
|
var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
|
|
|
|
|
|
- var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif\n";
|
|
|
+ var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || defined( LAMBERT ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif\n";
|
|
|
|
|
|
var cube_frag = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tgl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n\tgl_FragColor.a *= opacity;\n}\n";
|
|
|
|
|
@@ -5782,9 +5782,9 @@
|
|
|
|
|
|
var depth_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n}\n";
|
|
|
|
|
|
- var distanceRGBA_frag = "uniform vec3 lightPos;\nuniform float shadowCameraNear;\nuniform float shadowCameraFar;\nvarying vec4 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition.xyz - lightPos.xyz );\n\tdist = ( dist - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}\n";
|
|
|
+ var distanceRGBA_frag = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}\n";
|
|
|
|
|
|
- var distanceRGBA_vert = "varying vec4 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition;\n}\n";
|
|
|
+ var distanceRGBA_vert = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}\n";
|
|
|
|
|
|
var equirect_frag = "uniform sampler2D tEquirect;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldPosition );\n\tvec2 sampleUV;\n\tsampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n}\n";
|
|
|
|
|
@@ -6125,9 +6125,9 @@
|
|
|
UniformsLib.common,
|
|
|
UniformsLib.displacementmap,
|
|
|
{
|
|
|
- lightPos: { value: new Vector3() },
|
|
|
- shadowCameraNear: { value: 1 },
|
|
|
- shadowCameraFar: { value: 1000 }
|
|
|
+ referencePosition: { value: new Vector3() },
|
|
|
+ nearDistance: { value: 1 },
|
|
|
+ farDistance: { value: 1000 }
|
|
|
}
|
|
|
] ),
|
|
|
|
|
@@ -7688,6 +7688,85 @@
|
|
|
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * @author WestLangley / http://github.com/WestLangley
|
|
|
+ *
|
|
|
+ * parameters = {
|
|
|
+ *
|
|
|
+ * referencePosition: <float>,
|
|
|
+ * nearDistance: <float>,
|
|
|
+ * farDistance: <float>,
|
|
|
+ *
|
|
|
+ * skinning: <bool>,
|
|
|
+ * morphTargets: <bool>,
|
|
|
+ *
|
|
|
+ * map: new THREE.Texture( <Image> ),
|
|
|
+ *
|
|
|
+ * alphaMap: new THREE.Texture( <Image> ),
|
|
|
+ *
|
|
|
+ * displacementMap: new THREE.Texture( <Image> ),
|
|
|
+ * displacementScale: <float>,
|
|
|
+ * displacementBias: <float>
|
|
|
+ *
|
|
|
+ * }
|
|
|
+ */
|
|
|
+
|
|
|
+ function MeshDistanceMaterial( parameters ) {
|
|
|
+
|
|
|
+ Material.call( this );
|
|
|
+
|
|
|
+ this.type = 'MeshDistanceMaterial';
|
|
|
+
|
|
|
+ this.referencePosition = new THREE.Vector3();
|
|
|
+ this.nearDistance = 1;
|
|
|
+ this.farDistance = 1000;
|
|
|
+
|
|
|
+ this.skinning = false;
|
|
|
+ this.morphTargets = false;
|
|
|
+
|
|
|
+ this.map = null;
|
|
|
+
|
|
|
+ this.alphaMap = null;
|
|
|
+
|
|
|
+ this.displacementMap = null;
|
|
|
+ this.displacementScale = 1;
|
|
|
+ this.displacementBias = 0;
|
|
|
+
|
|
|
+ this.fog = false;
|
|
|
+ this.lights = false;
|
|
|
+
|
|
|
+ this.setValues( parameters );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ MeshDistanceMaterial.prototype = Object.create( Material.prototype );
|
|
|
+ MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
|
|
|
+
|
|
|
+ MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
|
|
|
+
|
|
|
+ MeshDistanceMaterial.prototype.copy = function ( source ) {
|
|
|
+
|
|
|
+ Material.prototype.copy.call( this, source );
|
|
|
+
|
|
|
+ this.referencePosition.copy( source.referencePosition );
|
|
|
+ this.nearDistance = source.nearDistance;
|
|
|
+ this.farDistance = source.farDistance;
|
|
|
+
|
|
|
+ this.skinning = source.skinning;
|
|
|
+ this.morphTargets = source.morphTargets;
|
|
|
+
|
|
|
+ this.map = source.map;
|
|
|
+
|
|
|
+ this.alphaMap = source.alphaMap;
|
|
|
+
|
|
|
+ this.displacementMap = source.displacementMap;
|
|
|
+ this.displacementScale = source.displacementScale;
|
|
|
+ this.displacementBias = source.displacementBias;
|
|
|
+
|
|
|
+ return this;
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
/**
|
|
|
* @author bhouston / http://clara.io
|
|
|
* @author WestLangley / http://github.com/WestLangley
|
|
@@ -9131,34 +9210,29 @@
|
|
|
|
|
|
// init
|
|
|
|
|
|
- var depthMaterialTemplate = new MeshDepthMaterial();
|
|
|
- depthMaterialTemplate.depthPacking = RGBADepthPacking;
|
|
|
- depthMaterialTemplate.clipping = true;
|
|
|
-
|
|
|
- var distanceShader = ShaderLib[ "distanceRGBA" ];
|
|
|
- var distanceUniforms = UniformsUtils.clone( distanceShader.uniforms );
|
|
|
-
|
|
|
for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
|
|
|
|
|
|
var useMorphing = ( i & _MorphingFlag ) !== 0;
|
|
|
var useSkinning = ( i & _SkinningFlag ) !== 0;
|
|
|
|
|
|
- var depthMaterial = depthMaterialTemplate.clone();
|
|
|
- depthMaterial.morphTargets = useMorphing;
|
|
|
- depthMaterial.skinning = useSkinning;
|
|
|
+ var depthMaterial = new MeshDepthMaterial( {
|
|
|
+
|
|
|
+ depthPacking: RGBADepthPacking,
|
|
|
+
|
|
|
+ morphTargets: useMorphing,
|
|
|
+ skinning: useSkinning
|
|
|
+
|
|
|
+ } );
|
|
|
|
|
|
_depthMaterials[ i ] = depthMaterial;
|
|
|
|
|
|
- var distanceMaterial = new ShaderMaterial( {
|
|
|
- defines: {
|
|
|
- 'USE_SHADOWMAP': ''
|
|
|
- },
|
|
|
- uniforms: distanceUniforms,
|
|
|
- vertexShader: distanceShader.vertexShader,
|
|
|
- fragmentShader: distanceShader.fragmentShader,
|
|
|
+ //
|
|
|
+
|
|
|
+ var distanceMaterial = new MeshDistanceMaterial( {
|
|
|
+
|
|
|
morphTargets: useMorphing,
|
|
|
- skinning: useSkinning,
|
|
|
- clipping: true
|
|
|
+ skinning: useSkinning
|
|
|
+
|
|
|
} );
|
|
|
|
|
|
_distanceMaterials[ i ] = distanceMaterial;
|
|
@@ -9460,11 +9534,11 @@
|
|
|
result.wireframeLinewidth = material.wireframeLinewidth;
|
|
|
result.linewidth = material.linewidth;
|
|
|
|
|
|
- if ( isPointLight && result.uniforms.lightPos !== undefined ) {
|
|
|
+ if ( isPointLight && result.isMeshDistanceMaterial ) {
|
|
|
|
|
|
- result.uniforms.lightPos.value.copy( lightPositionWorld );
|
|
|
- result.uniforms.shadowCameraNear.value = shadowCameraNear;
|
|
|
- result.uniforms.shadowCameraFar.value = shadowCameraFar;
|
|
|
+ result.referencePosition.copy( lightPositionWorld );
|
|
|
+ result.nearDistance = shadowCameraNear;
|
|
|
+ result.farDistance = shadowCameraFar;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -17935,6 +18009,7 @@
|
|
|
|
|
|
var shaderIDs = {
|
|
|
MeshDepthMaterial: 'depth',
|
|
|
+ MeshDistanceMaterial: 'distanceRGBA',
|
|
|
MeshNormalMaterial: 'normal',
|
|
|
MeshBasicMaterial: 'basic',
|
|
|
MeshLambertMaterial: 'lambert',
|
|
@@ -22356,7 +22431,8 @@
|
|
|
material.isMeshPhongMaterial ||
|
|
|
material.isMeshStandardMaterial ||
|
|
|
material.isMeshNormalMaterial ||
|
|
|
- material.isMeshDepthMaterial ) {
|
|
|
+ material.isMeshDepthMaterial ||
|
|
|
+ material.isMeshDistanceMaterial ) {
|
|
|
|
|
|
refreshUniformsCommon( m_uniforms, material );
|
|
|
|
|
@@ -22399,13 +22475,11 @@
|
|
|
|
|
|
} else if ( material.isMeshDepthMaterial ) {
|
|
|
|
|
|
- if ( material.displacementMap ) {
|
|
|
+ refreshUniformsDepth( m_uniforms, material );
|
|
|
|
|
|
- m_uniforms.displacementMap.value = material.displacementMap;
|
|
|
- m_uniforms.displacementScale.value = material.displacementScale;
|
|
|
- m_uniforms.displacementBias.value = material.displacementBias;
|
|
|
+ } else if ( material.isMeshDistanceMaterial ) {
|
|
|
|
|
|
- }
|
|
|
+ refreshUniformsDistance( m_uniforms, material );
|
|
|
|
|
|
} else if ( material.isMeshNormalMaterial ) {
|
|
|
|
|
@@ -22716,6 +22790,34 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function refreshUniformsDepth( uniforms, material ) {
|
|
|
+
|
|
|
+ if ( material.displacementMap ) {
|
|
|
+
|
|
|
+ uniforms.displacementMap.value = material.displacementMap;
|
|
|
+ uniforms.displacementScale.value = material.displacementScale;
|
|
|
+ uniforms.displacementBias.value = material.displacementBias;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function refreshUniformsDistance( uniforms, material ) {
|
|
|
+
|
|
|
+ if ( material.displacementMap ) {
|
|
|
+
|
|
|
+ uniforms.displacementMap.value = material.displacementMap;
|
|
|
+ uniforms.displacementScale.value = material.displacementScale;
|
|
|
+ uniforms.displacementBias.value = material.displacementBias;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ uniforms.referencePosition.value.copy( material.referencePosition );
|
|
|
+ uniforms.nearDistance.value = material.nearDistance;
|
|
|
+ uniforms.farDistance.value = material.farDistance;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
function refreshUniformsNormal( uniforms, material ) {
|
|
|
|
|
|
if ( material.bumpMap ) {
|
|
@@ -29624,6 +29726,7 @@
|
|
|
MeshNormalMaterial: MeshNormalMaterial,
|
|
|
MeshLambertMaterial: MeshLambertMaterial,
|
|
|
MeshDepthMaterial: MeshDepthMaterial,
|
|
|
+ MeshDistanceMaterial: MeshDistanceMaterial,
|
|
|
MeshBasicMaterial: MeshBasicMaterial,
|
|
|
LineDashedMaterial: LineDashedMaterial,
|
|
|
LineBasicMaterial: LineBasicMaterial,
|
|
@@ -44129,6 +44232,7 @@
|
|
|
exports.MeshNormalMaterial = MeshNormalMaterial;
|
|
|
exports.MeshLambertMaterial = MeshLambertMaterial;
|
|
|
exports.MeshDepthMaterial = MeshDepthMaterial;
|
|
|
+ exports.MeshDistanceMaterial = MeshDistanceMaterial;
|
|
|
exports.MeshBasicMaterial = MeshBasicMaterial;
|
|
|
exports.LineDashedMaterial = LineDashedMaterial;
|
|
|
exports.LineBasicMaterial = LineBasicMaterial;
|