S&box Wiki

History for Shader States

Revision Difference

Shader_States#545913

<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. ## 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 | `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` | ## Example usage ``` PS { #include "common/pixel.hlsl" RenderState( DepthEnable, false ); // Disable depth testing 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: 14ms

DB GetPage 3
Get RevNew 1
Get RevOld 6
Render Body 0
Render Sidebar 1