Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/nodes/accessors/Bitangent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,48 @@ import { cameraViewMatrix } from './Camera.js';
import { normalGeometry, normalLocal, normalView, normalWorld, transformedNormalView } from './Normal.js';
import { tangentGeometry, tangentLocal, tangentView, tangentWorld, transformedTangentView } from './Tangent.js';

/** @module Bitangent **/

const getBitangent = ( crossNormalTangent ) => crossNormalTangent.mul( tangentGeometry.w ).xyz;

/**
* TSL object that represents the bitangent attribute of the current rendered object.
*
* @type {Node<vec3>}
*/
export const bitangentGeometry = /*@__PURE__*/ varying( getBitangent( normalGeometry.cross( tangentGeometry ) ), 'v_bitangentGeometry' ).normalize().toVar( 'bitangentGeometry' );

/**
* TSL object that represents the vertex bitangent in local space of the current rendered object.
*
* @type {Node<vec3>}
*/
export const bitangentLocal = /*@__PURE__*/ varying( getBitangent( normalLocal.cross( tangentLocal ) ), 'v_bitangentLocal' ).normalize().toVar( 'bitangentLocal' );

/**
* TSL object that represents the vertex bitangent in view space of the current rendered object.
*
* @type {Node<vec4>}
*/
export const bitangentView = /*@__PURE__*/ varying( getBitangent( normalView.cross( tangentView ) ), 'v_bitangentView' ).normalize().toVar( 'bitangentView' );

/**
* TSL object that represents the vertex bitangent in world space of the current rendered object.
*
* @type {Node<vec4>}
*/
export const bitangentWorld = /*@__PURE__*/ varying( getBitangent( normalWorld.cross( tangentWorld ) ), 'v_bitangentWorld' ).normalize().toVar( 'bitangentWorld' );

/**
* TSL object that represents the transformed vertex bitangent in view space of the current rendered object.
*
* @type {Node<vec4>}
*/
export const transformedBitangentView = /*@__PURE__*/ getBitangent( transformedNormalView.cross( transformedTangentView ) ).normalize().toVar( 'transformedBitangentView' );

/**
* TSL object that represents the transformed vertex bitangent in world space of the current rendered object.
*
* @type {Node<vec4>}
*/
export const transformedBitangentWorld = /*@__PURE__*/ transformedBitangentView.transformDirection( cameraViewMatrix ).normalize().toVar( 'transformedBitangentWorld' );
64 changes: 64 additions & 0 deletions src/nodes/accessors/CubeTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { nodeProxy, vec3 } from '../tsl/TSLBase.js';

import { CubeReflectionMapping, CubeRefractionMapping, WebGPUCoordinateSystem } from '../../constants.js';

/** @module CubeTextureNode **/

