@galacean/engine-core 1.2.0-alpha.11 → 1.2.0-alpha.12

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.
@@ -3184,7 +3184,7 @@ function _extends() {
3184
3184
  return _extends.apply(this, arguments);
3185
3185
  }
3186
3186
 
3187
- var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;uniform vec3 camera_Forward;"; // eslint-disable-line
3187
+ var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;uniform vec3 camera_Forward;uniform vec4 camera_ProjectionParams;"; // eslint-disable-line
3188
3188
 
3189
3189
  var common = "#define GLSLIFY 1\n#define PI 3.14159265359\n#define RECIPROCAL_PI 0.31830988618\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate( a ) clamp( a, 0.0, 1.0 )\nfloat pow2(float x){return x*x;}vec4 RGBMToLinear(vec4 value,float maxRange){return vec4(value.rgb*value.a*maxRange,1.0);}vec4 gammaToLinear(vec4 srgbIn){return vec4(pow(srgbIn.rgb,vec3(2.2)),srgbIn.a);}vec4 linearToGamma(vec4 linearIn){return vec4(pow(linearIn.rgb,vec3(1.0/2.2)),linearIn.a);}uniform vec4 camera_DepthBufferParams;float remapDepthBufferLinear01(float z){return 1.0/(camera_DepthBufferParams.x*z+camera_DepthBufferParams.y);}\n#ifdef GRAPHICS_API_WEBGL2\n#define INVERSE_MAT(mat) inverse(mat)\n#else\nmat2 inverseMat(mat2 m){return mat2(m[1][1],-m[0][1],-m[1][0],m[0][0])/(m[0][0]*m[1][1]-m[0][1]*m[1][0]);}mat3 inverseMat(mat3 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2];float a10=m[1][0],a11=m[1][1],a12=m[1][2];float a20=m[2][0],a21=m[2][1],a22=m[2][2];float b01=a22*a11-a12*a21;float b11=-a22*a10+a12*a20;float b21=a21*a10-a11*a20;float det=a00*b01+a01*b11+a02*b21;return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;}mat4 inverseMat(mat4 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2],a03=m[0][3],a10=m[1][0],a11=m[1][1],a12=m[1][2],a13=m[1][3],a20=m[2][0],a21=m[2][1],a22=m[2][2],a23=m[2][3],a30=m[3][0],a31=m[3][1],a32=m[3][2],a33=m[3][3],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return mat4(a11*b11-a12*b10+a13*b09,a02*b10-a01*b11-a03*b09,a31*b05-a32*b04+a33*b03,a22*b04-a21*b05-a23*b03,a12*b08-a10*b11-a13*b07,a00*b11-a02*b08+a03*b07,a32*b02-a30*b05-a33*b01,a20*b05-a22*b02+a23*b01,a10*b10-a11*b08+a13*b06,a01*b08-a00*b10-a03*b06,a30*b04-a31*b02+a33*b00,a21*b02-a20*b04-a23*b00,a11*b07-a10*b09-a12*b06,a00*b09-a01*b07+a02*b06,a31*b01-a30*b03-a32*b00,a20*b03-a21*b01+a22*b00)/det;}\n#define INVERSE_MAT(mat) inverseMat(mat)\n#endif\n"; // eslint-disable-line
3190
3190
 
@@ -3345,7 +3345,7 @@ var ParticleShaderLib = {
3345
3345
  particle_mesh: particle_mesh
3346
3346
  };
3347
3347
 
3348
- var normal_get = "#define GLSLIFY 1\nvec3 getNormal(bool isFrontFacing){\n#ifdef RENDERER_HAS_NORMAL\nvec3 normal=normalize(v_normal);\n#elif defined(HAS_DERIVATIVES)\nvec3 pos_dx=dFdx(v_pos);vec3 pos_dy=dFdy(v_pos);vec3 normal=normalize(cross(pos_dx,pos_dy));\n#else\nvec3 normal=vec3(0,0,1);\n#endif\nnormal*=float(isFrontFacing)*2.0-1.0;return normal;}vec3 getNormalByNormalTexture(mat3 tbn,sampler2D normalTexture,float normalIntensity,vec2 uv,bool isFrontFacing){vec3 normal=texture2D(normalTexture,uv).rgb;normal=normalize(tbn*((2.0*normal-1.0)*vec3(normalIntensity,normalIntensity,1.0)));normal*=float(isFrontFacing)*2.0-1.0;return normal;}mat3 getTBN(bool isFrontFacing){\n#if defined(RENDERER_HAS_NORMAL) && defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY) )\nmat3 tbn=v_TBN;\n#else\nvec3 normal=getNormal(isFrontFacing);vec3 position=v_pos;vec2 uv=isFrontFacing? v_uv:-v_uv;\n#ifdef HAS_DERIVATIVES\nvec3 dp1=dFdx(position);vec3 dp2=dFdy(position);vec2 duv1=dFdx(uv);vec2 duv2=dFdy(uv);vec3 dp2perp=cross(dp2,normal);vec3 dp1perp=cross(normal,dp1);vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;vec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;float invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));mat3 tbn=mat3(tangent*invmax,bitangent*invmax,normal);\n#else\nmat3 tbn=mat3(vec3(0.0),vec3(0.0),normal);\n#endif\n#endif\nreturn tbn;}"; // eslint-disable-line
3348
+ var normal_get = "#define GLSLIFY 1\nvec3 getNormal(bool isFrontFacing){\n#ifdef RENDERER_HAS_NORMAL\nvec3 normal=normalize(v_normal);\n#elif defined(HAS_DERIVATIVES)\nvec3 pos_dx=dFdx(v_pos);vec3 pos_dy=dFdy(v_pos);vec3 normal=normalize(cross(pos_dx,pos_dy));normal*=camera_ProjectionParams.x;\n#else\nvec3 normal=vec3(0,0,1);\n#endif\nnormal*=float(isFrontFacing)*2.0-1.0;return normal;}vec3 getNormalByNormalTexture(mat3 tbn,sampler2D normalTexture,float normalIntensity,vec2 uv,bool isFrontFacing){vec3 normal=texture2D(normalTexture,uv).rgb;normal=normalize(tbn*((2.0*normal-1.0)*vec3(normalIntensity,normalIntensity,1.0)));normal*=float(isFrontFacing)*2.0-1.0;return normal;}mat3 getTBN(bool isFrontFacing){\n#if defined(RENDERER_HAS_NORMAL) && defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY) )\nmat3 tbn=v_TBN;\n#else\nvec3 normal=getNormal(isFrontFacing);vec3 position=v_pos;vec2 uv=isFrontFacing? v_uv:-v_uv;\n#ifdef HAS_DERIVATIVES\nvec3 dp1=dFdx(position);vec3 dp2=dFdy(position);vec2 duv1=dFdx(uv);vec2 duv2=dFdy(uv);vec3 dp2perp=cross(dp2,normal);vec3 dp1perp=cross(normal,dp1);vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;vec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;float denom=max(dot(tangent,tangent),dot(bitangent,bitangent));float invmax=(denom==0.0)? 0.0 : camera_ProjectionParams.x/sqrt(denom);mat3 tbn=mat3(tangent*invmax,bitangent*invmax,normal);\n#else\nmat3 tbn=mat3(vec3(0.0),vec3(0.0),normal);\n#endif\n#endif\nreturn tbn;}"; // eslint-disable-line
3349
3349
 
