Skip to content
Snippets Groups Projects
Commit 0a18412d authored by Alexander Rose's avatar Alexander Rose
Browse files

refactor draw/multiSample .render args

parent b67d16bd
No related branches found
No related tags found
No related merge requests found
......@@ -402,14 +402,15 @@ namespace Canvas3D {
cam = stereoCamera;
}
const ctx = { renderer, camera: cam, scene, helper };
if (MultiSamplePass.isEnabled(p.multiSample)) {
if (!cameraChanged && allowMulti && !controls.props.spin) {
while (!multiSampleHelper.render(renderer, cam, scene, helper, true, p.transparentBackground, p));
while (!multiSampleHelper.render(ctx, p, true));
} else {
multiSampleHelper.render(renderer, cam, scene, helper, true, p.transparentBackground, p);
multiSampleHelper.render(ctx, p, true);
}
} else {
passes.draw.render(renderer, cam, scene, helper, true, p.transparentBackground, p.postprocessing, p.marking);
passes.draw.render(ctx, p, true);
}
pickHelper.dirty = true;
didRender = true;
......
......@@ -53,6 +53,19 @@ function getDepthMergeRenderable(ctx: WebGLContext, depthTexturePrimitives: Text
return createComputeRenderable(renderItem, values);
}
type Props = {
postprocessing: PostprocessingProps
marking: MarkingProps
transparentBackground: boolean;
}
type RenderContext = {
renderer: Renderer;
camera: Camera | StereoCamera;
scene: Scene;
helper: Helper;
}
export class DrawPass {
private readonly drawTarget: RenderTarget;
......@@ -264,25 +277,25 @@ export class DrawPass {
renderer.renderBlendedTransparent(scene.primitives, camera, null);
}
private _render(renderer: Renderer, camera: ICamera, scene: Scene, helper: Helper, toDrawingBuffer: boolean, transparentBackground: boolean, postprocessingProps: PostprocessingProps, markingProps: MarkingProps) {
private _render(renderer: Renderer, camera: ICamera, scene: Scene, helper: Helper, toDrawingBuffer: boolean, props: Props) {
const volumeRendering = scene.volumes.renderables.length > 0;
const postprocessingEnabled = PostprocessingPass.isEnabled(postprocessingProps);
const antialiasingEnabled = AntialiasingPass.isEnabled(postprocessingProps);
const markingEnabled = MarkingPass.isEnabled(markingProps);
const postprocessingEnabled = PostprocessingPass.isEnabled(props.postprocessing);
const antialiasingEnabled = AntialiasingPass.isEnabled(props.postprocessing);
const markingEnabled = MarkingPass.isEnabled(props.marking);
const { x, y, width, height } = camera.viewport;
renderer.setViewport(x, y, width, height);
renderer.update(camera);
if (transparentBackground && !antialiasingEnabled && toDrawingBuffer) {
if (props.transparentBackground && !antialiasingEnabled && toDrawingBuffer) {
this.drawTarget.bind();
renderer.clear(false);
}
if (this.wboitEnabled) {
this._renderWboit(renderer, camera, scene, transparentBackground, postprocessingProps);
this._renderWboit(renderer, camera, scene, props.transparentBackground, props.postprocessing);
} else {
this._renderBlended(renderer, camera, scene, !volumeRendering && !postprocessingEnabled && !antialiasingEnabled && toDrawingBuffer, transparentBackground, postprocessingProps);
this._renderBlended(renderer, camera, scene, !volumeRendering && !postprocessingEnabled && !antialiasingEnabled && toDrawingBuffer, props.transparentBackground, props.postprocessing);
}
if (postprocessingEnabled) {
......@@ -294,7 +307,7 @@ export class DrawPass {
}
if (markingEnabled) {
const markingDepthTest = markingProps.ghostEdgeStrength < 1;
const markingDepthTest = props.marking.ghostEdgeStrength < 1;
if (markingDepthTest) {
this.marking.depthTarget.bind();
renderer.clear(false);
......@@ -305,7 +318,7 @@ export class DrawPass {
renderer.clear(false);
renderer.renderMarkingMask(scene.primitives, camera, markingDepthTest ? this.marking.depthTarget.texture : null);
this.marking.update(markingProps);
this.marking.update(props.marking);
this.marking.render(camera.viewport, postprocessingEnabled ? this.postprocessing.target : this.colorTarget);
}
......@@ -323,7 +336,7 @@ export class DrawPass {
}
if (antialiasingEnabled) {
this.antialiasing.render(camera, toDrawingBuffer, postprocessingProps);
this.antialiasing.render(camera, toDrawingBuffer, props.postprocessing);
} else if (toDrawingBuffer) {
this.drawTarget.bind();
......@@ -338,16 +351,17 @@ export class DrawPass {
this.webgl.gl.flush();
}
render(renderer: Renderer, camera: Camera | StereoCamera, scene: Scene, helper: Helper, toDrawingBuffer: boolean, transparentBackground: boolean, postprocessingProps: PostprocessingProps, markingProps: MarkingProps) {
renderer.setTransparentBackground(transparentBackground);
render(ctx: RenderContext, props: Props, toDrawingBuffer: boolean) {
const { renderer, camera, scene, helper } = ctx;
renderer.setTransparentBackground(props.transparentBackground);
renderer.setDrawingBufferSize(this.colorTarget.getWidth(), this.colorTarget.getHeight());
renderer.setPixelRatio(this.webgl.pixelRatio);
if (StereoCamera.is(camera)) {
this._render(renderer, camera.left, scene, helper, toDrawingBuffer, transparentBackground, postprocessingProps, markingProps);
this._render(renderer, camera.right, scene, helper, toDrawingBuffer, transparentBackground, postprocessingProps, markingProps);
this._render(renderer, camera.left, scene, helper, toDrawingBuffer, props);
this._render(renderer, camera.right, scene, helper, toDrawingBuffer, props);
} else {
this._render(renderer, camera, scene, helper, toDrawingBuffer, transparentBackground, postprocessingProps, markingProps);
this._render(renderer, camera, scene, helper, toDrawingBuffer, props);
}
}
......
......@@ -83,11 +83,12 @@ export class ImagePass {
Viewport.set(this._camera.viewport, 0, 0, this._width, this._height);
this._camera.update();
const ctx = { renderer: this.renderer, camera: this._camera, scene: this.scene, helper: this.helper };
if (MultiSamplePass.isEnabled(this.props.multiSample)) {
this.multiSampleHelper.render(this.renderer, this._camera, this.scene, this.helper, false, this.props.transparentBackground, this.props);
this.multiSampleHelper.render(ctx, this.props, false);
this._colorTarget = this.multiSamplePass.colorTarget;
} else {
this.drawPass.render(this.renderer, this._camera, this.scene, this.helper, false, this.props.transparentBackground, this.props.postprocessing, this.props.marking);
this.drawPass.render(ctx, this.props, false);
this._colorTarget = this.drawPass.getColorTarget(this.props.postprocessing);
}
}
......
......@@ -59,6 +59,14 @@ type Props = {
multiSample: MultiSampleProps
postprocessing: PostprocessingProps
marking: MarkingProps
transparentBackground: boolean;
}
type RenderContext = {
renderer: Renderer;
camera: Camera | StereoCamera;
scene: Scene;
helper: Helper;
}
export class MultiSamplePass {
......@@ -97,11 +105,11 @@ export class MultiSamplePass {
}
}
render(sampleIndex: number, renderer: Renderer, camera: Camera | StereoCamera, scene: Scene, helper: Helper, toDrawingBuffer: boolean, transparentBackground: boolean, props: Props) {
render(sampleIndex: number, ctx: RenderContext, props: Props, toDrawingBuffer: boolean) {
if (props.multiSample.mode === 'temporal') {
return this.renderTemporalMultiSample(sampleIndex, renderer, camera, scene, helper, toDrawingBuffer, transparentBackground, props);
return this.renderTemporalMultiSample(sampleIndex, ctx, props, toDrawingBuffer);
} else {
this.renderMultiSample(renderer, camera, scene, helper, toDrawingBuffer, transparentBackground, props);
this.renderMultiSample(ctx, toDrawingBuffer, props);
return sampleIndex;
}
}
......@@ -114,7 +122,8 @@ export class MultiSamplePass {
}
}
private renderMultiSample(renderer: Renderer, camera: Camera | StereoCamera, scene: Scene, helper: Helper, toDrawingBuffer: boolean, transparentBackground: boolean, props: Props) {
private renderMultiSample(ctx: RenderContext, toDrawingBuffer: boolean, props: Props) {
const { camera } = ctx;
const { compose, composeTarget, drawPass, webgl } = this;
const { gl, state } = webgl;
......@@ -148,7 +157,7 @@ export class MultiSamplePass {
ValueCell.update(compose.values.uWeight, sampleWeight);
// render scene
drawPass.render(renderer, camera, scene, helper, false, transparentBackground, props.postprocessing, props.marking);
drawPass.render(ctx, props, false);
// compose rendered scene with compose target
composeTarget.bind();
......@@ -181,7 +190,8 @@ export class MultiSamplePass {
camera.update();
}
private renderTemporalMultiSample(sampleIndex: number, renderer: Renderer, camera: Camera | StereoCamera, scene: Scene, helper: Helper, toDrawingBuffer: boolean, transparentBackground: boolean, props: Props) {
private renderTemporalMultiSample(sampleIndex: number, ctx: RenderContext, props: Props, toDrawingBuffer: boolean) {
const { camera } = ctx;
const { compose, composeTarget, holdTarget, drawPass, webgl } = this;
const { gl, state } = webgl;
......@@ -198,7 +208,7 @@ export class MultiSamplePass {
const sampleWeight = 1.0 / offsetList.length;
if (sampleIndex === -1) {
drawPass.render(renderer, camera, scene, helper, false, transparentBackground, props.postprocessing, props.marking);
drawPass.render(ctx, props, false);
ValueCell.update(compose.values.uWeight, 1.0);
ValueCell.update(compose.values.tColor, drawPass.getColorTarget(props.postprocessing).texture);
compose.update();
......@@ -226,7 +236,7 @@ export class MultiSamplePass {
camera.update();
// render scene
drawPass.render(renderer, camera, scene, helper, false, transparentBackground, props.postprocessing, props.marking);
drawPass.render(ctx, props, false);
// compose rendered scene with compose target
composeTarget.bind();
......@@ -325,8 +335,8 @@ export class MultiSampleHelper {
}
/** Return `true` while more samples are needed */
render(renderer: Renderer, camera: Camera | StereoCamera, scene: Scene, helper: Helper, toDrawingBuffer: boolean, transparentBackground: boolean, props: Props) {
this.sampleIndex = this.multiSamplePass.render(this.sampleIndex, renderer, camera, scene, helper, toDrawingBuffer, transparentBackground, props);
render(ctx: RenderContext, props: Props, toDrawingBuffer: boolean) {
this.sampleIndex = this.multiSamplePass.render(this.sampleIndex, ctx, props, toDrawingBuffer);
return this.sampleIndex < 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment