S&box Wiki

Revision Difference

Shader_Reference#549094

<cat>Material.ShaderReference</cat> <title>Shader Reference</title> # 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" ); >; Float3Attribute( g_vColorTint, g_vColorTint ); // Only needed if your variable is not showing up in the material editor ``` 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 | ## 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.⤶ ⤶ 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); >;⤶ ```⤶