123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- /// <reference path="../../../dist/preview release/babylon.d.ts"/>
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var BABYLON;
- (function (BABYLON) {
- var ShadowOnlyMaterialDefines = (function (_super) {
- __extends(ShadowOnlyMaterialDefines, _super);
- function ShadowOnlyMaterialDefines() {
- var _this = _super.call(this) || this;
- _this.CLIPPLANE = false;
- _this.POINTSIZE = false;
- _this.FOG = false;
- _this.NORMAL = false;
- _this.NUM_BONE_INFLUENCERS = 0;
- _this.BonesPerMesh = 0;
- _this.INSTANCES = false;
- _this.rebuild();
- return _this;
- }
- return ShadowOnlyMaterialDefines;
- }(BABYLON.MaterialDefines));
- var ShadowOnlyMaterial = (function (_super) {
- __extends(ShadowOnlyMaterial, _super);
- function ShadowOnlyMaterial(name, scene) {
- var _this = _super.call(this, name, scene) || this;
- _this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
- _this._scaledDiffuse = new BABYLON.Color3();
- _this._defines = new ShadowOnlyMaterialDefines();
- _this._cachedDefines = new ShadowOnlyMaterialDefines();
- _this._cachedDefines.BonesPerMesh = -1;
- return _this;
- }
- ShadowOnlyMaterial.prototype.needAlphaBlending = function () {
- return true;
- };
- ShadowOnlyMaterial.prototype.needAlphaTesting = function () {
- return false;
- };
- ShadowOnlyMaterial.prototype.getAlphaTestTexture = function () {
- return null;
- };
- // Methods
- ShadowOnlyMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
- if (!mesh) {
- return true;
- }
- if (this._defines.INSTANCES !== useInstances) {
- return false;
- }
- return false;
- };
- ShadowOnlyMaterial.prototype.isReady = function (mesh, useInstances) {
- if (this.checkReadyOnlyOnce) {
- if (this._wasPreviouslyReady) {
- return true;
- }
- }
- var scene = this.getScene();
- if (!this.checkReadyOnEveryCall) {
- if (this._renderId === scene.getRenderId()) {
- if (this._checkCache(scene, mesh, useInstances)) {
- return true;
- }
- }
- }
- var engine = scene.getEngine();
- var needNormals = false;
- this._defines.reset();
- // Effect
- if (scene.clipPlane) {
- this._defines.CLIPPLANE = true;
- }
- // Point size
- if (this.pointsCloud || scene.forcePointsCloud) {
- this._defines.POINTSIZE = true;
- }
- // Fog
- if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
- this._defines.FOG = true;
- }
- if (scene.lightsEnabled) {
- needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, 1);
- }
- // Attribs
- if (mesh) {
- if (needNormals && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
- this._defines.NORMAL = true;
- }
- if (mesh.useBones && mesh.computeBonesUsingShaders) {
- this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
- this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
- }
- // Instances
- if (useInstances) {
- this._defines.INSTANCES = true;
- }
- }
- // Get correct effect
- if (!this._defines.isEqual(this._cachedDefines)) {
- this._defines.cloneTo(this._cachedDefines);
- scene.resetCachedMaterial();
- // Fallbacks
- var fallbacks = new BABYLON.EffectFallbacks();
- if (this._defines.FOG) {
- fallbacks.addFallback(1, "FOG");
- }
- BABYLON.MaterialHelper.HandleFallbacksForShadows(this._defines, fallbacks, 1);
- if (this._defines.NUM_BONE_INFLUENCERS > 0) {
- fallbacks.addCPUSkinningFallback(0, mesh);
- }
- //Attributes
- var attribs = [BABYLON.VertexBuffer.PositionKind];
- if (this._defines.NORMAL) {
- attribs.push(BABYLON.VertexBuffer.NormalKind);
- }
- BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
- BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
- var shaderName = "shadowOnly";
- var join = this._defines.toString();
- var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType",
- "vFogInfos", "vFogColor", "pointSize",
- "mBones",
- "vClipPlane", "depthValues"
- ];
- var samplers = [];
- BABYLON.MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, 1);
- this._effect = scene.getEngine().createEffect(shaderName, attribs, uniforms, samplers, join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: 1 });
- }
- if (!this._effect.isReady()) {
- return false;
- }
- this._renderId = scene.getRenderId();
- this._wasPreviouslyReady = true;
- return true;
- };
- ShadowOnlyMaterial.prototype.bindOnlyWorldMatrix = function (world) {
- this._effect.setMatrix("world", world);
- };
- ShadowOnlyMaterial.prototype.bind = function (world, mesh) {
- var scene = this.getScene();
- // Matrices
- this.bindOnlyWorldMatrix(world);
- this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
- // Bones
- BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
- if (scene.getCachedMaterial() !== this) {
- // Clip plane
- BABYLON.MaterialHelper.BindClipPlane(this._effect, scene);
- // Point size
- if (this.pointsCloud) {
- this._effect.setFloat("pointSize", this.pointSize);
- }
- this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
- }
- // Lights
- if (scene.lightsEnabled) {
- BABYLON.MaterialHelper.BindLights(scene, mesh, this._effect, this._defines, 1);
- }
- // View
- if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
- this._effect.setMatrix("view", scene.getViewMatrix());
- }
- // Fog
- BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._effect);
- _super.prototype.bind.call(this, world, mesh);
- };
- ShadowOnlyMaterial.prototype.clone = function (name) {
- var _this = this;
- return BABYLON.SerializationHelper.Clone(function () { return new ShadowOnlyMaterial(name, _this.getScene()); }, this);
- };
- ShadowOnlyMaterial.prototype.serialize = function () {
- var serializationObject = BABYLON.SerializationHelper.Serialize(this);
- serializationObject.customType = "BABYLON.ShadowOnlyMaterial";
- return serializationObject;
- };
- // Statics
- ShadowOnlyMaterial.Parse = function (source, scene, rootUrl) {
- return BABYLON.SerializationHelper.Parse(function () { return new ShadowOnlyMaterial(source.name, scene); }, source, scene, rootUrl);
- };
- return ShadowOnlyMaterial;
- }(BABYLON.Material));
- __decorate([
- BABYLON.serialize()
- ], ShadowOnlyMaterial.prototype, "_worldViewProjectionMatrix", void 0);
- BABYLON.ShadowOnlyMaterial = ShadowOnlyMaterial;
- })(BABYLON || (BABYLON = {}));
- //# sourceMappingURL=babylon.shadowOnlyMaterial.js.map
- BABYLON.Effect.ShadersStore['shadowOnlyVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<shadowsVertexDeclaration>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
- BABYLON.Effect.ShadersStore['shadowOnlyPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n\n#include<lightFragmentDeclaration>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0..1]\n\nvec4 color=vec4(0.,0.,0.,1.0-clamp(shadow,0.,1.));\n#include<fogFragment>\ngl_FragColor=color;\n}";
|