S&box Wiki

Shader States

Render States

Render states are set within the actual shader stages themselves. They are set by using the preprocessor definition RenderState( Name, Argument ); and you can set as many states as you like. Every state is optional and if the render state is not set it will be set to a default value. Please refer to the list below for the types of render states you can set.

RenderState( Name, Argument );

Name Valid Arguments
FillMode WIREFRAME, SOLID
CullMode NONE, BACK, FRONT
DepthBias true, false
DepthBiasClamp true, false
SlopeScaleDepthBias true, false
DepthClipEnable true, false
MultisampleEnable true, false
SampleMask true, false
DepthEnable true, false
DepthWriteEnable true, false
DepthFunc NEVER, LESS, EQUAL, LESS_EQUAL, GREATER, NOT_EQUAL, GREATER_EQUAL, ALWAYS
StencilEnable true, false
StencilReadMask A value from 0 -> 255
StencilWriteMask A value from 0 -> 255
StencilFailOp KEEP, ZERO, REPLACE, INCR_SAT, DECR_SAT, INVERT, INCR, DECR
StencilDepthFailOp KEEP, ZERO, REPLACE, INCR_SAT, DECR_SAT, INVERT, INCR, DECR
StencilPassOp KEEP, ZERO, REPLACE, INCR_SAT, DECR_SAT, INVERT, INCR, DECR
StencilFunc NEVER, LESS, EQUAL, LESS_EQUAL, GREATER, NOT_EQUAL, GREATER_EQUAL, ALWAYS
BackStencilFailOp KEEP, ZERO, REPLACE, INCR_SAT, DECR_SAT, INVERT, INCR, DECR
BackStencilDepthFailOp KEEP, ZERO, REPLACE, INCR_SAT, DECR_SAT, INVERT, INCR, DECR
BackStencilPassOp KEEP, ZERO, REPLACE, INCR_SAT, DECR_SAT, INVERT, INCR, DECR
BackStencilFunc NEVER, LESS, EQUAL, LESS_EQUAL, GREATER, NOT_EQUAL, GREATER_EQUAL, ALWAYS
StencilRef A value from 0 -> 255
AlphaToCoverageEnable true, false
BlendEnable true, false
IndependentBlendEnable true, false
SrcBlend ZERO, ONE, SRC_COLOR, INV_SRC_COLOR, SRC_ALPHA, INV_SRC_ALPHA, DEST_ALPHA, INV_DEST_ALPHA, DEST_COLOR, INV_DEST_COLOR, SRC_ALPHA_SAT, BLEND_FACTOR, SRC1_COLOR, INV_SRC1_COLOR, SRC1_ALPHA, INV_SRC1_ALPHA
DstBlend ZERO, ONE, SRC_COLOR, INV_SRC_COLOR, SRC_ALPHA, INV_SRC_ALPHA, DEST_ALPHA, INV_DEST_ALPHA, DEST_COLOR, INV_DEST_COLOR, SRC_ALPHA_SAT, BLEND_FACTOR, SRC1_COLOR, INV_SRC1_COLOR, SRC1_ALPHA, INV_SRC1_ALPHA
BlendOp ADD, SUBTRACT, REV_SUBTRACT, MIN, MAX
SrcBlendAlpha ZERO, ONE, SRC_COLOR, INV_SRC_COLOR, SRC_ALPHA, INV_SRC_ALPHA, DEST_ALPHA, INV_DEST_ALPHA, DEST_COLOR, INV_DEST_COLOR, SRC_ALPHA_SAT, BLEND_FACTOR, SRC1_COLOR, INV_SRC1_COLOR, SRC1_ALPHA, INV_SRC1_ALPHA
DstBlendAlpha ZERO, ONE, SRC_COLOR, INV_SRC_COLOR, SRC_ALPHA, INV_SRC_ALPHA, DEST_ALPHA, INV_DEST_ALPHA, DEST_COLOR, INV_DEST_COLOR, SRC_ALPHA_SAT, BLEND_FACTOR, SRC1_COLOR, INV_SRC1_COLOR, SRC1_ALPHA, INV_SRC1_ALPHA
BlendOpAlpha ADD, SUBTRACT, REV_SUBTRACT, MIN, MAX
ColorWriteEnable0 false, R, G, B, A, RG, RB, RA, GB, GA, BA, GBA, RBA, RGA, RGB, RGBA
ColorWriteEnable1 false, R, G, B, A, RG, RB, RA, GB, GA, BA, GBA, RBA, RGA, RGB, RGBA
ColorWriteEnable2 false, R, G, B, A, RG, RB, RA, GB, GA, BA, GBA, RBA, RGA, RGB, RGBA
ColorWriteEnable3 false, R, G, B, A, RG, RB, RA, GB, GA, BA, GBA, RBA, RGA, RGB, RGBA
SrgbWriteEnable0 true, false
SrgbWriteEnable1 true, false
SrgbWriteEnable2 true, false
SrgbWriteEnable3 true, false
BlendFactor true, false
HighPrecisionBlendEnable true, false
AlphaTestEnable true, false
AlphaTestRef true, false
AlphaTestFunc NEVER, LESS, EQUAL, LESS_EQUAL, GREATER, NOT_EQUAL, GREATER_EQUAL, ALWAYS

Example usage

PS { #include "common/pixel.hlsl" RenderState( CullMode, NONE ); // Always render backfaces RenderState( BlendEnable, true ); // Enable blending, used for transparency RenderState( AlphaToCoverageEnable, true ); // Proper transparency sorting // These are likely not compatible with BlendEnable and AlphaToCoverage, they're included as an example: RenderState( DepthEnable, false ); // Disable depth testing RenderState( DepthWriteEnable, false ); // Don't write to the depth buffer RenderState( DepthFunc, LESS_EQUAL ); // Set depth function, not needed! RenderState( FillMode, WIREFRAME ); // Render the wireframe of the model // // Main // float4 MainPs( PixelInput i ) : SV_Target0 { Material m = Material::From( i ); return ShadingModelStandard::Shade( i, m ); } }