Skip to content

Commit

Permalink
Fix all meshes being marked as dirty when creating a new texture
Browse files Browse the repository at this point in the history
  • Loading branch information
ladevieq committed Jul 20, 2020
1 parent 040a7a0 commit e6988ca
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 73 deletions.
4 changes: 2 additions & 2 deletions dist/preview release/babylon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20711,7 +20711,7 @@ declare module BABYLON {
/**
* Override the default coordinates mode to projection for RTT as it is the most common case for rendered textures.
*/
coordinatesMode: number;
_coordinatesMode: number;
/**
* Define the camera used to render the texture.
*/
Expand Down Expand Up @@ -30163,7 +30163,7 @@ declare module BABYLON {
* This is part of the texture as textures usually maps to one uv set.
*/
coordinatesIndex: number;
private _coordinatesMode;
_coordinatesMode: number;
/**
* How a texture is mapped.
*
Expand Down
2 changes: 1 addition & 1 deletion dist/preview release/babylon.js

Large diffs are not rendered by default.

74 changes: 36 additions & 38 deletions dist/preview release/babylon.max.js
Original file line number Diff line number Diff line change
Expand Up @@ -86231,7 +86231,7 @@ var RenderTargetTexture = /** @class */ (function (_super) {
/**
* Override the default coordinates mode to projection for RTT as it is the most common case for rendered textures.
*/
_this.coordinatesMode = _Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_4__["Texture"].PROJECTION_MODE;
_this._coordinatesMode = _Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_4__["Texture"].PROJECTION_MODE;
/**
* Define if the camera viewport should be respected while rendering the texture or if the render should be done to the entire texture.
*/
Expand Down Expand Up @@ -86303,7 +86303,7 @@ var RenderTargetTexture = /** @class */ (function (_super) {
if (!delayAllocation) {
if (isCube) {
_this._texture = scene.getEngine().createRenderTargetCubeTexture(_this.getRenderSize(), _this._renderTargetOptions);
_this.coordinatesMode = _Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_4__["Texture"].INVCUBIC_MODE;
_this._coordinatesMode = _Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_4__["Texture"].INVCUBIC_MODE;
_this._textureMatrix = _Maths_math_vector__WEBPACK_IMPORTED_MODULE_3__["Matrix"].Identity();
}
else {
Expand Down Expand Up @@ -166227,24 +166227,23 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _Materials_Textures_renderTargetTexture__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../Materials/Textures/renderTargetTexture */ "./Materials/Textures/renderTargetTexture.ts");
/* harmony import */ var _Materials_Textures_multiRenderTarget__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../Materials/Textures/multiRenderTarget */ "./Materials/Textures/multiRenderTarget.ts");
/* harmony import */ var _Materials_material__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../Materials/material */ "./Materials/material.ts");
/* harmony import */ var _Materials_standardMaterial__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../Materials/standardMaterial */ "./Materials/standardMaterial.ts");
/* harmony import */ var _Engines_constants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../Engines/constants */ "./Engines/constants.ts");
/* harmony import */ var _Maths_math__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../Maths/math */ "./Maths/math.ts");
/* harmony import */ var _directEffectManager__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./directEffectManager */ "./Radiosity/directEffectManager.ts");

/* harmony import */ var _Engines_constants__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../Engines/constants */ "./Engines/constants.ts");
/* harmony import */ var _Maths_math__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../Maths/math */ "./Maths/math.ts");
/* harmony import */ var _directEffectManager__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./directEffectManager */ "./Radiosity/directEffectManager.ts");





// import { StandardMaterial } from "../Materials/standardMaterial";



