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

Nodes: Add LineDashedNodeMaterial #26528

Merged
merged 4 commits into from
Aug 6, 2023
Merged

Nodes: Add LineDashedNodeMaterial #26528

merged 4 commits into from
Aug 6, 2023

Conversation

aardgoose
Copy link
Contributor

Add support for dashed lines.

@sunag
materialReferences() fail when accessed across code flows. The generate() methods added resolve the problem but there is probably a better fix. The required outputNodes for the lineScale reference are cached against the fragment shader but required in the vertex shader. Without the changes the required uniform name is missing from the generated code.

ie (pseudo code).

uniform lineScale;

varying = ( * lineLength );

instead of:

varying = ( lineScale * lineLength );

const node = this.getFloat( this.scope );
this.node = node;

return node;
Copy link
Collaborator

@sunag sunag Aug 3, 2023

Choose a reason for hiding this comment

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

The code below should work, or maybe we have some issue in the build process.

class LineMaterialNode extends MaterialNode {

	constructor( scope ) {

		super( scope );

	}


	construct( /* builder */ ) {

		return this.getFloat( this.scope );

	}

}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that initially, but it failed as described. I traced it through the path for varying() where the reference is included in the vertex shader flow and the uniform name is omitted in the code produced.

The output from the construct() phase is entered into the nodes properties[ 'fragment' ] so isn't available at that point. I don't understand the code well enough to known if there is a better solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm... Make sense, construct() must build the output node once. I will fix this.

import NodeMaterial, { addNodeMaterial } from './NodeMaterial.js';
import { attribute } from '../core/AttributeNode.js';
import { varying } from '../core/VaryingNode.js';
import { lineScale, lineDashSize, lineGapSize } from '../accessors/LineMaterialNode..js';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems to have two points in ..js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


export default LineMaterialNode;

export const lineScale = nodeImmutable( LineMaterialNode, LineMaterialNode.SCALE );
Copy link
Collaborator

@sunag sunag Aug 3, 2023

Choose a reason for hiding this comment

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

I think the ideal nomenclature would be:

materialLineScale
materialLineDashSize
materialLineGapSize

For that we can use properties node-based, e.g:

import { dashSize } from '../core/PropertyNode.js';

class LineDashedNodeMaterial extends NodeMaterial {

	constructor( parameters ) {

		...

		this.dashSizeNode = null;
		...

	}

	constructVariants( { stack } ) {

		const dashSizeNode = this.dashSizeNode ? float( this.dashSizeNode ) : materialDashSize;

		stack.assign( dashSize, dashSizeNode );
		...
		
	}

@mrdoob mrdoob added this to the r156 milestone Aug 4, 2023
@sunag sunag merged commit e19a621 into mrdoob:dev Aug 6, 2023

class LineMaterialNode extends MaterialNode {

constructor( scope ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need such a pass-through constructor? I think these lines (7-11) can be just removed.

@@ -57,5 +57,7 @@ export const iridescenceThickness = nodeImmutable( PropertyNode, 'float', 'Iride
export const specularColor = nodeImmutable( PropertyNode, 'color', 'SpecularColor' );
export const shininess = nodeImmutable( PropertyNode, 'float', 'Shininess' );
export const output = nodeImmutable( PropertyNode, 'vec4', 'Output' );
export const dashSize = nodeImmutable( PropertyNode, 'float', 'dashScale' );
export const gapSize= nodeImmutable( PropertyNode, 'float', 'gapSize' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing space before the = sign.

@aardgoose aardgoose deleted the dash branch September 5, 2023 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants