185 lines
4.9 KiB
HLSL
185 lines
4.9 KiB
HLSL
static const float PixelKernel[13] = { -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6 };
|
|
static const float BlurWeights[13] = { 0.002216, 0.008764, 0.026995, 0.064759, 0.120985, 0.176033, 0.199471, 0.176033, 0.120985, 0.064759, 0.026995, 0.008764, 0.002216 };
|
|
|
|
float CurrentTime : Time;
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
// States
|
|
//--------------------------------------------------------------------------------------
|
|
BlendState NoBlending
|
|
{
|
|
BlendEnable[0] = FALSE;
|
|
RenderTargetWriteMask[0] = 0x0F;
|
|
};
|
|
|
|
DepthStencilState RenderWithoutStencilState
|
|
{
|
|
DepthEnable = false;
|
|
DepthWriteMask = ZERO;
|
|
DepthFunc = Always;
|
|
};
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
// Textures
|
|
//--------------------------------------------------------------------------------------
|
|
Texture2D ColorMap : ColorMap;
|
|
Texture2D Calculated : InputTexture;
|
|
Texture2D DistortMap : DistortMap;
|
|
SamplerState samLinear
|
|
{
|
|
Filter = ANISOTROPIC;
|
|
AddressU = Wrap;
|
|
AddressV = Wrap;
|
|
};
|
|
|
|
SamplerState samLinearClamp
|
|
{
|
|
Filter = ANISOTROPIC;
|
|
AddressU = Clamp;
|
|
AddressV = Clamp;
|
|
};
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
struct VS_OUTPUT
|
|
{
|
|
float4 Pos : SV_POSITION;
|
|
float2 Tex : TEXCOORD0;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
// Vertex Shader
|
|
//--------------------------------------------------------------------------------------
|
|
VS_OUTPUT VS(float4 Pos : POSITION, float3 Norm : NORMAL, float2 Tex : TEXCOORD)
|
|
{
|
|
VS_OUTPUT output = (VS_OUTPUT)0;
|
|
output.Pos = Pos;
|
|
output.Pos.w = 1.0f;
|
|
output.Tex = Tex;
|
|
return output;
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
// Pixel Shader
|
|
//--------------------------------------------------------------------------------------
|
|
float4 IntensityPS( VS_OUTPUT input) : SV_Target
|
|
{
|
|
float4 color = ColorMap.Sample(samLinear, input.Tex);
|
|
|
|
float3 ColorToIntensity = float3(0.294, 0.582, 0.114);
|
|
color.rgb *= ColorToIntensity;
|
|
color.rgb = color.r + color.g + color.b;
|
|
|
|
return color;
|
|
}
|
|
|
|
|
|
float4 ShowTexturePS( VS_OUTPUT input) : SV_Target
|
|
{
|
|
float4 color = Calculated.Sample(samLinear, input.Tex);
|
|
return color;
|
|
}
|
|
|
|
|
|
float4 ComposePS( VS_OUTPUT input) : SV_Target
|
|
{
|
|
const float DistortTextureScale = 8.0f;
|
|
const float DistortStrength = 10.0f;
|
|
const float DistortSpeed = 0.25f;
|
|
const float3 ColorToIntensity = float3(0.294, 0.582, 0.114);
|
|
|
|
float2 distort = (DistortMap.Sample(samLinear, DistortTextureScale * input.Tex + float2(sin(CurrentTime * DistortSpeed), cos(CurrentTime * DistortSpeed))).xy - 0.5f) * 1.0f;
|
|
|
|
// get DDX DDY of the input texture
|
|
float2 CalculatedSize;
|
|
ColorMap.GetDimensions(CalculatedSize.x, CalculatedSize.y);
|
|
CalculatedSize = 1.0f / CalculatedSize;
|
|
|
|
float4 bloom = Calculated.Sample(samLinear, input.Tex);
|
|
|
|
// bloom step
|
|
bloom = pow(bloom, 2.0f) * 2.0f;
|
|
|
|
float4 intensity = bloom;
|
|
intensity.rgb *= ColorToIntensity;
|
|
intensity.rgb = intensity.r + intensity.g + intensity.b;
|
|
float4 color = ColorMap.Sample(samLinearClamp, input.Tex + distort * CalculatedSize * intensity * DistortStrength);
|
|
|
|
return color + bloom;
|
|
}
|
|
|
|
const float pi4 = 3.141 / 4.0;
|
|
float4 BlurPS( VS_OUTPUT input) : SV_Target
|
|
{
|
|
// get DDX DDY of the input texture
|
|
float2 ddxy;
|
|
Calculated.GetDimensions(ddxy.x, ddxy.y);
|
|
ddxy = 1.0f / ddxy;
|
|
|
|
// Blur
|
|
float4 color = 0;
|
|
float2 SamplePos;
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
SamplePos = input.Tex + ddxy * 4.0 * float2(sin(pi4 * i), cos(pi4 * i));
|
|
color += Calculated.Sample(samLinearClamp, SamplePos);
|
|
}
|
|
|
|
return color / 8.0;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
technique10 Intensity
|
|
{
|
|
pass P0
|
|
{
|
|
SetVertexShader( CompileShader( vs_4_0, VS() ) );
|
|
SetGeometryShader( NULL );
|
|
SetPixelShader( CompileShader( ps_4_0, IntensityPS() ) );
|
|
SetDepthStencilState( NULL, 0 );
|
|
SetBlendState( NULL, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
|
|
}
|
|
}
|
|
|
|
|
|
technique10 ShowTexture
|
|
{
|
|
pass P0
|
|
{
|
|
SetVertexShader( CompileShader( vs_4_0, VS() ) );
|
|
SetGeometryShader( NULL );
|
|
SetPixelShader( CompileShader( ps_4_0, ShowTexturePS() ) );
|
|
SetDepthStencilState( NULL, 0 );
|
|
SetBlendState( NULL, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
|
|
}
|
|
}
|
|
|
|
|
|
technique10 Blur
|
|
{
|
|
pass P0
|
|
{
|
|
SetVertexShader( CompileShader( vs_4_0, VS() ) );
|
|
SetGeometryShader( NULL );
|
|
SetPixelShader( CompileShader( ps_4_0, BlurPS() ) );
|
|
SetDepthStencilState( NULL, 0 );
|
|
SetBlendState( NULL, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
|
|
}
|
|
}
|
|
|
|
|
|
technique10 Compose
|
|
{
|
|
pass P0
|
|
{
|
|
SetVertexShader( CompileShader( vs_4_0, VS() ) );
|
|
SetGeometryShader( NULL );
|
|
SetPixelShader( CompileShader( ps_4_0, ComposePS() ) );
|
|
SetDepthStencilState( NULL, 0 );
|
|
SetBlendState( NULL, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
|
|
}
|
|
}
|