mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-24 07:43:44 +02:00
Convert GLSL shaders to PortableGL's shader format
PortableGL supports shaders, but requires them to be compiled ahead-of-time to C or C++. I'll write a compiler later to translate from GLSL to this format automatically at build time.
This commit is contained in:
parent
995c5303a3
commit
2cd8202af3
39 changed files with 1265 additions and 0 deletions
19
meson.build
19
meson.build
|
@ -610,6 +610,25 @@ if is_libretro
|
||||||
include_directories('src/util/sigslot/adapter'),
|
include_directories('src/util/sigslot/adapter'),
|
||||||
],
|
],
|
||||||
sources: global_sources + [
|
sources: global_sources + [
|
||||||
|
'shader/flatColor.pgl.c',
|
||||||
|
'shader/simple.pgl.c',
|
||||||
|
'shader/simpleAlpha.pgl.c',
|
||||||
|
'shader/simpleSprite.pgl.c',
|
||||||
|
'shader/alphaSprite.pgl.c',
|
||||||
|
'shader/trans.pgl.c',
|
||||||
|
'shader/transSimple.pgl.c',
|
||||||
|
'shader/hue.pgl.c',
|
||||||
|
'shader/simpleColor.pgl.c',
|
||||||
|
'shader/flashMap.pgl.c',
|
||||||
|
'shader/sprite.pgl.c',
|
||||||
|
'shader/plane.pgl.c',
|
||||||
|
'shader/gray.pgl.c',
|
||||||
|
'shader/tilemap.pgl.c',
|
||||||
|
'shader/bitmapBlit.pgl.c',
|
||||||
|
'shader/simpleMatrix.pgl.c',
|
||||||
|
'shader/blurH.pgl.c',
|
||||||
|
'shader/blurV.pgl.c',
|
||||||
|
'shader/tilemapvx.pgl.c',
|
||||||
'src/core.cpp',
|
'src/core.cpp',
|
||||||
'src/mkxp-threads.cpp',
|
'src/mkxp-threads.cpp',
|
||||||
'src/portablegl.cpp',
|
'src/portablegl.cpp',
|
||||||
|
|
29
shader/alphaSprite.pgl.c
Normal file
29
shader/alphaSprite.pgl.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include "alphaSprite.pgl.h"
|
||||||
|
|
||||||
|
void mkxpAlphaSpriteVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct AlphaSpriteVarying *output = (struct AlphaSpriteVarying *)_output;
|
||||||
|
struct AlphaSpriteAttribs *attribs = (struct AlphaSpriteAttribs *)_attribs;
|
||||||
|
struct AlphaSpriteUniforms *uniforms = (struct AlphaSpriteUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, mult_mat4_vec4(uniforms->spriteMat, (pgl_vec4){attribs->position.x, attribs->position.y, 0, 1}));
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
if (uniforms->renderPattern) {
|
||||||
|
if (uniforms->patternTile) {
|
||||||
|
pgl_vec2 scroll = mult_vec2s(uniforms->patternScroll, div_vec2s(uniforms->patternSizeInv, uniforms->texSizeInv));
|
||||||
|
output->v_patCoord = sub_vec2s(mult_vec2s(attribs->texCoord, div_vec2s(uniforms->patternSizeInv, uniforms->patternZoom)), mult_vec2s(scroll, uniforms->patternSizeInv));
|
||||||
|
} else {
|
||||||
|
pgl_vec2 scroll = mult_vec2s(uniforms->patternScroll, div_vec2s(uniforms->patternSizeInv, uniforms->texSizeInv));
|
||||||
|
output->v_patCoord = sub_vec2s(mult_vec2s(attribs->texCoord, div_vec2s(uniforms->texSizeInv, uniforms->patternZoom)), mult_vec2s(scroll, uniforms->texSizeInv));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpAlphaSpriteFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct AlphaSpriteVarying *input = (struct AlphaSpriteVarying *)_input;
|
||||||
|
struct AlphaSpriteUniforms *uniforms = (struct AlphaSpriteUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_FragColor = mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
builtins->gl_FragColor.w *= uniforms->alpha;
|
||||||
|
}
|
39
shader/alphaSprite.pgl.h
Normal file
39
shader/alphaSprite.pgl.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct AlphaSpriteUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_mat4 spriteMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 patternSizeInv;
|
||||||
|
pgl_vec2 patternScroll;
|
||||||
|
pgl_vec2 patternZoom;
|
||||||
|
bool renderPattern;
|
||||||
|
bool patternTile;
|
||||||
|
GLuint texture;
|
||||||
|
float alpha;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AlphaSpriteAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AlphaSpriteVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
pgl_vec2 v_patCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpAlphaSpriteVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpAlphaSpriteFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
38
shader/bitmapBlit.pgl.c
Normal file
38
shader/bitmapBlit.pgl.c
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#include "bitmapBlit.pgl.h"
|
||||||
|
|
||||||
|
void mkxpBitmapBlitVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct BitmapBlitVarying *output = (struct BitmapBlitVarying *)_output;
|
||||||
|
struct BitmapBlitAttribs *attribs = (struct BitmapBlitAttribs *)_attribs;
|
||||||
|
struct BitmapBlitUniforms *uniforms = (struct BitmapBlitUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 pos = add_vec2s(attribs->position, uniforms->translation);
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){pos.x, pos.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpBitmapBlitFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct BitmapBlitVarying *input = (struct BitmapBlitVarying *)_input;
|
||||||
|
struct BitmapBlitUniforms *uniforms = (struct BitmapBlitUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 coor = input->v_texCoord;
|
||||||
|
pgl_vec2 dstCoor = mult_vec2s(sub_vec2s(coor, (pgl_vec2){uniforms->subRect.x, uniforms->subRect.y}), (pgl_vec2){uniforms->subRect.z, uniforms->subRect.w});
|
||||||
|
pgl_vec4 srcFrag = mkxp_pgl_texture2D(uniforms->source, coor.x, coor.y);
|
||||||
|
pgl_vec4 dstFrag = mkxp_pgl_texture2D(uniforms->destination, dstCoor.x, dstCoor.y);
|
||||||
|
pgl_vec4 resFrag;
|
||||||
|
float co1 = srcFrag.w * uniforms->opacity;
|
||||||
|
float co2 = dstFrag.w * (1.0 - co1);
|
||||||
|
resFrag.w = co1 + co2;
|
||||||
|
if (resFrag.w == 0.0) {
|
||||||
|
resFrag.x = srcFrag.x;
|
||||||
|
resFrag.y = srcFrag.y;
|
||||||
|
resFrag.z = srcFrag.z;
|
||||||
|
} else {
|
||||||
|
pgl_vec3 frag = add_vec3s((pgl_vec3){co1*srcFrag.x, co1*srcFrag.y, co1*srcFrag.z}, (pgl_vec3){co2*dstFrag.x, co2*dstFrag.y, co2*dstFrag.z});
|
||||||
|
resFrag.x = frag.x / resFrag.w;
|
||||||
|
resFrag.y = frag.y / resFrag.w;
|
||||||
|
resFrag.z = frag.z / resFrag.w;
|
||||||
|
}
|
||||||
|
builtins->gl_FragColor = resFrag;
|
||||||
|
}
|
34
shader/bitmapBlit.pgl.h
Normal file
34
shader/bitmapBlit.pgl.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct BitmapBlitUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
GLuint source;
|
||||||
|
GLuint destination;
|
||||||
|
pgl_vec4 subRect;
|
||||||
|
float opacity;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BitmapBlitAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BitmapBlitVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpBitmapBlitVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpBitmapBlitFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
25
shader/blurH.pgl.c
Normal file
25
shader/blurH.pgl.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#include "blurH.pgl.h"
|
||||||
|
|
||||||
|
void mkxpBlurHVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct BlurHVarying *output = (struct BlurHVarying *)_output;
|
||||||
|
struct BlurHAttribs *attribs = (struct BlurHAttribs *)_attribs;
|
||||||
|
struct BlurHUniforms *uniforms = (struct BlurHUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){attribs->position.x, attribs->position.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
output->v_blurCoord[0] = mult_vec2s((pgl_vec2){attribs->texCoord.x-1.0f, attribs->texCoord.y}, uniforms->texSizeInv);
|
||||||
|
output->v_blurCoord[1] = mult_vec2s((pgl_vec2){attribs->texCoord.x+1.0f, attribs->texCoord.y}, uniforms->texSizeInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpBlurHFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct BlurHVarying *input = (struct BlurHVarying *)_input;
|
||||||
|
struct BlurHUniforms *uniforms = (struct BlurHUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec4 frag = {0, 0, 0, 0};
|
||||||
|
frag = add_vec4s(frag, mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y));
|
||||||
|
frag = add_vec4s(frag, mkxp_pgl_texture2D(uniforms->texture, input->v_blurCoord[0].x, input->v_blurCoord[0].y));
|
||||||
|
frag = add_vec4s(frag, mkxp_pgl_texture2D(uniforms->texture, input->v_blurCoord[1].x, input->v_blurCoord[1].y));
|
||||||
|
builtins->gl_FragColor = div_vec4s(frag, (pgl_vec4){3.0, 3.0, 3.0, 3.0});
|
||||||
|
}
|
31
shader/blurH.pgl.h
Normal file
31
shader/blurH.pgl.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct BlurHUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
GLuint texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BlurHAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BlurHVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
pgl_vec2 v_blurCoord[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpBlurHVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpBlurHFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
25
shader/blurV.pgl.c
Normal file
25
shader/blurV.pgl.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#include "blurV.pgl.h"
|
||||||
|
|
||||||
|
void mkxpBlurVVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct BlurVVarying *output = (struct BlurVVarying *)_output;
|
||||||
|
struct BlurVAttribs *attribs = (struct BlurVAttribs *)_attribs;
|
||||||
|
struct BlurVUniforms *uniforms = (struct BlurVUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){attribs->position.x, attribs->position.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
output->v_blurCoord[0] = mult_vec2s((pgl_vec2){attribs->texCoord.x, attribs->texCoord.y-1.0f}, uniforms->texSizeInv);
|
||||||
|
output->v_blurCoord[1] = mult_vec2s((pgl_vec2){attribs->texCoord.x, attribs->texCoord.y+1.0f}, uniforms->texSizeInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpBlurVFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct BlurVVarying *input = (struct BlurVVarying *)_input;
|
||||||
|
struct BlurVUniforms *uniforms = (struct BlurVUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec4 frag = {0, 0, 0, 0};
|
||||||
|
frag = add_vec4s(frag, mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y));
|
||||||
|
frag = add_vec4s(frag, mkxp_pgl_texture2D(uniforms->texture, input->v_blurCoord[0].x, input->v_blurCoord[0].y));
|
||||||
|
frag = add_vec4s(frag, mkxp_pgl_texture2D(uniforms->texture, input->v_blurCoord[1].x, input->v_blurCoord[1].y));
|
||||||
|
builtins->gl_FragColor = div_vec4s(frag, (pgl_vec4){3.0, 3.0, 3.0, 3.0});
|
||||||
|
}
|
31
shader/blurV.pgl.h
Normal file
31
shader/blurV.pgl.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct BlurVUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
GLuint texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BlurVAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BlurVVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
pgl_vec2 v_blurCoord[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpBlurVVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpBlurVFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
21
shader/flashMap.pgl.c
Normal file
21
shader/flashMap.pgl.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#include "flashMap.pgl.h"
|
||||||
|
|
||||||
|
void mkxpFlashMapVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct FlashMapVarying *output = (struct FlashMapVarying *)_output;
|
||||||
|
struct FlashMapAttribs *attribs = (struct FlashMapAttribs *)_attribs;
|
||||||
|
struct FlashMapUniforms *uniforms = (struct FlashMapUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 pos = add_vec2s(attribs->position, uniforms->translation);
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){pos.x, pos.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
output->v_color = attribs->color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpFlashMapFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct FlashMapVarying *input = (struct FlashMapVarying *)_input;
|
||||||
|
struct FlashMapUniforms *uniforms = (struct FlashMapUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_FragColor = (pgl_vec4){input->v_color.x * uniforms->alpha, input->v_color.y * uniforms->alpha, input->v_color.z * uniforms->alpha, 1};
|
||||||
|
}
|
33
shader/flashMap.pgl.h
Normal file
33
shader/flashMap.pgl.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct FlashMapUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
float alpha;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FlashMapAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
pgl_vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FlashMapVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
pgl_vec4 v_color;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpFlashMapVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpFlashMapFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
16
shader/flatColor.pgl.c
Normal file
16
shader/flatColor.pgl.c
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include "flatColor.pgl.h"
|
||||||
|
|
||||||
|
void mkxpFlatColorVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct FlatColorUniforms *uniforms = (struct FlatColorUniforms *)_uniforms;
|
||||||
|
struct FlatColorAttribs *attribs = (struct FlatColorAttribs *)_attribs;
|
||||||
|
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){attribs->position.x, attribs->position.y, 0, 1});
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpFlatColorFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct FlatColorUniforms *uniforms = (struct FlatColorUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_FragColor = uniforms->color;
|
||||||
|
}
|
23
shader/flatColor.pgl.h
Normal file
23
shader/flatColor.pgl.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct FlatColorUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FlatColorAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpFlatColorVS(float *_output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpFlatColorFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
28
shader/gray.pgl.c
Normal file
28
shader/gray.pgl.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include "gray.pgl.h"
|
||||||
|
|
||||||
|
void mkxpGrayVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct GrayVarying *output = (struct GrayVarying *)_output;
|
||||||
|
struct GrayAttribs *attribs = (struct GrayAttribs *)_attribs;
|
||||||
|
struct GrayUniforms *uniforms = (struct GrayUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 pos = add_vec2s(attribs->position, uniforms->translation);
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){pos.x, pos.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const pgl_vec3 lumaF = {.299, .587, .114};
|
||||||
|
|
||||||
|
void mkxpGrayFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct GrayVarying *input = (struct GrayVarying *)_input;
|
||||||
|
struct GrayUniforms *uniforms = (struct GrayUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec4 frag = mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
float luma = dot_vec3s((pgl_vec3){frag.x, frag.y, frag.z}, lumaF);
|
||||||
|
pgl_vec3 gray = pgl_mix_vec3((pgl_vec3){frag.x, frag.y, frag.z}, (pgl_vec3){luma, luma, luma}, uniforms->gray);
|
||||||
|
frag.x = gray.x;
|
||||||
|
frag.y = gray.y;
|
||||||
|
frag.z = gray.z;
|
||||||
|
builtins->gl_FragColor = frag;
|
||||||
|
}
|
32
shader/gray.pgl.h
Normal file
32
shader/gray.pgl.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct GrayUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
GLuint texture;
|
||||||
|
float gray;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GrayAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GrayVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpGrayVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpGrayFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
44
shader/hue.pgl.c
Normal file
44
shader/hue.pgl.c
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
#include "hue.pgl.h"
|
||||||
|
|
||||||
|
void mkxpHueVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct HueVarying *output = (struct HueVarying *)_output;
|
||||||
|
struct HueAttribs *attribs = (struct HueAttribs *)_attribs;
|
||||||
|
struct HueUniforms *uniforms = (struct HueUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 pos = add_vec2s(attribs->position, uniforms->translation);
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){pos.x, pos.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static pgl_vec3 rgb2hsv(pgl_vec3 c)
|
||||||
|
{
|
||||||
|
const pgl_vec4 K = (pgl_vec4){0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0};
|
||||||
|
pgl_vec4 p = pgl_mix_vec4((pgl_vec4){c.z, c.y, K.w, K.z}, (pgl_vec4){c.y, c.z, K.x, K.y}, c.z <= c.y);
|
||||||
|
pgl_vec4 q = pgl_mix_vec4((pgl_vec4){p.x, p.y, p.w, c.x}, (pgl_vec4){c.x, p.y, p.z, p.x}, p.x <= c.x);
|
||||||
|
float d = q.x - minf(q.w, q.y);
|
||||||
|
const float eps = 1.0e-10;
|
||||||
|
return (pgl_vec3){fabs(q.z + (q.w - q.y) / (6.0 * d + eps)), d / (q.x + eps), q.x};
|
||||||
|
}
|
||||||
|
|
||||||
|
static pgl_vec3 hsv2rgb(pgl_vec3 c)
|
||||||
|
{
|
||||||
|
const pgl_vec4 K = (pgl_vec4){1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0};
|
||||||
|
pgl_vec3 p = fabsf_vec3(sub_vec3s(mult_vec3s(fractf_vec3(add_vec3s((pgl_vec3){c.x, c.x, c.x}, (pgl_vec3){K.x, K.y, K.z})), (pgl_vec3){6.0, 6.0, 6.0}), (pgl_vec3){K.w, K.w, K.w}));
|
||||||
|
return mult_vec3s((pgl_vec3){c.z, c.z, c.z}, pgl_mix_vec3((pgl_vec3){K.x, K.x, K.x}, pgl_clamp_vec3(sub_vec3s(p, (pgl_vec3){K.x, K.x, K.x}), 0.0, 1.0), c.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpHueFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct HueVarying *input = (struct HueVarying *)_input;
|
||||||
|
struct HueUniforms *uniforms = (struct HueUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec4 color = mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
pgl_vec3 hsv = rgb2hsv((pgl_vec3){color.x, color.y, color.z});
|
||||||
|
hsv.x += uniforms->hueAdjust;
|
||||||
|
pgl_vec3 rgb = hsv2rgb(hsv);
|
||||||
|
color.x = rgb.x;
|
||||||
|
color.y = rgb.y;
|
||||||
|
color.z = rgb.z;
|
||||||
|
builtins->gl_FragColor = color;
|
||||||
|
}
|
32
shader/hue.pgl.h
Normal file
32
shader/hue.pgl.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct HueUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
GLuint texture;
|
||||||
|
float hueAdjust;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct HueAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct HueVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpHueVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpHueFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
40
shader/plane.pgl.c
Normal file
40
shader/plane.pgl.c
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#include "plane.pgl.h"
|
||||||
|
|
||||||
|
void mkxpPlaneVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct PlaneVarying *output = (struct PlaneVarying *)_output;
|
||||||
|
struct PlaneAttribs *attribs = (struct PlaneAttribs *)_attribs;
|
||||||
|
struct PlaneUniforms *uniforms = (struct PlaneUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 pos = add_vec2s(attribs->position, uniforms->translation);
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){pos.x, pos.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const pgl_vec3 lumaF = {.299, .587, .114};
|
||||||
|
|
||||||
|
void mkxpPlaneFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct PlaneVarying *input = (struct PlaneVarying *)_input;
|
||||||
|
struct PlaneUniforms *uniforms = (struct PlaneUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec4 frag = mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
float luma = dot_vec3s((pgl_vec3){frag.x, frag.y, frag.z}, lumaF);
|
||||||
|
pgl_vec3 gray = pgl_mix_vec3((pgl_vec3){frag.x, frag.y, frag.z}, (pgl_vec3){luma, luma, luma}, uniforms->tone.w);
|
||||||
|
frag.x = gray.x;
|
||||||
|
frag.y = gray.y;
|
||||||
|
frag.z = gray.z;
|
||||||
|
frag.x += uniforms->tone.x;
|
||||||
|
frag.y += uniforms->tone.y;
|
||||||
|
frag.z += uniforms->tone.z;
|
||||||
|
frag.w += uniforms->opacity;
|
||||||
|
pgl_vec3 color = pgl_mix_vec3((pgl_vec3){frag.x, frag.y, frag.z}, (pgl_vec3){uniforms->color.x, uniforms->color.y, uniforms->color.z}, uniforms->color.w);
|
||||||
|
frag.x = color.x;
|
||||||
|
frag.y = color.y;
|
||||||
|
frag.z = color.z;
|
||||||
|
pgl_vec3 flash = pgl_mix_vec3((pgl_vec3){frag.x, frag.y, frag.z}, (pgl_vec3){uniforms->flash.x, uniforms->flash.y, uniforms->flash.z}, uniforms->flash.w);
|
||||||
|
frag.x = flash.x;
|
||||||
|
frag.y = flash.y;
|
||||||
|
frag.z = flash.z;
|
||||||
|
builtins->gl_FragColor = frag;
|
||||||
|
}
|
35
shader/plane.pgl.h
Normal file
35
shader/plane.pgl.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct PlaneUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
GLuint texture;
|
||||||
|
pgl_vec4 tone;
|
||||||
|
float opacity;
|
||||||
|
pgl_vec4 color;
|
||||||
|
pgl_vec4 flash;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PlaneAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PlaneVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpPlaneVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpPlaneFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
20
shader/simple.pgl.c
Normal file
20
shader/simple.pgl.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "simple.pgl.h"
|
||||||
|
|
||||||
|
void mkxpSimpleVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SimpleVarying *output = (struct SimpleVarying *)_output;
|
||||||
|
struct SimpleAttribs *attribs = (struct SimpleAttribs *)_attribs;
|
||||||
|
struct SimpleUniforms *uniforms = (struct SimpleUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 pos = add_vec2s(attribs->position, uniforms->translation);
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){pos.x, pos.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpSimpleFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SimpleVarying *input = (struct SimpleVarying *)_input;
|
||||||
|
struct SimpleUniforms *uniforms = (struct SimpleUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_FragColor = mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
}
|
31
shader/simple.pgl.h
Normal file
31
shader/simple.pgl.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct SimpleUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
GLuint texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpSimpleVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpSimpleFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
22
shader/simpleAlpha.pgl.c
Normal file
22
shader/simpleAlpha.pgl.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#include "simpleAlpha.pgl.h"
|
||||||
|
|
||||||
|
void mkxpSimpleAlphaVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SimpleAlphaVarying *output = (struct SimpleAlphaVarying *)_output;
|
||||||
|
struct SimpleAlphaAttribs *attribs = (struct SimpleAlphaAttribs *)_attribs;
|
||||||
|
struct SimpleAlphaUniforms *uniforms = (struct SimpleAlphaUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 pos = add_vec2s(attribs->position, uniforms->translation);
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){pos.x, pos.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
output->v_color = attribs->color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpSimpleAlphaFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SimpleAlphaVarying *input = (struct SimpleAlphaVarying *)_input;
|
||||||
|
struct SimpleAlphaUniforms *uniforms = (struct SimpleAlphaUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_FragColor = mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
builtins->gl_FragColor.w *= input->v_color.w;
|
||||||
|
}
|
33
shader/simpleAlpha.pgl.h
Normal file
33
shader/simpleAlpha.pgl.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct SimpleAlphaUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
GLuint texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleAlphaAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
pgl_vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleAlphaVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
pgl_vec4 v_color;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpSimpleAlphaVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpSimpleAlphaFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
20
shader/simpleColor.pgl.c
Normal file
20
shader/simpleColor.pgl.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "simpleColor.pgl.h"
|
||||||
|
|
||||||
|
void mkxpSimpleColorVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SimpleColorVarying *output = (struct SimpleColorVarying *)_output;
|
||||||
|
struct SimpleColorAttribs *attribs = (struct SimpleColorAttribs *)_attribs;
|
||||||
|
struct SimpleColorUniforms *uniforms = (struct SimpleColorUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 pos = add_vec2s(attribs->position, uniforms->translation);
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){pos.x, pos.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
output->v_color = attribs->color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpSimpleColorFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SimpleColorVarying *input = (struct SimpleColorVarying *)_input;
|
||||||
|
|
||||||
|
builtins->gl_FragColor = input->v_color;
|
||||||
|
}
|
32
shader/simpleColor.pgl.h
Normal file
32
shader/simpleColor.pgl.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct SimpleColorUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleColorAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
pgl_vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleColorVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
pgl_vec4 v_color;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpSimpleColorVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpSimpleColorFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
21
shader/simpleMatrix.pgl.c
Normal file
21
shader/simpleMatrix.pgl.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#include "simpleMatrix.pgl.h"
|
||||||
|
|
||||||
|
void mkxpSimpleMatrixVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SimpleMatrixVarying *output = (struct SimpleMatrixVarying *)_output;
|
||||||
|
struct SimpleMatrixAttribs *attribs = (struct SimpleMatrixAttribs *)_attribs;
|
||||||
|
struct SimpleMatrixUniforms *uniforms = (struct SimpleMatrixUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, mult_mat4_vec4(uniforms->matrix, (pgl_vec4){attribs->position.x, attribs->position.y, 0, 1}));
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
output->v_color = attribs->color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpSimpleMatrixFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SimpleMatrixVarying *input = (struct SimpleMatrixVarying *)_input;
|
||||||
|
struct SimpleMatrixUniforms *uniforms = (struct SimpleMatrixUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_FragColor = mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
builtins->gl_FragColor.w *= input->v_color.w;
|
||||||
|
}
|
33
shader/simpleMatrix.pgl.h
Normal file
33
shader/simpleMatrix.pgl.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct SimpleMatrixUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_mat4 matrix;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
GLuint texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleMatrixAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
pgl_vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleMatrixVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
pgl_vec4 v_color;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpSimpleMatrixVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpSimpleMatrixFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
28
shader/simpleSprite.pgl.c
Normal file
28
shader/simpleSprite.pgl.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include "simpleSprite.pgl.h"
|
||||||
|
|
||||||
|
void mkxpSimpleSpriteVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SimpleSpriteVarying *output = (struct SimpleSpriteVarying *)_output;
|
||||||
|
struct SimpleSpriteAttribs *attribs = (struct SimpleSpriteAttribs *)_attribs;
|
||||||
|
struct SimpleSpriteUniforms *uniforms = (struct SimpleSpriteUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, mult_mat4_vec4(uniforms->spriteMat, (pgl_vec4){attribs->position.x, attribs->position.y, 0, 1}));
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
if (uniforms->renderPattern) {
|
||||||
|
if (uniforms->patternTile) {
|
||||||
|
pgl_vec2 scroll = mult_vec2s(uniforms->patternScroll, div_vec2s(uniforms->patternSizeInv, uniforms->texSizeInv));
|
||||||
|
output->v_patCoord = sub_vec2s(mult_vec2s(attribs->texCoord, div_vec2s(uniforms->patternSizeInv, uniforms->patternZoom)), mult_vec2s(scroll, uniforms->patternSizeInv));
|
||||||
|
} else {
|
||||||
|
pgl_vec2 scroll = mult_vec2s(uniforms->patternScroll, div_vec2s(uniforms->patternSizeInv, uniforms->texSizeInv));
|
||||||
|
output->v_patCoord = sub_vec2s(mult_vec2s(attribs->texCoord, div_vec2s(uniforms->texSizeInv, uniforms->patternZoom)), mult_vec2s(scroll, uniforms->texSizeInv));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpSimpleSpriteFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SimpleSpriteVarying *input = (struct SimpleSpriteVarying *)_input;
|
||||||
|
struct SimpleSpriteUniforms *uniforms = (struct SimpleSpriteUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_FragColor = mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
}
|
38
shader/simpleSprite.pgl.h
Normal file
38
shader/simpleSprite.pgl.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct SimpleSpriteUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_mat4 spriteMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 patternSizeInv;
|
||||||
|
pgl_vec2 patternScroll;
|
||||||
|
pgl_vec2 patternZoom;
|
||||||
|
bool renderPattern;
|
||||||
|
bool patternTile;
|
||||||
|
GLuint texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleSpriteAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleSpriteVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
pgl_vec2 v_patCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpSimpleSpriteVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpSimpleSpriteFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
98
shader/sprite.pgl.c
Normal file
98
shader/sprite.pgl.c
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
#include "sprite.pgl.h"
|
||||||
|
|
||||||
|
void mkxpSpriteVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SpriteVarying *output = (struct SpriteVarying *)_output;
|
||||||
|
struct SpriteAttribs *attribs = (struct SpriteAttribs *)_attribs;
|
||||||
|
struct SpriteUniforms *uniforms = (struct SpriteUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, mult_mat4_vec4(uniforms->spriteMat, (pgl_vec4){attribs->position.x, attribs->position.y, 0, 1}));
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
if (uniforms->renderPattern) {
|
||||||
|
if (uniforms->patternTile) {
|
||||||
|
pgl_vec2 scroll = mult_vec2s(uniforms->patternScroll, div_vec2s(uniforms->patternSizeInv, uniforms->texSizeInv));
|
||||||
|
output->v_patCoord = sub_vec2s(mult_vec2s(attribs->texCoord, div_vec2s(uniforms->patternSizeInv, uniforms->patternZoom)), mult_vec2s(scroll, uniforms->patternSizeInv));
|
||||||
|
} else {
|
||||||
|
pgl_vec2 scroll = mult_vec2s(uniforms->patternScroll, div_vec2s(uniforms->patternSizeInv, uniforms->texSizeInv));
|
||||||
|
output->v_patCoord = sub_vec2s(mult_vec2s(attribs->texCoord, div_vec2s(uniforms->texSizeInv, uniforms->patternZoom)), mult_vec2s(scroll, uniforms->texSizeInv));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const pgl_vec3 lumaF = {.299, .587, .114};
|
||||||
|
static const pgl_vec2 repeat = {1, 1};
|
||||||
|
|
||||||
|
static pgl_vec3 blendNormal(pgl_vec3 base, pgl_vec3 blend) {
|
||||||
|
return blend;
|
||||||
|
}
|
||||||
|
|
||||||
|
static pgl_vec3 blendNormalOpacity(pgl_vec3 base, pgl_vec3 blend, float opacity) {
|
||||||
|
return add_vec3s(mult_vec3s(blendNormal(base, blend), (pgl_vec3){opacity, opacity, opacity}), mult_vec3s(base, (pgl_vec3){1.0f - opacity, 1.0f - opacity, 1.0f - opacity}));
|
||||||
|
}
|
||||||
|
|
||||||
|
static pgl_vec3 blendAdd(pgl_vec3 base, pgl_vec3 blend) {
|
||||||
|
return minf_vec3(add_vec3s(base, blend), (pgl_vec3){1.0, 1.0, 1.0});
|
||||||
|
}
|
||||||
|
|
||||||
|
static pgl_vec3 blendAddOpacity(pgl_vec3 base, pgl_vec3 blend, float opacity) {
|
||||||
|
return add_vec3s(mult_vec3s(blendAdd(base, blend), (pgl_vec3){opacity, opacity, opacity}), mult_vec3s(base, (pgl_vec3){1.0f - opacity, 1.0f - opacity, 1.0f - opacity}));
|
||||||
|
}
|
||||||
|
|
||||||
|
static pgl_vec3 blendSubtract(pgl_vec3 base, pgl_vec3 blend) {
|
||||||
|
return maxf_vec3(sub_vec3s(base, blend), (pgl_vec3){0.0, 0.0, 0.0});
|
||||||
|
}
|
||||||
|
|
||||||
|
static pgl_vec3 blendSubtractOpacity(pgl_vec3 base, pgl_vec3 blend, float opacity) {
|
||||||
|
return add_vec3s(mult_vec3s(blendSubtract(base, blend), (pgl_vec3){opacity, opacity, opacity}), mult_vec3s(base, (pgl_vec3){1.0f - opacity, 1.0f - opacity, 1.0f - opacity}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpSpriteFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct SpriteVarying *input = (struct SpriteVarying *)_input;
|
||||||
|
struct SpriteUniforms *uniforms = (struct SpriteUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec4 frag = mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
if (uniforms->renderPattern) {
|
||||||
|
pgl_vec2 patCoordRepeat = modulusf_vec2(input->v_patCoord, repeat);
|
||||||
|
pgl_vec4 pattfrag = mkxp_pgl_texture2D(uniforms->pattern, patCoordRepeat.x, patCoordRepeat.y);
|
||||||
|
if (uniforms->patternBlendType == 1) {
|
||||||
|
pgl_vec3 blended = blendAddOpacity((pgl_vec3){frag.x, frag.y, frag.z}, (pgl_vec3){pattfrag.x, pattfrag.y, pattfrag.z}, pattfrag.w * uniforms->patternOpacity);
|
||||||
|
frag.x = blended.x;
|
||||||
|
frag.y = blended.y;
|
||||||
|
frag.z = blended.z;
|
||||||
|
}
|
||||||
|
else if (uniforms->patternBlendType == 2) {
|
||||||
|
pgl_vec3 blended = blendSubtractOpacity((pgl_vec3){frag.x, frag.y, frag.z}, (pgl_vec3){pattfrag.x, pattfrag.y, pattfrag.z}, pattfrag.w * uniforms->patternOpacity);
|
||||||
|
frag.x = blended.x;
|
||||||
|
frag.y = blended.y;
|
||||||
|
frag.z = blended.z;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pgl_vec3 blended = blendNormalOpacity((pgl_vec3){frag.x, frag.y, frag.z}, (pgl_vec3){pattfrag.x, pattfrag.y, pattfrag.z}, pattfrag.w * uniforms->patternOpacity);
|
||||||
|
frag.x = blended.x;
|
||||||
|
frag.y = blended.y;
|
||||||
|
frag.z = blended.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
float luma = dot_vec3s((pgl_vec3){frag.x, frag.y, frag.z}, lumaF);
|
||||||
|
pgl_vec3 gray = pgl_mix_vec3((pgl_vec3){frag.x, frag.y, frag.z}, (pgl_vec3){luma, luma, luma}, uniforms->tone.w);
|
||||||
|
frag.x = gray.x;
|
||||||
|
frag.y = gray.y;
|
||||||
|
frag.z = gray.z;
|
||||||
|
frag.x += uniforms->tone.x;
|
||||||
|
frag.y += uniforms->tone.y;
|
||||||
|
frag.z += uniforms->tone.z;
|
||||||
|
frag.w *= uniforms->opacity;
|
||||||
|
pgl_vec3 color = pgl_mix_vec3((pgl_vec3){frag.x, frag.y, frag.z}, (pgl_vec3){uniforms->color.x, uniforms->color.y, uniforms->color.z}, uniforms->color.w);
|
||||||
|
frag.x = color.x;
|
||||||
|
frag.y = color.y;
|
||||||
|
frag.z = color.z;
|
||||||
|
if (uniforms->invert) {
|
||||||
|
frag.x = 1.0f - frag.x;
|
||||||
|
frag.y = 1.0f - frag.y;
|
||||||
|
frag.z = 1.0f - frag.z;
|
||||||
|
}
|
||||||
|
float underBush = input->v_texCoord.y < uniforms->bushDepth;
|
||||||
|
frag.w *= pgl_clamp(uniforms->bushOpacity + underBush, 0.0, 1.0);
|
||||||
|
builtins->gl_FragColor = frag;
|
||||||
|
}
|
47
shader/sprite.pgl.h
Normal file
47
shader/sprite.pgl.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct SpriteUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_mat4 spriteMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 patternSizeInv;
|
||||||
|
pgl_vec2 patternScroll;
|
||||||
|
pgl_vec2 patternZoom;
|
||||||
|
bool renderPattern;
|
||||||
|
bool patternTile;
|
||||||
|
GLuint texture;
|
||||||
|
pgl_vec4 tone;
|
||||||
|
float opacity;
|
||||||
|
pgl_vec4 color;
|
||||||
|
float bushDepth;
|
||||||
|
float bushOpacity;
|
||||||
|
GLuint pattern;
|
||||||
|
int patternBlendType;
|
||||||
|
float patternOpacity;
|
||||||
|
bool invert;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SpriteAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SpriteVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
pgl_vec2 v_patCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpSpriteVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpSpriteFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
53
shader/tilemap.pgl.c
Normal file
53
shader/tilemap.pgl.c
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#include "tilemap.pgl.h"
|
||||||
|
|
||||||
|
static const float tileW = 32.0;
|
||||||
|
static const float tileH = 32.0;
|
||||||
|
static const float autotileW = 3.0*tileW;
|
||||||
|
static const float autotileH = 4.0*tileW;
|
||||||
|
static const float atAreaW = autotileW;
|
||||||
|
static const float atAreaH = autotileH*nAutotiles;
|
||||||
|
static const float atAniOffsetX = 3.0*tileW;
|
||||||
|
static const float atAniOffsetY = tileH;
|
||||||
|
|
||||||
|
void mkxpTilemapVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct TilemapVarying *output = (struct TilemapVarying *)_output;
|
||||||
|
struct TilemapAttribs *attribs = (struct TilemapAttribs *)_attribs;
|
||||||
|
struct TilemapUniforms *uniforms = (struct TilemapUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 tex = attribs->texCoord;
|
||||||
|
int atIndex = tex.y / autotileH;
|
||||||
|
int pred = tex.x <= atAreaW && tex.y <= atAreaH;
|
||||||
|
int frame = uniforms->aniIndex - uniforms->atFrames[atIndex] * (uniforms->aniIndex / uniforms->atFrames[atIndex]);
|
||||||
|
int row = frame / 8;
|
||||||
|
int col = frame - 8 * row;
|
||||||
|
tex.x += atAniOffsetX * (float)(col * pred);
|
||||||
|
tex.y += atAniOffsetY * (float)(row * pred);
|
||||||
|
pgl_vec2 pos = add_vec2s(attribs->position, uniforms->translation);
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){pos.x, pos.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(tex, uniforms->texSizeInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const pgl_vec3 lumaF = {.299, .587, .114};
|
||||||
|
|
||||||
|
void mkxpTilemapFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct TilemapVarying *input = (struct TilemapVarying *)_input;
|
||||||
|
struct TilemapUniforms *uniforms = (struct TilemapUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec4 frag = mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
float luma = dot_vec3s((pgl_vec3){frag.x, frag.y, frag.z}, lumaF);
|
||||||
|
pgl_vec3 gray = pgl_mix_vec3((pgl_vec3){frag.x, frag.y, frag.z}, (pgl_vec3){luma, luma, luma}, uniforms->tone.w);
|
||||||
|
frag.x = gray.x;
|
||||||
|
frag.y = gray.y;
|
||||||
|
frag.z = gray.z;
|
||||||
|
frag.x += uniforms->tone.x;
|
||||||
|
frag.y += uniforms->tone.y;
|
||||||
|
frag.z += uniforms->tone.z;
|
||||||
|
frag.w += uniforms->opacity;
|
||||||
|
pgl_vec3 color = pgl_mix_vec3((pgl_vec3){frag.x, frag.y, frag.z}, (pgl_vec3){uniforms->color.x, uniforms->color.y, uniforms->color.z}, uniforms->color.w);
|
||||||
|
frag.x = color.x;
|
||||||
|
frag.y = color.y;
|
||||||
|
frag.z = color.z;
|
||||||
|
builtins->gl_FragColor = frag;
|
||||||
|
}
|
38
shader/tilemap.pgl.h
Normal file
38
shader/tilemap.pgl.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define nAutotiles 7
|
||||||
|
|
||||||
|
struct TilemapUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
int aniIndex;
|
||||||
|
int atFrames[nAutotiles];
|
||||||
|
GLuint texture;
|
||||||
|
pgl_vec4 tone;
|
||||||
|
float opacity;
|
||||||
|
pgl_vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TilemapAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TilemapVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpTilemapVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpTilemapFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
29
shader/tilemapvx.pgl.c
Normal file
29
shader/tilemapvx.pgl.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include "tilemapvx.pgl.h"
|
||||||
|
|
||||||
|
static const pgl_vec2 atAreaA = {9.0*32.0, 12.0*32.0};
|
||||||
|
static const float atAreaCX = 12.0*32.0;
|
||||||
|
static const float atAreaCW = 4.0*32.0;
|
||||||
|
|
||||||
|
void mkxpTilemapVXVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct TilemapVXVarying *output = (struct TilemapVXVarying *)_output;
|
||||||
|
struct TilemapVXAttribs *attribs = (struct TilemapVXAttribs *)_attribs;
|
||||||
|
struct TilemapVXUniforms *uniforms = (struct TilemapVXUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 tex = attribs->texCoord;
|
||||||
|
float pred;
|
||||||
|
pred = tex.x <= atAreaA.x && tex.y <= atAreaA.y;
|
||||||
|
tex.x += uniforms->aniOffset.x * pred;
|
||||||
|
pred = tex.x >= atAreaCX && tex.x <= (atAreaCX+atAreaCW) && tex.y <= atAreaA.y;
|
||||||
|
tex.y += uniforms->aniOffset.y * pred;
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){attribs->position.x + uniforms->translation.x, attribs->position.y + uniforms->translation.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(tex, uniforms->texSizeInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpTilemapVXFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct TilemapVXVarying *input = (struct TilemapVXVarying *)_input;
|
||||||
|
struct TilemapVXUniforms *uniforms = (struct TilemapVXUniforms *)_uniforms;
|
||||||
|
|
||||||
|
builtins->gl_FragColor = mkxp_pgl_texture2D(uniforms->texture, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
}
|
32
shader/tilemapvx.pgl.h
Normal file
32
shader/tilemapvx.pgl.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct TilemapVXUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
pgl_vec2 aniOffset;
|
||||||
|
GLuint texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TilemapVXAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TilemapVXVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpTilemapVXVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpTilemapVXFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
25
shader/trans.pgl.c
Normal file
25
shader/trans.pgl.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#include "trans.pgl.h"
|
||||||
|
|
||||||
|
void mkxpTransVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct TransVarying *output = (struct TransVarying *)_output;
|
||||||
|
struct TransAttribs *attribs = (struct TransAttribs *)_attribs;
|
||||||
|
struct TransUniforms *uniforms = (struct TransUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 pos = add_vec2s(attribs->position, uniforms->translation);
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){pos.x, pos.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpTransFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct TransVarying *input = (struct TransVarying *)_input;
|
||||||
|
struct TransUniforms *uniforms = (struct TransUniforms *)_uniforms;
|
||||||
|
|
||||||
|
float transV = mkxp_pgl_texture2D(uniforms->transMap, input->v_texCoord.x, input->v_texCoord.y).x;
|
||||||
|
float cTransV = pgl_clamp(transV, uniforms->prog, uniforms->prog + uniforms->vague);
|
||||||
|
float alpha = (cTransV - uniforms->prog) / uniforms->vague;
|
||||||
|
pgl_vec4 newFrag = mkxp_pgl_texture2D(uniforms->currentScene, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
pgl_vec4 oldFrag = mkxp_pgl_texture2D(uniforms->frozenScene, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
builtins->gl_FragColor = pgl_mix_vec4(newFrag, oldFrag, alpha);
|
||||||
|
}
|
35
shader/trans.pgl.h
Normal file
35
shader/trans.pgl.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct TransUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
GLuint currentScene;
|
||||||
|
GLuint frozenScene;
|
||||||
|
GLuint transMap;
|
||||||
|
float prog;
|
||||||
|
float vague;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TransAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TransVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpTransVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpTransFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
22
shader/transSimple.pgl.c
Normal file
22
shader/transSimple.pgl.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#include "transSimple.pgl.h"
|
||||||
|
|
||||||
|
void mkxpTransSimpleVS(float *_output, pgl_vec4 *_attribs, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct TransSimpleVarying *output = (struct TransSimpleVarying *)_output;
|
||||||
|
struct TransSimpleAttribs *attribs = (struct TransSimpleAttribs *)_attribs;
|
||||||
|
struct TransSimpleUniforms *uniforms = (struct TransSimpleUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec2 pos = add_vec2s(attribs->position, uniforms->translation);
|
||||||
|
builtins->gl_Position = mult_mat4_vec4(uniforms->projMat, (pgl_vec4){pos.x, pos.y, 0, 1});
|
||||||
|
output->v_texCoord = mult_vec2s(attribs->texCoord, uniforms->texSizeInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mkxpTransSimpleFS(float *_input, Shader_Builtins *builtins, void *_uniforms)
|
||||||
|
{
|
||||||
|
struct TransSimpleVarying *input = (struct TransSimpleVarying *)_input;
|
||||||
|
struct TransSimpleUniforms *uniforms = (struct TransSimpleUniforms *)_uniforms;
|
||||||
|
|
||||||
|
pgl_vec4 newPixel = mkxp_pgl_texture2D(uniforms->currentScene, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
pgl_vec4 oldPixel = mkxp_pgl_texture2D(uniforms->frozenScene, input->v_texCoord.x, input->v_texCoord.y);
|
||||||
|
builtins->gl_FragColor = pgl_mix_vec4(newPixel, oldPixel, uniforms->prog);
|
||||||
|
}
|
33
shader/transSimple.pgl.h
Normal file
33
shader/transSimple.pgl.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#include <portablegl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct TransSimpleUniforms
|
||||||
|
{
|
||||||
|
pgl_mat4 projMat;
|
||||||
|
pgl_vec2 texSizeInv;
|
||||||
|
pgl_vec2 translation;
|
||||||
|
GLuint frozenScene;
|
||||||
|
GLuint currentScene;
|
||||||
|
float prog;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TransSimpleAttribs
|
||||||
|
{
|
||||||
|
pgl_vec2 position;
|
||||||
|
pgl_vec2 texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TransSimpleVarying
|
||||||
|
{
|
||||||
|
pgl_vec2 v_texCoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mkxpTransSimpleVS(float *output, pgl_vec4 *attribs, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
void mkxpTransSimpleFS(float *input, Shader_Builtins *builtins, void *uniforms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
Loading…
Add table
Reference in a new issue