The drawing is now completely shader based, which makes away with all usage of the depracted matrix stack. This also allows us to do things like simple translations and texture coordinate translation directly instead of doing everything indirectly through matrices. Fixed vertex attributes ('vertexPointer()' etc) are also replaced with user defined attribute arrays.
34 lines
689 B
GLSL
34 lines
689 B
GLSL
/* Shader for approximating the way RMXP does bitmap
|
|
* blending via DirectDraw */
|
|
|
|
uniform sampler2D source;
|
|
uniform sampler2D destination;
|
|
|
|
uniform vec4 subRect;
|
|
|
|
uniform float opacity;
|
|
|
|
varying vec2 v_texCoord;
|
|
|
|
void main()
|
|
{
|
|
vec2 coor = v_texCoord;
|
|
vec2 dstCoor = (coor - subRect.xy) * subRect.zw;
|
|
|
|
vec4 srcFrag = texture2D(source, coor);
|
|
vec4 dstFrag = texture2D(destination, dstCoor);
|
|
|
|
vec4 resFrag;
|
|
|
|
float ab = opacity;
|
|
const float as = srcFrag.a;
|
|
const float ad = dstFrag.a;
|
|
|
|
const float at = ab*as;
|
|
resFrag.a = at + ad - ad*at;
|
|
|
|
resFrag.rgb = mix(dstFrag.rgb, srcFrag.rgb, ab*as);
|
|
resFrag.rgb = mix(srcFrag.rgb, resFrag.rgb, ad*resFrag.a);
|
|
|
|
gl_FragColor = resFrag;
|
|
}
|