Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
f8ca9f2
wip nme prepass
CraigFeldspar Jun 22, 2023
bdf6eea
compilation & update works for prepass + nme
CraigFeldspar Jun 23, 2023
ff38831
successful write in prepass
CraigFeldspar Jun 24, 2023
94b41f1
adding prepassTextureBlock
CraigFeldspar Jun 26, 2023
6f6494a
.
CraigFeldspar Jun 27, 2023
25a30dd
added readFrameBuffer - to remove. Instead going for noPrePassDefaultRT
CraigFeldspar Jun 27, 2023
c0786f2
prepass texture read OK
CraigFeldspar Jun 29, 2023
de60d75
share depth bug
CraigFeldspar Jun 29, 2023
2b76a9d
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
CraigFeldspar Jun 29, 2023
62790fb
Merge remote-tracking branch 'origin/master'
CraigFeldspar Jun 29, 2023
ea4eed9
resize ok
CraigFeldspar Jun 29, 2023
9ac6875
msaa works
CraigFeldspar Jun 29, 2023
dcca59f
lint
CraigFeldspar Jun 30, 2023
04fff43
Merge remote-tracking branch 'upstream/master'
CraigFeldspar Jun 30, 2023
5ca262b
cleanup + color => position in prepass block
CraigFeldspar Jun 30, 2023
09cc6f3
lint
CraigFeldspar Jun 30, 2023
a085c78
port name for multi input nodes
CraigFeldspar Jun 30, 2023
52b53d2
format
CraigFeldspar Jun 30, 2023
4d7346b
fixing imports
CraigFeldspar Jun 30, 2023
01bf745
fix import #2
CraigFeldspar Jun 30, 2023
2bafc05
fixing imports #3
CraigFeldspar Jun 30, 2023
e542019
format
CraigFeldspar Jun 30, 2023
c6fb8ed
Merge remote-tracking branch 'upstream/master'
CraigFeldspar Jul 1, 2023
4065f57
bugfix when non prepass material is rendered last
CraigFeldspar Jul 2, 2023
1a7dd85
fixing code so tests pass
CraigFeldspar Jul 4, 2023
0fa4778
fixing bad test using wrong API for prepass
CraigFeldspar Jul 4, 2023
cd1f973
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
CraigFeldspar Jul 4, 2023
15b1214
Merge remote-tracking branch 'origin/master'
CraigFeldspar Jul 4, 2023
831e11b
Update packages/dev/core/src/Engines/WebGL/webGLHardwareTexture.ts
CraigFeldspar Jul 7, 2023
0432d57
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
CraigFeldspar Jul 18, 2023
34b7bcc
Merge remote-tracking branch 'upstream/master'
CraigFeldspar Jul 20, 2023
ee54bae
removing read/write prepass texture from the same pass
CraigFeldspar Jul 20, 2023
8d7f8c8
revert msaa webglrtwrapper code
CraigFeldspar Jul 20, 2023
8e428f2
remove ref increment in setTexture
CraigFeldspar Jul 20, 2023
62c30e3
cleaning ppr
CraigFeldspar Jul 20, 2023
2399651
remove prepass capable from fragment block
CraigFeldspar Jul 20, 2023
a8f851f
clean PR code
CraigFeldspar Jul 20, 2023
205e5a6
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
CraigFeldspar Jul 21, 2023
914b8de
Merge remote-tracking branch 'origin/master'
CraigFeldspar Jul 21, 2023
c408c72
removing size forced hack
CraigFeldspar Jul 21, 2023
77129f5
add PrePassOutputBlock
CraigFeldspar Jul 21, 2023
7fe2747
separate prepass output to its own block
CraigFeldspar Jul 21, 2023
e3a8de7
fixing exports
CraigFeldspar Jul 21, 2023
d7ba8d0
fixing nits
CraigFeldspar Jul 21, 2023
9038a5a
fix prepass required textures
CraigFeldspar Jul 21, 2023
a509fd7
removing old code
CraigFeldspar Jul 22, 2023
e746a0e
adding clarification comment
CraigFeldspar Jul 22, 2023
71af8e6
fixing postprocess prepass textures
CraigFeldspar Aug 1, 2023
1c4357a
merge with master
CraigFeldspar Aug 24, 2023
0ccf2e2
PR feedback
CraigFeldspar Aug 24, 2023
05848e8
format
CraigFeldspar Aug 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/dev/core/src/Engines/WebGL/webGLHardwareTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export class WebGLHardwareTexture implements HardwareTextureWrapper {
}
}

public getMSAARenderBuffer(index = 0) {
return this._MSAARenderBuffers?.[index] ?? null;
}

public release() {
this.releaseMSAARenderBuffers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ export class WebGLRenderTargetWrapper extends RenderTargetWrapper {
const depthbuffer = this._depthStencilBuffer;
const framebuffer = renderTarget._MSAAFramebuffer || renderTarget._framebuffer;

if (renderTarget._depthStencilBuffer) {
if (renderTarget._depthStencilBuffer && renderTarget._depthStencilBuffer !== depthbuffer) {
gl.deleteRenderbuffer(renderTarget._depthStencilBuffer);
}
renderTarget._depthStencilBuffer = this._depthStencilBuffer;

renderTarget._depthStencilBuffer = depthbuffer;
const attachment = renderTarget._generateStencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
this._engine._bindUnboundFramebuffer(framebuffer);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthbuffer);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, depthbuffer);
this._engine._bindUnboundFramebuffer(null);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/dev/core/src/Engines/renderTargetWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export class RenderTargetWrapper {
if (!this._textures) {
this._textures = [];
}
if (this._textures[index] === texture) {
return;
}

if (this._textures[index] && disposePrevious) {
this._textures[index].dispose();
}
Expand Down
26 changes: 24 additions & 2 deletions packages/dev/core/src/Materials/Node/Blocks/Dual/textureBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import "../../../../Shaders/ShadersInclude/helperFunctions";
import { ImageSourceBlock } from "./imageSourceBlock";
import { NodeMaterialConnectionPointCustomObject } from "../../nodeMaterialConnectionPointCustomObject";
import { EngineStore } from "../../../../Engines/engineStore";
import type { PrePassTextureBlock } from "../Input/prePassTextureBlock";

/**
* Block used to read a texture from a sampler
Expand All @@ -35,7 +36,7 @@ export class TextureBlock extends NodeMaterialBlock {
private _mainUVName: string;
private _mainUVDefineName: string;
private _fragmentOnly: boolean;
private _imageSource: Nullable<ImageSourceBlock>;
private _imageSource: Nullable<ImageSourceBlock | PrePassTextureBlock>;

protected _texture: Nullable<Texture>;
/**
Expand Down Expand Up @@ -70,12 +71,25 @@ export class TextureBlock extends NodeMaterialBlock {
}
}

private static _IsPrePassTextureBlock(block: Nullable<ImageSourceBlock | PrePassTextureBlock>): block is PrePassTextureBlock {
return block?.getClassName() === "PrePassTextureBlock";
}

private get _isSourcePrePass() {
return TextureBlock._IsPrePassTextureBlock(this._imageSource);
}

/**
* Gets the sampler name associated with this texture
*/
public get samplerName(): string {
if (this._imageSource) {
return this._imageSource.samplerName;
if (!TextureBlock._IsPrePassTextureBlock(this._imageSource)) {
return this._imageSource.samplerName;
}
if (this.source.connectedPoint) {
return this._imageSource.getSamplerName(this.source.connectedPoint);
}
}
return this._samplerName;
}
Expand Down Expand Up @@ -370,6 +384,10 @@ export class TextureBlock extends NodeMaterialBlock {
}

public isReady() {
if (this._isSourcePrePass) {
return true;
}

if (this.texture && !this.texture.isReadyOrNotBlocking()) {
return false;
}
Expand All @@ -378,6 +396,10 @@ export class TextureBlock extends NodeMaterialBlock {
}

public bind(effect: Effect) {
if (this._isSourcePrePass) {
effect.setFloat(this._textureInfoName, 1);
}

if (!this.texture) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import type { NodeMaterialConnectionPoint } from "../../nodeMaterialBlockConnect
import { RegisterClass } from "../../../../Misc/typeStore";
import type { Scene } from "../../../../scene";
import type { AbstractMesh } from "../../../../Meshes/abstractMesh";
import type { NodeMaterialDefines } from "../../nodeMaterial";
import type { NodeMaterialDefines, NodeMaterial } from "../../nodeMaterial";
import { editableInPropertyPage, PropertyTypeForEdition } from "../../../../Decorators/nodeDecorator";
import { MaterialHelper } from "../../../materialHelper";

import type { NodeMaterial } from "../../nodeMaterial";
import type { Effect } from "../../../effect";
import type { Mesh } from "../../../../Meshes/mesh";

Expand All @@ -31,7 +29,6 @@ export class FragmentOutputBlock extends NodeMaterialBlock {
this.registerInput("rgba", NodeMaterialBlockConnectionPointTypes.Color4, true);
this.registerInput("rgb", NodeMaterialBlockConnectionPointTypes.AutoDetect, true);
this.registerInput("a", NodeMaterialBlockConnectionPointTypes.Float, true);

this.rgb.addExcludedConnectionPointFromAllowedTypes(
NodeMaterialBlockConnectionPointTypes.Color3 | NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Float
);
Expand Down Expand Up @@ -152,6 +149,10 @@ export class FragmentOutputBlock extends NodeMaterialBlock {
state.compilationString += `gl_FragDepthEXT = log2(vFragmentDepth) * logarithmicDepthConstant * 0.5;\n`;
}

state.compilationString += `#if defined(PREPASS)\r\n`;
state.compilationString += `gl_FragData[0] = gl_FragColor;\r\n`;
state.compilationString += `#endif\r\n`;

return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from "./TBNBlock";
export * from "./heightToNormalBlock";
export * from "./fragDepthBlock";
export * from "./shadowMapBlock";
export * from "./prePassOutputBlock";
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { NodeMaterialBlock } from "../../nodeMaterialBlock";
import { NodeMaterialBlockConnectionPointTypes } from "../../Enums/nodeMaterialBlockConnectionPointTypes";
import type { NodeMaterialBuildState } from "../../nodeMaterialBuildState";
import { NodeMaterialBlockTargets } from "../../Enums/nodeMaterialBlockTargets";
import type { NodeMaterialConnectionPoint } from "../../nodeMaterialBlockConnectionPoint";
import { RegisterClass } from "../../../../Misc/typeStore";

/**
* Block used to output values on the prepass textures
*/
export class PrePassOutputBlock extends NodeMaterialBlock {
/**
* Create a new PrePassOutputBlock
* @param name defines the block name
*/
public constructor(name: string) {
super(name, NodeMaterialBlockTargets.Fragment, true);

this.registerInput("viewDepth", NodeMaterialBlockConnectionPointTypes.Float, true);
this.registerInput("worldPosition", NodeMaterialBlockConnectionPointTypes.AutoDetect, true);
this.registerInput("viewNormal", NodeMaterialBlockConnectionPointTypes.AutoDetect, true);

this.inputs[1].addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4);
this.inputs[2].addExcludedConnectionPointFromAllowedTypes(NodeMaterialBlockConnectionPointTypes.Vector3 | NodeMaterialBlockConnectionPointTypes.Vector4);
}

/**
* Gets the current class name
* @returns the class name
*/
public getClassName() {
return "PrePassOutputBlock";
}

/**
* Gets the view depth component
*/
public get viewDepth(): NodeMaterialConnectionPoint {
return this._inputs[0];
}

/**
* Gets the world position component
*/
public get worldPosition(): NodeMaterialConnectionPoint {
return this._inputs[1];
}

/**
* Gets the view normal component
*/
public get viewNormal(): NodeMaterialConnectionPoint {
return this._inputs[2];
}

protected _buildBlock(state: NodeMaterialBuildState) {
super._buildBlock(state);

const worldPosition = this.worldPosition;
const viewNormal = this.viewNormal;
const viewDepth = this.viewDepth;

state.sharedData.blocksWithDefines.push(this);

const comments = `//${this.name}`;
state._emitFunctionFromInclude("helperFunctions", comments);

state.compilationString += `#if defined(PREPASS)\r\n`;
state.compilationString += `#ifdef PREPASS_DEPTH\r\n`;
if (viewDepth.connectedPoint) {
state.compilationString += ` gl_FragData[PREPASS_DEPTH_INDEX] = vec4(${viewDepth.associatedVariableName}, 0.0, 0.0, 1.0);\r\n`;
} else {
// We have to write something on the viewDepth output or it will raise a gl error
state.compilationString += ` gl_FragData[PREPASS_DEPTH_INDEX] = vec4(0.0, 0.0, 0.0, 0.0);\r\n`;
}
state.compilationString += `#endif\r\n`;
state.compilationString += `#ifdef PREPASS_POSITION\r\n`;
if (worldPosition.connectedPoint) {
state.compilationString += ` gl_FragData[PREPASS_POSITION_INDEX] = vec4(${worldPosition.associatedVariableName}.rgb, ${
worldPosition.connectedPoint.type === NodeMaterialBlockConnectionPointTypes.Vector4 ? worldPosition.associatedVariableName + ".a" : "1.0"
});\r\n`;
} else {
// We have to write something on the position output or it will raise a gl error
state.compilationString += ` gl_FragData[PREPASS_POSITION_INDEX] = vec4(0.0, 0.0, 0.0, 0.0);\r\n`;
}
state.compilationString += `#endif\r\n`;
state.compilationString += `#ifdef PREPASS_NORMAL\r\n`;
if (viewNormal.connectedPoint) {
state.compilationString += ` gl_FragData[PREPASS_NORMAL_INDEX] = vec4(${viewNormal.associatedVariableName}.rgb, ${
viewNormal.connectedPoint.type === NodeMaterialBlockConnectionPointTypes.Vector4 ? viewNormal.associatedVariableName + ".a" : "1.0"
});\r\n`;
} else {
// We have to write something on the normal output or it will raise a gl error
state.compilationString += ` gl_FragData[PREPASS_NORMAL_INDEX] = vec4(0.0, 0.0, 0.0, 0.0);\r\n`;
}
state.compilationString += `#endif\r\n`;
state.compilationString += `#endif\r\n`;

return this;
}
}

RegisterClass("BABYLON.PrePassOutputBlock", PrePassOutputBlock);
1 change: 1 addition & 0 deletions packages/dev/core/src/Materials/Node/Blocks/Input/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./inputBlock";
export * from "./animatedInputBlockTypes";
export * from "./prePassTextureBlock";
Loading