LGUI2:Pixel Shaders
Jump to navigation
Jump to search
A LavishGUI 2 Pixel Shader is a piece of code that determines the color of each pixel as a scene is rendered. Pixel Shaders are supported by Brushes.
Defining a Pixel Shader
A Pixel Shader is defined by a JSON object enclosed by {}.
LavishGUI 2 supports multiple shader models in order to support many graphics engines. Different versions of DirectX allow use of different shader models:
- DirectX 9: Use ps_3_0 or ps_2_0
- DirectX 10: Additionally supports ps_4_0 and friends
- DirectX 10.1: Additionally supports ps_4_1
- DirectX 11: Additionally supports ps_5_0
- DirectX 11.1: Additionally supports ps_5_1
- DirectX 12: Additionally supports ps_6_0 (note that DirectX 12 is not yet supported)
Pixel Shader properties | |
---|---|
entryPoint | The name of the Entry Point function within the pixel shader code. Default is PS. |
useFile | A boolean (true/false) value indicating whether the pixel shader definition is a file (true) or the code itself (false). Default is false. |
ps_5_0 | Pixel Shader model 5.0 code or filename |
ps_4_1 | Pixel Shader model 4.1 code or filename |
ps_4_0 | Pixel Shader model 4.0 code or filename |
ps_4_0_level_9_3 | Pixel Shader model 4.0 level 9.3 code or filename |
ps_4_0_level_9_1 | Pixel Shader model 4.0 level 9.1 code or filename |
ps_3_0 | Pixel Shader model 3.0 code or filename |
ps_2_0 | Pixel Shader model 2.0 code or filename |
One or more pixel shader profiles can be provided. The renderer will choose the highest compatible shader model -- so for example, if both "ps_3_0" and "ps_4_0" are provided, in DirectX 9 mode the ps_3_0 shader will be used, but in DirectX 11 mode the ps_4_0 shader will be used.
Examples
- A simple solid green shader
- NOTE: Because JSON formatting does not allow multiple lines within a String, \n is used (as part of the standard) to introduce additional lines. Pixel Shader code is therefore placed on a single line with \n indicating each new line.
"pixelShader": { "entryPoint": "SimplePixelShader", "ps_4_0_level_9_1": "struct PixelShaderInput\n{\n float4 pos : SV_POSITION;\n};\nfloat4 SimplePixelShader(PixelShaderInput input) : SV_TARGET\n{\n // Draw the entire triangle green.\n return float4(0.0f, 0.2f, 0.0f, 1.0f);\n}" }
The above Pixel Shader code, formatted for you to read:
struct PixelShaderInput { float4 pos : SV_POSITION; }; float4 SimplePixelShader(PixelShaderInput input) : SV_TARGET { // Draw the entire triangle green. return float4(0.0f, 0.2f, 0.0f, 1.0f); }
LavishGUI 2 Topics