S&box Wiki
Home
/
Edit Material API
View
Edit
History
No Category
Developer Overview
The Project System
Publishing To Asset Party
Getting Started With Hammer
Mapping Basics
Mapping Entities
Advanced Mapping Techniques
Getting Started with Modeldoc
Animgraph & Animation
Physics
Modeldoc Nodes
Advanced Modelling
UI Basics
Styles & Stylesheets
Razor Templates
Game Menus
Materials
Built In Shaders
Shaders
Shader Reference
Sounds & Audio
Particles
Getting Started
Making Games
Input
Networking
Physics
Rendering
Editor & Tools
VR
Misc
Playing Guides
Console Commands & Variables
Dedicated Server
Preview
Log in to edit
Material API
<cat>Material.ShaderBasic</cat> <title>Material API</title> # What is the Material API The Material API is a collection of helper methods & texture inputs to describe the surface of your material. The main purpose of the Material API is to prepare your data and pass it to a <page>ShadingModel</page>. The Material API is automatically used when you add the `common/pixel.hlsl` include to your pixel shader. ``` PS { #include "common/pixel.hlsl" float4 MainPs( PixelInput i ) : SV_Target0 { // Gather our texture inputs and convert them to the material struct Material m = GatherMaterial( i ); // Force our object to be metallic m.Metalness = 1.3f; // Shade our surface with lighting return FinalizePixelMaterial( i, m ); } } ``` # Texture Inputs By default, the Material API provides a set of texture inputs. These texture inputs can be used to automatically populate the Material struct for you. To populate your Material object, simply call `GatherMaterial` using your `PixelInput` as the argument. GatherMaterial will automatically transform your normal map to be within object space, set up texture compression & pack different textures into one texture to reduce memory. ``` Material m = GatherMaterial( i ); ``` <upload src="653cb/8daa5101c74c705.png" size="77533" name="image.png" /> # Material The following is an overview of the **Material** struct defined in `common/pixel.material.structs.hlsl`. It is included automatically by `common/pixel.hlsl`. | Property | Type | Default Value | Notes | | --- | --- | --- | --- | | Albedo | float3 | (1.0, 1.0, 1.0) | | | Emission | float3 | (0.0, 0.0, 0.0) | | | Opacity | float | 1.0 | | | TintMask | float | 1.0 | | | Normal | float3 | (0.0, 0.0, 1.0) | The normal vector of the material in world space | | Roughness | float | 1.0 | | | Metalness | float | 0.0 | | | AmbientOcclusion | float3 | (1.0, 1.0, 1.0) | Can be normal AO or bent normal AO | | Sheen | float3 | (0.0, 0.0, 0.0) | | | SheenRoughness | float | 0.0 | | | Clearcoat | float | 0.0 | | | ClearcoatRoughness | float | 0.03 | | | ClearcoatNormal | float3 | (0.0, 0.0, 1.0) | | | Anisotropy | float | 0.0 | | | AnisotropyRotation | float3 | (1.0, 0.0, 0.0) | | | Thickness | float | 0.5 | | | SubsurfacePower | float | 12.234 | | | SheenColor | float3 | sqrt(baseColor) | | | SubsurfaceColor | float3 | (0.0, 0.0, 0.0) | | | Transmission | float3 | (1.0, 1.0, 1.0) | | | Absorption | float3 | (0.0, 0.0, 0.0) | | | IndexOfRefraction | float | 1.5 | | | MicroThickness | float | 0.0 | | ## Shading Models Different shading models may use different subsets of the properties available in the **Material** struct. `Albedo`, `Emission`, `Opacity`, `TintMask`, `Normal`, `Roughness`, `Metalness`, and `AmbientOcclusion` are available across all shading models. `Sheen`, `SheenRoughness`, `Clearcoat`, `ClearcoatRoughness`, `ClearcoatNormal`, `Anisotropy`, `AnisotropyRotation` are **unused by the standard shading model** at the time of writing. | Shading Model | Thickness | Subsurface Power | Sheen Color | Subsurface Color | Transmission | Absorption | Index of Refraction | Micro Thickness | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Standard | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | | Subsurface | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | | Cloth | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | | Refraction | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ |
S&box Wiki
Development
Developer Overview
6
Editor Overview
General FAQ
System Requirements
The s&box wiki
Troubleshooting
Useful Links
The Project System
4
Adding Assets
Creating a Game Project
Project Settings Window - Games
Project Types
Publishing To Asset Party
2
Uploading assets
Uploading projects
Hammer
Getting Started With Hammer
3
Getting Started With Hammer
Making Your First Map
Mapping Resources
Mapping Basics
7
Cordons
Hotspot Materials
Selection Sets
Standard Mapping Dimensions
Tool Materials
Tools Visualisation Modes
Using Entities That Require a Mesh
Mapping Entities
2
Creating a Door
Light Entities
Advanced Mapping Techniques
8
Collaborating With Prefabs and Git
Instances
Prefabs
Quixel Bridge Plugin
Tilesets
Tilesets-Advanced
Tilesets-Proxies
VIS Optimizations
Models & Animation
Getting Started with Modeldoc
7
Automatic Model Setup
Breakpieces
Creating a Model
Guide to Models
Importing Rust Weapons
LODs
ModelDoc FAQ & best practices
Animgraph & Animation
3
Animations without Animgraph
AnimEvents, AnimGraph Tags, Attachments
Animgraph
Physics
3
Cloth Physics
Collisions, Physics & Surface Types
Jiggle Bones
Modeldoc Nodes
1
Custom ModelDoc nodes
Advanced Modelling
6
Bodygroups
Citizen
First Person
IKChains and Stride Retargeting
Morphs
Vertex Normals
User Interface
UI Basics
6
Custom Fonts
Embedding Websites
Enabling Pointer Events
Events and Input
Localization
UI Basics
Styles & Stylesheets
2
Custom Style Properties
Supported Style Properties
Razor Templates
3
A Razor Overview
Generic Components
Templates
Game Menus
0
Materials & Shaders
Materials
5
Guide to Materials
Material Attributes
Material Resources
Texture Settings
Using Dynamic Expressions
Built In Shaders
2
Foliage Shader
Glass Shader
Shaders
4
Compute Shaders
Constant Buffers
Material API
Shading Model
Shader Reference
5
Anatomy of Shader Files
Getting rid of Tex2D macros
Shader Reference
Shader States
Texture Format Cheat-Sheet
Other Assets
Sounds & Audio
3
Guide to Sounds
Sound Events
Soundscapes
Particles
5
Creating animated sprites
Creating your first particle effect
Understanding Particle Editor
Using custom sprites
Using particle systems from C#
Coding
Getting Started
6
Cheat Sheet
Debugging
Learning Resources
Setting up Rider
Setting up Visual Studio
Setting up Visual Studio Code
Making Games
2
Components
GameObjects
Input
4
Commands
ConVars
Input System
Speech Recognition
Networking
7
Auth Tokens
Http Requests
Networked Types
Networking Basics
RPCs
Setting Up Networking
WebSockets
Physics
4
Collisions
Hitboxes
Traces
Triggers
Rendering
3
Render Tags
RenderHooks
Scenes
Editor & Tools
7
Creating a Tool
Custom Asset Types
Guide to Widgets
Hammer API
Hammer Gizmos
Hotload Performance
Widget Docking
VR
3
Getting Started
VR Input
VR Overlays
Misc
13
Asset Types
Attributes and Component Properties
Backend API
Cloud Assets in code
Code Accesslist
CPU Performance Profiling
DisplayInfo
FileSystem
Mounting assets at runtime
package/find
Setting Up A Navigation Mesh
Threaded Tasks
TypeLibrary
Playing
Playing Guides
3
Default Keybinds
Proton
s&box on macOS (Experimental)
Console Commands & Variables
1
Launch Arguments
Dedicated Server
1
Dedicated Servers