3350
3350
  var ShaderLib = _extends({
3351
3351
  common: common,
@@ -4831,10 +4831,11 @@ __decorate([
4831
4831
  renderStateDataMap && this._applyShaderDataValue(renderStateDataMap, shaderData);
4832
4832
  var hardwareRenderer = engine._hardwareRenderer;
4833
4833
  var lastRenderState = engine._lastRenderState;
4834
+ var context = engine._renderContext;
4834
4835
  this.blendState._apply(hardwareRenderer, lastRenderState);
4835
4836
  this.depthState._apply(hardwareRenderer, lastRenderState);
4836
4837
  this.stencilState._apply(hardwareRenderer, lastRenderState);
4837
- this.rasterState._apply(hardwareRenderer, lastRenderState, frontFaceInvert);
4838
+ this.rasterState._apply(hardwareRenderer, lastRenderState, context.flipProjection ? !frontFaceInvert : frontFaceInvert);
4838
4839
  };
4839
4840
  return RenderState;
4840
4841
  }();
@@ -5837,22 +5838,26 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component1) {
5837
5838
  * @internal
5838
5839
  */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, worldMatrix) {
5839
5840
  var shaderData = this.shaderData;
5840
- var virtualCamera = context.virtualCamera;
5841
5841
  var mvMatrix = this._mvMatrix;
5842
- var mvpMatrix = this._mvpMatrix;
5843
5842
  var mvInvMatrix = this._mvInvMatrix;
5844
5843
  var normalMatrix = this._normalMatrix;
5845
- miniprogram.Matrix.multiply(virtualCamera.viewMatrix, worldMatrix, mvMatrix);
5846
- miniprogram.Matrix.multiply(virtualCamera.viewProjectionMatrix, worldMatrix, mvpMatrix);
5844
+ miniprogram.Matrix.multiply(context.viewMatrix, worldMatrix, mvMatrix);
5847
5845
  miniprogram.Matrix.invert(mvMatrix, mvInvMatrix);
5848
5846
  miniprogram.Matrix.invert(worldMatrix, normalMatrix);
5849
5847
  normalMatrix.transpose();
5850
5848
  shaderData.setMatrix(exports.Renderer._localMatrixProperty, this.entity.transform.localMatrix);
5851
5849
  shaderData.setMatrix(exports.Renderer._worldMatrixProperty, worldMatrix);
5852
5850
  shaderData.setMatrix(exports.Renderer._mvMatrixProperty, mvMatrix);
5853
- shaderData.setMatrix(exports.Renderer._mvpMatrixProperty, mvpMatrix);
5854
5851
  shaderData.setMatrix(exports.Renderer._mvInvMatrixProperty, mvInvMatrix);
5855
5852
  shaderData.setMatrix(exports.Renderer._normalMatrixProperty, normalMatrix);
5853
+ this._updateMVPShaderData(context, worldMatrix);
5854
+ };
5855
+ /**
5856
+ * @internal
5857
+ */ _proto._updateMVPShaderData = function _updateMVPShaderData(context, worldMatrix) {
5858
+ var mvpMatrix = this._mvpMatrix;
5859
+ miniprogram.Matrix.multiply(context.viewProjectionMatrix, worldMatrix, mvpMatrix);
5860
+ this.shaderData.setMatrix(exports.Renderer._mvpMatrixProperty, mvpMatrix);
5856
5861
  };
5857
5862
  /**
5858
5863
  * @internal
@@ -14519,14 +14524,31 @@ var ComponentCloner = /*#__PURE__*/ function() {
14519
14524
  * @internal
14520
14525
  * Rendering context.
14521
14526
  */ var RenderContext = /*#__PURE__*/ function() {
14522
- function RenderContext() {}
14527
+ function RenderContext() {
14528
+ this._projectionParams = new miniprogram.Vector4();
14529
+ this.flipProjection = false;
14530
+ }
14523
14531
  var _proto = RenderContext.prototype;
14524
- _proto.applyVirtualCamera = function applyVirtualCamera(virtualCamera) {
14532
+ _proto.applyVirtualCamera = function applyVirtualCamera(virtualCamera, flipProjection) {
14525
14533
  this.virtualCamera = virtualCamera;
14534
+ this.flipProjection = flipProjection;
14526
14535
  var shaderData = this.camera.shaderData;
14527
- shaderData.setMatrix(RenderContext._viewMatrixProperty, virtualCamera.viewMatrix);
14528
- shaderData.setMatrix(RenderContext._projectionMatrixProperty, virtualCamera.projectionMatrix);
14529
- shaderData.setMatrix(RenderContext.vpMatrixProperty, virtualCamera.viewProjectionMatrix);
14536
+ var viewMatrix = virtualCamera.viewMatrix, projectionMatrix = virtualCamera.projectionMatrix, viewProjectionMatrix = virtualCamera.viewProjectionMatrix;
14537
+ if (flipProjection) {
14538
+ miniprogram.Matrix.multiply(RenderContext._flipYMatrix, projectionMatrix, RenderContext._flipYProjectionMatrix);
14539
+ miniprogram.Matrix.multiply(RenderContext._flipYProjectionMatrix, viewMatrix, RenderContext._flipYViewProjectionMatrix);
14540
+ projectionMatrix = RenderContext._flipYProjectionMatrix;
14541
+ viewProjectionMatrix = RenderContext._flipYViewProjectionMatrix;
14542
+ }
14543
+ this.viewMatrix = viewMatrix;
14544
+ this.projectionMatrix = projectionMatrix;
14545
+ this.viewProjectionMatrix = viewProjectionMatrix;
14546
+ shaderData.setMatrix(RenderContext._viewMatrixProperty, viewMatrix);
14547
+ shaderData.setMatrix(RenderContext._projectionMatrixProperty, projectionMatrix);
14548
+ shaderData.setMatrix(RenderContext.vpMatrixProperty, viewProjectionMatrix);
14549
+ var projectionParams = this._projectionParams;
14550
+ projectionParams.set(flipProjection ? -1 : 1, virtualCamera.nearClipPlane, virtualCamera.farClipPlane, 0);
14551
+ shaderData.setVector4(RenderContext._cameraProjectionProperty, projectionParams);
14530
14552
  };
14531
14553
  return RenderContext;
14532
14554
  }();
@@ -14536,12 +14558,24 @@ var ComponentCloner = /*#__PURE__*/ function() {
14536
14558
  (function() {
14537
14559
  RenderContext.pipelineStageKey = ShaderTagKey.getByName("pipelineStage");
14538
14560
  })();
14561
+ (function() {
14562
+ /** @internal */ RenderContext._flipYMatrix = new miniprogram.Matrix(1, 0, 0, 0, 0, -1);
14563
+ })();
14564
+ (function() {
14565
+ RenderContext._cameraProjectionProperty = ShaderProperty.getByName("camera_ProjectionParams");
14566
+ })();
14539
14567
  (function() {
14540
14568
  RenderContext._viewMatrixProperty = ShaderProperty.getByName("camera_ViewMat");
14541
14569
  })();
14542
14570
  (function() {
14543
14571
  RenderContext._projectionMatrixProperty = ShaderProperty.getByName("camera_ProjMat");
14544
14572
  })();
14573
+ (function() {
14574
+ RenderContext._flipYProjectionMatrix = new miniprogram.Matrix();
14575
+ })();
14576
+ (function() {
14577
+ RenderContext._flipYViewProjectionMatrix = new miniprogram.Matrix();
14578
+ })();
14545
14579
 
14546
14580
  var RenderData = /*#__PURE__*/ function() {
14547
14581
  function RenderData() {}
@@ -19737,6 +19771,9 @@ ShaderPool.init();
19737
19771
  // view-proj matrix
19738
19772
  miniprogram.Matrix.multiply(projectionMatrix, viewProjMatrix, viewProjMatrix);
19739
19773
  var originViewProjMatrix = cameraShaderData.getMatrix(RenderContext.vpMatrixProperty);
19774
+ if (context.flipProjection) {
19775
+ miniprogram.Matrix.multiply(RenderContext._flipYMatrix, viewProjMatrix, viewProjMatrix);
19776
+ }
19740
19777
  cameraShaderData.setMatrix(RenderContext.vpMatrixProperty, viewProjMatrix);
19741
19778
  var compileMacros = Shader._compileMacros;
19742
19779
  ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, materialShaderData._macroCollection, compileMacros);
@@ -22064,6 +22101,8 @@ var passNum = 0;
22064
22101
  this.viewMatrix = new miniprogram.Matrix();
22065
22102
  this.projectionMatrix = new miniprogram.Matrix();
22066
22103
  this.viewProjectionMatrix = new miniprogram.Matrix();
22104
+ this.nearClipPlane = 0.1;
22105
+ this.farClipPlane = 100;
22067
22106
  /** Only orth mode use. */ this.forward = new miniprogram.Vector3();
22068
22107
  };
22069
22108
 
@@ -22348,7 +22387,7 @@ var /**
22348
22387
  })();
22349
22388
  (function() {
22350
22389
  // prettier-ignore
22351
- /** @internal */ ShadowUtils._shadowMapCoordMatrix = new miniprogram.Matrix(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);
22390
+ /** @internal */ ShadowUtils._shadowMapCoordMatrix = new miniprogram.Matrix(0.5, 0.0, 0.0, 0.0, 0.0, -0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);
22352
22391
  })();
22353
22392
  (function() {
22354
22393
  ShadowUtils._frustumCorners = [
@@ -22700,6 +22739,7 @@ var /**
22700
22739
  rhi.viewport(x, y, shadowTileResolution, shadowTileResolution);
22701
22740
  // for no cascade is for the edge,for cascade is for the beyond maxCascade pixel can use (0,0,0) trick sample the shadowMap
22702
22741
  rhi.scissor(x + 1, y + 1, shadowTileResolution - 2, shadowTileResolution - 2);
22742
+ // @todo: It is more appropriate to prevent duplication based on `virtualCamera` at `RenderQueue#render`.
22703
22743
  engine._renderCount++;
22704
22744
  opaqueQueue.render(camera, exports.Layer.Everything, exports.PipelineStage.ShadowCaster);
22705
22745
  alphaTestQueue.render(camera, exports.Layer.Everything, exports.PipelineStage.ShadowCaster);
@@ -22810,7 +22850,7 @@ var /**
22810
22850
  var sceneShaderData = this._camera.scene.shaderData;
22811
22851
  sceneShaderData.setVector2(CascadedShadowCasterPass._lightShadowBiasProperty, this._shadowBias);
22812
22852
  sceneShaderData.setVector3(CascadedShadowCasterPass._lightDirectionProperty, light.direction);
22813
- context.applyVirtualCamera(virtualCamera);
22853
+ context.applyVirtualCamera(virtualCamera, true);
22814
22854
  };
22815
22855
  return CascadedShadowCasterPass;
22816
22856
  }(PipelinePass);
@@ -22999,19 +23039,25 @@ var /**
22999
23039
  var scene = camera.scene;
23000
23040
  var cullingResults = this._cullingResults;
23001
23041
  var sunlight = scene._lightManager._sunlight;
23042
+ var depthOnlyPass = this._depthOnlyPass;
23043
+ var depthPassEnabled = camera.depthTextureMode === exports.DepthTextureMode.PrePass && depthOnlyPass._supportDepthTexture;
23044
+ var rt2DEnabled = camera.renderTarget && cubeFace == undefined;
23002
23045
  camera.engine._spriteMaskManager.clear();
23003
23046
  if (scene.castShadows && sunlight && sunlight.shadowType !== exports.ShadowType.None) {
23004
23047
  this._cascadedShadowCaster.onRender(context);
23005
23048
  }
23006
23049
  cullingResults.reset();
23007
23050
  this._allSpriteMasks.length = 0;
23008
- context.applyVirtualCamera(camera._virtualCamera);
23009
- this._callRender(context);
23051
+ context.applyVirtualCamera(camera._virtualCamera, depthPassEnabled || rt2DEnabled);
23052
+ this._prepareRender(context);
23010
23053
  cullingResults.sort();
23011
- var depthOnlyPass = this._depthOnlyPass;
23012
- if (camera.depthTextureMode === exports.DepthTextureMode.PrePass && depthOnlyPass._supportDepthTexture) {
23054
+ if (depthPassEnabled) {
23013
23055
  depthOnlyPass.onConfig(camera);
23014
23056
  depthOnlyPass.onRender(context, cullingResults);
23057
+ if (!rt2DEnabled) {
23058
+ context.applyVirtualCamera(camera._virtualCamera, false);
23059
+ this._updateMVPShaderData(context);
23060
+ }
23015
23061
  } else {
23016
23062
  camera.shaderData.setTexture(exports.Camera._cameraDepthTextureProperty, camera.engine._whiteTexture2D);
23017
23063
  }
@@ -23128,9 +23174,9 @@ var /**
23128
23174
  (pass._renderState || material.renderState)._apply(engine, false, pass._renderStateDataMap, material.shaderData);
23129
23175
  rhi.drawPrimitive(mesh._primitive, mesh.subMesh, program);
23130
23176
  };
23131
- _proto._callRender = function _callRender(context) {
23132
- var engine = context.camera.engine;
23177
+ _proto._prepareRender = function _prepareRender(context) {
23133
23178
  var camera = context.camera;
23179
+ var engine = camera.engine;
23134
23180
  var renderers = camera.scene._componentsManager._renderers;
23135
23181
  var elements = renderers._elements;
23136
23182
  for(var i = renderers.length - 1; i >= 0; --i){
@@ -23149,6 +23195,15 @@ var /**
23149
23195
  renderer._prepareRender(context);
23150
23196
  }
23151
23197
  };
23198
+ _proto._updateMVPShaderData = function _updateMVPShaderData(context) {
23199
+ var camera = context.camera;
23200
+ var renderers = camera.scene._componentsManager._renderers;
23201
+ var elements = renderers._elements;
23202
+ for(var i = renderers.length - 1; i >= 0; --i){
23203
+ var renderer = elements[i];
23204
+ renderer._updateMVPShaderData(context, renderer.entity.transform.worldMatrix);
23205
+ }
23206
+ };
23152
23207
  _create_class(BasicRenderPipeline, [
23153
23208
  {
23154
23209
  key: "defaultRenderPass",
@@ -23220,8 +23275,6 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23220
23275
  _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
23221
23276
  _this._isCustomViewMatrix = false;
23222
23277
  _this._isCustomProjectionMatrix = false;
23223
- _this._nearClipPlane = 0.1;
23224
- _this._farClipPlane = 100;
23225
23278
  _this._fieldOfView = 45;
23226
23279
  _this._orthographicSize = 10;
23227
23280
  _this._isProjectionDirty = true;
@@ -23503,7 +23556,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23503
23556
  shaderData.setVector3(exports.Camera._cameraForwardProperty, transform.worldForward);
23504
23557
  shaderData.setVector3(exports.Camera._cameraUpProperty, transform.worldUp);
23505
23558
  var depthBufferParams = this._depthBufferParams;
23506
- var farDivideNear = this._farClipPlane / this._nearClipPlane;
23559
+ var farDivideNear = this.farClipPlane / this.nearClipPlane;
23507
23560
  depthBufferParams.set(1.0 - farDivideNear, farDivideNear, 0, 0);
23508
23561
  shaderData.setVector4(exports.Camera._cameraDepthBufferParamsProperty, depthBufferParams);
23509
23562
  };
@@ -23544,10 +23597,10 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23544
23597
  get: /**
23545
23598
  * Near clip plane - the closest point to the camera when rendering occurs.
23546
23599
  */ function get() {
23547
- return this._nearClipPlane;
23600
+ return this._virtualCamera.nearClipPlane;
23548
23601
  },
23549
23602
  set: function set(value) {
23550
- this._nearClipPlane = value;
23603
+ this._virtualCamera.nearClipPlane = value;
23551
23604
  this._projectionMatrixChange();
23552
23605
  }
23553
23606
  },
@@ -23556,10 +23609,10 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23556
23609
  get: /**
23557
23610
  * Far clip plane - the furthest point to the camera when rendering occurs.
23558
23611
  */ function get() {
23559
- return this._farClipPlane;
23612
+ return this._virtualCamera.farClipPlane;
23560
23613
  },
23561
23614
  set: function set(value) {
23562
- this._farClipPlane = value;
23615
+ this._virtualCamera.farClipPlane = value;
23563
23616
  this._projectionMatrixChange();
23564
23617
  }
23565
23618
  },
@@ -23695,11 +23748,11 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23695
23748
  this._isProjectionDirty = false;
23696
23749
  var aspectRatio = this.aspectRatio;
23697
23750
  if (!virtualCamera.isOrthographic) {
23698
- miniprogram.Matrix.perspective(miniprogram.MathUtil.degreeToRadian(this._fieldOfView), aspectRatio, this._nearClipPlane, this._farClipPlane, projectionMatrix);
23751
+ miniprogram.Matrix.perspective(miniprogram.MathUtil.degreeToRadian(this._fieldOfView), aspectRatio, this.nearClipPlane, this.farClipPlane, projectionMatrix);
23699
23752
  } else {
23700
23753
  var width = this._orthographicSize * aspectRatio;
23701
23754
  var height = this._orthographicSize;
23702
- miniprogram.Matrix.ortho(-width, width, -height, height, this._nearClipPlane, this._farClipPlane, projectionMatrix);
23755
+ miniprogram.Matrix.ortho(-width, width, -height, height, this.nearClipPlane, this.farClipPlane, projectionMatrix);
23703
23756
  }
23704
23757
  return projectionMatrix;
23705
23758
  },
@@ -31327,6 +31380,7 @@ exports.Script = Script;
31327
31380
  exports.Shader = Shader;
31328
31381
  exports.ShaderData = ShaderData;
31329
31382
  exports.ShaderFactory = ShaderFactory;
31383
+ exports.ShaderLib = ShaderLib;
31330
31384
  exports.ShaderMacro = ShaderMacro;
31331
31385
  exports.ShaderMacroCollection = ShaderMacroCollection;
31332
31386
  exports.ShaderPass = ShaderPass;
package/dist/module.js CHANGED
@@ -3179,7 +3179,7 @@ function _extends() {
3179
3179
  return _extends.apply(this, arguments);
3180
3180
  }
3181
3181
 
3182
- var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;uniform vec3 camera_Forward;"; // eslint-disable-line
3182
+ var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;uniform vec3 camera_Forward;uniform vec4 camera_ProjectionParams;"; // eslint-disable-line
3183
3183
 
3184
3184
  var common = "#define GLSLIFY 1\n#define PI 3.14159265359\n#define RECIPROCAL_PI 0.31830988618\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate( a ) clamp( a, 0.0, 1.0 )\nfloat pow2(float x){return x*x;}vec4 RGBMToLinear(vec4 value,float maxRange){return vec4(value.rgb*value.a*maxRange,1.0);}vec4 gammaToLinear(vec4 srgbIn){return vec4(pow(srgbIn.rgb,vec3(2.2)),srgbIn.a);}vec4 linearToGamma(vec4 linearIn){return vec4(pow(linearIn.rgb,vec3(1.0/2.2)),linearIn.a);}uniform vec4 camera_DepthBufferParams;float remapDepthBufferLinear01(float z){return 1.0/(camera_DepthBufferParams.x*z+camera_DepthBufferParams.y);}\n#ifdef GRAPHICS_API_WEBGL2\n#define INVERSE_MAT(mat) inverse(mat)\n#else\nmat2 inverseMat(mat2 m){return mat2(m[1][1],-m[0][1],-m[1][0],m[0][0])/(m[0][0]*m[1][1]-m[0][1]*m[1][0]);}mat3 inverseMat(mat3 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2];float a10=m[1][0],a11=m[1][1],a12=m[1][2];float a20=m[2][0],a21=m[2][1],a22=m[2][2];float b01=a22*a11-a12*a21;float b11=-a22*a10+a12*a20;float b21=a21*a10-a11*a20;float det=a00*b01+a01*b11+a02*b21;return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;}mat4 inverseMat(mat4 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2],a03=m[0][3],a10=m[1][0],a11=m[1][1],a12=m[1][2],a13=m[1][3],a20=m[2][0],a21=m[2][1],a22=m[2][2],a23=m[2][3],a30=m[3][0],a31=m[3][1],a32=m[3][2],a33=m[3][3],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return mat4(a11*b11-a12*b10+a13*b09,a02*b10-a01*b11-a03*b09,a31*b05-a32*b04+a33*b03,a22*b04-a21*b05-a23*b03,a12*b08-a10*b11-a13*b07,a00*b11-a02*b08+a03*b07,a32*b02-a30*b05-a33*b01,a20*b05-a22*b02+a23*b01,a10*b10-a11*b08+a13*b06,a01*b08-a00*b10-a03*b06,a30*b04-a31*b02+a33*b00,a21*b02-a20*b04-a23*b00,a11*b07-a10*b09-a12*b06,a00*b09-a01*b07+a02*b06,a31*b01-a30*b03-a32*b00,a20*b03-a21*b01+a22*b00)/det;}\n#define INVERSE_MAT(mat) inverseMat(mat)\n#endif\n"; // eslint-disable-line
3185
3185
 
@@ -3340,7 +3340,7 @@ var ParticleShaderLib = {
3340
3340
  particle_mesh: particle_mesh
3341
3341
  };
3342
3342
 
3343
- var normal_get = "#define GLSLIFY 1\nvec3 getNormal(bool isFrontFacing){\n#ifdef RENDERER_HAS_NORMAL\nvec3 normal=normalize(v_normal);\n#elif defined(HAS_DERIVATIVES)\nvec3 pos_dx=dFdx(v_pos);vec3 pos_dy=dFdy(v_pos);vec3 normal=normalize(cross(pos_dx,pos_dy));\n#else\nvec3 normal=vec3(0,0,1);\n#endif\nnormal*=float(isFrontFacing)*2.0-1.0;return normal;}vec3 getNormalByNormalTexture(mat3 tbn,sampler2D normalTexture,float normalIntensity,vec2 uv,bool isFrontFacing){vec3 normal=texture2D(normalTexture,uv).rgb;normal=normalize(tbn*((2.0*normal-1.0)*vec3(normalIntensity,normalIntensity,1.0)));normal*=float(isFrontFacing)*2.0-1.0;return normal;}mat3 getTBN(bool isFrontFacing){\n#if defined(RENDERER_HAS_NORMAL) && defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY) )\nmat3 tbn=v_TBN;\n#else\nvec3 normal=getNormal(isFrontFacing);vec3 position=v_pos;vec2 uv=isFrontFacing? v_uv:-v_uv;\n#ifdef HAS_DERIVATIVES\nvec3 dp1=dFdx(position);vec3 dp2=dFdy(position);vec2 duv1=dFdx(uv);vec2 duv2=dFdy(uv);vec3 dp2perp=cross(dp2,normal);vec3 dp1perp=cross(normal,dp1);vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;vec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;float invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));mat3 tbn=mat3(tangent*invmax,bitangent*invmax,normal);\n#else\nmat3 tbn=mat3(vec3(0.0),vec3(0.0),normal);\n#endif\n#endif\nreturn tbn;}"; // eslint-disable-line
3343
+ var normal_get = "#define GLSLIFY 1\nvec3 getNormal(bool isFrontFacing){\n#ifdef RENDERER_HAS_NORMAL\nvec3 normal=normalize(v_normal);\n#elif defined(HAS_DERIVATIVES)\nvec3 pos_dx=dFdx(v_pos);vec3 pos_dy=dFdy(v_pos);vec3 normal=normalize(cross(pos_dx,pos_dy));normal*=camera_ProjectionParams.x;\n#else\nvec3 normal=vec3(0,0,1);\n#endif\nnormal*=float(isFrontFacing)*2.0-1.0;return normal;}vec3 getNormalByNormalTexture(mat3 tbn,sampler2D normalTexture,float normalIntensity,vec2 uv,bool isFrontFacing){vec3 normal=texture2D(normalTexture,uv).rgb;normal=normalize(tbn*((2.0*normal-1.0)*vec3(normalIntensity,normalIntensity,1.0)));normal*=float(isFrontFacing)*2.0-1.0;return normal;}mat3 getTBN(bool isFrontFacing){\n#if defined(RENDERER_HAS_NORMAL) && defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY) )\nmat3 tbn=v_TBN;\n#else\nvec3 normal=getNormal(isFrontFacing);vec3 position=v_pos;vec2 uv=isFrontFacing? v_uv:-v_uv;\n#ifdef HAS_DERIVATIVES\nvec3 dp1=dFdx(position);vec3 dp2=dFdy(position);vec2 duv1=dFdx(uv);vec2 duv2=dFdy(uv);vec3 dp2perp=cross(dp2,normal);vec3 dp1perp=cross(normal,dp1);vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;vec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;float denom=max(dot(tangent,tangent),dot(bitangent,bitangent));float invmax=(denom==0.0)? 0.0 : camera_ProjectionParams.x/sqrt(denom);mat3 tbn=mat3(tangent*invmax,bitangent*invmax,normal);\n#else\nmat3 tbn=mat3(vec3(0.0),vec3(0.0),normal);\n#endif\n#endif\nreturn tbn;}"; // eslint-disable-line
3344
3344
 
3345
3345
  var ShaderLib = _extends({
3346
3346
  common: common,
@@ -4826,10 +4826,11 @@ __decorate([
4826
4826
  renderStateDataMap && this._applyShaderDataValue(renderStateDataMap, shaderData);
4827
4827
  var hardwareRenderer = engine._hardwareRenderer;
4828
4828
  var lastRenderState = engine._lastRenderState;
4829
+ var context = engine._renderContext;
4829
4830
  this.blendState._apply(hardwareRenderer, lastRenderState);
4830
4831
  this.depthState._apply(hardwareRenderer, lastRenderState);
4831
4832
  this.stencilState._apply(hardwareRenderer, lastRenderState);
4832
- this.rasterState._apply(hardwareRenderer, lastRenderState, frontFaceInvert);
4833
+ this.rasterState._apply(hardwareRenderer, lastRenderState, context.flipProjection ? !frontFaceInvert : frontFaceInvert);
4833
4834
  };
4834
4835
  return RenderState;
4835
4836
  }();
@@ -5832,22 +5833,26 @@ var Renderer = (_Renderer = /*#__PURE__*/ function(Component1) {
5832
5833
  * @internal
5833
5834
  */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, worldMatrix) {
5834
5835
  var shaderData = this.shaderData;
5835
- var virtualCamera = context.virtualCamera;
5836
5836
  var mvMatrix = this._mvMatrix;
5837
- var mvpMatrix = this._mvpMatrix;
5838
5837
  var mvInvMatrix = this._mvInvMatrix;
5839
5838
  var normalMatrix = this._normalMatrix;
5840
- Matrix.multiply(virtualCamera.viewMatrix, worldMatrix, mvMatrix);
5841
- Matrix.multiply(virtualCamera.viewProjectionMatrix, worldMatrix, mvpMatrix);
5839
+ Matrix.multiply(context.viewMatrix, worldMatrix, mvMatrix);
5842
5840
  Matrix.invert(mvMatrix, mvInvMatrix);
5843
5841
  Matrix.invert(worldMatrix, normalMatrix);
5844
5842
  normalMatrix.transpose();
5845
5843
  shaderData.setMatrix(Renderer._localMatrixProperty, this.entity.transform.localMatrix);
5846
5844
  shaderData.setMatrix(Renderer._worldMatrixProperty, worldMatrix);
5847
5845
  shaderData.setMatrix(Renderer._mvMatrixProperty, mvMatrix);
5848
- shaderData.setMatrix(Renderer._mvpMatrixProperty, mvpMatrix);
5849
5846
  shaderData.setMatrix(Renderer._mvInvMatrixProperty, mvInvMatrix);
5850
5847
  shaderData.setMatrix(Renderer._normalMatrixProperty, normalMatrix);
5848
+ this._updateMVPShaderData(context, worldMatrix);
5849
+ };
5850
+ /**
5851
+ * @internal
5852
+ */ _proto._updateMVPShaderData = function _updateMVPShaderData(context, worldMatrix) {
5853
+ var mvpMatrix = this._mvpMatrix;
5854
+ Matrix.multiply(context.viewProjectionMatrix, worldMatrix, mvpMatrix);
5855
+ this.shaderData.setMatrix(Renderer._mvpMatrixProperty, mvpMatrix);
5851
5856
  };
5852
5857
  /**
5853
5858
  * @internal
@@ -14514,14 +14519,31 @@ var ComponentCloner = /*#__PURE__*/ function() {
14514
14519
  * @internal
14515
14520
  * Rendering context.
14516
14521
  */ var RenderContext = /*#__PURE__*/ function() {
14517
- function RenderContext() {}
14522
+ function RenderContext() {
14523
+ this._projectionParams = new Vector4();
14524
+ this.flipProjection = false;
14525
+ }
14518
14526
  var _proto = RenderContext.prototype;
14519
- _proto.applyVirtualCamera = function applyVirtualCamera(virtualCamera) {
14527
+ _proto.applyVirtualCamera = function applyVirtualCamera(virtualCamera, flipProjection) {
14520
14528
  this.virtualCamera = virtualCamera;
14529
+ this.flipProjection = flipProjection;
14521
14530
  var shaderData = this.camera.shaderData;
14522
- shaderData.setMatrix(RenderContext._viewMatrixProperty, virtualCamera.viewMatrix);
14523
- shaderData.setMatrix(RenderContext._projectionMatrixProperty, virtualCamera.projectionMatrix);
14524
- shaderData.setMatrix(RenderContext.vpMatrixProperty, virtualCamera.viewProjectionMatrix);
14531
+ var viewMatrix = virtualCamera.viewMatrix, projectionMatrix = virtualCamera.projectionMatrix, viewProjectionMatrix = virtualCamera.viewProjectionMatrix;
14532
+ if (flipProjection) {
14533
+ Matrix.multiply(RenderContext._flipYMatrix, projectionMatrix, RenderContext._flipYProjectionMatrix);
14534
+ Matrix.multiply(RenderContext._flipYProjectionMatrix, viewMatrix, RenderContext._flipYViewProjectionMatrix);
14535
+ projectionMatrix = RenderContext._flipYProjectionMatrix;
14536
+ viewProjectionMatrix = RenderContext._flipYViewProjectionMatrix;
14537
+ }
14538
+ this.viewMatrix = viewMatrix;
14539
+ this.projectionMatrix = projectionMatrix;
14540
+ this.viewProjectionMatrix = viewProjectionMatrix;
14541
+ shaderData.setMatrix(RenderContext._viewMatrixProperty, viewMatrix);
14542
+ shaderData.setMatrix(RenderContext._projectionMatrixProperty, projectionMatrix);
14543
+ shaderData.setMatrix(RenderContext.vpMatrixProperty, viewProjectionMatrix);
14544
+ var projectionParams = this._projectionParams;
14545
+ projectionParams.set(flipProjection ? -1 : 1, virtualCamera.nearClipPlane, virtualCamera.farClipPlane, 0);
14546
+ shaderData.setVector4(RenderContext._cameraProjectionProperty, projectionParams);
14525
14547
  };
14526
14548
  return RenderContext;
14527
14549
  }();
@@ -14531,12 +14553,24 @@ var ComponentCloner = /*#__PURE__*/ function() {
14531
14553
  (function() {
14532
14554
  RenderContext.pipelineStageKey = ShaderTagKey.getByName("pipelineStage");
14533
14555
  })();
14556
+ (function() {
14557
+ /** @internal */ RenderContext._flipYMatrix = new Matrix(1, 0, 0, 0, 0, -1);
14558
+ })();
14559
+ (function() {
14560
+ RenderContext._cameraProjectionProperty = ShaderProperty.getByName("camera_ProjectionParams");
14561
+ })();
14534
14562
  (function() {
14535
14563
  RenderContext._viewMatrixProperty = ShaderProperty.getByName("camera_ViewMat");
14536
14564
  })();
14537
14565
  (function() {
14538
14566
  RenderContext._projectionMatrixProperty = ShaderProperty.getByName("camera_ProjMat");
14539
14567
  })();
14568
+ (function() {
14569
+ RenderContext._flipYProjectionMatrix = new Matrix();
14570
+ })();
14571
+ (function() {
14572
+ RenderContext._flipYViewProjectionMatrix = new Matrix();
14573
+ })();
14540
14574
 
14541
14575
  var RenderData = /*#__PURE__*/ function() {
14542
14576
  function RenderData() {}
@@ -19732,6 +19766,9 @@ ShaderPool.init();
19732
19766
  // view-proj matrix
19733
19767
  Matrix.multiply(projectionMatrix, viewProjMatrix, viewProjMatrix);
19734
19768
  var originViewProjMatrix = cameraShaderData.getMatrix(RenderContext.vpMatrixProperty);
19769
+ if (context.flipProjection) {
19770
+ Matrix.multiply(RenderContext._flipYMatrix, viewProjMatrix, viewProjMatrix);
19771
+ }
19735
19772
  cameraShaderData.setMatrix(RenderContext.vpMatrixProperty, viewProjMatrix);
19736
19773
  var compileMacros = Shader._compileMacros;
19737
19774
  ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, materialShaderData._macroCollection, compileMacros);
@@ -22059,6 +22096,8 @@ var passNum = 0;
22059
22096
  this.viewMatrix = new Matrix();
22060
22097
  this.projectionMatrix = new Matrix();
22061
22098
  this.viewProjectionMatrix = new Matrix();
22099
+ this.nearClipPlane = 0.1;
22100
+ this.farClipPlane = 100;
22062
22101
  /** Only orth mode use. */ this.forward = new Vector3();
22063
22102
  };
22064
22103
 
@@ -22343,7 +22382,7 @@ var /**
22343
22382
  })();
22344
22383
  (function() {
22345
22384
  // prettier-ignore
22346
- /** @internal */ ShadowUtils._shadowMapCoordMatrix = new Matrix(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);
22385
+ /** @internal */ ShadowUtils._shadowMapCoordMatrix = new Matrix(0.5, 0.0, 0.0, 0.0, 0.0, -0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);
22347
22386
  })();
22348
22387
  (function() {
22349
22388
  ShadowUtils._frustumCorners = [
@@ -22695,6 +22734,7 @@ var /**
22695
22734
  rhi.viewport(x, y, shadowTileResolution, shadowTileResolution);
22696
22735
  // for no cascade is for the edge,for cascade is for the beyond maxCascade pixel can use (0,0,0) trick sample the shadowMap
22697
22736
  rhi.scissor(x + 1, y + 1, shadowTileResolution - 2, shadowTileResolution - 2);
22737
+ // @todo: It is more appropriate to prevent duplication based on `virtualCamera` at `RenderQueue#render`.
22698
22738
  engine._renderCount++;
22699
22739
  opaqueQueue.render(camera, Layer.Everything, PipelineStage.ShadowCaster);
22700
22740
  alphaTestQueue.render(camera, Layer.Everything, PipelineStage.ShadowCaster);
@@ -22805,7 +22845,7 @@ var /**
22805
22845
  var sceneShaderData = this._camera.scene.shaderData;
22806
22846
  sceneShaderData.setVector2(CascadedShadowCasterPass._lightShadowBiasProperty, this._shadowBias);
22807
22847
  sceneShaderData.setVector3(CascadedShadowCasterPass._lightDirectionProperty, light.direction);
22808
- context.applyVirtualCamera(virtualCamera);
22848
+ context.applyVirtualCamera(virtualCamera, true);
22809
22849
  };
22810
22850
  return CascadedShadowCasterPass;
22811
22851
  }(PipelinePass);
@@ -22994,19 +23034,25 @@ var /**
22994
23034
  var scene = camera.scene;
22995
23035
  var cullingResults = this._cullingResults;
22996
23036
  var sunlight = scene._lightManager._sunlight;
23037
+ var depthOnlyPass = this._depthOnlyPass;
23038
+ var depthPassEnabled = camera.depthTextureMode === DepthTextureMode.PrePass && depthOnlyPass._supportDepthTexture;
23039
+ var rt2DEnabled = camera.renderTarget && cubeFace == undefined;
22997
23040
  camera.engine._spriteMaskManager.clear();
22998
23041
  if (scene.castShadows && sunlight && sunlight.shadowType !== ShadowType.None) {
22999
23042
  this._cascadedShadowCaster.onRender(context);
23000
23043
  }
23001
23044
  cullingResults.reset();
23002
23045
  this._allSpriteMasks.length = 0;
23003
- context.applyVirtualCamera(camera._virtualCamera);
23004
- this._callRender(context);
23046
+ context.applyVirtualCamera(camera._virtualCamera, depthPassEnabled || rt2DEnabled);
23047
+ this._prepareRender(context);
23005
23048
  cullingResults.sort();
23006
- var depthOnlyPass = this._depthOnlyPass;
23007
- if (camera.depthTextureMode === DepthTextureMode.PrePass && depthOnlyPass._supportDepthTexture) {
23049
+ if (depthPassEnabled) {
23008
23050
  depthOnlyPass.onConfig(camera);
23009
23051
  depthOnlyPass.onRender(context, cullingResults);
23052
+ if (!rt2DEnabled) {
23053
+ context.applyVirtualCamera(camera._virtualCamera, false);
23054
+ this._updateMVPShaderData(context);
23055
+ }
23010
23056
  } else {
23011
23057
  camera.shaderData.setTexture(Camera._cameraDepthTextureProperty, camera.engine._whiteTexture2D);
23012
23058
  }
@@ -23123,9 +23169,9 @@ var /**
23123
23169
  (pass._renderState || material.renderState)._apply(engine, false, pass._renderStateDataMap, material.shaderData);
23124
23170
  rhi.drawPrimitive(mesh._primitive, mesh.subMesh, program);
23125
23171
  };
23126
- _proto._callRender = function _callRender(context) {
23127
- var engine = context.camera.engine;
23172
+ _proto._prepareRender = function _prepareRender(context) {
23128
23173
  var camera = context.camera;
23174
+ var engine = camera.engine;
23129
23175
  var renderers = camera.scene._componentsManager._renderers;
23130
23176
  var elements = renderers._elements;
23131
23177
  for(var i = renderers.length - 1; i >= 0; --i){
@@ -23144,6 +23190,15 @@ var /**
23144
23190
  renderer._prepareRender(context);
23145
23191
  }
23146
23192
  };
23193
+ _proto._updateMVPShaderData = function _updateMVPShaderData(context) {
23194
+ var camera = context.camera;
23195
+ var renderers = camera.scene._componentsManager._renderers;
23196
+ var elements = renderers._elements;
23197
+ for(var i = renderers.length - 1; i >= 0; --i){
23198
+ var renderer = elements[i];
23199
+ renderer._updateMVPShaderData(context, renderer.entity.transform.worldMatrix);
23200
+ }
23201
+ };
23147
23202
  _create_class(BasicRenderPipeline, [
23148
23203
  {
23149
23204
  key: "defaultRenderPass",
@@ -23215,8 +23270,6 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23215
23270
  _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
23216
23271
  _this._isCustomViewMatrix = false;
23217
23272
  _this._isCustomProjectionMatrix = false;
23218
- _this._nearClipPlane = 0.1;
23219
- _this._farClipPlane = 100;
23220
23273
  _this._fieldOfView = 45;
23221
23274
  _this._orthographicSize = 10;
23222
23275
  _this._isProjectionDirty = true;
@@ -23498,7 +23551,7 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23498
23551
  shaderData.setVector3(Camera._cameraForwardProperty, transform.worldForward);
23499
23552
  shaderData.setVector3(Camera._cameraUpProperty, transform.worldUp);
23500
23553
  var depthBufferParams = this._depthBufferParams;
23501
- var farDivideNear = this._farClipPlane / this._nearClipPlane;
23554
+ var farDivideNear = this.farClipPlane / this.nearClipPlane;
23502
23555
  depthBufferParams.set(1.0 - farDivideNear, farDivideNear, 0, 0);
23503
23556
  shaderData.setVector4(Camera._cameraDepthBufferParamsProperty, depthBufferParams);
23504
23557
  };
@@ -23539,10 +23592,10 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23539
23592
  get: /**
23540
23593
  * Near clip plane - the closest point to the camera when rendering occurs.
23541
23594
  */ function get() {
23542
- return this._nearClipPlane;
23595
+ return this._virtualCamera.nearClipPlane;
23543
23596
  },
23544
23597
  set: function set(value) {
23545
- this._nearClipPlane = value;
23598
+ this._virtualCamera.nearClipPlane = value;
23546
23599
  this._projectionMatrixChange();
23547
23600
  }
23548
23601
  },
@@ -23551,10 +23604,10 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23551
23604
  get: /**
23552
23605
  * Far clip plane - the furthest point to the camera when rendering occurs.
23553
23606
  */ function get() {
23554
- return this._farClipPlane;
23607
+ return this._virtualCamera.farClipPlane;
23555
23608
  },
23556
23609
  set: function set(value) {
23557
- this._farClipPlane = value;
23610
+ this._virtualCamera.farClipPlane = value;
23558
23611
  this._projectionMatrixChange();
23559
23612
  }
23560
23613
  },
@@ -23690,11 +23743,11 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23690
23743
  this._isProjectionDirty = false;
23691
23744
  var aspectRatio = this.aspectRatio;
23692
23745
  if (!virtualCamera.isOrthographic) {
23693
- Matrix.perspective(MathUtil.degreeToRadian(this._fieldOfView), aspectRatio, this._nearClipPlane, this._farClipPlane, projectionMatrix);
23746
+ Matrix.perspective(MathUtil.degreeToRadian(this._fieldOfView), aspectRatio, this.nearClipPlane, this.farClipPlane, projectionMatrix);
23694
23747
  } else {
23695
23748
  var width = this._orthographicSize * aspectRatio;
23696
23749
  var height = this._orthographicSize;
23697
- Matrix.ortho(-width, width, -height, height, this._nearClipPlane, this._farClipPlane, projectionMatrix);
23750
+ Matrix.ortho(-width, width, -height, height, this.nearClipPlane, this.farClipPlane, projectionMatrix);
23698
23751
  }
23699
23752
  return projectionMatrix;
23700
23753
  },
@@ -31221,5 +31274,5 @@ var cacheDir = new Vector3();
31221
31274
  return CubeProbe;
31222
31275
  }(Probe);
31223
31276
 
31224
- export { AmbientLight, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationRectCurve, AnimationRefCurve, AnimationStringCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorLayerMask, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AssetPromise, AssetType, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, Basic2DBatcher, BasicRenderPipeline, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlendState, BlinnPhongMaterial, BoolUpdateFlag, BoxColliderShape, BoxShape, Buffer, BufferBindFlag, BufferMesh, BufferUsage, BufferUtil, Burst, Camera, CameraClearFlags, CameraType, Canvas, CapsuleColliderShape, CharacterController, CircleShape, CloneManager, Collider, ColliderShape, ColliderShapeUpAxis, CollisionDetectionMode, ColorOverLifetimeModule, ColorSpace, ColorWriteMask, CompareFunction, Component, ConeEmitType, ConeShape, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, CurveKey, DataType, DependentMode, DepthState, DepthTextureMode, DiffuseMode, DirectLight, DynamicCollider, DynamicColliderConstraints, EmissionModule, Engine, EngineObject, Entity, EventDispatcher, FixedJoint, FogMode, Font, FontStyle, GLCapabilityType, GradientAlphaKey, GradientColorKey, HemisphereShape, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolationType, Joint, JointLimits, JointMotor, Keyframe, Keys, Layer, Light, Loader, Logger, MainModule, Material, Mesh, MeshRenderer, MeshTopology, ModelMesh, OverflowMode, PBRBaseMaterial, PBRMaterial, PBRSpecularMaterial, ParticleCompositeCurve, ParticleCompositeGradient, ParticleCurve, ParticleCurveMode, ParticleGenerator, ParticleGradient, ParticleGradientMode, ParticleMaterial, ParticleRenderMode, ParticleRenderer, ParticleScaleMode, ParticleShapeArcMode, ParticleShapeType, ParticleSimulationSpace, ParticleStopMode, PhysicsMaterial, PhysicsMaterialCombineMode, PhysicsScene, PipelineStage, PlaneColliderShape, Platform, PointLight, Pointer, PointerButton, PointerPhase, Primitive, PrimitiveMesh, Probe, RasterState, ReferResource, RenderBufferDepthFormat, RenderFace, RenderPass, RenderQueue, RenderQueueType, RenderState, RenderStateElementKey as RenderStateDataKey, RenderTarget, RenderTargetBlendState, Renderer, ResourceManager, RotationOverLifetimeModule, Scene, SceneManager, Script, SetDataOptions, Shader, ShaderData, ShaderFactory, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, SizeOverLifetimeModule, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SphereColliderShape, SphereShape, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, StencilState, SubMesh, SubShader, SunMode, SystemInfo, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureSheetAnimationModule, TextureUsage, TextureWrapMode, Time, TrailMaterial, TrailRenderer, Transform, UnlitMaterial, Utils, VelocityOverLifetimeModule, VertexAttribute, VertexBufferBinding, VertexElement, VertexElementFormat, WrapMode, XRManager, assignmentClone, deepClone, dependentComponents, ignoreClone, request, resourceLoader, shallowClone };
31277
+ export { AmbientLight, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationRectCurve, AnimationRefCurve, AnimationStringCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorLayerMask, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AssetPromise, AssetType, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, Basic2DBatcher, BasicRenderPipeline, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlendState, BlinnPhongMaterial, BoolUpdateFlag, BoxColliderShape, BoxShape, Buffer, BufferBindFlag, BufferMesh, BufferUsage, BufferUtil, Burst, Camera, CameraClearFlags, CameraType, Canvas, CapsuleColliderShape, CharacterController, CircleShape, CloneManager, Collider, ColliderShape, ColliderShapeUpAxis, CollisionDetectionMode, ColorOverLifetimeModule, ColorSpace, ColorWriteMask, CompareFunction, Component, ConeEmitType, ConeShape, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, CurveKey, DataType, DependentMode, DepthState, DepthTextureMode, DiffuseMode, DirectLight, DynamicCollider, DynamicColliderConstraints, EmissionModule, Engine, EngineObject, Entity, EventDispatcher, FixedJoint, FogMode, Font, FontStyle, GLCapabilityType, GradientAlphaKey, GradientColorKey, HemisphereShape, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolationType, Joint, JointLimits, JointMotor, Keyframe, Keys, Layer, Light, Loader, Logger, MainModule, Material, Mesh, MeshRenderer, MeshTopology, ModelMesh, OverflowMode, PBRBaseMaterial, PBRMaterial, PBRSpecularMaterial, ParticleCompositeCurve, ParticleCompositeGradient, ParticleCurve, ParticleCurveMode, ParticleGenerator, ParticleGradient, ParticleGradientMode, ParticleMaterial, ParticleRenderMode, ParticleRenderer, ParticleScaleMode, ParticleShapeArcMode, ParticleShapeType, ParticleSimulationSpace, ParticleStopMode, PhysicsMaterial, PhysicsMaterialCombineMode, PhysicsScene, PipelineStage, PlaneColliderShape, Platform, PointLight, Pointer, PointerButton, PointerPhase, Primitive, PrimitiveMesh, Probe, RasterState, ReferResource, RenderBufferDepthFormat, RenderFace, RenderPass, RenderQueue, RenderQueueType, RenderState, RenderStateElementKey as RenderStateDataKey, RenderTarget, RenderTargetBlendState, Renderer, ResourceManager, RotationOverLifetimeModule, Scene, SceneManager, Script, SetDataOptions, Shader, ShaderData, ShaderFactory, ShaderLib, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, SizeOverLifetimeModule, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SphereColliderShape, SphereShape, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, StencilState, SubMesh, SubShader, SunMode, SystemInfo, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureSheetAnimationModule, TextureUsage, TextureWrapMode, Time, TrailMaterial, TrailRenderer, Transform, UnlitMaterial, Utils, VelocityOverLifetimeModule, VertexAttribute, VertexBufferBinding, VertexElement, VertexElementFormat, WrapMode, XRManager, assignmentClone, deepClone, dependentComponents, ignoreClone, request, resourceLoader, shallowClone };
31225
31278
  //# sourceMappingURL=module.js.map