Skip to content

ViewportDepthNode: Fix material.depthNode=depth assign #29116

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

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions src/nodes/display/RenderOutputNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import TempNode from '../core/TempNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeObject } from '../shadernode/ShaderNode.js';

import { SRGBColorSpace, NoToneMapping } from '../../constants.js';
import { LinearSRGBColorSpace, SRGBColorSpace, NoToneMapping } from '../../constants.js';

class RenderOutputNode extends TempNode {

Expand All @@ -24,8 +24,8 @@ class RenderOutputNode extends TempNode {

// tone mapping

const toneMapping = this.toneMapping !== null ? this.toneMapping : context.toneMapping;
const outputColorSpace = this.outputColorSpace !== null ? this.outputColorSpace : context.outputColorSpace;
const toneMapping = ( this.toneMapping !== null ? this.toneMapping : context.toneMapping ) || NoToneMapping;
const outputColorSpace = ( this.outputColorSpace !== null ? this.outputColorSpace : context.outputColorSpace ) || LinearSRGBColorSpace;

if ( toneMapping !== NoToneMapping ) {

Expand Down
31 changes: 16 additions & 15 deletions src/nodes/display/ViewportDepthNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ViewportDepthNode extends Node {

const { scope } = this;

if ( scope === ViewportDepthNode.DEPTH ) {
if ( scope === ViewportDepthNode.DEPTH_BASE ) {

return builder.getFragDepth();

Expand All @@ -34,43 +34,43 @@ class ViewportDepthNode extends Node {
setup( { camera } ) {

const { scope } = this;
const texture = this.valueNode;
const value = this.valueNode;

let node = null;

if ( scope === ViewportDepthNode.DEPTH ) {
if ( scope === ViewportDepthNode.DEPTH_BASE ) {

if ( texture !== null ) {
if ( value !== null ) {

node = depthBase().assign( texture );
node = depthBase().assign( value );

} else {
}

if ( camera.isPerspectiveCamera ) {
} else if ( scope === ViewportDepthNode.DEPTH ) {

node = viewZToPerspectiveDepth( positionView.z, cameraNear, cameraFar );
if ( camera.isPerspectiveCamera ) {

} else {
node = viewZToPerspectiveDepth( positionView.z, cameraNear, cameraFar );

node = viewZToOrthographicDepth( positionView.z, cameraNear, cameraFar );
} else {

}
node = viewZToOrthographicDepth( positionView.z, cameraNear, cameraFar );

}

} else if ( scope === ViewportDepthNode.LINEAR_DEPTH ) {

if ( texture !== null ) {
if ( value !== null ) {

if ( camera.isPerspectiveCamera ) {

const viewZ = perspectiveDepthToViewZ( texture, cameraNear, cameraFar );
const viewZ = perspectiveDepthToViewZ( value, cameraNear, cameraFar );

node = viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );

} else {

node = texture;
node = value;

}

Expand Down Expand Up @@ -104,12 +104,13 @@ export const viewZToPerspectiveDepth = ( viewZ, near, far ) => near.add( viewZ )
// maps perspective depth in [ 0, 1 ] to viewZ
export const perspectiveDepthToViewZ = ( depth, near, far ) => near.mul( far ).div( far.sub( near ).mul( depth ).sub( far ) );

ViewportDepthNode.DEPTH_BASE = 'depthBase';
ViewportDepthNode.DEPTH = 'depth';
ViewportDepthNode.LINEAR_DEPTH = 'linearDepth';

export default ViewportDepthNode;

const depthBase = nodeProxy( ViewportDepthNode, ViewportDepthNode.DEPTH );
const depthBase = nodeProxy( ViewportDepthNode, ViewportDepthNode.DEPTH_BASE );

export const depth = nodeImmutable( ViewportDepthNode, ViewportDepthNode.DEPTH );
export const linearDepth = nodeProxy( ViewportDepthNode, ViewportDepthNode.LINEAR_DEPTH );
Expand Down