r3f-materials
Three.js materials in R3F, built-in materials (Standard, Physical, Basic, etc.), ShaderMaterial with custom GLSL, uniforms binding and animation, and material properties. Use when choosing materials, creating custom shaders, or binding dynamic uniforms.
What this skill does
# R3F Materials
Materials define surface appearance—color, texture, reflectivity, transparency, and custom shader effects.
## Quick Start
```tsx
// Built-in material
<mesh>
<boxGeometry />
<meshStandardMaterial color="hotpink" metalness={0.8} roughness={0.2} />
</mesh>
// Custom shader
<mesh>
<planeGeometry />
<shaderMaterial
uniforms={{ uTime: { value: 0 } }}
vertexShader={vertexShader}
fragmentShader={fragmentShader}
/>
</mesh>
```
## Built-in Materials
### Material Comparison
| Material | Lighting | Use Case | Performance |
|----------|----------|----------|-------------|
| `MeshBasicMaterial` | None | UI, unlit, debug | Fastest |
| `MeshStandardMaterial` | PBR | General 3D | Good |
| `MeshPhysicalMaterial` | PBR+ | Glass, car paint | Slower |
| `MeshLambertMaterial` | Diffuse | Matte surfaces | Fast |
| `MeshPhongMaterial` | Specular | Shiny plastic | Fast |
| `MeshToonMaterial` | Cel-shaded | Stylized | Good |
| `MeshNormalMaterial` | None | Debug normals | Fastest |
| `MeshDepthMaterial` | None | Depth passes | Fastest |
### MeshBasicMaterial (Unlit)
```tsx
<meshBasicMaterial
color="#ff0000" // Base color
map={texture} // Color texture
transparent={true} // Enable transparency
opacity={0.5} // Transparency level
alphaMap={alphaTexture} // Transparency texture
side={THREE.DoubleSide} // Render both sides
wireframe={true} // Wireframe mode
fog={false} // Ignore scene fog
/>
```
### MeshStandardMaterial (PBR)
```tsx
<meshStandardMaterial
// Base
color="#ffffff"
map={colorTexture}
// PBR properties
metalness={0.5} // 0 = dielectric, 1 = metal
metalnessMap={metalMap}
roughness={0.5} // 0 = mirror, 1 = diffuse
roughnessMap={roughMap}
// Normal mapping
normalMap={normalTexture}
normalScale={[1, 1]}
// Ambient occlusion
aoMap={aoTexture}
aoMapIntensity={1}
// Displacement
displacementMap={dispMap}
displacementScale={0.1}
// Emission
emissive="#000000"
emissiveMap={emissiveTexture}
emissiveIntensity={1}
// Environment
envMap={cubeTexture}
envMapIntensity={1}
/>
```
### MeshPhysicalMaterial (Advanced PBR)
```tsx
<meshPhysicalMaterial
// Inherits all MeshStandardMaterial props, plus:
// Clearcoat (car paint, lacquer)
clearcoat={1}
clearcoatRoughness={0.1}
clearcoatNormalMap={ccNormal}
// Transmission (glass, water)
transmission={0.9} // 0 = opaque, 1 = fully transmissive
thickness={0.5} // Volume thickness
ior={1.5} // Index of refraction
// Sheen (fabric, velvet)
sheen={1}
sheenRoughness={0.5}
sheenColor="#ff00ff"
// Iridescence (soap bubbles, oil slicks)
iridescence={1}
iridescenceIOR={1.3}
iridescenceThicknessRange={[100, 400]}
/>
```
### MeshToonMaterial (Cel-shaded)
```tsx
<meshToonMaterial
color="#6fa8dc"
gradientMap={gradientTexture} // 3-5 color ramp texture
/>
// Create gradient texture
const gradientTexture = useMemo(() => {
const canvas = document.createElement('canvas');
canvas.width = 4;
canvas.height = 1;
const ctx = canvas.getContext('2d')!;
// 4-step toon shading
ctx.fillStyle = '#444'; ctx.fillRect(0, 0, 1, 1);
ctx.fillStyle = '#888'; ctx.fillRect(1, 0, 1, 1);
ctx.fillStyle = '#bbb'; ctx.fillRect(2, 0, 1, 1);
ctx.fillStyle = '#fff'; ctx.fillRect(3, 0, 1, 1);
const texture = new THREE.CanvasTexture(canvas);
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
return texture;
}, []);
```
## Common Properties (All Materials)
```tsx
<meshStandardMaterial
// Rendering
transparent={false}
opacity={1}
alphaTest={0} // Discard pixels below threshold
alphaToCoverage={false} // MSAA alpha
// Faces
side={THREE.FrontSide} // FrontSide | BackSide | DoubleSide
// Depth
depthTest={true}
depthWrite={true}
// Stencil
stencilWrite={false}
stencilFunc={THREE.AlwaysStencilFunc}
// Blending
blending={THREE.NormalBlending}
// Other
visible={true}
fog={true}
toneMapped={true}
/>
```
## Textures
### Loading Textures
```tsx
import { useTexture } from '@react-three/drei';
function TexturedMesh() {
const [colorMap, normalMap, roughnessMap] = useTexture([
'/textures/color.jpg',
'/textures/normal.jpg',
'/textures/roughness.jpg'
]);
return (
<mesh>
<boxGeometry />
<meshStandardMaterial
map={colorMap}
normalMap={normalMap}
roughnessMap={roughnessMap}
/>
</mesh>
);
}
```
### Texture Settings
```tsx
import { useTexture } from '@react-three/drei';
import * as THREE from 'three';
const texture = useTexture('/texture.jpg', (tex) => {
tex.wrapS = tex.wrapT = THREE.RepeatWrapping;
tex.repeat.set(4, 4);
tex.anisotropy = 16; // Sharper at angles
});
```
## ShaderMaterial
Full control via GLSL vertex and fragment shaders:
```tsx
import { useRef } from 'react';
import { useFrame } from '@react-three/fiber';
import * as THREE from 'three';
const vertexShader = `
varying vec2 vUv;
varying vec3 vNormal;
void main() {
vUv = uv;
vNormal = normalize(normalMatrix * normal);
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const fragmentShader = `
uniform float uTime;
uniform vec3 uColor;
varying vec2 vUv;
varying vec3 vNormal;
void main() {
float pulse = sin(uTime * 2.0) * 0.5 + 0.5;
vec3 color = mix(uColor, vec3(1.0), pulse * 0.3);
// Simple rim lighting
float rim = 1.0 - dot(vNormal, vec3(0.0, 0.0, 1.0));
color += rim * 0.5;
gl_FragColor = vec4(color, 1.0);
}
`;
function CustomShaderMesh() {
const materialRef = useRef<THREE.ShaderMaterial>(null!);
useFrame(({ clock }) => {
materialRef.current.uniforms.uTime.value = clock.elapsedTime;
});
return (
<mesh>
<sphereGeometry args={[1, 32, 32]} />
<shaderMaterial
ref={materialRef}
vertexShader={vertexShader}
fragmentShader={fragmentShader}
uniforms={{
uTime: { value: 0 },
uColor: { value: new THREE.Color('#ff6b6b') }
}}
/>
</mesh>
);
}
```
## Uniforms
### Uniform Types
```tsx
uniforms={{
// Scalars
uFloat: { value: 1.0 },
uInt: { value: 1 },
uBool: { value: true },
// Vectors
uVec2: { value: new THREE.Vector2(1, 2) },
uVec3: { value: new THREE.Vector3(1, 2, 3) },
uVec4: { value: new THREE.Vector4(1, 2, 3, 4) },
uColor: { value: new THREE.Color('#ff0000') },
// Matrices
uMat3: { value: new THREE.Matrix3() },
uMat4: { value: new THREE.Matrix4() },
// Textures
uTexture: { value: texture },
uCubeTexture: { value: cubeTexture },
// Arrays
uFloatArray: { value: [1.0, 2.0, 3.0] },
uVec3Array: { value: [new THREE.Vector3(), new THREE.Vector3()] }
}}
```
### Animating Uniforms
```tsx
function AnimatedShader() {
const materialRef = useRef<THREE.ShaderMaterial>(null!);
useFrame(({ clock, mouse }) => {
const uniforms = materialRef.current.uniforms;
uniforms.uTime.value = clock.elapsedTime;
uniforms.uMouse.value.set(mouse.x, mouse.y);
uniforms.uResolution.value.set(window.innerWidth, window.innerHeight);
});
return (
<shaderMaterial
ref={materialRef}
uniforms={{
uTime: { value: 0 },
uMouse: { value: new THREE.Vector2() },
uResolution: { value: new THREE.Vector2() }
}}
// ...
/>
);
}
```
### Shared Uniforms
```tsx
// Create shared uniform object
const globalUniforms = useMemo(() => ({
uTime: { value: 0 },
uGlobalColor: { value: new THREE.Color('#00ff00') }
}), []);
// Update in useFrame
useFrame(({ clock }) => {
globalUniforms.uTime.value = clock.elapsedTime;
});
// Use in multiple materials
<mesh>
<boxGeometry />
<shaderMaterial uniforms={{ ...globalUniforms, uLocalProp: { value: 1 } }}Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.