S&box Wiki
Home
/
Edit Shader Reference
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
Log in to edit
Shader Reference
<cat>Material.ShaderReference</cat> <title>Shader Reference</title> # Global Variables These variables can be called anywhere in the global namespace. |Data Type|Name|Description| |-----|----------| |float|g_flTime|Current time| |float|g_flViewportMinZ|Near clip plane| |float|g_flViewportMaxZ|Far clip plane| |float2|g_vViewportSize|Viewport size in pixels| |float2|g_vInvViewportSize|1 divided by g_vViewportSize| |float2|g_vViewportOffset|The offset of the viewport in pixels| |float2|g_vRenderTargetSize|The absolute size of the current render target| |float3|g_vCameraPositionWs|Camera position in world space| |float3|g_vCameraDirWs|Camera direction in world space| |float4x4|g_matViewToProjection|| |float4x4|g_matWorldToView|| |float4x4|g_matProjectionToWorld|| |float4x4|g_matWorldToProjection|| # Variables Variables will show up in Material Editor. They're defined like this. ``` float3 g_vColorTint < UiType( Color ); Default3( 1.0, 1.0, 1.0 ); UiGroup( "Color,10/20" ); >; float2 g_vTexCoordScale < UiType( Slider ); UiStep( 1 ); Default2( 1.0, 1.0 ); UiGroup( "Texture Coordinates,10/21" ); >; Float3Attribute( g_vColorTint, g_vColorTint ); // Only needed if your variable is not showing up in the material editor Float2Attribute( g_vTexCoordScale, g_vTexCoordScale); ``` A list of attributes you can expose can be seen below | Data Type | Attribute Function | |-----------|--------------------| | bool | BoolAttribute | | int/uint | IntAttribute | | float | FloatAttribute | | float2 | Float2Attribute | | float3 | Float3Attribute | | float4 | Float4Attribute | | float/float2/float3/float4 | TextureAttribute | ## UiType Describes how the variable should be represented in the editor. |Name|Description| |-----|----------| | VectorText | Text boxes and sliders (this is the default) | | Slider | A slider type. Usually combined with a Range setting. | | Color | A Color picker, works on float3 or float4. | | Texture | A texture picker | | CheckBox | On or off, generally used on bool | ## UiStep `UiStep` lets you set the amount of each interval or step that the value increases or decreases by. ## Default The `Default` lets you specify the default value for the variable. If you're filling a `float2`, it should be `Default2`, if you're filling a `float4` it should be `Default4` etc. ## Range The `Range` lets you cap the variable to a specific range. If you're filling a `float2`, it should be `Range2`, if you're filling a `float4` it should be `Range4` etc. ``` float g_flAlphaTestReference < Range(0.01, 0.99); UiType(Slider); >; float2 g_vTexCoordScrollSpeed < Range2(-10, -10, 10, 10); UiType(VectorText); >; ``` ## UiGroup The `UiGroup` is used to sort the variable into a group, subgroup and define its order. So for example, given this.. ``` float4 BorderColorL < UiType( Color ); Default4( 0.0, 0.0, 0.0, 1.0 ); UiGroup( "Border,10/Colors,10/1" ); >; float4 BorderColorT < UiType( Color ); Default4( 0.0, 0.0, 0.0, 1.0 ); UiGroup( "Border,10/Colors,10/2" ); >; float4 BorderColorR < UiType( Color ); Default4( 0.0, 0.0, 0.0, 1.0 ); UiGroup( "Border,10/Colors,10/3" ); >; float4 BorderColorB < UiType( Color ); Default4( 0.0, 0.0, 0.0, 1.0 ); UiGroup( "Border,10/Colors,10/4" ); >; ``` You end up with this <upload src="1/8d89e07e3fc960b.png" size="16898" name="image.png" /> The format is: ``` Heading,Order / Group,Order / VariableOrder ``` ## Expression `Expression` is used to evaluate an expression on the variable, using the [Dynamic Expressions](Using_Dynamic_Expressions) language. A good reason for their use is to save GPU instructions, since they get evaluated on the CPU prior to rendering. The expression can refer to: the variable itself with `this`, as well as to any other variables or features. ``` float3 g_vColorTint < Default3(1, 1, 1); UiType(Color); Expression(SrgbGammaToLinear(this)); >; float4 g_vTexCoordXform < Expression(g_flTexCoordRotation*3.14159)/180); >; int g_nFoliageAnimationMode < Expression(F_FOLIAGE_ANIMATION); >; ```
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
4
Animations without Animgraph
AnimEvents, AnimGraph Tags, Attachments
Animgraph
Delta Animations
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
7
Custom Fonts
Embedding Websites
Enabling Pointer Events
Events and Input
Localization
UI Basics
UI with Components
Styles & Stylesheets
0
Razor Templates
3
A Razor Overview
Generic Components
Templates
Game Menus
1
Making a Custom Pause Screen
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
5
Cheat Sheet
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
8
Auth Tokens
Http Requests
Lobby System
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