-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
WebGPU: Introduce Fat Points #26930
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
WebGPU: Introduce Fat Points #26930
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d63257e
Introduce Fat Points
WestLangley 0b79919
Introduce FatPointsNodeMaterial
WestLangley 2a1c60e
Enable damping
WestLangley a7f384d
Clean up
WestLangley 6cf85a3
Clean up
WestLangley 8e1064f
Clean up
WestLangley c53add5
Clean up
WestLangley 3824a18
Delete FatPointsMaterial
WestLangley 26e3419
Clean up
WestLangley 136db0a
Add screenshot
WestLangley 277c4af
Updated files
WestLangley 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
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,21 @@ | ||
| import MaterialNode from './MaterialNode.js'; | ||
| import { addNodeClass } from '../core/Node.js'; | ||
| import { nodeImmutable } from '../shadernode/ShaderNode.js'; | ||
|
|
||
| class FatPointsMaterialNode extends MaterialNode { | ||
|
|
||
| setup( /*builder*/ ) { | ||
|
|
||
| return this.getFloat( this.scope ); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| FatPointsMaterialNode.POINTWIDTH = 'pointWidth'; | ||
|
|
||
| export default FatPointsMaterialNode; | ||
|
|
||
| export const materialPointWidth = nodeImmutable( FatPointsMaterialNode, FatPointsMaterialNode.POINTWIDTH ); | ||
|
|
||
| addNodeClass( 'FatPointsMaterialNode', FatPointsMaterialNode ); | ||
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,163 @@ | ||
| import NodeMaterial, { addNodeMaterial } from './NodeMaterial.js'; | ||
| import { varying } from '../core/VaryingNode.js'; | ||
| import { property } from '../core/PropertyNode.js'; | ||
| import { attribute } from '../core/AttributeNode.js'; | ||
| import { cameraProjectionMatrix } from '../accessors/CameraNode.js'; | ||
| import { materialColor } from '../accessors/MaterialNode.js'; | ||
| import { modelViewMatrix } from '../accessors/ModelNode.js'; | ||
| import { positionGeometry } from '../accessors/PositionNode.js'; | ||
| import { smoothstep } from '../math/MathNode.js'; | ||
| import { tslFn, vec2, vec4 } from '../shadernode/ShaderNode.js'; | ||
| import { uv } from '../accessors/UVNode.js'; | ||
| import { materialPointWidth } from '../accessors/FatPointsMaterialNode.js'; // or should this be a property, instead? | ||
| import { viewport } from '../display/ViewportNode.js'; | ||
|
|
||
| import { PointsMaterial } from 'three'; | ||
|
|
||
| const defaultValues = new PointsMaterial(); | ||
|
|
||
| class FatPointsNodeMaterial extends NodeMaterial { | ||
WestLangley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| constructor( params = {} ) { | ||
|
|
||
| super(); | ||
|
|
||
| this.normals = false; | ||
|
|
||
| this.lights = false; | ||
|
|
||
| this.useAlphaToCoverage = true; | ||
|
|
||
| this.useColor = params.vertexColors; | ||
|
|
||
| this.pointWidth = 1; | ||
|
|
||
| this.pointColorNode = null; | ||
|
|
||
| this.setDefaultValues( defaultValues ); | ||
|
|
||
| this.setupShaders(); | ||
|
|
||
| this.setValues( params ); | ||
|
|
||
| } | ||
|
|
||
| setupShaders() { | ||
|
|
||
| const useAlphaToCoverage = this.alphaToCoverage; | ||
| const useColor = this.useColor; | ||
|
|
||
| this.vertexNode = tslFn( () => { | ||
|
|
||
| //vUv = uv; | ||
| varying( vec2(), 'vUv' ).assign( uv() ); // @TODO: Analyze other way to do this | ||
|
|
||
| const instancePosition = attribute( 'instancePosition' ); | ||
|
|
||
| // camera space | ||
| const mvPos = property( 'vec4', 'mvPos' ); | ||
| mvPos.assign( modelViewMatrix.mul( vec4( instancePosition, 1.0 ) ) ); | ||
|
|
||
| const aspect = viewport.z.div( viewport.w ); | ||
|
|
||
| // clip space | ||
| const clipPos = cameraProjectionMatrix.mul( mvPos ); | ||
|
|
||
| // offset in ndc space | ||
| const offset = property( 'vec2', 'offset' ); | ||
| offset.assign( positionGeometry.xy ); | ||
| offset.assign( offset.mul( materialPointWidth ) ); | ||
| offset.assign( offset.div( viewport.z ) ); | ||
| offset.y.assign( offset.y.mul( aspect ) ); | ||
|
|
||
| // back to clip space | ||
| offset.assign( offset.mul( clipPos.w ) ); | ||
|
|
||
| //clipPos.xy += offset; | ||
| clipPos.assign( clipPos.add( vec4( offset, 0, 0 ) ) ); | ||
|
|
||
| return clipPos; | ||
|
|
||
| //vec4 mvPosition = mvPos; // this was used for somethihng... | ||
|
|
||
| } )(); | ||
|
|
||
| this.colorNode = tslFn( () => { | ||
|
|
||
| const vUv = varying( vec2(), 'vUv' ); | ||
|
|
||
| // force assignment into correct place in flow | ||
| const alpha = property( 'float', 'alpha' ); | ||
| alpha.assign( 1 ); | ||
|
|
||
| const a = vUv.x; | ||
| const b = vUv.y; | ||
|
|
||
| const len2 = a.mul( a ).add( b.mul( b ) ); | ||
|
|
||
| if ( useAlphaToCoverage ) { | ||
|
|
||
| // force assignment out of following 'if' statement - to avoid uniform control flow errors | ||
| const dlen = property( 'float', 'dlen' ); | ||
| dlen.assign( len2.fwidth() ); | ||
|
|
||
| alpha.assign( smoothstep( dlen.oneMinus(), dlen.add( 1 ), len2 ).oneMinus() ); | ||
|
|
||
| } else { | ||
|
|
||
| len2.greaterThan( 1.0 ).discard(); | ||
|
|
||
| } | ||
|
|
||
| let pointColorNode; | ||
|
|
||
| if ( this.pointColorNode ) { | ||
|
|
||
| pointColorNode = this.pointColorNode; | ||
|
|
||
| } else { | ||
|
|
||
| if ( useColor ) { | ||
|
|
||
| const instanceColor = attribute( 'instanceColor' ); | ||
|
|
||
| pointColorNode = instanceColor; // todo: instance color should be attenuated by material color | ||
|
|
||
| } else { | ||
|
|
||
| pointColorNode = materialColor; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| return vec4( pointColorNode, alpha ); | ||
|
|
||
| } )(); | ||
|
|
||
| this.needsUpdate = true; | ||
|
|
||
| } | ||
|
|
||
| get alphaToCoverage() { | ||
|
|
||
| return this.useAlphaToCoverage; | ||
|
|
||
| } | ||
|
|
||
| set alphaToCoverage( value ) { | ||
|
|
||
| if ( this.useAlphaToCoverage !== value ) { | ||
|
|
||
| this.useAlphaToCoverage = value; | ||
| this.setupShaders(); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| export default FatPointsNodeMaterial; | ||
|
|
||
| addNodeMaterial( 'FatPointsNodeMaterial', FatPointsNodeMaterial ); | ||
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,21 @@ | ||
| import { | ||
| Mesh | ||
| } from 'three'; | ||
| import { FatPointsGeometry } from '../points/FatPointsGeometry.js'; | ||
| import { FatPointsMaterial } from '../points/FatPointsMaterial.js'; | ||
|
|
||
| class FatPoints extends Mesh { | ||
|
|
||
| constructor( geometry = new FatPointsGeometry(), material = new FatPointsMaterial( { color: Math.random() * 0xffffff } ) ) { | ||
|
|
||
| super( geometry, material ); | ||
|
|
||
| this.isFatPoints = true; | ||
|
|
||
| this.type = 'FatPoints'; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| export { FatPoints }; |
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.
Uh oh!
There was an error while loading. Please reload this page.