-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
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
Nodes: Fix VideoTexture in WebGPUBackend & ColorSpaceNode revision #26261
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
import TempNode from '../core/TempNode.js'; | ||
import { mix } from '../math/MathNode.js'; | ||
import { addNodeClass } from '../core/Node.js'; | ||
import { addNodeElement, ShaderNode, nodeObject, vec4 } from '../shadernode/ShaderNode.js'; | ||
import { addNodeElement, ShaderNode, nodeObject, nodeProxy, vec4 } from '../shadernode/ShaderNode.js'; | ||
|
||
import { LinearEncoding, LinearSRGBColorSpace, sRGBEncoding, SRGBColorSpace } from 'three'; | ||
import { LinearSRGBColorSpace, SRGBColorSpace } from 'three'; | ||
|
||
export const LinearToLinear = new ShaderNode( ( inputs ) => { | ||
const sRGBToLinearShader = new ShaderNode( ( inputs ) => { | ||
|
||
return inputs.value; | ||
const { value } = inputs; | ||
const { rgb } = value; | ||
|
||
const a = rgb.mul( 0.9478672986 ).add( 0.0521327014 ).pow( 2.4 ); | ||
const b = rgb.mul( 0.0773993808 ); | ||
const factor = rgb.lessThanEqual( 0.04045 ); | ||
|
||
const rgbResult = mix( a, b, factor ); | ||
|
||
return vec4( rgbResult, value.a ); | ||
|
||
} ); | ||
|
||
export const LinearTosRGB = new ShaderNode( ( inputs ) => { | ||
const LinearTosRGBShader = new ShaderNode( ( inputs ) => { | ||
|
||
const { value } = inputs; | ||
const { rgb } = value; | ||
|
@@ -26,82 +35,75 @@ export const LinearTosRGB = new ShaderNode( ( inputs ) => { | |
|
||
} ); | ||
|
||
const EncodingLib = { | ||
LinearToLinear, | ||
LinearTosRGB | ||
}; | ||
const getColorSpaceMethod = ( colorSpace ) => { | ||
|
||
class ColorSpaceNode extends TempNode { | ||
let method = null; | ||
|
||
constructor( method, node ) { | ||
if ( colorSpace === LinearSRGBColorSpace ) { | ||
|
||
super( 'vec4' ); | ||
method = 'Linear'; | ||
|
||
this.method = method; | ||
} else if ( colorSpace === SRGBColorSpace ) { | ||
|
||
this.node = node; | ||
method = 'sRGB'; | ||
|
||
} | ||
|
||
fromColorSpace( colorSpace ) { | ||
|
||
let method = null; | ||
|
||
if ( colorSpace === LinearSRGBColorSpace ) { | ||
|
||
method = 'Linear'; | ||
|
||
} else if ( colorSpace === SRGBColorSpace ) { | ||
|
||
method = 'sRGB'; | ||
return method; | ||
|
||
} | ||
|
||
this.method = 'LinearTo' + method; | ||
|
||
return this; | ||
|
||
} | ||
|
||
fromEncoding( encoding ) { // @deprecated, r152 | ||
|
||
console.warn( 'THREE.ColorSpaceNode: Method .fromEncoding renamed to .fromColorSpace.' ); | ||
}; | ||
|
||
let method = null; | ||
const getMethod = ( source, target ) => { | ||
|
||
if ( encoding === LinearEncoding ) { | ||
return getColorSpaceMethod( source ) + 'To' + getColorSpaceMethod( target ); | ||
|
||
method = 'Linear'; | ||
}; | ||
|
||
} else if ( encoding === sRGBEncoding ) { | ||
class ColorSpaceNode extends TempNode { | ||
|
||
method = 'sRGB'; | ||
constructor( method, node ) { | ||
|
||
} | ||
super( 'vec4' ); | ||
|
||
this.method = 'LinearTo' + method; | ||
this.method = method; | ||
|
||
return this; | ||
this.node = node; | ||
|
||
} | ||
|
||
construct() { | ||
|
||
const { method, node } = this; | ||
|
||
return EncodingLib[ method ].call( { value: node } ); | ||
if ( method === ColorSpaceNode.LINEAR_TO_LINEAR ) | ||
return node; | ||
|
||
return Methods[ method ].call( { value: node } ); | ||
|
||
} | ||
|
||
} | ||
|
||
ColorSpaceNode.LINEAR_TO_LINEAR = 'LinearToLinear'; | ||
ColorSpaceNode.LINEAR_TO_SRGB = 'LinearTosRGB'; | ||
ColorSpaceNode.LINEAR_TO_sRGB = 'LinearTosRGB'; | ||
ColorSpaceNode.sRGB_TO_LINEAR = 'sRGBToLinear'; | ||
|
||
const Methods = { | ||
[ ColorSpaceNode.LINEAR_TO_sRGB ]: LinearTosRGBShader, | ||
[ ColorSpaceNode.sRGB_TO_LINEAR ]: sRGBToLinearShader | ||
}; | ||
|
||
export default ColorSpaceNode; | ||
|
||
export const colorSpace = ( node, colorSpace ) => nodeObject( new ColorSpaceNode( null, nodeObject( node ) ).fromColorSpace( colorSpace ) ); | ||
export const linearToColorSpace = ( node, colorSpace ) => nodeObject( new ColorSpaceNode( getMethod( LinearSRGBColorSpace, colorSpace ), nodeObject( node ) ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's is not possible currently. We need to know what the source is to made the conversion properly. |
||
export const colorSpaceToLinear = ( node, colorSpace ) => nodeObject( new ColorSpaceNode( getMethod( colorSpace, LinearSRGBColorSpace ), nodeObject( node ) ) ); | ||
|
||
export const linearTosRGB = nodeProxy( ColorSpaceNode, ColorSpaceNode.LINEAR_TO_sRGB ); | ||
export const sRGBToLinear = nodeProxy( ColorSpaceNode, ColorSpaceNode.sRGB_TO_LINEAR ); | ||
|
||
addNodeElement( 'colorSpace', colorSpace ); | ||
addNodeElement( 'linearTosRGB', linearTosRGB ); | ||
addNodeElement( 'sRGBToLinear', sRGBToLinear ); | ||
addNodeElement( 'linearToColorSpace', linearToColorSpace ); | ||
addNodeElement( 'colorSpaceToLinear', colorSpaceToLinear ); | ||
|
||
addNodeClass( ColorSpaceNode ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should name this method something like
needsForceLinear
orneedsConversionToLinear
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.. Maybe needsColorConversionToLinear