summaryrefslogtreecommitdiffstats
path: root/ui/gfx/resources/blur.fx
blob: 2f0de7ad457800e290098cf997eb7ad89bd53592 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Pixel shader used to do a bloom. It's expected that the consumers set
// TexelKernel before using.

Texture2D textureMap;

cbuffer cbPerObject {
  float4x4 gWVP;
};

struct VS_IN {
  float3 posL : POSITION;
  float2 texC : TEXC;
};

struct VS_OUT {
  float4 posW : SV_POSITION;
  float2 texC : TEXC;
};

SamplerState Sampler {
  Filter = MIN_MAG_MIP_POINT;
  AddressU = Clamp;
  AddressV = Clamp;
};

VS_OUT VS(VS_IN vIn) {
  VS_OUT vOut;
  vOut.posW = mul(float4(vIn.posL, 1.0f), gWVP);
  vOut.texC = vIn.texC;
  return vOut;
}

// Size of the kernel.
static const int g_cKernelSize = 13;

static const float BlurWeights[g_cKernelSize] = {
1.0f / 4096.0f,
12.0f / 4096.0f,
66.0f / 4096.0f,
220.0f / 4096.0f,
495.0f / 4096.0f,
792.0f / 4096.0f,
924.0f / 4096.0f,
792.0f / 4096.0f,
495.0f / 4096.0f,
220.0f / 4096.0f,
66.0f / 4096.0f,
12.0f / 4096.0f,
1.0f / 4096.0f,
};

// Set by consumer as it depends upon width/height of viewport.
float4 TexelKernel[g_cKernelSize];

float4 PS(VS_OUT pIn) : SV_Target {
  float4 c = 0;
  for (int i = 0; i < g_cKernelSize; i++)  {
    c += textureMap.Sample(Sampler, float2(pIn.texC) + TexelKernel[i].xy) *
                           BlurWeights[i];
  }
  return c;
}

technique10 ViewTech {
  pass P0 {
    SetVertexShader(CompileShader(vs_4_0, VS()));
    SetGeometryShader(NULL);
    SetPixelShader(CompileShader(ps_4_0, PS()));
  }
}