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

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

Lisätty oranssin tiilen kuvat, varjostinsäätöä ja Blender tiedostot

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        float radius = 4.0;
36        float3 glow = float3(0, 0, 0);
37        for (int x = -3; x<3; x++) {
38                for (int y = -3; y<3; y++) {
39                        float w = 0.0;
40                        if (!(x == 0 && y == 0))
41                                w = 0.1 * 1.0 / sqrt(float(x*x + y*y));
42                        glow += w * tex2D(TextureSampler, uv + float2(radius * x / Resolution.x, radius * y / Resolution.y)).rgb;
43                }
44        }
45        glow *= 1.0 / 6.0 * 6.0;
46        color += 0.6 * glow;
47
48        return float4(color, 1);
49}
50
51
52void SpriteVertexShader(inout float4 color    : COLOR0,
53                        inout float2 texCoord : TEXCOORD0,
54                        inout float4 position : SV_Position)
55{
56    position = mul(position, MatrixTransform);
57}
58
59technique Technique1
60{
61    pass Pass1
62    {
63        VertexShader = compile vs_3_0 SpriteVertexShader();
64        PixelShader = compile ps_3_0 PixShader();
65    }
66}
Note: See TracBrowser for help on using the repository browser.