- Create fx file
- Write fx code
- Compile fx file into ps file
- Set Build-Action on the fx file in Visual Studio to Content
- Set Build-Action on the ps file in Visual Studio to Resource
HLSL Shader Compiler is called fxc.exe
(Direct3D Shader Compiler) and it
can be located in C:\Program Files (x86)\Windows Kits\10\bin\x86\fxc.exe
Example on compile command with "/Fc -> output assembly code listing file" => cod file:
fxc.exe /T ps_2_0 /E main /WX /O0 /Fc /Zi /Fo ContrastAdjust.ps ContrastAdjust.fx
Example on compile:
fxc.exe /T ps_2_0 /E main /WX /O0 /Fo ContrastAdjust.ps ContrastAdjust.fx
Code example for ContrastAdjust:
sampler2D Input : register(s0);
float Brightness : register(c0);
float Contrast : register(c1);
float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 color = tex2D(Input, uv);
float4 result = color;
result = color + Brightness;
result = ((result - 0.5) * pow((Contrast + 1.0) / 1.0, 2)) + 0.5;
result.a = color.a;
return result;
}
Output assembly code listing file "cod file" for ContrastAdjust:
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
// Parameters:
//
// float Brightness;
// float Contrast;
// sampler2D Input;
//
//
// Registers:
//
// Name Reg Size
// ------------ ----- ----
// Brightness c0 1
// Contrast c1 1
// Input s0 1
//
ps_2_0
def c2, -0.5, 1, 0.5, 0
dcl t0.xy // uv<0,1>
dcl_2d s0
#line 7 "C:\Code\atc-net\atc-wpf\src\Atc.Wpf\Media\ShaderEffects\Shaders\ContrastAdjust.fx"
texld r0, t0, s0 // ::color<0,1,2,3>
#line 10
mov r1.w, c2.y
add r1.x, r1.w, c1.x
mul r1.x, r1.x, r1.x
add r1.yzw, r0.wzyx, c0.x // ::result<2,1,0>
add r1.yzw, r1, c2.x
mad r0.xyz, r1.wzyx, r1.x, c2.z // ::result<0,1,2>
mov oC0, r0 // ::main<0,1,2,3>
// approximately 8 instruction slots used (1 texture, 7 arithmetic)
Actual script:
fxc.exe /T ps_2_0 /E main /WX /O0 /Fo ContrastAdjust.ps ContrastAdjust.fx
fxc.exe /T ps_2_0 /E main /WX /O0 /Fo Desaturate.ps Desaturate.fx
fxc.exe /T ps_2_0 /E main /WX /O0 /Fo Fade.ps Fade.fx
fxc.exe /T ps_2_0 /E main /WX /O0 /Fo InvertColors.ps InvertColors.fx
fxc.exe /T ps_2_0 /E main /WX /O0 /Fo Monochrome.ps Monochrome.fx
fxc.exe /T ps_2_0 /E main /WX /O0 /Fo Saturate.ps Saturate.fx