-
-
Notifications
You must be signed in to change notification settings - Fork 36k
Nodes: Add VelocityNode
and MotionBlurNode
.
#29058
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
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
caaa78c
Nodes: Add VelocityNode.
Mugen87 b09e6fe
E2E: Update screenshot.
Mugen87 2495754
apply immutable node
sunag 2f71511
updates
sunag 64e6eaa
update
sunag c738d23
Enable damping.
Mugen87 94bfc06
Updated MRT example.
Mugen87 46a45be
Nodes: Add `MotionBlur` node.
Mugen87 9a4b19a
Examples: Clean up
Mugen87 285ea20
E2E: Update screenshot.
Mugen87 c418832
Merge branch 'dev' into pr/29058
sunag 1390197
updates
sunag 0a3a34b
update
sunag f322de4
ReflectorNode: Add MRT support
sunag 33e60b1
cleanup
sunag 0e4cf3b
updates
sunag 24c8216
camera angle
sunag 213bf02
cleanup
sunag 5b39722
updates
sunag 9c0a201
update imports
sunag 291f251
Revert "updates"
sunag 5316919
Revert "cleanup"
sunag de2844c
updates
sunag 5c82b99
update limits
sunag 65c25ba
update
sunag 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
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { addNodeClass } from '../core/Node.js'; | ||
import TempNode from '../core/TempNode.js'; | ||
import { modelWorldMatrix } from './ModelNode.js'; | ||
import { positionLocal } from './PositionNode.js'; | ||
import { nodeProxy } from '../shadernode/ShaderNode.js'; | ||
import { NodeUpdateType } from '../core/constants.js'; | ||
import { Matrix4 } from '../../math/Matrix4.js'; | ||
import { uniform } from '../core/UniformNode.js'; | ||
import { sub } from '../math/OperatorNode.js'; | ||
|
||
const _worldMatrixCache = new WeakMap(); | ||
|
||
class VelocityNode extends TempNode { | ||
|
||
constructor() { | ||
|
||
super( 'vec2' ); | ||
|
||
this.updateBeforeType = NodeUpdateType.OBJECT; | ||
this.updateAfterType = NodeUpdateType.OBJECT; | ||
|
||
this.previousProjectionViewMatrix = uniform( new Matrix4() ); | ||
this.currentProjectionViewMatrix = uniform( new Matrix4() ); | ||
this.previousModelMatrix = uniform( new Matrix4() ); | ||
|
||
} | ||
|
||
updateBefore( frame ) { | ||
|
||
const camera = frame.camera; | ||
const object = frame.object; | ||
|
||
this.previousProjectionViewMatrix.value.copy( this.currentProjectionViewMatrix.value ); | ||
this.currentProjectionViewMatrix.value.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ); | ||
|
||
const previousModelMatrix = getPreviousModelMatrix( object ); | ||
this.previousModelMatrix.value.copy( previousModelMatrix ); | ||
|
||
} | ||
|
||
updateAfter( frame ) { | ||
|
||
const object = frame.object; | ||
|
||
const previousModelMatrix = getPreviousModelMatrix( object ); | ||
|
||
previousModelMatrix.copy( object.matrixWorld ); | ||
|
||
} | ||
|
||
setup( /*builder*/ ) { | ||
|
||
const clipPositionCurrent = this.currentProjectionViewMatrix.mul( modelWorldMatrix ).mul( positionLocal ).toVar(); | ||
const clipPositionPrevious = this.previousProjectionViewMatrix.mul( this.previousModelMatrix ).mul( positionLocal ).toVar(); | ||
|
||
const ndcPositionCurrent = clipPositionCurrent.xy.div( clipPositionCurrent.w ); | ||
const ndcPositionPrevious = clipPositionPrevious.xy.div( clipPositionPrevious.w ); | ||
let velocity = sub( ndcPositionCurrent, ndcPositionPrevious ).mul( 0.5 ); | ||
velocity = velocity.mul( 0.5 ).add( 0.5 ); | ||
Mugen87 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return velocity; | ||
|
||
} | ||
|
||
} | ||
|
||
function getPreviousModelMatrix( object ) { | ||
|
||
let previousModelMatrix = _worldMatrixCache.get( object ); | ||
|
||
if ( previousModelMatrix === undefined ) { | ||
|
||
previousModelMatrix = new Matrix4(); | ||
_worldMatrixCache.set( object, previousModelMatrix ); | ||
|
||
} | ||
|
||
return previousModelMatrix; | ||
|
||
} | ||
|
||
export default VelocityNode; | ||
|
||
export const velocity = nodeProxy( VelocityNode ); | ||
|
||
addNodeClass( 'VelocityNode', VelocityNode ); |
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.
Uh oh!
There was an error while loading. Please reload this page.