|
@@ -83,18 +83,12 @@ private class DrawableShader extends h3d.impl.Shader {
|
|
|
|
|
|
#elseif (js || cpp)
|
|
|
|
|
|
+
|
|
|
public var hasColorKey : Bool;
|
|
|
|
|
|
// not supported
|
|
|
- public var skew : Float;
|
|
|
public var sinusDeform : h3d.Vector;
|
|
|
- public var hasAlphaMap : Bool;
|
|
|
- public var hasMultMap : Bool;
|
|
|
- public var multMap : h3d.mat.Texture;
|
|
|
- public var multUV : h3d.Vector;
|
|
|
- public var multMapFactor : Float;
|
|
|
- public var alphaMap : h3d.mat.Texture;
|
|
|
- public var alphaUV : h3d.Vector;
|
|
|
+
|
|
|
// --
|
|
|
|
|
|
public var filter : Bool;
|
|
@@ -103,11 +97,14 @@ private class DrawableShader extends h3d.impl.Shader {
|
|
|
public var hasAlpha : Bool;
|
|
|
public var hasVertexAlpha : Bool;
|
|
|
public var hasVertexColor : Bool;
|
|
|
+ public var hasAlphaMap : Bool;
|
|
|
+ public var hasMultMap : Bool;
|
|
|
+ public var isAlphaPremul : Bool;
|
|
|
|
|
|
- override function customSetup(driver:h3d.impl.GlDriver) {
|
|
|
- driver.setupTexture(tex, None, filter ? Linear : Nearest, tileWrap ? Repeat : Clamp);
|
|
|
- }
|
|
|
-
|
|
|
+ /**
|
|
|
+ * This is the constant set, they are set / compiled for first draw and will enabled on all render thereafter
|
|
|
+ *
|
|
|
+ */
|
|
|
override function getConstants( vertex : Bool ) {
|
|
|
var cst = [];
|
|
|
if( vertex ) {
|
|
@@ -124,6 +121,9 @@ private class DrawableShader extends h3d.impl.Shader {
|
|
|
}
|
|
|
if( hasVertexAlpha ) cst.push("#define hasVertexAlpha");
|
|
|
if( hasVertexColor ) cst.push("#define hasVertexColor");
|
|
|
+ if( hasAlphaMap ) cst.push("#define hasAlphaMap");
|
|
|
+ if( hasMultMap ) cst.push("#define hasMultMap");
|
|
|
+ if( isAlphaPremul ) cst.push("#define isAlphaPremul");
|
|
|
return cst.join("\n");
|
|
|
}
|
|
|
|
|
@@ -145,7 +145,7 @@ private class DrawableShader extends h3d.impl.Shader {
|
|
|
#end
|
|
|
uniform vec3 matA;
|
|
|
uniform vec3 matB;
|
|
|
- uniform lowp float zValue;
|
|
|
+ uniform float zValue;
|
|
|
|
|
|
#if hasUVPos
|
|
|
uniform vec2 uvPos;
|
|
@@ -154,10 +154,10 @@ private class DrawableShader extends h3d.impl.Shader {
|
|
|
uniform vec2 uvScale;
|
|
|
#end
|
|
|
|
|
|
- varying lowp vec2 tuv;
|
|
|
+ varying vec2 tuv;
|
|
|
|
|
|
void main(void) {
|
|
|
- vec3 spos = vec3(pos.xy, 1.0);
|
|
|
+ vec3 spos = vec3(pos.x,pos.y, 1.0);
|
|
|
#if hasSize
|
|
|
spos = spos * size;
|
|
|
#end
|
|
@@ -167,7 +167,7 @@ private class DrawableShader extends h3d.impl.Shader {
|
|
|
tmp.z = zValue;
|
|
|
tmp.w = 1.;
|
|
|
gl_Position = tmp;
|
|
|
- vec2 t = uv;
|
|
|
+ lowp vec2 t = uv;
|
|
|
#if hasUVScale
|
|
|
t *= uvScale;
|
|
|
#end
|
|
@@ -187,43 +187,72 @@ private class DrawableShader extends h3d.impl.Shader {
|
|
|
|
|
|
static var FRAGMENT = "
|
|
|
|
|
|
- varying lowp vec2 tuv;
|
|
|
+ varying vec2 tuv;
|
|
|
uniform sampler2D tex;
|
|
|
|
|
|
#if hasVertexAlpha
|
|
|
- varying lowp float talpha;
|
|
|
+ varying float talpha;
|
|
|
#end
|
|
|
+
|
|
|
#if hasVertexColor
|
|
|
- varying lowp vec4 tcolor;
|
|
|
+ varying vec4 tcolor;
|
|
|
+ #end
|
|
|
+
|
|
|
+ #if hasAlphaMap
|
|
|
+ uniform vec4 alphaUV;
|
|
|
+ uniform sampler2D alphaMap;
|
|
|
+ #end
|
|
|
+
|
|
|
+ #if hasMultMap
|
|
|
+ uniform float multMapFactor;
|
|
|
+ uniform vec4 multUV;
|
|
|
+ uniform sampler2D multMap;
|
|
|
#end
|
|
|
|
|
|
- uniform lowp float alpha;
|
|
|
- uniform lowp vec3 colorKey/*byte4*/;
|
|
|
+ uniform float alpha;
|
|
|
+ uniform vec3 colorKey/*byte4*/;
|
|
|
|
|
|
- uniform lowp vec4 colorAdd;
|
|
|
- uniform lowp vec4 colorMul;
|
|
|
- uniform mediump mat4 colorMatrix;
|
|
|
+ uniform vec4 colorAdd;
|
|
|
+ uniform vec4 colorMul;
|
|
|
+ uniform mat4 colorMatrix;
|
|
|
|
|
|
void main(void) {
|
|
|
- lowp vec4 col = texture2D(tex, tuv);
|
|
|
+ vec4 col = texture2D(tex, tuv).rgba;
|
|
|
+
|
|
|
#if killAlpha
|
|
|
- if( c.a - 0.001 ) discard;
|
|
|
+ if( col.a - 0.001 <= 0.0 ) discard;
|
|
|
#end
|
|
|
+
|
|
|
#if hasColorKey
|
|
|
- lowp vec3 dc = col.rgb - colorKey;
|
|
|
- if( dot(dc,dc) < 0.001 ) discard;
|
|
|
- #end
|
|
|
- #if hasAlpha
|
|
|
- col.w *= alpha;
|
|
|
+ vec3 dc = col.rgb - colorKey;
|
|
|
+ if( dot(dc, dc) < 0.00001 ) discard;
|
|
|
#end
|
|
|
+
|
|
|
+ #if isAlphaPremul
|
|
|
+ col.rgb /= col.a;
|
|
|
+ #end
|
|
|
+
|
|
|
#if hasVertexAlpha
|
|
|
col.a *= talpha;
|
|
|
- #end
|
|
|
+ #end
|
|
|
+
|
|
|
#if hasVertexColor
|
|
|
col *= tcolor;
|
|
|
#end
|
|
|
+
|
|
|
+ #if hasAlphaMap
|
|
|
+ col.a *= texture2D( alphaMap, tuv * alphaUV.zw + alphaUV.xy).r;
|
|
|
+ #end
|
|
|
+
|
|
|
+ #if hasMultMap
|
|
|
+ col *= multMapFactor * texture2D(multMap,tuv * multUV.zw + multUV.xy);
|
|
|
+ #end
|
|
|
+
|
|
|
+ #if hasAlpha
|
|
|
+ col.a *= alpha;
|
|
|
+ #end
|
|
|
#if hasColorMatrix
|
|
|
- col = colorMatrix * col;
|
|
|
+ col *= colorMatrix;
|
|
|
#end
|
|
|
#if hasColorMul
|
|
|
col *= colorMul;
|
|
@@ -231,6 +260,11 @@ private class DrawableShader extends h3d.impl.Shader {
|
|
|
#if hasColorAdd
|
|
|
col += colorAdd;
|
|
|
#end
|
|
|
+
|
|
|
+ #if isAlphaPremul
|
|
|
+ col.rgb *= col.a;
|
|
|
+ #end
|
|
|
+
|
|
|
gl_FragColor = col;
|
|
|
}
|
|
|
|
|
@@ -248,7 +282,9 @@ class Drawable extends Sprite {
|
|
|
var shader : DrawableShader;
|
|
|
|
|
|
public var alpha(get, set) : Float;
|
|
|
+ #if !openfl
|
|
|
public var skew(get, set) : Null<Float>;
|
|
|
+ #end
|
|
|
|
|
|
public var filter(get, set) : Bool;
|
|
|
public var color(get, set) : h3d.Vector;
|
|
@@ -273,10 +309,11 @@ class Drawable extends Sprite {
|
|
|
function new(parent) {
|
|
|
super(parent);
|
|
|
shader = new DrawableShader();
|
|
|
+ writeAlpha = true;
|
|
|
+ blendMode = Normal;
|
|
|
shader.alpha = 1;
|
|
|
shader.zValue = 0;
|
|
|
writeAlpha = true;
|
|
|
- blendMode = Normal;
|
|
|
}
|
|
|
|
|
|
inline function get_alpha() {
|
|
@@ -294,6 +331,7 @@ class Drawable extends Sprite {
|
|
|
return b;
|
|
|
}
|
|
|
|
|
|
+ #if !openfl
|
|
|
inline function get_skew() : Null<Float> {
|
|
|
return shader.skew;
|
|
|
}
|
|
@@ -301,6 +339,7 @@ class Drawable extends Sprite {
|
|
|
inline function set_skew(v : Null<Float> ) {
|
|
|
return shader.skew = skew;
|
|
|
}
|
|
|
+ #end
|
|
|
|
|
|
inline function get_multiplyFactor() {
|
|
|
return shader.multMapFactor;
|
|
@@ -400,13 +439,18 @@ class Drawable extends Sprite {
|
|
|
if( tile == null )
|
|
|
tile = core.nullTile;
|
|
|
|
|
|
+ var tex : h3d.mat.Texture = tile.getTexture();
|
|
|
+ tex.filter = filter ? Linear : Nearest;
|
|
|
+
|
|
|
+ var isTexPremul = tex.flags.has(AlphaPremultiplied);
|
|
|
+
|
|
|
switch( blendMode ) {
|
|
|
case Normal:
|
|
|
- mat.blend(SrcAlpha, OneMinusSrcAlpha);
|
|
|
+ mat.blend(isTexPremul ? One : SrcAlpha, OneMinusSrcAlpha);
|
|
|
case None:
|
|
|
mat.blend(One, Zero);
|
|
|
case Add:
|
|
|
- mat.blend(SrcAlpha, One);
|
|
|
+ mat.blend(isTexPremul ? One : SrcAlpha, One);
|
|
|
case SoftAdd:
|
|
|
mat.blend(OneMinusDstColor, One);
|
|
|
case Multiply:
|
|
@@ -458,6 +502,12 @@ class Drawable extends Sprite {
|
|
|
tmp.z = absY + tile.dx * matB + tile.dy * matD;
|
|
|
shader.matB = tmp;
|
|
|
shader.tex = tile.getTexture();
|
|
|
+ /*
|
|
|
+ shader.isAlphaPremul = isTexPremul
|
|
|
+ && (shader.hasAlphaMap || shader.hasAlpha || shader.hasMultMap
|
|
|
+ || shader.hasVertexAlpha || shader.hasVertexColor
|
|
|
+ || shader.colorMatrix != null || shader.colorAdd != null
|
|
|
+ || shader.colorMul != null );*/
|
|
|
mat.shader = shader;
|
|
|
engine.selectMaterial(mat);
|
|
|
}
|