Vital.sandbox
Model

self:set_material_flag

Shared

Enables or disables a specific rendering flag on a material


Syntax

local status = self:set_material_flag(component, material, flag, state)

Parameters

TypeNameDescription
stringcomponentPath of the component containing the material
stringmaterialName of the material to modify
Supports * as a wildcard to match multiple materials by pattern
intflagFlag index to toggle
Refer Flags section
boolstateDetermines the flag state:
• When true - enables the specified flag
• When false - disables the specified flag

Returns

TypeNameDescription
boolstatustrue on successful execution, or false on failure

Flags

ValueNameDescription
0FLAG_DISABLE_DEPTH_TESTDraws the material on top of all other objects, bypassing depth sorting. May cause z-fighting after the transparent pass
1FLAG_ALBEDO_FROM_VERTEX_COLORSets the albedo color from the per-vertex color defined in the mesh
2FLAG_SRGB_VERTEX_COLORTreats vertex colours as nonlinear sRGB and converts them to linear for rendering. Only effective on Forward+ and Mobile
3FLAG_USE_POINT_SIZEUses point size to alter primitive point rendering; changes albedo texture lookup to use POINT_COORD instead of UV
4FLAG_FIXED_SIZEScales the object by depth so it always appears the same size on screen
5FLAG_BILLBOARD_KEEP_SCALEPreserves the scale set on the mesh when billboarding. Only applies when billboard_mode is BILLBOARD_ENABLED
6FLAG_UV1_USE_TRIPLANARUses triplanar texture lookup for all texture lookups that would normally use UV
7FLAG_UV2_USE_TRIPLANARUses triplanar texture lookup for all texture lookups that would normally use UV2
8FLAG_UV1_USE_WORLD_TRIPLANARUses world-space triplanar texture lookup for all lookups that would normally use UV
9FLAG_UV2_USE_WORLD_TRIPLANARUses world-space triplanar texture lookup for all lookups that would normally use UV2
10FLAG_AO_ON_UV2Uses UV2 coordinates to look up the ambient occlusion texture
11FLAG_EMISSION_ON_UV2Uses UV2 coordinates to look up the emission texture
12FLAG_ALBEDO_TEXTURE_FORCE_SRGBForces the shader to convert the albedo texture from nonlinear sRGB to linear encoding
13FLAG_DONT_RECEIVE_SHADOWSDisables receiving shadows cast by other objects
14FLAG_DISABLE_AMBIENT_LIGHTDisables the contribution of ambient light on this material
15FLAG_USE_SHADOW_TO_OPACITYEnables the shadow-to-opacity feature
16FLAG_USE_TEXTURE_REPEATEnables texture repeat when UV coordinates fall outside the 0–1 range. May cause edge artefacts with linear filtering
17FLAG_INVERT_HEIGHTMAPInverts values read from the depth texture to convert them to height values
18FLAG_SUBSURFACE_MODE_SKINEnables skin mode for subsurface scattering to improve the look of human skin
19FLAG_PARTICLE_TRAILS_MODEEnables shader parts required for GPUParticles3D trails such as RibbonTrailMesh or TubeTrailMesh. Enabling this on non-GPUParticles3D materials will break rendering
20FLAG_ALBEDO_TEXTURE_MSDFEnables multichannel signed distance field rendering for the albedo shader
21FLAG_DISABLE_FOGDisables depth-based or volumetric fog on this material
22FLAG_DISABLE_SPECULAR_OCCLUSIONDisables specular occlusion
23FLAG_USE_Z_CLIP_SCALEEnables the use of z_clip_scale
24FLAG_USE_FOV_OVERRIDEEnables the use of fov_override

Examples

Toggle various material's flags on a model
local entity = model.create("character")

--Disable depth test so the material always renders on top
entity:set_material_flag("Skeleton3D/Body", "outline", 0, true)

--Disable shadow receiving on a material
entity:set_material_flag("Skeleton3D/Head", "face", 13, false)

--Enable ambient occlusion from UV2 on all body materials using a wildcard
entity:set_material_flag("Skeleton3D/Body", "*", 10, true)

--Restore depth test on the outline material
entity:set_material_flag("Skeleton3D/Body", "outline", 0, false)

On this page