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

NodeMaterial: Add .fog and .colorSpace properties #26440

Merged
merged 1 commit into from
Jul 16, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/jsm/nodes/materials/MeshNormalNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class MeshNormalNodeMaterial extends NodeMaterial {

this.isMeshNormalNodeMaterial = true;

this.colorSpace = false;

this.setDefaultValues( defaultValues );

this.setValues( parameters );
Expand Down
35 changes: 23 additions & 12 deletions examples/jsm/nodes/materials/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ class NodeMaterial extends ShaderMaterial {

this.forceSinglePass = false;

this.unlit = this.constructor === NodeMaterial.prototype.constructor; // Extended materials are not unlit by default

this.fog = true;
this.lights = true;
this.normals = true;
this.unlit = this.constructor === NodeMaterial.prototype.constructor; // Extended materials are not unlit by default
this.colorSpace = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe applyColorSpace?

Copy link
Collaborator Author

@sunag sunag Sep 17, 2023

Choose a reason for hiding this comment

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

Maybe we can make it more like material.toneMapped?

this.toneMapped = true;

Copy link
Contributor

Choose a reason for hiding this comment

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

So... colorSpaced?


this.lightsNode = null;
this.envNode = null;
Expand Down Expand Up @@ -321,29 +324,37 @@ class NodeMaterial extends ShaderMaterial {

// FOG

const fogNode = builder.fogNode;
if ( this.fog === true ) {

if ( fogNode ) outputNode = vec4( fogNode.mixAssign( outputNode.rgb ), outputNode.a );
const fogNode = builder.fogNode;

if ( fogNode ) outputNode = vec4( fogNode.mixAssign( outputNode.rgb ), outputNode.a );

}

// ENCODING

const renderTarget = renderer.getRenderTarget();
if ( this.colorSpace === true ) {

let outputColorSpace;
const renderTarget = renderer.getRenderTarget();

if ( renderTarget !== null ) {
let outputColorSpace;

outputColorSpace = renderTarget.texture.colorSpace;
if ( renderTarget !== null ) {

} else {
outputColorSpace = renderTarget.texture.colorSpace;

outputColorSpace = renderer.outputColorSpace;
} else {

}
outputColorSpace = renderer.outputColorSpace;

}

if ( outputColorSpace !== LinearSRGBColorSpace && outputColorSpace !== NoColorSpace ) {

if ( outputColorSpace !== LinearSRGBColorSpace && outputColorSpace !== NoColorSpace ) {
outputNode = outputNode.linearToColorSpace( outputColorSpace );

outputNode = outputNode.linearToColorSpace( outputColorSpace );
}

}

Expand Down