source: 2016/23/ohjaajat/Punasininen/Punasininen/PunasininenContent/Shockwave.fx @ 7198

Revision 7198, 1.7 KB checked in by sieerinn, 3 years ago (diff)

Varjostinohjelmakikkailua

Line 
1static const int MAX_WAVES = 3;
2float4 Waves[MAX_WAVES];
3float2 Resolution;
4
5float4x4 MatrixTransform;
6sampler TextureSampler: register(s0);
7
8
9float2 Shock(float2 uv, float2 center, float time, float coefficient)
10{
11        float3 shockParams = float3(10.0, 0.9, 0.1);
12
13        float dist = distance(uv, center);
14        if ((dist <= time + shockParams.z) && (dist >= time - shockParams.z))
15        {
16                float diff = dist - time;
17                float powDiff = 1.0 - pow(abs(diff * shockParams.x), shockParams.y);
18                float diffTime = diff * powDiff;
19                float2 diffUV = normalize(uv - center);
20                uv += diffUV * diffTime * coefficient;
21        }
22        return uv;
23}
24
25float4 PixShader(float2 texCoord: TEXCOORD0) : COLOR0
26{
27        float2 uv = texCoord;
28       
29        [unroll] for(int i=0; i<MAX_WAVES; i++)
30        {
31                float4 wave = Waves[i];
32                uv = Shock(uv, float2(wave.x, wave.y), wave.z, wave.w);
33        }
34        float3 color = tex2D(TextureSampler, uv).rgb;
35
36        float radius = 5.0;
37        float3 glow = float3(0, 0, 0);
38        for (int x = -3; x<3; x++) {
39                for (int y = -3; y<3; y++) {
40                        float w = 0.0;
41                        if (!(x == 0 && y == 0))
42                                w = 0.1 * 1.0 / sqrt(float(x*x + y*y));
43                        glow += w * tex2D(TextureSampler, uv + float2(radius * x / Resolution.x,
44                                radius * y / Resolution.y)).rgb;
45                }
46        }
47        glow *= 1.0 / 6.0 * 6.0;
48        color += 1.0 * glow;
49
50        return float4(color, 1);
51}
52
53
54void SpriteVertexShader(inout float4 color    : COLOR0,
55                        inout float2 texCoord : TEXCOORD0,
56                        inout float4 position : SV_Position)
57{
58    position = mul(position, MatrixTransform);
59}
60
61technique Technique1
62{
63    pass Pass1
64    {
65        VertexShader = compile vs_3_0 SpriteVertexShader();
66        PixelShader = compile ps_3_0 PixShader();
67    }
68}
Note: See TracBrowser for help on using the repository browser.