-
Notifications
You must be signed in to change notification settings - Fork 0
/
transition.rb
108 lines (95 loc) · 2.56 KB
/
transition.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# coding: UTF-8
class TransitionShader < DXRuby::Shader
hlsl = <<EOS
float g_min;
float g_max;
float2 scale;
texture tex0;
texture tex1;
sampler Samp0 = sampler_state
{
Texture =<tex0>;
};
sampler Samp1 = sampler_state
{
Texture =<tex1>;
AddressU = WRAP;
AddressV = WRAP;
};
struct PixelIn
{
float2 UV : TEXCOORD0;
};
struct PixelOut
{
float4 Color : COLOR0;
};
PixelOut PS(PixelIn input)
{
PixelOut output;
output.Color = tex2D( Samp0, input.UV );
output.Color.a *= smoothstep(g_min, g_max, tex2D( Samp1, input.UV * scale ).r );
return output;
}
technique Transition
{
pass P0
{
PixelShader = compile ps_2_0 PS();
}
}
EOS
@@core = DXRuby::Shader::Core.new(
hlsl,
{
:g_min => :float,
:g_max => :float,
:scale => :float, # HLSL側がfloat2の場合は:floatを指定して[Float, Flaot]という形で渡す
:tex1 => :texture,
}
)
# durationは遷移にかけるフレーム数、imageはルール画像のImageオブジェクト(省略でクロスフェード)、vagueは曖昧さ
def initialize(duration, image=nil, vague=nil)
super(@@core, "Transition")
if image
@image = image
@vague = vague == nil ? 40 : vague
else
@image = DXRuby::Image.new(1, 1, [0,0,0])
@vague = 256
end
@duration = duration
@count = 0
self.g_min = [email protected](@duration)
self.g_max = 0.0
self.tex1 = @image
self.scale = [DXRuby::Window.width.fdiv(@image.width), DXRuby::Window.height.fdiv(@image.height)]
# シェーダパラメータ設定のメソッドは外部非公開とする
class << self
protected :g_min, :g_min=, :g_max, :g_max=, :scale, :scale=, :tex1, :tex1=
end
end
def start(duration = nil)
@duration = duration if duration
@count = 0
self.g_min = [email protected](@duration)
self.g_max = 0.0
end
def next
@count += 1
self.g_min = (((@vague+@duration).fdiv(@duration)) * @count - @vague).fdiv(@duration)
self.g_max = (((@vague+@duration).fdiv(@duration)) * @count).fdiv(@duration)
end
def frame_count=(c)
@count = c
self.g_min = (((@vague+@duration).fdiv(@duration)) * @count - @vague).fdiv(@duration)
self.g_max = (((@vague+@duration).fdiv(@duration)) * @count).fdiv(@duration)
end
def frame_count
@count
end
# 描画対象を指定する。RenderTargetオブジェクトか、Windowを渡す。デフォルトはWindow。
def target=(t)
self.scale = [t.width.fdiv(@image.width), t.height.fdiv(@image.height)]
end
end