S&box Wiki

History for Shader States

Revision Difference

Shader_States#545916

<cat>Code.Shader</cat> <title>Shader States</title> # 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. 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. Some render states require a preprocessor definition to be set in the common header because you're handling the render state yourself. Please refer to the list below ## RenderState( Name, Argument ); | Name | Valid Arguments | | Name | Valid Arguments | Preprocessor definition | |------|-----------------| | 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 | `true`, `false` | | StencilWriteMask | `true`, `false` | | 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 | `true`, `false` | | 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` | | FillMode | `WIREFRAME`, `SOLID` | | | CullMode | `NONE`, `BACK`, `FRONT` | CULL_MODE_ALREADY_SET | | DepthBias | `true`, `false` | | | DepthBiasClamp | `true`, `false` | | | SlopeScaleDepthBias | `true`, `false` | | | DepthClipEnable | `true`, `false` | | | MultisampleEnable | `true`, `false` | | | SampleMask | `true`, `false` | | | DepthEnable | `true`, `false` | DEPTH_STATE_ALREADY_SET | | DepthWriteEnable | `true`, `false` | DEPTH_STATE_ALREADY_SET | | DepthFunc | `NEVER`, `LESS`, `EQUAL`, `LESS_EQUAL`, `GREATER`, `NOT_EQUAL`, `GREATER_EQUAL`, `ALWAYS` | DEPTH_STATE_ALREADY_SET | | StencilEnable | `true`, `false` | STENCIL_ALREADY_SET | | StencilReadMask | A value from 0 -> 255 | STENCIL_ALREADY_SET | | StencilWriteMask | A value from 0 -> 255 | STENCIL_ALREADY_SET | | 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` | STENCIL_ALREADY_SET | | StencilFunc | `NEVER`, `LESS`, `EQUAL`, `LESS_EQUAL`, `GREATER`, `NOT_EQUAL`, `GREATER_EQUAL`, `ALWAYS` | STENCIL_ALREADY_SET | | 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` | STENCIL_ALREADY_SET | | BackStencilFunc | `NEVER`, `LESS`, `EQUAL`, `LESS_EQUAL`, `GREATER`, `NOT_EQUAL`, `GREATER_EQUAL`, `ALWAYS` | STENCIL_ALREADY_SET | | StencilRef | A value from 0 -> 255 | STENCIL_ALREADY_SET | | AlphaToCoverageEnable | `true`, `false` | | | BlendEnable | `true`, `false` | BLEND_MODE_ALREADY_SET | | 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` | COLOR_WRITE_ALREADY_SET | | 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 COMMON { // Required for us to set depth #define DEPTH_STATE_ALREADY_SET } PS { #include "common/pixel.hlsl" RenderState( DepthEnable, false ); // Disable depth testing RenderState( FillMode, WIREFRAME ); // Render the wireframe of the model 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 // PixelOutput MainPs( PixelInput i ) { Material m = GatherMaterial( i ); /* m.Metalness = 1.3f; // Forces the object to be metalic */ return FinalizePixelMaterial( i, m ); } } ``` # Sampler States Sampler states dictate how you "sample" your texture. This can range from specifying how the value should wrap around the texture to what kind of filtering is used on the texture and which comparison function should be selected. Sampler states are NOT REQUIRED to be set and are OPTIONAL! ## Filter( MODE ); | Filter Modes | | ------------ | | MIN_MAG_MIP_POINT | | MIN_MAG_POINT_MIP_LINEAR | | MIN_POINT_MAG_LINEAR_MIP_POINT | | MIN_POINT_MAG_MIP_LINEAR | | MIN_LINEAR_MAG_MIP_POINT | | MIN_LINEAR_MAG_POINT_MIP_LINEAR | | MIN_MAG_LINEAR_MIP_POINT | | MIN_MAG_MIP_LINEAR | | ANISOTROPIC | | COMPARISON_MIN_MAG_MIP_POINT | | COMPARISON_MIN_MAG_POINT_MIP_LINEAR | | COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT | | COMPARISON_MIN_POINT_MAG_MIP_LINEAR | | COMPARISON_MIN_LINEAR_MAG_MIP_POINT | | COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR | | COMPARISON_MIN_MAG_LINEAR_MIP_POINT | | COMPARISON_MIN_MAG_MIP_LINEAR | | COMPARISON_ANISOTROPIC | | USER_CONFIG | | ANISO | | BILINEAR | | TRILINEAR | | POINT | | NEAREST | ## AddressU( WRAPPING )/AddressV( WRAPPING )/AddressW( WRAPPING ) | Address Wrapping Modes | | ---------------------- | | WRAP | | MIRROR | | CLAMP | | BORDER | | MIRROR_ONCE | ## ComparisonFunc( FUNC ) | Comparison Functions | | -------------------- | | NEVER | | LESS | | EQUAL | | LESS_EQUAL | | GREATER | | NOT_EQUAL | | GREATER_EQUAL | | ALWAYS | ## Example usage ``` PS { // Point filtered texture, wrapping with Clamp, Mirror and Border with the equal comparison function CreateTexture2D( g_MyTexture ) < Attribute( "MyAwesomeTexture" ); Filter( MIN_MAG_LINEAR_MIP_POINT ); AddressU( CLAMP ); AddressV( MIRROR ); AddressW( BORDER ); ComparisonFunc( EQUAL ); >; } ```

Special Pages


Wikis

?

Render Time: 17ms

DB GetPage 4
Get RevNew 1
Get RevOld 7
Render Body 0
Render Sidebar 2