_Meshes_mesh__WEBPACK_IMPORTED_MODULE_0__["Mesh"].prototype.initForDirect = function (shadowMapSize, scene) {
var mrt = new _Materials_Textures_multiRenderTarget__WEBPACK_IMPORTED_MODULE_3__["MultiRenderTarget"]("mesh-textures", shadowMapSize, 2, scene, {
generateMipMaps: false,
samplingModes: [_Engines_constants__WEBPACK_IMPORTED_MODULE_6__["Constants"].TEXTURE_BILINEAR_SAMPLINGMODE, _Engines_constants__WEBPACK_IMPORTED_MODULE_6__["Constants"].TEXTURE_BILINEAR_SAMPLINGMODE],
types: [_Engines_constants__WEBPACK_IMPORTED_MODULE_6__["Constants"].TEXTURETYPE_FLOAT, _Engines_constants__WEBPACK_IMPORTED_MODULE_6__["Constants"].TEXTURETYPE_FLOAT],
samplingModes: [_Engines_constants__WEBPACK_IMPORTED_MODULE_5__["Constants"].TEXTURE_BILINEAR_SAMPLINGMODE, _Engines_constants__WEBPACK_IMPORTED_MODULE_5__["Constants"].TEXTURE_BILINEAR_SAMPLINGMODE],
types: [_Engines_constants__WEBPACK_IMPORTED_MODULE_5__["Constants"].TEXTURETYPE_FLOAT, _Engines_constants__WEBPACK_IMPORTED_MODULE_5__["Constants"].TEXTURETYPE_FLOAT],
});
this.directInfo = {
shadowMapSize: shadowMapSize,
Expand All @@ -166266,27 +166265,26 @@ var Arealight = /** @class */ (function () {
this.normal = normal.clone().normalize();
this.size = size;
this.depthMapSize = depthMapSize;
this.depthMap = new _Materials_Textures_renderTargetTexture__WEBPACK_IMPORTED_MODULE_2__["RenderTargetTexture"]("depthMap", this.depthMapSize, scene, false, true, _Engines_constants__WEBPACK_IMPORTED_MODULE_6__["Constants"].TEXTURETYPE_FLOAT, true, _Engines_constants__WEBPACK_IMPORTED_MODULE_6__["Constants"].TEXTURE_BILINEAR_SAMPLINGMODE, true, false);
this.depthMap = new _Materials_Textures_renderTargetTexture__WEBPACK_IMPORTED_MODULE_2__["RenderTargetTexture"]("depthMap", this.depthMapSize, scene, false, true, _Engines_constants__WEBPACK_IMPORTED_MODULE_5__["Constants"].TEXTURETYPE_FLOAT, true, _Engines_constants__WEBPACK_IMPORTED_MODULE_5__["Constants"].TEXTURE_BILINEAR_SAMPLINGMODE, true, false);
this._generateSamples(sampleCount);
for (var _i = 0, _a = this.samples; _i < _a.length; _i++) {
var sample = _a[_i];
var mat = new _Materials_standardMaterial__WEBPACK_IMPORTED_MODULE_5__["StandardMaterial"]("", scene);
mat.emissiveColor = new _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Color3"](1, 0, 0);
var box = _Meshes_mesh__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateBox("", 1.5, scene);
box.position = sample;
box.material = mat;
}
// for (const sample of this.samples) {
// const mat = new StandardMaterial("", scene);
// mat.emissiveColor = new Color3(1, 0, 0);
// const box = Mesh.CreateBox("", 1.5, scene);
// box.position = sample;
// box.material = mat;
// }
}
Arealight.prototype._generateSamples = function (sampleCount) {
this.samples = [];
var viewMatrix = _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].LookAtLH(this.position, this.position.add(this.normal), _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Vector3"].Up());
var viewMatrix = _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].LookAtLH(this.position, this.position.add(this.normal), _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Vector3"].Up());
viewMatrix.invert();
for (var sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) {
var _a = this.sampleRectangle(sampleIndex), u = _a[0], v = _a[1];
var x = u * this.size.width;
var y = v * this.size.height;
var localPosition = new _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Vector3"](x, y, 0);
var worldPosition = _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Vector3"].TransformCoordinates(localPosition, viewMatrix);
var localPosition = new _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Vector3"](x, y, 0);
var worldPosition = _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Vector3"].TransformCoordinates(localPosition, viewMatrix);
this.samples.push(worldPosition);
}
};
Expand Down Expand Up @@ -166371,16 +166369,16 @@ var DirectRenderer = /** @class */ (function () {
this._normalBias = this._options.normalBias || 1e-4;
this.meshes = meshes || [];
this.lights = lights || [];
this._projectionMatrix = _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].PerspectiveFovLH(Math.PI / 2, 1, // squared texture
this._projectionMatrix = _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].PerspectiveFovLH(Math.PI / 2, 1, // squared texture
this._near, this._far);
this._projectionMatrixPX = this._projectionMatrix.multiply(_Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].FromValues(2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1));
this._projectionMatrixNX = this._projectionMatrix.multiply(_Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].FromValues(2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 1));
this._projectionMatrixPY = this._projectionMatrix.multiply(_Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].FromValues(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1));
this._projectionMatrixNY = this._projectionMatrix.multiply(_Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].FromValues(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 0, -1, 0, 1));
this._projectionMatrixPX = this._projectionMatrix.multiply(_Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].FromValues(2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1));
this._projectionMatrixNX = this._projectionMatrix.multiply(_Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].FromValues(2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 1));
this._projectionMatrixPY = this._projectionMatrix.multiply(_Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].FromValues(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1));
this._projectionMatrixNY = this._projectionMatrix.multiply(_Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].FromValues(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 0, -1, 0, 1));
var engine = this._scene.getEngine();
var gl = engine._gl;
this._frambuffer0 = gl.createFramebuffer();
this._directEffectsManager = new _directEffectManager__WEBPACK_IMPORTED_MODULE_8__["DirectEffectsManager"](this._scene);
this._directEffectsManager = new _directEffectManager__WEBPACK_IMPORTED_MODULE_7__["DirectEffectsManager"](this._scene);
while (!this._directEffectsManager.isReady()) {
}
}
Expand Down Expand Up @@ -166412,7 +166410,7 @@ var DirectRenderer = /** @class */ (function () {
};
DirectRenderer.prototype.renderSampleToShadowMapTexture = function (light, samplePosition) {
var _this = this;
var viewMatrix = _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].LookAtLH(samplePosition, samplePosition.add(light.normal), _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Vector3"].Up());
var viewMatrix = _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].LookAtLH(samplePosition, samplePosition.add(light.normal), _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Vector3"].Up());
var engine = this._scene.getEngine();
var gl = engine._gl;
var effect = this._directEffectsManager.shadowMappingEffect;
Expand Down Expand Up @@ -166502,7 +166500,7 @@ var DirectRenderer = /** @class */ (function () {
var vb = {};
vb[_Meshes_buffer__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind] = this._directEffectsManager.screenQuadVB;
effect.setTexture("inputTexture", origin);
effect.setVector2("texelSize", _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Vector2"].One().divide(new _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Vector2"](origin.getSize().width, origin.getSize().height)));
effect.setVector2("texelSize", _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Vector2"].One().divide(new _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Vector2"](origin.getSize().width, origin.getSize().height)));
engine.bindBuffers(vb, this._directEffectsManager.screenQuadIB, effect);
engine.setDirectViewport(0, 0, dest.getSize().width, dest.getSize().height);
engine.drawElementsType(_Materials_material__WEBPACK_IMPORTED_MODULE_4__["Material"].TriangleFillMode, 0, 6);
Expand All @@ -166517,14 +166515,14 @@ var DirectRenderer = /** @class */ (function () {
DirectRenderer.prototype.renderVisibilityMapCubeSample = function (light, samplePosition) {
var engine = this._scene.getEngine();
var gl = engine._gl;
var viewMatrix = _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].LookAtLH(samplePosition, samplePosition.add(light.normal), _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Vector3"].Up());
var xAxis = new _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Vector3"](viewMatrix.m[0], viewMatrix.m[4], viewMatrix.m[8]); // Tangent
var yAxis = new _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Vector3"](viewMatrix.m[1], viewMatrix.m[5], viewMatrix.m[9]); // "Up"
var zAxis = new _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Vector3"](viewMatrix.m[2], viewMatrix.m[6], viewMatrix.m[10]); // depth
var viewMatrixPX = _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].LookAtLH(samplePosition, samplePosition.add(xAxis), yAxis);
var viewMatrixNX = _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].LookAtLH(samplePosition, samplePosition.subtract(xAxis), yAxis);
var viewMatrixPY = _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].LookAtLH(samplePosition, samplePosition.add(yAxis), zAxis.scale(-1));
var viewMatrixNY = _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Matrix"].LookAtLH(samplePosition, samplePosition.subtract(yAxis), zAxis);
var viewMatrix = _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].LookAtLH(samplePosition, samplePosition.add(light.normal), _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Vector3"].Up());
var xAxis = new _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Vector3"](viewMatrix.m[0], viewMatrix.m[4], viewMatrix.m[8]); // Tangent
var yAxis = new _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Vector3"](viewMatrix.m[1], viewMatrix.m[5], viewMatrix.m[9]); // "Up"
var zAxis = new _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Vector3"](viewMatrix.m[2], viewMatrix.m[6], viewMatrix.m[10]); // depth
var viewMatrixPX = _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].LookAtLH(samplePosition, samplePosition.add(xAxis), yAxis);
var viewMatrixNX = _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].LookAtLH(samplePosition, samplePosition.subtract(xAxis), yAxis);
var viewMatrixPY = _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].LookAtLH(samplePosition, samplePosition.add(yAxis), zAxis.scale(-1));
var viewMatrixNY = _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Matrix"].LookAtLH(samplePosition, samplePosition.subtract(yAxis), zAxis);
var viewMatrices = [
viewMatrix,
viewMatrixPX,
Expand Down Expand Up @@ -166567,7 +166565,7 @@ var DirectRenderer = /** @class */ (function () {
engine.bindFramebuffer(light.depthMap._texture, cubeSides[viewIndex] - gl.TEXTURE_CUBE_MAP_POSITIVE_X);
// Full cube viewport when rendering the front face
engine.setDirectViewport(viewportOffsets[viewIndex][0] * light.depthMapSize.width, viewportOffsets[viewIndex][1] * light.depthMapSize.height, light.depthMapSize.width * viewportMultipliers[viewIndex][0], light.depthMapSize.height * viewportMultipliers[viewIndex][1]);
engine.clear(new _Maths_math__WEBPACK_IMPORTED_MODULE_7__["Color4"](0, 0, 0, 0), true, true);
engine.clear(new _Maths_math__WEBPACK_IMPORTED_MODULE_6__["Color4"](0, 0, 0, 0), true, true);
this._setCubeVisibilityUniforms(this._directEffectsManager.visibilityEffect, viewMatrices[viewIndex], projectionMatrices[viewIndex]);
this._directEffectsManager.visibilityEffect.setVector3("lightPos", samplePosition);
this._directEffectsManager.visibilityEffect.setFloat("normalBias", this._normalBias);
Expand Down
2 changes: 1 addition & 1 deletion dist/preview release/babylon.max.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/preview release/babylon.module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21353,7 +21353,7 @@ declare module "babylonjs/Materials/Textures/renderTargetTexture" {
/**
* Override the default coordinates mode to projection for RTT as it is the most common case for rendered textures.
*/
coordinatesMode: number;
_coordinatesMode: number;
/**
* Define the camera used to render the texture.
*/
Expand Down Expand Up @@ -31109,7 +31109,7 @@ declare module "babylonjs/Materials/Textures/baseTexture" {
* This is part of the texture as textures usually maps to one uv set.
*/
coordinatesIndex: number;
private _coordinatesMode;
_coordinatesMode: number;
/**
* How a texture is mapped.
*
Expand Down Expand Up @@ -96816,7 +96816,7 @@ declare module BABYLON {
/**
* Override the default coordinates mode to projection for RTT as it is the most common case for rendered textures.
*/
coordinatesMode: number;
_coordinatesMode: number;
/**
* Define the camera used to render the texture.
*/
Expand Down Expand Up @@ -106268,7 +106268,7 @@ declare module BABYLON {
* This is part of the texture as textures usually maps to one uv set.
*/
coordinatesIndex: number;
private _coordinatesMode;
_coordinatesMode: number;
/**
* How a texture is mapped.
*
Expand Down
Loading

0 comments on commit e6988ca

Please sign in to comment.