#if _dx_ > 11 cbuffer cbChangeOnCamera : register(b0) { matrix mViewProj; }; cbuffer cbPosition : register(b1) { matrix mWorld; }; cbuffer cbColor : register(b2) { float4 vFontColor; }; Texture2D FontTexture : register(t0); Texture3D FontTexture3D : register(t0); SamplerState FontTextureSampler : register(s1); // static sampler -> share root sig #elif _dx_ > 9 cbuffer cbChangeOnCamera : register(b0) { matrix mViewProj; }; cbuffer cbPosition : register(b1) { matrix mWorld; }; cbuffer cbColor : register(b2) { float4 vFontColor; }; Texture2D FontTexture : register(t0); Texture3D FontTexture3D : register(t0); SamplerState FontTextureSampler : register(s0); #else uniform row_major float4x4 mViewProj : register(c0); uniform row_major float4x4 mWorld : register(c4); uniform float4 vFontColor : register(c8); texture FontTexture : register(t0); sampler2D FontTexture_Sampler2D : register(s0) { Texture = ; MinFilter = Point; MipFilter = Point; MagFilter = Point; AddressU = Border; AddressV = Border; }; sampler3D FontTexture_Sampler3D : register(s0) { Texture = ; MinFilter = Point; MipFilter = Point; MagFilter = Point; AddressU = Border; AddressV = Border; AddressW = Border; }; #endif struct VS_INPUT_X { float2 Pos : POSITION; float2 Tex : TEXCOORD; float4 Color : COLOR; }; struct VS_OUTPUT_X { float4 Pos : SV_POSITION; float2 Tex : TEXCOORD0; float4 Color : COLOR0; }; // Vertex Shader VS_OUTPUT_X VS_X(VS_INPUT_X In) { VS_OUTPUT_X Out; #if (_dx_ <= 12) Out.Pos = mul(float4(In.Pos.xy, 0.5f, 1.0f), mViewProj); #else Out.Pos = mul(float4(In.Pos.xy, 0.5f, 1.0f), mWorld); Out.Pos = mul(Out.Pos, mViewProj); #endif Out.Tex = In.Tex; Out.Color = In.Color; return Out; } // Pixel Shader (Single Layer) float4 PS_X(VS_OUTPUT_X In) : SV_TARGET { float2 vUV = In.Tex.xy; #if _dx_ > 9 float4 vColor = FontTexture.Sample(FontTextureSampler, vUV.xy); float fValue = vColor.r; // DirectX 10/11/12 Support DXGI_FORMAT_R8_UINT Only(DXGI_FORMAT_A8_UINT don't exist) #else float4 vColor = tex2D(FontTexture_Sampler2D, vUV.xy); float fValue = vColor.r; // D3DFMT_L8 >> R #endif float4 vOutput; // RGBA vOutput.r = In.Color.r; vOutput.g = In.Color.g; vOutput.b = In.Color.b; vOutput.a = In.Color.a*fValue; return vOutput; } float MaskTest(float fValue, float fLayer) { if (fValue < 1.0f) return 0.0f; float fPowValue = fLayer; float fPowValue1 = fLayer*2.0f; if (fValue < fPowValue) return 0.0f; float fRem = fmod(fValue, fPowValue1); if (fRem >= fPowValue) return 1.0f; else return 0.0f; } // Pixel Shader (24x Layer) float4 PS_24X(VS_OUTPUT_X In) : SV_TARGET { float2 vUV = In.Tex.xy; //float fLayer = In.Tex.z; float fLayer = 0.0f; #if _dx_ > 9 float4 vColor = FontTexture.Sample(FontTextureSampler, vUV); #else float4 vColor = tex2D(FontTexture_Sampler2D, vUV); #endif float fValue = vColor.r; if (fValue < 1.0f) discard; // Skip float fPowValue = fLayer; float fPowValue1 = fLayer*2.0f; if (fValue < fPowValue) discard; // Skip float fRem = fmod(fValue, fPowValue1); if (fRem < fPowValue) discard; // Skip else return vFontColor; return float4(0.5f, 0.25f, 0.25f, 1.0f); } float4 GetTex2DColor(float2 v2In) { float4 vOutColor; #if _dx_ > 9 float4 vColor = FontTexture.Sample(FontTextureSampler, v2In); float fValue = vColor.r; // DirectX 10/11/12 Support DXGI_FORMAT_R8_UINT Only(DXGI_FORMAT_A8_UINT don't exist) #else float4 vColor = tex2D(FontTexture_Sampler2D, v2In); float fValue = vColor.r; // D3DFMT_L8 >> R #endif vOutColor.r = fValue; vOutColor.g = fValue; vOutColor.b = fValue; vOutColor.a = fValue; return vOutColor; } float4 BoxBlur_CB(float2 vTex, float fX, float fY) { float4 v4Color = float4(0, 0, 0, 0); float2 v2Blur; v2Blur.y = vTex.y; const float fRange = 5.0; const float fMid = fRange * 0.5 + 0.5; const float fMidVal = fRange * 0.5 - 0.5; float fWeightSum = 0.0; for (float i = 0.0; i < fRange; i += 1.0) { v2Blur.x = vTex.x + (i - fMidVal) * fX; for (float j = 0.0; j < fRange; j += 1.0) { v2Blur.y = vTex.y + (j - fMidVal) * fY; float fWeight = 1.0; fWeightSum = fWeightSum + fWeight; v4Color += GetTex2DColor(v2Blur.xy) * fWeight; } } v4Color = v4Color / fWeightSum; v4Color.a = 1.0; return v4Color; } float4 CrossBlur_CB(float2 vTex, float fX, float fY) { float4 v4Color = float4(0, 0, 0, 0); float2 v2Blur; const float fRange = 20.0; const float fMid = fRange * 0.5 + 0.5; const float fMidVal = fRange * 0.5 - 0.5; float fWeightSum = 0.0; for (float i = 0.0; i < fRange; i += 1.0) { v2Blur.x = vTex.x + (i - fMidVal) * fX; if (abs(i - fMidVal) <= 4.5) { for (float j = 0.0; j < fRange; j += 1.0) { if (abs(j - fMidVal) <= 4.5) { v2Blur.y = vTex.y + (j - fMidVal) * fY; float fWeight = 1.0; fWeightSum = fWeightSum + fWeight; v4Color += GetTex2DColor(v2Blur.xy) * fWeight; } } } } v4Color = v4Color / fWeightSum; v4Color.a = 1.0; return v4Color; } float4 XBlur_CB(float2 vTex, float fX, float fY) { float4 v4Color = float4(0, 0, 0, 0); float2 v2Blur; const float fRange = 20.0; const float fMid = fRange * 0.5 + 0.5; const float fMidVal = fRange * 0.5 - 0.5; float fWeightSum = 0.0; for (float i = 0.0; i < fRange; i += 1.0) { v2Blur.x = vTex.x + (i - fMidVal) * fX; for (float j = 0.0; j < fRange; j += 1.0) { if (i == j || i == (fRange - 1.0 - j)) { v2Blur.y = vTex.y + (j - fMidVal) * fY; float fWeight = 1.0; fWeightSum = fWeightSum + fWeight; v4Color += GetTex2DColor(v2Blur.xy) * fWeight; } } } v4Color = v4Color / fWeightSum; v4Color.a = 1.0; return v4Color; } float4 CircleBlur_CB(float2 vTex, float fX, float fY) { float4 v4Color = float4(0, 0, 0, 0); float2 v2Blur; const float fRange = 30.0; const float fMid = fRange * 0.5 + 0.5; const float fMidVal = fRange * 0.5 - 0.5; float fWeightSum = 0.0; for (float i = 0.0; i < fRange; i += 1.0) { v2Blur.x = vTex.x + fX * (i - fMidVal); for (float j = 0.0; j < fRange; j += 1.0) { v2Blur.y = vTex.y + fY * (j - fMidVal); float fWeight; float fDis; fWeight = (i - fMidVal) * (i - fMidVal) + (j - fMidVal) * (j - fMidVal); fDis = sqrt(fWeight); if (fDis <= fRange * 0.5) { fWeight = 1.0 / fDis; fWeightSum = fWeightSum + fWeight; v4Color += GetTex2DColor(v2Blur.xy) * fWeight; } } } v4Color = v4Color / fWeightSum; v4Color.a = 1.0; return v4Color; } float4 PS_G(VS_OUTPUT_X In) : SV_TARGET { float2 vUV = In.Tex.xy; float fValue; fValue = BoxBlur_CB(vUV, ddx(vUV.x), ddy(vUV.y)).r; fValue = fValue * 0.75f; fValue += GetTex2DColor(vUV).r; float4 vOutput; vOutput.r = In.Color.r; vOutput.g = In.Color.g; vOutput.b = In.Color.b; vOutput.a = In.Color.a*fValue; return vOutput; }