序列帧动画Shader
序列帧动画Shader效果
制作一张序列帧动画贴图
可以使用TexturePackerGUI,制作起来很方便
动画效果:
GLSL代码
vertex shader
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
precision mediump float;
attribute vec3 kzPosition;
attribute vec2 kzTextureCoordinate0;
uniform highp mat4 kzProjectionCameraWorldMatrix;
uniform vec2 TextureOffset;
uniform vec2 TextureTiling;
varying vec2 vTexCoord;
varying vec2 AnimUV;
uniform vec2 TextureScale;
uniform int Index;//控制
void main()
{
vTexCoord = kzTextureCoordinate0;
float indexY = floor(float(Index)/TextureScale.x);
float indexX = float(Index)-TextureScale.x*indexY;
AnimUV = vec2(vTexCoord.x/TextureScale.x,vTexCoord.y/TextureScale.y);
AnimUV.x += indexX/TextureScale.x;
AnimUV.y += (TextureScale.y-1.0-indexY)/TextureScale.y;//反转方向
gl_Position = kzProjectionCameraWorldMatrix * vec4(kzPosition.xyz, 1.0);
}
fragment shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
precision mediump float;
uniform sampler2D Texture;
uniform float BlendIntensity;
varying vec2 vTexCoord;
varying vec2 AnimUV;
void main()
{
vec4 color = texture2D(Texture, AnimUV);
gl_FragColor.rgb = color.rgb ;
gl_FragColor.a = BlendIntensity;
}
本文由作者按照 CC BY 4.0 进行授权