package; import openfl.display.Shader; import openfl.utils.ByteArray; /** * ... * @author */ class MyShader extends Shader { @:glVertexHeader( "attribute float openfl_Alpha; attribute vec4 openfl_ColorMultiplier; attribute vec4 openfl_ColorOffset; attribute vec4 openfl_Position; attribute vec2 openfl_TextureCoord; varying float openfl_Alphav; varying vec4 openfl_ColorMultiplierv; varying vec4 openfl_ColorOffsetv; varying vec2 openfl_TextureCoordv; uniform mat4 openfl_Matrix; uniform bool openfl_HasColorTransform; uniform vec2 openfl_TextureSize;" ) @:glVertexBody( "openfl_Alphav = openfl_Alpha; openfl_TextureCoordv = openfl_TextureCoord; if (openfl_HasColorTransform) { openfl_ColorMultiplierv = openfl_ColorMultiplier; openfl_ColorOffsetv = openfl_ColorOffset / 255.0; } gl_Position = openfl_Matrix * openfl_Position;" ) @:glVertexSource( "#pragma header void main(void) { #pragma body }" ) @:glFragmentHeader( "varying float openfl_Alphav; varying vec4 openfl_ColorMultiplierv; varying vec4 openfl_ColorOffsetv; varying vec2 openfl_TextureCoordv; uniform bool openfl_HasColorTransform; uniform vec2 openfl_TextureSize; uniform sampler2D bitmap; uniform float custom_Value;" ) @:glFragmentBody( "vec4 color = texture2D (bitmap, openfl_TextureCoordv); if (color.a == 0.0) { gl_FragColor = vec4 (0.0, 0.0, 0.0, 0.0); } else if (openfl_HasColorTransform) { color = vec4 (color.rgb / color.a, color.a); mat4 colorMultiplier = mat4 (0); colorMultiplier[0][0] = openfl_ColorMultiplierv.x; colorMultiplier[1][1] = openfl_ColorMultiplierv.y; colorMultiplier[2][2] = openfl_ColorMultiplierv.z; colorMultiplier[3][3] = 1.0; // openfl_ColorMultiplierv.w; color = clamp (openfl_ColorOffsetv + (color * colorMultiplier), 0.0, 1.0); if (color.a > 0.0) { gl_FragColor = vec4 (color.rgb * color.a * openfl_Alphav, color.a * openfl_Alphav); } else { gl_FragColor = vec4 (0.0, 0.0, 0.0, 0.0); } } else { gl_FragColor = color * openfl_Alphav; }" ) @:glFragmentSource( "#pragma header vec3 hsb2rgb( vec3 c ) { vec3 rgb = clamp( abs( mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0 ); rgb = rgb * rgb * (3.0 - 2.0 * rgb); return (1.0 - c.y) * mix( vec3(1.0), rgb, c.z); } void main(void) { #pragma body gl_FragColor = vec4( hsb2rgb( vec3(openfl_TextureCoordv.x, openfl_TextureCoordv.y, custom_Value) ), openfl_Alphav ); " + #if emscripten "gl_FragColor = gl_FragColor.bgra;}" #else "}" #end ) public function new(code:ByteArray=null) { super(code); } }