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

Revision 7204, 1.7 KB checked in by sieerinn, 7 years ago (diff)

Hohtoefekti tehty ilman varjostinohjelmia

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        [unroll] for(int i=0; i<MAX_WAVES; i++)
29        {
30                float4 wave = Waves[i];
31                uv = Shock(uv, float2(wave.x, wave.y), wave.z, wave.w);
32        }
33        float3 color = tex2D(TextureSampler, uv).rgb;
34       
35        /*
36        float radius = 1.5;
37        float3 glow = float3(0, 0, 0);
38        for (int x = -5; x<5; x++) {
39                for (int y = -5; y<5; 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, radius * y / Resolution.y)).rgb;
44                }
45        }
46        glow *= 1.0 / 10.0 * 10.0;
47        color += 0.2 * glow;
48        */
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.