source: 2015/koodauskerho/sieerinn/JypeliShaderTest/JypeliShaderTest/JypeliShaderTestContent/Shockwave.fx @ 7176

Revision 7176, 1.3 KB checked in by sieerinn, 6 years ago (diff)
Line 
1
2static const int MAX_WAVES = 8;
3float4 Waves[MAX_WAVES];
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        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
35        float3 color = tex2D(TextureSampler, uv).rgb;
36        return float4(color, 1);
37}
38
39
40void SpriteVertexShader(inout float4 color    : COLOR0,
41                        inout float2 texCoord : TEXCOORD0,
42                        inout float4 position : SV_Position)
43{
44    position = mul(position, MatrixTransform);
45}
46
47technique Technique1
48{
49    pass Pass1
50    {
51        VertexShader = compile vs_3_0 SpriteVertexShader();
52        PixelShader = compile ps_3_0 PixShader();
53    }
54}
Note: See TracBrowser for help on using the repository browser.