|
@@ -1,81 +0,0 @@
|
|
|
-import { Effect } from "../Materials/effect";
|
|
|
-
|
|
|
-let name = 'spriteMapPixelShader';
|
|
|
-let shader = `precision highp float;
|
|
|
-varying vec3 vPosition;
|
|
|
-varying vec2 vUV;
|
|
|
-varying vec2 tUV;
|
|
|
-uniform float time;
|
|
|
-uniform float spriteCount;
|
|
|
-uniform sampler2D spriteSheet;
|
|
|
-uniform vec2 spriteMapSize;
|
|
|
-uniform vec2 outputSize;
|
|
|
-uniform vec2 stageSize;
|
|
|
-uniform float maxAnimationFrames;
|
|
|
-uniform sampler2D frameMap;
|
|
|
-uniform sampler2D tileMaps[LAYERS];
|
|
|
-uniform sampler2D animationMap;
|
|
|
-uniform vec3 colorMul;
|
|
|
-float mt;
|
|
|
-float fdStep=1./4.;
|
|
|
-mat4 getFrameData(float frameID){
|
|
|
-float fX=frameID/spriteCount;
|
|
|
-return mat4(
|
|
|
-texture(frameMap,vec2(fX,0.),0.),
|
|
|
-texture(frameMap,vec2(fX,fdStep*1.),0.),
|
|
|
-texture(frameMap,vec2(fX,fdStep*2.),0.),
|
|
|
-vec4(0.)
|
|
|
-);
|
|
|
-}
|
|
|
-void main(){
|
|
|
-vec4 color=vec4(0.);
|
|
|
-vec2 tileUV=fract(tUV);
|
|
|
-#ifdef FLIPU
|
|
|
-tileUV.y=1.0-tileUV.y;
|
|
|
-#endif
|
|
|
-vec2 tileID=floor(tUV);
|
|
|
-vec2 sheetUnits=1./spriteMapSize;
|
|
|
-float spriteUnits=1./spriteCount;
|
|
|
-vec2 stageUnits=1./stageSize;
|
|
|
-for(int i=0; i<LAYERS; i++){
|
|
|
-float frameID;
|
|
|
-switch(i){
|
|
|
-#define LAYER_ID_SWITCH
|
|
|
-}
|
|
|
-vec4 animationData=texture(animationMap,vec2((frameID+0.5)/spriteCount,0.),0.);
|
|
|
-if(animationData.y>0.){
|
|
|
-mt=mod(time*animationData.z,1.0);
|
|
|
-float aFrameSteps=1./maxAnimationFrames;
|
|
|
-for(float f=0.; f<maxAnimationFrames; f++){
|
|
|
-if(animationData.y>mt){
|
|
|
-frameID=animationData.x;
|
|
|
-break;
|
|
|
-}
|
|
|
-animationData=texture(animationMap,vec2((frameID+0.5)/spriteCount,aFrameSteps*f),0.);
|
|
|
-}
|
|
|
-}
|
|
|
-
|
|
|
-mat4 frameData=getFrameData(frameID+0.5);
|
|
|
-vec2 frameSize=(frameData[0].wz)/spriteMapSize;
|
|
|
-vec2 offset=frameData[0].xy*sheetUnits;
|
|
|
-vec2 ratio=frameData[2].xy/frameData[0].wz;
|
|
|
-
|
|
|
-if(frameData[2].z == 1.){
|
|
|
-tileUV.xy=tileUV.yx;
|
|
|
-}
|
|
|
-if(i == 0){
|
|
|
-color=texture(spriteSheet,tileUV*frameSize+offset);
|
|
|
-} else {
|
|
|
-vec4 nc=texture(spriteSheet,tileUV*frameSize+offset);
|
|
|
-float alpha=min(color.a+nc.a,1.0);
|
|
|
-vec3 mixed=mix(color.xyz,nc.xyz,nc.a);
|
|
|
-color=vec4(mixed,alpha);
|
|
|
-}
|
|
|
-}
|
|
|
-color.xyz*=colorMul;
|
|
|
-gl_FragColor=color;
|
|
|
-}`;
|
|
|
-
|
|
|
-Effect.ShadersStore[name] = shader;
|
|
|
-/** @hidden */
|
|
|
-export var spriteMapPixelShader = { name, shader };
|