-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
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: Add TransitionNode
.
#28847
Merged
Merged
Nodes: Add TransitionNode
.
#28847
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
afeb015
TransitionNode sketch
cmhhelgeson 841d0dd
cleanup
cmhhelgeson b291f0c
fix non-functional controller
cmhhelgeson 9bd2f99
texture loading fixed
cmhhelgeson ceb4b09
lint fix
cmhhelgeson f4f06f5
fix screenshot
cmhhelgeson cf7114f
remove texture import
cmhhelgeson 42b3583
Update TransitionNode.js
Mugen87 afe5421
Update webgpu_postprocessing_transition.html
Mugen87 ed6fa44
Merge branch 'dev' into webgpu_transition_pass
Mugen87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update TransitionNode.js
- Loading branch information
commit 42b358396d6bb693e6fae9c211c005ded666e123
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import TempNode from '../core/TempNode.js'; | ||
import { uv } from '../accessors/UVNode.js'; | ||
import { addNodeElement, tslFn, nodeObject, float } from '../shadernode/ShaderNode.js'; | ||
import { addNodeElement, tslFn, nodeObject, float, int, vec4, If } from '../shadernode/ShaderNode.js'; | ||
import { clamp, mix } from '../math/MathNode.js'; | ||
import { sub } from '../math/OperatorNode.js'; | ||
|
||
class TransitionNode extends TempNode { | ||
|
||
|
@@ -39,11 +40,23 @@ class TransitionNode extends TempNode { | |
const texelOne = sampleTexture( textureNodeA ); | ||
const texelTwo = sampleTexture( textureNodeB ); | ||
|
||
const transitionTexel = sampleTexture( mixTextureNode ); | ||
const r = mixRatioNode.mul( thresholdNode.mul( 2.0 ).add( 1.0 ) ).sub( thresholdNode ); | ||
const mixf = clamp( transitionTexel.r.sub( r ).mul( float( 1.0 ).div( thresholdNode ) ), 0.0, 1.0 ); | ||
const color = vec4().toVar(); | ||
|
||
return mix( texelOne, texelTwo, useTextureNode.equal( 1 ).cond( mixf, mixRatioNode ) ); | ||
If( useTextureNode.equal( int( 1 ) ), () => { | ||
|
||
const transitionTexel = sampleTexture( mixTextureNode ); | ||
const r = mixRatioNode.mul( thresholdNode.mul( 2.0 ).add( 1.0 ) ).sub( thresholdNode ); | ||
const mixf = clamp( sub( transitionTexel.r, r ).mul( float( 1.0 ).div( thresholdNode ) ), 0.0, 1.0 ); | ||
|
||
color.assign( mix( texelOne, texelTwo, mixf ) ); | ||
|
||
} ).else( () => { | ||
|
||
color.assign( mix( texelTwo, texelOne, mixRatioNode ) ); | ||
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. The transition was broken when |
||
|
||
} ); | ||
|
||
return color; | ||
|
||
} ); | ||
|
||
|
@@ -55,7 +68,7 @@ class TransitionNode extends TempNode { | |
|
||
} | ||
|
||
export const transition = ( nodeA, nodeB, mixTexture, mixRatio, threshold, useTexture ) => nodeObject( new TransitionNode( nodeObject( nodeA ).toTexture(), nodeObject( nodeB ).toTexture(), nodeObject( mixTexture ).toTexture(), nodeObject( mixRatio ), nodeObject( threshold ), nodeObject( useTexture ) ) ); | ||
export const transition = ( nodeA, nodeB, mixTexture, mixRatio = 0.0, threshold = 0.1, useTexture = 0 ) => nodeObject( new TransitionNode( nodeObject( nodeA ).toTexture(), nodeObject( nodeB ).toTexture(), nodeObject( mixTexture ).toTexture(), nodeObject( mixRatio ), nodeObject( threshold ), nodeObject( useTexture ) ) ); | ||
|
||
addNodeElement( 'transition', transition ); | ||
|
||
|
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 have refactored this bit since I think the
if
clause makes the code more readable.