Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node: Add SobelOperatorNode. #28733

Merged
merged 3 commits into from
Jun 24, 2024
Merged

Node: Add SobelOperatorNode. #28733

merged 3 commits into from
Jun 24, 2024

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Jun 24, 2024

Related issue: -

Description

This PR adds Sobel edge detection for WebGPURenderer.

@Mugen87 Mugen87 added this to the r166 milestone Jun 24, 2024
@RenaudRohlinger
Copy link
Collaborator

Splendid. 👏

@Mugen87 Mugen87 merged commit 43d276e into mrdoob:dev Jun 24, 2024
11 checks passed
@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jun 24, 2024

@RenaudRohlinger @sunag I want to make a DepthOfFieldNode via porting a bokeh shader. For that I need to sample the scene's depth (viewZ) in the pass which will also be required for a series of other effects like AO.

I've tried doing this:

const scenePass = pass( scene, camera );

const scenePassColor = scenePass.getTextureNode();
const scenePassViewZ = scenePass.getViewZNode();

postProcessing.outputNode = scenePassColor.dof( scenePassViewZ, focus, aperture, maxBlur );

In the DOF node, I access the viewZ in the TSL code but unfortunately get a Maximum call stack size exceeded error.

Uncaught RangeError: Maximum call stack size exceeded
at Proxy.build (Node.js:295:7)
at Proxy.generate (OperatorNode.js:156:19)
at Proxy.build (Node.js:375:19)
at Proxy.build (TempNode.js:50:16)
at Proxy.generate (OperatorNode.js:156:19)
at Proxy.build (Node.js:375:19)
at Proxy.build (TempNode.js:50:16)
at Proxy.generate (OperatorNode.js:156:19)
at Proxy.build (Node.js:375:19)
at Proxy.build (TempNode.js:50:16)

Do I perform the setup incorrectly?

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jun 24, 2024

For reference here is the full code: Mugen87@f117497

If I replace const factor = this.focus.add( this.viewZNode ); with const factor = this.focus.add( 1.0 ); in DepthOfFieldNode, the runtime error disappears.

@RenaudRohlinger
Copy link
Collaborator

RenaudRohlinger commented Jun 24, 2024

For this you should use getTextureDepthNode() I think. I made an AO Node a while ago using it.

And then if necessary:

perspectiveDepthToViewZ(
    yourTextureDepth,
    cameraNear,
    cameraFar
 )

Also I'm not sure anymore, with #28720 this logic might have changed.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jun 24, 2024

It seems getViewZNode() from PassNode should do the exact same thing. What's great about this method is that I would not need a reference to the camera in the DOF node.

Also I'm not sure anymore, with #28720 this logic might have changed.

Right, let's see what @sunag says about this issue.

Here is a live example demonstrating the error: https://rawcdn.githack.com/mrdoob/three.js/f117497aa28a1326d8fb7fe306a04936718f94c0/examples/webgpu_postprocessing_dof.html

@sunag
Copy link
Collaborator

sunag commented Jun 24, 2024

@Mugen87 Maybe it's something else, the use of getViewZNode() seems right. I will clone you code here for check.

@sunag
Copy link
Collaborator

sunag commented Jun 24, 2024

Mugen87@f117497#r143473219 This fix the error but even so don't show the dof effect...

@sunag
Copy link
Collaborator

sunag commented Jun 24, 2024

@Mugen87 It's cache related try replace sampleTexture to:

const sampleTexture = ( uv ) => this.textureNode.uv( uv );

image

I think that toVar() will no more be necessary.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jun 24, 2024

Now it works! Thanks for the support^^.

Latest commit: Mugen87@0669cf4

Live example: https://rawcdn.githack.com/Mugen87/three.js/0669cf47e3487ee492830f2d85919541c388e773/examples/webgpu_postprocessing_dof.html

I'll file a PR tomorrow!

@Methuselah96 Methuselah96 mentioned this pull request Jun 25, 2024
36 tasks
@Mugen87 Mugen87 changed the title Addons: Add SobelOperatorNode. Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants