|
@@ -25,6 +25,8 @@ export class DepthRenderer {
|
|
|
private _scene: Scene;
|
|
|
private _depthMap: RenderTargetTexture;
|
|
|
private _effect: Effect;
|
|
|
+ private readonly _storeNoneLinearDepth: boolean;
|
|
|
+ private readonly _supportsFloat: boolean;
|
|
|
|
|
|
private _cachedDefines: string;
|
|
|
private _camera: Nullable<Camera>;
|
|
@@ -46,16 +48,23 @@ export class DepthRenderer {
|
|
|
* @param scene The scene the renderer belongs to
|
|
|
* @param type The texture type of the depth map (default: Engine.TEXTURETYPE_FLOAT)
|
|
|
* @param camera The camera to be used to render the depth map (default: scene's active camera)
|
|
|
+ * @param storeNoneLinearDepth Defines whether the depth is stored linearly like in Babylon Shadows or directly like glFragCoord.z
|
|
|
*/
|
|
|
- constructor(scene: Scene, type: number = Constants.TEXTURETYPE_FLOAT, camera: Nullable<Camera> = null) {
|
|
|
+ constructor(scene: Scene, type: number = Constants.TEXTURETYPE_FLOAT, camera: Nullable<Camera> = null, storeNoneLinearDepth = false) {
|
|
|
this._scene = scene;
|
|
|
+ this._storeNoneLinearDepth = storeNoneLinearDepth;
|
|
|
+ this._supportsFloat = type !== Constants.TEXTURETYPE_UNSIGNED_BYTE;
|
|
|
+
|
|
|
DepthRenderer._SceneComponentInitialization(this._scene);
|
|
|
|
|
|
this._camera = camera;
|
|
|
var engine = scene.getEngine();
|
|
|
|
|
|
// Render target
|
|
|
- this._depthMap = new RenderTargetTexture("depthMap", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, this._scene, false, true, type);
|
|
|
+ var format = this._supportsFloat ? Constants.TEXTUREFORMAT_R : Constants.TEXTUREFORMAT_RGBA;
|
|
|
+ this._depthMap = new RenderTargetTexture("depthMap", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, this._scene, false, true, type,
|
|
|
+ false, undefined, undefined, undefined, undefined,
|
|
|
+ format);
|
|
|
this._depthMap.wrapU = Texture.CLAMP_ADDRESSMODE;
|
|
|
this._depthMap.wrapV = Texture.CLAMP_ADDRESSMODE;
|
|
|
this._depthMap.refreshRate = 1;
|
|
@@ -214,6 +223,16 @@ export class DepthRenderer {
|
|
|
MaterialHelper.PushAttributesForInstances(attribs);
|
|
|
}
|
|
|
|
|
|
+ // None linear depth
|
|
|
+ if (this._storeNoneLinearDepth) {
|
|
|
+ defines.push("#define NONELINEARDEPTH");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Float Mode
|
|
|
+ if (this._supportsFloat) {
|
|
|
+ defines.push("#define FLOAT");
|
|
|
+ }
|
|
|
+
|
|
|
// Get correct effect
|
|
|
var join = defines.join("\n");
|
|
|
if (this._cachedDefines !== join) {
|