|
|
@@ -1,5 +1,5 @@
|
|
|
import Node from './Node.js';
|
|
|
-import { nodeImmutable } from '../tsl/TSLCore.js';
|
|
|
+import { nodeImmutable, nodeObject } from '../tsl/TSLCore.js';
|
|
|
import { hashString } from './NodeUtils.js';
|
|
|
|
|
|
/**
|
|
|
@@ -28,8 +28,9 @@ class PropertyNode extends Node {
|
|
|
* @param {string} nodeType - The type of the node.
|
|
|
* @param {?string} [name=null] - The name of the property in the shader.
|
|
|
* @param {boolean} [varying=false] - Whether this property is a varying or not.
|
|
|
+ * @param {?Node} [placeholderNode=null] - The placeholder node if not assigned.
|
|
|
*/
|
|
|
- constructor( nodeType, name = null, varying = false ) {
|
|
|
+ constructor( nodeType, name = null, varying = false, placeholderNode = null ) {
|
|
|
|
|
|
super( nodeType );
|
|
|
|
|
|
@@ -50,6 +51,14 @@ class PropertyNode extends Node {
|
|
|
*/
|
|
|
this.varying = varying;
|
|
|
|
|
|
+ /**
|
|
|
+ * The placeholder node of the property if it is not assigned.
|
|
|
+ *
|
|
|
+ * @type {?Node}
|
|
|
+ * @default null
|
|
|
+ */
|
|
|
+ this.placeholderNode = nodeObject( placeholderNode );
|
|
|
+
|
|
|
/**
|
|
|
* This flag can be used for type testing.
|
|
|
*
|
|
|
@@ -108,6 +117,18 @@ class PropertyNode extends Node {
|
|
|
|
|
|
nodeVar = builder.getVarFromNode( this, this.name );
|
|
|
|
|
|
+ if ( this.placeholderNode !== null ) {
|
|
|
+
|
|
|
+ if ( builder.hasWriteUsage( this ) === false ) {
|
|
|
+
|
|
|
+ const snippet = this.placeholderNode.build( builder, this.getNodeType( builder ) );
|
|
|
+
|
|
|
+ builder.addLineFlowCode( `${ builder.getPropertyName( nodeVar ) } = ${ snippet }`, this );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return builder.getPropertyName( nodeVar );
|
|
|
@@ -125,9 +146,10 @@ export default PropertyNode;
|
|
|
* @function
|
|
|
* @param {string} type - The type of the node.
|
|
|
* @param {?string} [name=null] - The name of the property in the shader.
|
|
|
+ * @param {?Node} [placeholderNode=null] - The placeholder node if not assigned.
|
|
|
* @returns {PropertyNode}
|
|
|
*/
|
|
|
-export const property = ( type, name ) => new PropertyNode( type, name );
|
|
|
+export const property = ( type, name, placeholderNode = null ) => new PropertyNode( type, name, false, placeholderNode );
|
|
|
|
|
|
/**
|
|
|
* TSL function for creating a varying property node.
|
|
|
@@ -136,9 +158,10 @@ export const property = ( type, name ) => new PropertyNode( type, name );
|
|
|
* @function
|
|
|
* @param {string} type - The type of the node.
|
|
|
* @param {?string} [name=null] - The name of the varying in the shader.
|
|
|
+ * @param {?Node} [placeholderNode=null] - The placeholder node if not assigned.
|
|
|
* @returns {PropertyNode}
|
|
|
*/
|
|
|
-export const varyingProperty = ( type, name ) => new PropertyNode( type, name, true );
|
|
|
+export const varyingProperty = ( type, name, placeholderNode = null ) => new PropertyNode( type, name, true, placeholderNode );
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the shader variable `DiffuseColor`.
|
|
|
@@ -379,3 +402,12 @@ export const attenuationColor = /*@__PURE__*/ nodeImmutable( PropertyNode, 'colo
|
|
|
* @type {PropertyNode<float>}
|
|
|
*/
|
|
|
export const dispersion = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'Dispersion' );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the shader variable `AmbientOcclusion`.
|
|
|
+ * If no value is assigned to this property, it defaults to a placeholder value of `1.0`.
|
|
|
+ *
|
|
|
+ * @tsl
|
|
|
+ * @type {PropertyNode<float>}
|
|
|
+ */
|
|
|
+export const ambientOcclusion = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'AmbientOcclusion', false, 1 );
|