Skip to content

Conversation

@jjxtra
Copy link

@jjxtra jjxtra commented Jul 10, 2019

Render the depth buffer, useful when you post process only part of the geometry in your application, you can then draw that geometry over the depth buffer from the non-post processed geometry.

Render the depth buffer, useful when you post process only part of the geometry in your application, you can then draw that geometry over the depth buffer from the non-post processed geometry.
this.scene.overrideMaterial = null;
renderer.clearDepth();
renderer.setRenderTarget(this.renderToScreen ? null : readBuffer);
renderer.context.colorMask(false, false, false, false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally avoid making gl calls directly because it can mess up the renderer's internal state. You may have to do this:

renderer.state.buffers.color.setMask( ... );

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is sort of an awkward API, but it works for you, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is working, I will think about a demo, for now it is a contract job that I cannot post anything but the depth pass, which I am using for another personal side project, so happy to share.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work to add it to one of the boxes in this example?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do, the main use case I have found is post processing transparent objects like lines and particles that wrap around, through and behind solid objects.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something cool like that would be ... cool. :-)

@WestLangley
Copy link
Collaborator

@mrdoob Why do we have renderer.context exposed, while also having renderer.getContext()?

@WestLangley
Copy link
Collaborator

useful when you post process only part of the geometry in your application

I expect there are a lot of users who would appreciate seeing an example of that.

@mrdoob
Copy link
Owner

mrdoob commented Jul 11, 2019

@mrdoob Why do we have renderer.context exposed, while also having renderer.getContext()?

I think context was first and then getContext() was added later but kept the first to avoid breaking backwards compatibility. I think it would be okay to remove the former.

@mrdoob
Copy link
Owner

mrdoob commented Jul 11, 2019

Agreed that a simple example of the usage would be great. Also to ensure we don't beak it.

@mrdoob mrdoob added this to the r107 milestone Jul 11, 2019
@mrdoob
Copy link
Owner

mrdoob commented Jul 26, 2019

Do we need an example for this?

@mrdoob mrdoob modified the milestones: r107, r108 Jul 31, 2019
@mrdoob mrdoob modified the milestones: r108, r109 Aug 28, 2019
@mrdoob mrdoob modified the milestones: r109, r110 Sep 25, 2019
@mrdoob mrdoob modified the milestones: r110, r111 Oct 30, 2019
@mrdoob mrdoob modified the milestones: r111, r112 Nov 27, 2019
@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 22, 2019

I don't think this PR is acceptable since a depth pass should not render the scene with the same potentially expensive PBR materials than the beauty pass. AFAIK, doing renderer.context.colorMask(false, false, false, false); does not prevent the fragment shader from being executed.

Besides, I've often encountered situations where I want to sample the depth of the scene in the fragment shader of different object. Check out how the water foam is rendered in this example:

https://codesandbox.io/s/black-mountain-gojcn

Currently, I use this pattern:

scene.overrideMaterial = depthMaterial;

renderer.setRenderTarget(renderTarget);
renderer.render(scene, camera);
renderer.setRenderTarget(null);

scene.overrideMaterial = null;

where renderTarget has a configured DepthTexture if the extension is available. It would be great if a depth pre-pass feature not only renders the depth to achieve the benefits mentioned here #8676 (comment) but also can provide the depth as a render target for further processing.

@mrdoob mrdoob modified the milestones: r112, r113 Dec 23, 2019
@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 24, 2019

Closing for now. This needs to be implemented differently. #8676 actually looks more promising.

@Mugen87 Mugen87 closed this Dec 24, 2019
@Mugen87 Mugen87 removed this from the r113 milestone Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants