Skip to content

Commit

Permalink
- fixed core targets/targetFormat refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlaxenaire committed Feb 28, 2024
1 parent 81a67ad commit 126220b
Show file tree
Hide file tree
Showing 336 changed files with 3,745 additions and 3,715 deletions.
4 changes: 3 additions & 1 deletion dist/esm/core/materials/RenderMaterial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class RenderMaterial extends Material {
if (shaders.fragment && !shaders.fragment.entryPoint) {
shaders.fragment.entryPoint = "main";
}
renderingOptions.targetFormat = renderingOptions.targetFormat ?? this.renderer.options.preferredFormat;
if (!renderingOptions.targets || !renderingOptions.targets.length || !renderingOptions.targets[0].format) {
renderingOptions.targets[0].format = this.renderer.options.preferredFormat;
}
this.options = {
...this.options,
shaders,
Expand Down
1 change: 1 addition & 0 deletions dist/esm/core/meshes/FullscreenPlane.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FullscreenPlane extends MeshBaseMixin(class {
);
});
}
parameters.depthWriteEnabled = false;
super(renderer, null, { geometry, ...parameters });
this.size = {
document: {
Expand Down
20 changes: 11 additions & 9 deletions dist/esm/core/meshes/mixins/MeshBaseMixin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,20 @@ function MeshBaseMixin(Base) {
*/
setRenderingOptionsForRenderPass(renderPass) {
const renderingOptions = {
// sample count
sampleCount: renderPass.options.sampleCount,
// color attachments
...renderPass.options.colorAttachments.length && {
targetFormat: renderPass.options.colorAttachments[0].targetFormat,
// multiple render targets?
...renderPass.options.colorAttachments.length > 1 && {
additionalTargets: renderPass.options.colorAttachments.filter((c, i) => i > 0).map((colorAttachment) => {
return {
format: colorAttachment.targetFormat
};
})
}
targets: renderPass.options.colorAttachments.map((colorAttachment, index) => {
return {
// patch format...
format: colorAttachment.targetFormat,
// ...but keep original blend values if any
...this.options.targets?.length && this.options.targets[index] && this.options.targets[index].blend && {
blend: this.options.targets[index].blend
}
};
})
},
// depth
depth: renderPass.options.useDepth,
Expand Down
39 changes: 20 additions & 19 deletions dist/esm/core/pipelines/RenderPipelineEntry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,26 @@ ${this.shaders.full.head}`;
if (!this.shadersModulesReady)
return;
let vertexLocationIndex = -1;
const blend = this.options.rendering.blend ?? (this.options.rendering.transparent && {
color: {
srcFactor: "src-alpha",
dstFactor: "one-minus-src-alpha"
},
alpha: {
srcFactor: "one",
dstFactor: "one-minus-src-alpha"
if (this.options.rendering.targets.length) {
if (this.options.rendering.transparent) {
this.options.rendering.targets[0].blend = this.options.rendering.targets[0].blend ? this.options.rendering.targets[0].blend : {
color: {
srcFactor: "src-alpha",
dstFactor: "one-minus-src-alpha"
},
alpha: {
srcFactor: "one",
dstFactor: "one-minus-src-alpha"
}
};
}
});
} else {
this.options.rendering.targets = [
{
format: this.renderer.options.preferredFormat
}
];
}
this.descriptor = {
label: this.options.label,
layout: this.layout,
Expand Down Expand Up @@ -245,16 +255,7 @@ ${this.shaders.full.head}`;
fragment: {
module: this.shaders.fragment.module,
entryPoint: this.options.shaders.fragment.entryPoint,
targets: [
{
format: this.options.rendering.targetFormat ?? this.renderer.options.preferredFormat,
...blend && {
blend
}
},
...this.options.rendering.additionalTargets ?? []
// merge with additional targets if any
]
targets: this.options.rendering.targets
}
},
primitive: {
Expand Down
54 changes: 27 additions & 27 deletions dist/esm/core/renderPasses/RenderPass.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class RenderPass {
// color
useColorAttachments = true,
shouldUpdateView = true,
loadOp = "clear",
storeOp = "store",
clearValue = [0, 0, 0, 0],
targetFormat,
colorAttachments = [],
// depth
useDepth = true,
Expand All @@ -35,10 +31,10 @@ class RenderPass {
this.renderer = renderer;
if (useColorAttachments) {
const defaultColorAttachment = {
loadOp,
storeOp,
clearValue,
targetFormat: targetFormat ?? this.renderer.options.preferredFormat
loadOp: "clear",
storeOp: "store",
clearValue: [0, 0, 0, 0],
targetFormat: this.renderer.options.preferredFormat
};
if (!colorAttachments.length) {
colorAttachments = [defaultColorAttachment];
Expand All @@ -55,10 +51,6 @@ class RenderPass {
// color
useColorAttachments,
shouldUpdateView,
loadOp,
storeOp,
clearValue,
targetFormat: targetFormat ?? this.renderer.options.preferredFormat,
colorAttachments,
// depth
useDepth,
Expand All @@ -68,7 +60,6 @@ class RenderPass {
depthClearValue,
depthFormat
};
this.setClearValue(clearValue);
if (this.options.useDepth) {
this.createDepthTexture();
}
Expand Down Expand Up @@ -169,10 +160,14 @@ class RenderPass {
* @param colorAttachmentIndex - index of the color attachment for which to use this load operation
*/
setLoadOp(loadOp = "clear", colorAttachmentIndex = 0) {
this.options.loadOp = loadOp;
if (this.options.useColorAttachments && this.descriptor) {
if (this.descriptor.colorAttachments && this.descriptor.colorAttachments[colorAttachmentIndex]) {
this.descriptor.colorAttachments[colorAttachmentIndex].loadOp = loadOp;
if (this.options.useColorAttachments) {
if (this.options.colorAttachments[colorAttachmentIndex]) {
this.options.colorAttachments[colorAttachmentIndex].loadOp = loadOp;
}
if (this.descriptor) {
if (this.descriptor.colorAttachments && this.descriptor.colorAttachments[colorAttachmentIndex]) {
this.descriptor.colorAttachments[colorAttachmentIndex].loadOp = loadOp;
}
}
}
}
Expand All @@ -193,16 +188,21 @@ class RenderPass {
* @param colorAttachmentIndex - index of the color attachment for which to use this clear value
*/
setClearValue(clearValue = [0, 0, 0, 0], colorAttachmentIndex = 0) {
if (this.renderer.alphaMode === "premultiplied") {
const alpha = clearValue[3];
clearValue[0] = Math.min(clearValue[0], alpha);
clearValue[1] = Math.min(clearValue[1], alpha);
clearValue[2] = Math.min(clearValue[2], alpha);
} else {
this.options.clearValue = clearValue;
}
if (this.descriptor && this.descriptor.colorAttachments && this.descriptor.colorAttachments[colorAttachmentIndex]) {
this.descriptor.colorAttachments[colorAttachmentIndex].clearValue = clearValue;
if (this.options.useColorAttachments) {
if (this.renderer.alphaMode === "premultiplied") {
const alpha = clearValue[3];
clearValue[0] = Math.min(clearValue[0], alpha);
clearValue[1] = Math.min(clearValue[1], alpha);
clearValue[2] = Math.min(clearValue[2], alpha);
}
if (this.options.colorAttachments[colorAttachmentIndex]) {
this.options.colorAttachments[colorAttachmentIndex].clearValue = clearValue;
}
if (this.descriptor) {
if (this.descriptor.colorAttachments && this.descriptor.colorAttachments[colorAttachmentIndex]) {
this.descriptor.colorAttachments[colorAttachmentIndex].clearValue = clearValue;
}
}
}
}
/**
Expand Down
8 changes: 4 additions & 4 deletions dist/esm/core/renderPasses/RenderTarget.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ class RenderTarget {
this.type = "RenderTarget";
this.renderer = renderer;
this.uuid = generateUUID();
const { label, targetFormat, depthTexture, autoRender, ...renderPassParams } = parameters;
const { label, colorAttachments, depthTexture, autoRender, ...renderPassParams } = parameters;
this.options = {
label,
...renderPassParams,
...depthTexture && { depthTexture },
targetFormat: targetFormat ?? this.renderer.options.preferredFormat,
...colorAttachments && { colorAttachments },
autoRender: autoRender === void 0 ? true : autoRender
};
if (autoRender !== void 0) {
__privateSet(this, _autoRender, autoRender);
}
this.renderPass = new RenderPass(this.renderer, {
label: this.options.label ? `${this.options.label} Render Pass` : "Render Target Render Pass",
targetFormat: this.options.targetFormat,
...colorAttachments && { colorAttachments },
depthTexture: this.options.depthTexture ?? this.renderer.renderPass.depthTexture,
// reuse renderer depth texture for every pass
...renderPassParams
Expand All @@ -58,7 +58,7 @@ class RenderTarget {
this.renderTexture = new RenderTexture(this.renderer, {
label: this.options.label ? `${this.options.label} Render Texture` : "Render Target render texture",
name: "renderTexture",
format: this.options.targetFormat,
format: colorAttachments && colorAttachments.length && colorAttachments[0].targetFormat ? colorAttachments[0].targetFormat : this.renderer.options.preferredFormat,
...this.options.qualityRatio !== void 0 && { qualityRatio: this.options.qualityRatio }
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/esm/core/renderPasses/ShaderPass.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ShaderPass extends FullscreenPlane {
constructor(renderer, parameters = {}) {
renderer = renderer && renderer.renderer || renderer;
isRenderer(renderer, parameters.label ? parameters.label + " ShaderPass" : "ShaderPass");
parameters.transparent = true;
parameters.depth = false;
parameters.label = parameters.label ?? "ShaderPass " + renderer.shaderPasses?.length;
parameters.sampleCount = !!parameters.sampleCount ? parameters.sampleCount : renderer && renderer.postProcessingPass ? renderer && renderer.postProcessingPass.options.sampleCount : 1;
if (!parameters.shaders) {
Expand Down
4 changes: 2 additions & 2 deletions dist/esm/core/renderers/GPURenderer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ class GPURenderer {
setMainRenderPasses() {
this.renderPass = new RenderPass(this, {
label: "Main render pass",
targetFormat: this.options.preferredFormat,
//targetFormat: this.options.preferredFormat,
...this.options.renderPass
});
this.postProcessingPass = new RenderPass(this, {
label: "Post processing render pass",
targetFormat: this.options.preferredFormat,
//targetFormat: this.options.preferredFormat,
// no need to handle depth or perform MSAA on a fullscreen quad
useDepth: false,
sampleCount: 1
Expand Down
9 changes: 7 additions & 2 deletions dist/esm/curtains/meshes/PingPongPlane.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ class PingPongPlane extends FullscreenPlane {
constructor(renderer, parameters = {}) {
renderer = renderer && renderer.renderer || renderer;
isRenderer(renderer, parameters.label ? parameters.label + " PingPongPlane" : "PingPongPlane");
const colorAttachments = parameters.targets && parameters.targets.length && parameters.targets.map((target) => {
return {
targetFormat: target.format
};
});
parameters.outputTarget = new RenderTarget(renderer, {
label: parameters.label ? parameters.label + " render target" : "Ping Pong render target",
useDepth: false,
...parameters.targetFormat && { targetFormat: parameters.targetFormat }
...colorAttachments && { colorAttachments }
});
parameters.transparent = false;
parameters.depth = false;
Expand All @@ -24,7 +29,7 @@ class PingPongPlane extends FullscreenPlane {
this.createRenderTexture({
label: parameters.label ? `${parameters.label} render texture` : "PingPongPlane render texture",
name: "renderTexture",
...parameters.targetFormat && { format: parameters.targetFormat }
...parameters.targets && parameters.targets.length && { format: parameters.targets[0].format }
});
}
/**
Expand Down
Loading

0 comments on commit 126220b

Please sign in to comment.