import*asTHREEfrom'three/webgpu';// Standard PBR materialconstmaterial=newTHREE.MeshStandardNodeMaterial();// Physical material with advanced featuresconstphysicalMat=newTHREE.MeshPhysicalNodeMaterial();// Unlit materialconstbasicMat=newTHREE.MeshBasicNodeMaterial();
Material Properties
Color and Opacity
import{texture,color,float}from'three/tsl';// Color from texturematerial.colorNode=texture(diffuseMap);// Solid colormaterial.colorNode=color(0xff0000);// Computed colormaterial.colorNode=positionLocal.normalize();// Opacity (requires material.transparent = true)material.opacityNode=float(0.8);material.transparent=true;// Alpha test thresholdmaterial.alphaTestNode=float(0.5);
import{texture,normalMap,bumpMap}from'three/tsl';// Normal mapmaterial.normalNode=normalMap(texture(normalMapTexture));// Normal map with strengthmaterial.normalNode=normalMap(texture(normalMapTexture),float(0.5));// Bump map (height to normal)material.normalNode=bumpMap(texture(heightMap),0.05);
Physical Properties (MeshPhysicalNodeMaterial)
constmaterial=newTHREE.MeshPhysicalNodeMaterial();// Clearcoat (car paint effect)material.clearcoatNode=float(1.0);material.clearcoatRoughnessNode=float(0.1);material.clearcoatNormalNode=normalMap(texture(clearcoatNormalMap));// Transmission (glass/translucency)material.transmissionNode=float(0.9);material.thicknessNode=float(0.5);material.attenuationDistanceNode=float(1.0);material.attenuationColorNode=color(0xffffff);// Iridescence (soap bubble effect)material.iridescenceNode=float(1.0);material.iridescenceIORNode=float(1.3);material.iridescenceThicknessNode=float(400);// Sheen (fabric effect)material.sheenNode=float(1.0);material.sheenRoughnessNode=float(0.5);material.sheenColorNode=color(0xffffff);// Anisotropy (brushed metal)material.anisotropyNode=float(1.0);material.anisotropyRotationNode=float(0);// Specularmaterial.specularIntensityNode=float(1.0);material.specularColorNode=color(0xffffff);// Index of Refractionmaterial.iorNode=float(1.5);// Dispersion (rainbow effect in glass)material.dispersionNode=float(0.0);
import{positionLocal,normalLocal,texture}from'three/tsl';// Displace vertices along normalsconstdisplacement=texture(heightMap).r.mul(0.1);material.positionNode=positionLocal.add(normalLocal.mul(displacement));// Wave displacementconstwave=positionLocal.x.add(time).sin().mul(0.1);material.positionNode=positionLocal.add(vec3(0,wave,0));
Custom Vertex Shader
// Complete vertex position overridematerial.vertexNode=customVertexPosition;
Fragment Override
// Complete fragment output overridematerial.fragmentNode=vec4(finalColor,1.0);// Output node (respects lighting)material.outputNode=outputStruct;
Geometry Attributes
Position Nodes
import{positionGeometry,// Original mesh positionpositionLocal,// Position in model spacepositionWorld,// Position in world spacepositionView// Position in camera space}from'three/tsl';
Normal Nodes
import{normalGeometry,// Original mesh normalnormalLocal,// Normal in model spacenormalWorld,// Normal in world space (use for lighting)normalView// Normal in camera space}from'three/tsl';
import{uv}from'three/tsl';uv()// Primary UV set (UV0)uv(1)// Secondary UV set (UV1)uv(2)// Tertiary UV set (UV2)
Other Attributes
import{vertexColor,instanceIndex,vertexIndex}from'three/tsl';vertexColor()// Vertex colors (if present)instanceIndex// Index for instanced meshesvertexIndex// Current vertex index
Camera Nodes
import{cameraPosition,// Camera world positioncameraNear,// Near plane distancecameraFar,// Far plane distancecameraViewMatrix,// View matrixcameraProjectionMatrix,// Projection matrixcameraWorldMatrix// Camera world matrix}from'three/tsl';
import*asTHREEfrom'three/webgpu';import{texture,triplanarTexture,float}from'three/tsl';constmaterial=newTHREE.MeshStandardNodeMaterial();// Apply texture from all three axesmaterial.colorNode=triplanarTexture(texture(diffuseMap),null,// Y-axis texture (optional)null,// Z-axis texture (optional)float(0.1)// Blend sharpness);