/**
* This type of uniform node represents a cube texture.
*
* @augments module:TextureNode~TextureNode
*/
class CubeTextureNode extends TextureNode {

static get type() {
Expand All @@ -12,20 +19,46 @@ class CubeTextureNode extends TextureNode {

}

/**
* Constructs a new cube texture node.
*
* @param {CubeTexture} value - The cube texture.
* @param {Node<vec3>?} [uvNode=null] - The uv node.
* @param {Node<int>?} [levelNode=null] - The level node.
* @param {Node<float>?} [biasNode=null] - The bias node.
*/
constructor( value, uvNode = null, levelNode = null, biasNode = null ) {

super( value, uvNode, levelNode, biasNode );

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isCubeTextureNode = true;

}

/**
* Overwrites the default implementation to return a fixed value `'cubeTexture'`.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {String} The input type.
*/
getInputType( /*builder*/ ) {

return 'cubeTexture';

}

/**
* Returns a default uvs based on the mapping type of the cube texture.
*
* @return {Node<vec3>} The default uv attribute.
*/
getDefaultUV() {

const texture = this.value;
Expand All @@ -48,8 +81,22 @@ class CubeTextureNode extends TextureNode {

}

/**
* Overwritten with an empty implementation since the `updateMatrix` flag is ignored
* for cube textures. The uv transformation matrix is not applied to cube textures.
*
* @param {Boolean} value - The update toggle.
*/
setUpdateMatrix( /*updateMatrix*/ ) { } // Ignore .updateMatrix for CubeTextureNode

/**
* Setups the uv node. Depending on the backend as well as the texture type, it might be necessary
* to modify the uv node for correct sampling.
*
* @param {NodeBuilder} builder - The current node builder.
* @param {Node} uvNode - The uv node to setup.
* @return {Node} The updated uv node.
*/
setupUV( builder, uvNode ) {

const texture = this.value;
Expand All @@ -66,6 +113,13 @@ class CubeTextureNode extends TextureNode {

}

/**
* Generates the uv code snippet.
*
* @param {NodeBuilder} builder - The current node builder.
* @param {Node} cubeUV - The uv node to generate code for.
* @return {String} The generated code snippet.
*/
generateUV( builder, cubeUV ) {

return cubeUV.build( builder, 'vec3' );
Expand All @@ -76,4 +130,14 @@ class CubeTextureNode extends TextureNode {

export default CubeTextureNode;

/**
* TSL function for creating a cube texture node.
*
* @function
* @param {CubeTexture} value - The cube texture.
* @param {Node<vec3>?} [uvNode=null] - The uv node.
* @param {Node<int>?} [levelNode=null] - The level node.
* @param {Node<float>?} [biasNode=null] - The bias node.
* @returns {CubeTextureNode}
*/
export const cubeTexture = /*@__PURE__*/ nodeProxy( CubeTextureNode );
7 changes: 7 additions & 0 deletions src/nodes/accessors/MaterialProperties.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { uniform } from '../core/UniformNode.js';

/** @module MaterialProperties **/

/**
* TSL object that represents the refraction ratio of the material used for rendering the current object.
*
* @type {UniformNode<float>}
*/
export const materialRefractionRatio = /*@__PURE__*/ uniform( 0 ).onReference( ( { material } ) => material ).onRenderUpdate( ( { material } ) => material.refractionRatio );
66 changes: 53 additions & 13 deletions src/nodes/accessors/MaterialReferenceNode.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import ReferenceNode from './ReferenceNode.js';
//import { renderGroup } from '../core/UniformGroupNode.js';
//import { NodeUpdateType } from '../core/constants.js';
import { nodeObject } from '../tsl/TSLBase.js';

/** @module MaterialReferenceNode **/

/**
* This node is a special type of reference node which is intended
* for linking material properties with node values.
* ```js
* const opacityNode = materialReference( 'opacity', 'float', material );
* ```
* When changing `material.opacity`, the node value of `opacityNode` will
* automatically be updated.
*
* @augments module:ReferenceNode~ReferenceNode
*/
class MaterialReferenceNode extends ReferenceNode {

static get type() {
Expand All @@ -11,26 +22,45 @@ class MaterialReferenceNode extends ReferenceNode {

}

/**
* Constructs a new material reference node.
*
* @param {String} property - The name of the property the node refers to.
* @param {String} inputType - The uniform type that should be used to represent the property value.
* @param {Material?} [material=null] - The material the property belongs to. When no material is set,
* the node refers to the material of the current rendered object.
*/
constructor( property, inputType, material = null ) {

super( property, inputType, material );

/**
* The material the property belongs to. When no material is set,
* the node refers to the material of the current rendered object.
*
* @type {Material?}
* @default null
*/
this.material = material;

//this.updateType = NodeUpdateType.RENDER;

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isMaterialReferenceNode = true;

}

/*setNodeType( node ) {

super.setNodeType( node );

this.node.groupNode = renderGroup;

}*/

/**
* Updates the reference based on the given state. The state is only evaluated
* {@link module:MaterialReferenceNode~MaterialReferenceNode#material} is not set.
*
* @param {(NodeFrame|NodeBuilder)} state - The current state.
* @return {Object} The updated reference.
*/
updateReference( state ) {

this.reference = this.material !== null ? this.material : state.material;
Expand All @@ -43,4 +73,14 @@ class MaterialReferenceNode extends ReferenceNode {

export default MaterialReferenceNode;

export const materialReference = ( name, type, material ) => nodeObject( new MaterialReferenceNode( name, type, material ) );
/**
* TSL function for creating a material reference node.
*
* @function
* @param {String} name - The name of the property the node refers to.
* @param {String} type - The uniform type that should be used to represent the property value.
* @param {Material?} [material=null] - The material the property belongs to.
* When no material is set, the node refers to the material of the current rendered object.
* @returns {MaterialReferenceNode}
*/
export const materialReference = ( name, type, material = null ) => nodeObject( new MaterialReferenceNode( name, type, material ) );
Loading
Loading