Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Vertex
- {
- float4 pos : POSITION;
- float2 tex : TEXTURE;
- float3 norm : NORMAL;
- };
- struct PixelShaderArgs
- {
- float4 pos : SV_POSITION;
- float2 col : TEXTURE;
- float3 norm : NORMAL;
- };
- struct GaussianBlurShaderData
- {
- float2 Resolution;
- float Intensity;
- float Padding;
- };
- Texture2D ShaderTexture : register(t0);
- SamplerState Sampler : register(s0);
- float4x4 localMatrix : register(b0);
- cbuffer GaussianBlurShaderDataBuffer : register(b1)
- {
- GaussianBlurShaderData GaussianData;
- };
- PixelShaderArgs VertexShaderMain(Vertex vertex)
- {
- PixelShaderArgs output;
- output.pos = vertex.pos;
- output.col = vertex.tex;
- return output;
- }
- float Curve(float x)
- {
- x = x * 2.0 - 1.0;
- return -x * abs(x) * 0.5 + x + 0.5;
- }
- float4 GaussianBlur(float2 size, float2 uv, float radius)
- {
- if (radius >= 1.0)
- {
- float4 a = float4(0,0,0,0);
- float4 c = float4(0,0,0,0);
- float width = 1.0 / size.x;
- float divisor = 0.0;
- float weight = 0.0;
- float multiplier = 1.0 / radius;
- for (float x = -radius; x <= radius; x++)
- {
- a = ShaderTexture.Sample(Sampler, uv + float2(x * width, 0.0));
- weight = Curve(1.0 - (abs(x) * multiplier));
- c += a * weight;
- divisor += weight;
- }
- return float4(c.r / divisor, c.g / divisor, c.b / divisor, 1.0);
- }
- return ShaderTexture.Sample(Sampler, uv);
- }
- float4 PixelShaderMain(PixelShaderArgs pixelShaderArgs) : SV_Target
- {
- float2 uv = pixelShaderArgs.pos.xy / GaussianData.Resolution.xy;
- return GaussianBlur( GaussianData.Resolution.xy, uv, GaussianData.Intensity);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement