diff options
| author | claude-bot <[email protected]> | 2026-07-13 12:40:03 +0000 |
|---|---|---|
| committer | claude-bot <[email protected]> | 2026-07-13 12:40:03 +0000 |
| commit | 847962910f0bff071f3bf07c9abb87764fb6cac3 (patch) | |
| tree | ddcd429e134c7fd5f72ddc97ced175de8d66fcd0 /src/gl/shaders | |
| download | librw-847962910f0bff071f3bf07c9abb87764fb6cac3.tar.gz librw-847962910f0bff071f3bf07c9abb87764fb6cac3.zip | |
Snapshot for re3/reVC vendoring, per @lzcnt.
Source: https://github.com/aap/librw (master).
Diffstat (limited to 'src/gl/shaders')
| -rw-r--r-- | src/gl/shaders/Makefile | 45 | ||||
| -rw-r--r-- | src/gl/shaders/default.vert | 23 | ||||
| -rw-r--r-- | src/gl/shaders/default_vs_gl.inc | 25 | ||||
| -rw-r--r-- | src/gl/shaders/header.frag | 30 | ||||
| -rw-r--r-- | src/gl/shaders/header.vert | 128 | ||||
| -rw-r--r-- | src/gl/shaders/header_fs.inc | 32 | ||||
| -rw-r--r-- | src/gl/shaders/header_vs.inc | 130 | ||||
| -rw-r--r-- | src/gl/shaders/im2d.vert | 18 | ||||
| -rw-r--r-- | src/gl/shaders/im2d_gl.inc | 20 | ||||
| -rw-r--r-- | src/gl/shaders/im3d.vert | 15 | ||||
| -rw-r--r-- | src/gl/shaders/im3d_gl.inc | 17 | ||||
| -rw-r--r-- | src/gl/shaders/matfx_env.frag | 34 | ||||
| -rw-r--r-- | src/gl/shaders/matfx_env.vert | 31 | ||||
| -rw-r--r-- | src/gl/shaders/matfx_gl.inc | 69 | ||||
| -rw-r--r-- | src/gl/shaders/simple.frag | 14 | ||||
| -rw-r--r-- | src/gl/shaders/simple_fs_gl.inc | 17 | ||||
| -rw-r--r-- | src/gl/shaders/skin.vert | 32 | ||||
| -rw-r--r-- | src/gl/shaders/skin_gl.inc | 34 |
18 files changed, 714 insertions, 0 deletions
diff --git a/src/gl/shaders/Makefile b/src/gl/shaders/Makefile new file mode 100644 index 0000000..6471f17 --- /dev/null +++ b/src/gl/shaders/Makefile @@ -0,0 +1,45 @@ +all: header_vs.inc header_fs.inc im2d_gl.inc im3d_gl.inc default_vs_gl.inc simple_fs_gl.inc matfx_gl.inc skin_gl.inc + +header_vs.inc: header.vert + (echo 'const char *header_vert_src =';\ + sed 's/..*/"&\\n"/' header.vert;\ + echo ';') >header_vs.inc + +header_fs.inc: header.frag + (echo 'const char *header_frag_src =';\ + sed 's/..*/"&\\n"/' header.frag;\ + echo ';') >header_fs.inc + +im2d_gl.inc: im2d.vert + (echo 'const char *im2d_vert_src =';\ + sed 's/..*/"&\\n"/' im2d.vert;\ + echo ';') >im2d_gl.inc + +im3d_gl.inc: im3d.vert + (echo 'const char *im3d_vert_src =';\ + sed 's/..*/"&\\n"/' im3d.vert;\ + echo ';') >im3d_gl.inc + +default_vs_gl.inc: default.vert + (echo 'const char *default_vert_src =';\ + sed 's/..*/"&\\n"/' default.vert;\ + echo ';') >default_vs_gl.inc + +simple_fs_gl.inc: simple.frag + (echo 'const char *simple_frag_src =';\ + sed 's/..*/"&\\n"/' simple.frag;\ + echo ';') >simple_fs_gl.inc + +matfx_gl.inc: matfx_env.frag matfx_env.vert + (echo 'const char *matfx_env_vert_src =';\ + sed 's/..*/"&\\n"/' matfx_env.vert;\ + echo ';';\ + echo 'const char *matfx_env_frag_src =';\ + sed 's/..*/"&\\n"/' matfx_env.frag;\ + echo ';') >matfx_gl.inc + +skin_gl.inc: skin.vert + (echo 'const char *skin_vert_src =';\ + sed 's/..*/"&\\n"/' skin.vert;\ + echo ';') >skin_gl.inc + diff --git a/src/gl/shaders/default.vert b/src/gl/shaders/default.vert new file mode 100644 index 0000000..8e3fad7 --- /dev/null +++ b/src/gl/shaders/default.vert @@ -0,0 +1,23 @@ +VSIN(ATTRIB_POS) vec3 in_pos; + +VSOUT vec4 v_color; +VSOUT vec2 v_tex0; +VSOUT float v_fog; + +void +main(void) +{ + vec4 Vertex = u_world * vec4(in_pos, 1.0); + gl_Position = u_proj * u_view * Vertex; + vec3 Normal = mat3(u_world) * in_normal; + + v_tex0 = in_tex0; + + v_color = in_color; + v_color.rgb += u_ambLight.rgb*surfAmbient; + v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse; + v_color = clamp(v_color, 0.0, 1.0); + v_color *= u_matColor; + + v_fog = DoFog(gl_Position.w); +} diff --git a/src/gl/shaders/default_vs_gl.inc b/src/gl/shaders/default_vs_gl.inc new file mode 100644 index 0000000..6e3d6c4 --- /dev/null +++ b/src/gl/shaders/default_vs_gl.inc @@ -0,0 +1,25 @@ +const char *default_vert_src = +"VSIN(ATTRIB_POS) vec3 in_pos;\n" + +"VSOUT vec4 v_color;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 Vertex = u_world * vec4(in_pos, 1.0);\n" +" gl_Position = u_proj * u_view * Vertex;\n" +" vec3 Normal = mat3(u_world) * in_normal;\n" + +" v_tex0 = in_tex0;\n" + +" v_color = in_color;\n" +" v_color.rgb += u_ambLight.rgb*surfAmbient;\n" +" v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse;\n" +" v_color = clamp(v_color, 0.0, 1.0);\n" +" v_color *= u_matColor;\n" + +" v_fog = DoFog(gl_Position.w);\n" +"}\n" +; diff --git a/src/gl/shaders/header.frag b/src/gl/shaders/header.frag new file mode 100644 index 0000000..ba50165 --- /dev/null +++ b/src/gl/shaders/header.frag @@ -0,0 +1,30 @@ +#ifdef USE_UBOS +layout(std140) uniform State +{ + vec2 u_alphaRef; + vec4 u_fogData; + vec4 u_fogColor; +}; +#else +uniform vec4 u_alphaRef; + +uniform vec4 u_fogData; +uniform vec4 u_fogColor; +#endif + +#define u_fogStart (u_fogData.x) +#define u_fogEnd (u_fogData.y) +#define u_fogRange (u_fogData.z) +#define u_fogDisable (u_fogData.w) + +#ifndef GL2 +out vec4 fragColor; +#endif + +void DoAlphaTest(float a) +{ +#ifndef NO_ALPHATEST + if(a < u_alphaRef.x || a >= u_alphaRef.y) + discard; +#endif +} diff --git a/src/gl/shaders/header.vert b/src/gl/shaders/header.vert new file mode 100644 index 0000000..bb9881f --- /dev/null +++ b/src/gl/shaders/header.vert @@ -0,0 +1,128 @@ + +//#define DIRECTIONALS +//#define POINTLIGHTS +//#define SPOTLIGHTS + +#define ATTRIB_POS 0 +#define ATTRIB_NORMAL 1 +#define ATTRIB_COLOR 2 +#define ATTRIB_WEIGHTS 3 +#define ATTRIB_INDICES 4 +#define ATTRIB_TEXCOORDS0 5 +#define ATTRIB_TEXCOORDS1 6 + + +VSIN(ATTRIB_NORMAL) vec3 in_normal; +VSIN(ATTRIB_COLOR) vec4 in_color; +VSIN(ATTRIB_WEIGHTS) vec4 in_weights; +VSIN(ATTRIB_INDICES) vec4 in_indices; +VSIN(ATTRIB_TEXCOORDS0) vec2 in_tex0; +VSIN(ATTRIB_TEXCOORDS1) vec2 in_tex1; + + +#ifdef USE_UBOS +layout(std140) uniform State +{ + vec2 u_alphaRef; + vec4 u_fogData; + vec4 u_fogColor; +}; +#else +uniform vec4 u_alphaRef; +uniform vec4 u_fogData; +uniform vec4 u_fogColor; +#endif + +#define u_fogStart (u_fogData.x) +#define u_fogEnd (u_fogData.y) +#define u_fogRange (u_fogData.z) +#define u_fogDisable (u_fogData.w) + +#ifdef USE_UBOS +layout(std140) uniform Scene +{ + mat4 u_proj; + mat4 u_view; +}; +#else +uniform mat4 u_proj; +uniform mat4 u_view; +#endif + +#define MAX_LIGHTS 8 + +#ifdef USE_UBOS +layout(std140) uniform Object +{ + mat4 u_world; + vec4 u_ambLight; + vec4 u_lightParams[MAX_LIGHTS]; // type, radius, minusCosAngle, hardSpot + vec4 u_lightPosition[MAX_LIGHTS]; + vec4 u_lightDirection[MAX_LIGHTS]; + vec4 u_lightColor[MAX_LIGHTS]; +}; +#else +uniform mat4 u_world; +uniform vec4 u_ambLight; +uniform vec4 u_lightParams[MAX_LIGHTS]; // type, radius, minusCosAngle, hardSpot +uniform vec4 u_lightPosition[MAX_LIGHTS]; +uniform vec4 u_lightDirection[MAX_LIGHTS]; +uniform vec4 u_lightColor[MAX_LIGHTS]; +#endif + +uniform vec4 u_matColor; +uniform vec4 u_surfProps; // amb, spec, diff, extra + +#define surfAmbient (u_surfProps.x) +#define surfSpecular (u_surfProps.y) +#define surfDiffuse (u_surfProps.z) + +vec3 DoDynamicLight(vec3 V, vec3 N) +{ + vec3 color = vec3(0.0, 0.0, 0.0); + for(int i = 0; i < MAX_LIGHTS; i++){ + if(u_lightParams[i].x == 0.0) + break; +#ifdef DIRECTIONALS + if(u_lightParams[i].x == 1.0){ + // direct + float l = max(0.0, dot(N, -u_lightDirection[i].xyz)); + color += l*u_lightColor[i].rgb; + }else +#endif +#ifdef POINTLIGHTS + if(u_lightParams[i].x == 2.0){ + // point + vec3 dir = V - u_lightPosition[i].xyz; + float dist = length(dir); + float atten = max(0.0, (1.0 - dist/u_lightParams[i].y)); + float l = max(0.0, dot(N, -normalize(dir))); + color += l*u_lightColor[i].rgb*atten; + }else +#endif +#ifdef SPOTLIGHTS + if(u_lightParams[i].x == 3.0){ + // spot + vec3 dir = V - u_lightPosition[i].xyz; + float dist = length(dir); + float atten = max(0.0, (1.0 - dist/u_lightParams[i].y)); + dir /= dist; + float l = max(0.0, dot(N, -dir)); + float pcos = dot(dir, u_lightDirection[i].xyz); // cos to point + float ccos = -u_lightParams[i].z; + float falloff = (pcos-ccos)/(1.0-ccos); + if(falloff < 0.0) // outside of cone + l = 0.0; + l *= max(falloff, u_lightParams[i].w); + return l*u_lightColor[i].rgb*atten; + }else +#endif + ; + } + return color; +} + +float DoFog(float w) +{ + return clamp((w - u_fogEnd)*u_fogRange, u_fogDisable, 1.0); +} diff --git a/src/gl/shaders/header_fs.inc b/src/gl/shaders/header_fs.inc new file mode 100644 index 0000000..802bb4f --- /dev/null +++ b/src/gl/shaders/header_fs.inc @@ -0,0 +1,32 @@ +const char *header_frag_src = +"#ifdef USE_UBOS\n" +"layout(std140) uniform State\n" +"{\n" +" vec2 u_alphaRef;\n" +" vec4 u_fogData;\n" +" vec4 u_fogColor;\n" +"};\n" +"#else\n" +"uniform vec4 u_alphaRef;\n" + +"uniform vec4 u_fogData;\n" +"uniform vec4 u_fogColor;\n" +"#endif\n" + +"#define u_fogStart (u_fogData.x)\n" +"#define u_fogEnd (u_fogData.y)\n" +"#define u_fogRange (u_fogData.z)\n" +"#define u_fogDisable (u_fogData.w)\n" + +"#ifndef GL2\n" +"out vec4 fragColor;\n" +"#endif\n" + +"void DoAlphaTest(float a)\n" +"{\n" +"#ifndef NO_ALPHATEST\n" +" if(a < u_alphaRef.x || a >= u_alphaRef.y)\n" +" discard;\n" +"#endif\n" +"}\n" +; diff --git a/src/gl/shaders/header_vs.inc b/src/gl/shaders/header_vs.inc new file mode 100644 index 0000000..ffa4683 --- /dev/null +++ b/src/gl/shaders/header_vs.inc @@ -0,0 +1,130 @@ +const char *header_vert_src = + +"//#define DIRECTIONALS\n" +"//#define POINTLIGHTS\n" +"//#define SPOTLIGHTS\n" + +"#define ATTRIB_POS 0\n" +"#define ATTRIB_NORMAL 1\n" +"#define ATTRIB_COLOR 2\n" +"#define ATTRIB_WEIGHTS 3\n" +"#define ATTRIB_INDICES 4\n" +"#define ATTRIB_TEXCOORDS0 5\n" +"#define ATTRIB_TEXCOORDS1 6\n" + + +"VSIN(ATTRIB_NORMAL) vec3 in_normal;\n" +"VSIN(ATTRIB_COLOR) vec4 in_color;\n" +"VSIN(ATTRIB_WEIGHTS) vec4 in_weights;\n" +"VSIN(ATTRIB_INDICES) vec4 in_indices;\n" +"VSIN(ATTRIB_TEXCOORDS0) vec2 in_tex0;\n" +"VSIN(ATTRIB_TEXCOORDS1) vec2 in_tex1;\n" + + +"#ifdef USE_UBOS\n" +"layout(std140) uniform State\n" +"{\n" +" vec2 u_alphaRef;\n" +" vec4 u_fogData;\n" +" vec4 u_fogColor;\n" +"};\n" +"#else\n" +"uniform vec4 u_alphaRef;\n" +"uniform vec4 u_fogData;\n" +"uniform vec4 u_fogColor;\n" +"#endif\n" + +"#define u_fogStart (u_fogData.x)\n" +"#define u_fogEnd (u_fogData.y)\n" +"#define u_fogRange (u_fogData.z)\n" +"#define u_fogDisable (u_fogData.w)\n" + +"#ifdef USE_UBOS\n" +"layout(std140) uniform Scene\n" +"{\n" +" mat4 u_proj;\n" +" mat4 u_view;\n" +"};\n" +"#else\n" +"uniform mat4 u_proj;\n" +"uniform mat4 u_view;\n" +"#endif\n" + +"#define MAX_LIGHTS 8\n" + +"#ifdef USE_UBOS\n" +"layout(std140) uniform Object\n" +"{\n" +" mat4 u_world;\n" +" vec4 u_ambLight;\n" +" vec4 u_lightParams[MAX_LIGHTS]; // type, radius, minusCosAngle, hardSpot\n" +" vec4 u_lightPosition[MAX_LIGHTS];\n" +" vec4 u_lightDirection[MAX_LIGHTS];\n" +" vec4 u_lightColor[MAX_LIGHTS];\n" +"};\n" +"#else\n" +"uniform mat4 u_world;\n" +"uniform vec4 u_ambLight;\n" +"uniform vec4 u_lightParams[MAX_LIGHTS]; // type, radius, minusCosAngle, hardSpot\n" +"uniform vec4 u_lightPosition[MAX_LIGHTS];\n" +"uniform vec4 u_lightDirection[MAX_LIGHTS];\n" +"uniform vec4 u_lightColor[MAX_LIGHTS];\n" +"#endif\n" + +"uniform vec4 u_matColor;\n" +"uniform vec4 u_surfProps; // amb, spec, diff, extra\n" + +"#define surfAmbient (u_surfProps.x)\n" +"#define surfSpecular (u_surfProps.y)\n" +"#define surfDiffuse (u_surfProps.z)\n" + +"vec3 DoDynamicLight(vec3 V, vec3 N)\n" +"{\n" +" vec3 color = vec3(0.0, 0.0, 0.0);\n" +" for(int i = 0; i < MAX_LIGHTS; i++){\n" +" if(u_lightParams[i].x == 0.0)\n" +" break;\n" +"#ifdef DIRECTIONALS\n" +" if(u_lightParams[i].x == 1.0){\n" +" // direct\n" +" float l = max(0.0, dot(N, -u_lightDirection[i].xyz));\n" +" color += l*u_lightColor[i].rgb;\n" +" }else\n" +"#endif\n" +"#ifdef POINTLIGHTS\n" +" if(u_lightParams[i].x == 2.0){\n" +" // point\n" +" vec3 dir = V - u_lightPosition[i].xyz;\n" +" float dist = length(dir);\n" +" float atten = max(0.0, (1.0 - dist/u_lightParams[i].y));\n" +" float l = max(0.0, dot(N, -normalize(dir)));\n" +" color += l*u_lightColor[i].rgb*atten;\n" +" }else\n" +"#endif\n" +"#ifdef SPOTLIGHTS\n" +" if(u_lightParams[i].x == 3.0){\n" +" // spot\n" +" vec3 dir = V - u_lightPosition[i].xyz;\n" +" float dist = length(dir);\n" +" float atten = max(0.0, (1.0 - dist/u_lightParams[i].y));\n" +" dir /= dist;\n" +" float l = max(0.0, dot(N, -dir));\n" +" float pcos = dot(dir, u_lightDirection[i].xyz); // cos to point\n" +" float ccos = -u_lightParams[i].z;\n" +" float falloff = (pcos-ccos)/(1.0-ccos);\n" +" if(falloff < 0.0) // outside of cone\n" +" l = 0.0;\n" +" l *= max(falloff, u_lightParams[i].w);\n" +" return l*u_lightColor[i].rgb*atten;\n" +" }else\n" +"#endif\n" +" ;\n" +" }\n" +" return color;\n" +"}\n" + +"float DoFog(float w)\n" +"{\n" +" return clamp((w - u_fogEnd)*u_fogRange, u_fogDisable, 1.0);\n" +"}\n" +; diff --git a/src/gl/shaders/im2d.vert b/src/gl/shaders/im2d.vert new file mode 100644 index 0000000..cdb9da8 --- /dev/null +++ b/src/gl/shaders/im2d.vert @@ -0,0 +1,18 @@ +uniform vec4 u_xform; + +VSIN(ATTRIB_POS) vec4 in_pos; + +VSOUT vec4 v_color; +VSOUT vec2 v_tex0; +VSOUT float v_fog; + +void +main(void) +{ + gl_Position = in_pos; + gl_Position.xy = gl_Position.xy * u_xform.xy + u_xform.zw; + v_fog = DoFog(gl_Position.w); + gl_Position.xyz *= gl_Position.w; + v_color = in_color; + v_tex0 = in_tex0; +} diff --git a/src/gl/shaders/im2d_gl.inc b/src/gl/shaders/im2d_gl.inc new file mode 100644 index 0000000..4e1d631 --- /dev/null +++ b/src/gl/shaders/im2d_gl.inc @@ -0,0 +1,20 @@ +const char *im2d_vert_src = +"uniform vec4 u_xform;\n" + +"VSIN(ATTRIB_POS) vec4 in_pos;\n" + +"VSOUT vec4 v_color;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" gl_Position = in_pos;\n" +" gl_Position.xy = gl_Position.xy * u_xform.xy + u_xform.zw;\n" +" v_fog = DoFog(gl_Position.w);\n" +" gl_Position.xyz *= gl_Position.w;\n" +" v_color = in_color;\n" +" v_tex0 = in_tex0;\n" +"}\n" +; diff --git a/src/gl/shaders/im3d.vert b/src/gl/shaders/im3d.vert new file mode 100644 index 0000000..280b128 --- /dev/null +++ b/src/gl/shaders/im3d.vert @@ -0,0 +1,15 @@ +VSIN(ATTRIB_POS) vec3 in_pos; + +VSOUT vec4 v_color; +VSOUT vec2 v_tex0; +VSOUT float v_fog; + +void +main(void) +{ + vec4 Vertex = u_world * vec4(in_pos, 1.0); + gl_Position = u_proj * u_view * Vertex; + v_color = in_color; + v_tex0 = in_tex0; + v_fog = DoFog(gl_Position.w); +} diff --git a/src/gl/shaders/im3d_gl.inc b/src/gl/shaders/im3d_gl.inc new file mode 100644 index 0000000..40ec7a1 --- /dev/null +++ b/src/gl/shaders/im3d_gl.inc @@ -0,0 +1,17 @@ +const char *im3d_vert_src = +"VSIN(ATTRIB_POS) vec3 in_pos;\n" + +"VSOUT vec4 v_color;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 Vertex = u_world * vec4(in_pos, 1.0);\n" +" gl_Position = u_proj * u_view * Vertex;\n" +" v_color = in_color;\n" +" v_tex0 = in_tex0;\n" +" v_fog = DoFog(gl_Position.w);\n" +"}\n" +; diff --git a/src/gl/shaders/matfx_env.frag b/src/gl/shaders/matfx_env.frag new file mode 100644 index 0000000..0ef20d1 --- /dev/null +++ b/src/gl/shaders/matfx_env.frag @@ -0,0 +1,34 @@ +uniform sampler2D tex0; +uniform sampler2D tex1; + +uniform vec4 u_fxparams; + +#define shininess (u_fxparams.x) +#define disableFBA (u_fxparams.y) + +FSIN vec4 v_color; +FSIN vec4 v_envColor; +FSIN vec2 v_tex0; +FSIN vec2 v_tex1; +FSIN float v_fog; + +void +main(void) +{ + vec4 pass1 = v_color; + pass1 *= texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y)); + + vec4 pass2 = v_envColor*shininess*texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y)); + + pass1.rgb = mix(u_fogColor.rgb, pass1.rgb, v_fog); + pass2.rgb = mix(vec3(0.0, 0.0, 0.0), pass2.rgb, v_fog); + + float fba = max(pass1.a, disableFBA); + vec4 color; + color.rgb = pass1.rgb*pass1.a + pass2.rgb*fba; + color.a = pass1.a; + + DoAlphaTest(color.a); + + FRAGCOLOR(color); +} diff --git a/src/gl/shaders/matfx_env.vert b/src/gl/shaders/matfx_env.vert new file mode 100644 index 0000000..580a49f --- /dev/null +++ b/src/gl/shaders/matfx_env.vert @@ -0,0 +1,31 @@ +uniform mat4 u_texMatrix; +uniform vec4 u_colorClamp; +uniform vec4 u_envColor; + +VSIN(ATTRIB_POS) vec3 in_pos; + +VSOUT vec4 v_color; +VSOUT vec4 v_envColor; +VSOUT vec2 v_tex0; +VSOUT vec2 v_tex1; +VSOUT float v_fog; + +void +main(void) +{ + vec4 Vertex = u_world * vec4(in_pos, 1.0); + gl_Position = u_proj * u_view * Vertex; + vec3 Normal = mat3(u_world) * in_normal; + + v_tex0 = in_tex0; + v_tex1 = (u_texMatrix * vec4(Normal, 1.0)).xy; + + v_color = in_color; + v_color.rgb += u_ambLight.rgb*surfAmbient; + v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse; + v_color = clamp(v_color, 0.0, 1.0); + v_envColor = max(v_color, u_colorClamp) * u_envColor; + v_color *= u_matColor; + + v_fog = DoFog(gl_Position.w); +} diff --git a/src/gl/shaders/matfx_gl.inc b/src/gl/shaders/matfx_gl.inc new file mode 100644 index 0000000..a1dcaf8 --- /dev/null +++ b/src/gl/shaders/matfx_gl.inc @@ -0,0 +1,69 @@ +const char *matfx_env_vert_src = +"uniform mat4 u_texMatrix;\n" +"uniform vec4 u_colorClamp;\n" +"uniform vec4 u_envColor;\n" + +"VSIN(ATTRIB_POS) vec3 in_pos;\n" + +"VSOUT vec4 v_color;\n" +"VSOUT vec4 v_envColor;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT vec2 v_tex1;\n" +"VSOUT float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 Vertex = u_world * vec4(in_pos, 1.0);\n" +" gl_Position = u_proj * u_view * Vertex;\n" +" vec3 Normal = mat3(u_world) * in_normal;\n" + +" v_tex0 = in_tex0;\n" +" v_tex1 = (u_texMatrix * vec4(Normal, 1.0)).xy;\n" + +" v_color = in_color;\n" +" v_color.rgb += u_ambLight.rgb*surfAmbient;\n" +" v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse;\n" +" v_color = clamp(v_color, 0.0, 1.0);\n" +" v_envColor = max(v_color, u_colorClamp) * u_envColor;\n" +" v_color *= u_matColor;\n" + +" v_fog = DoFog(gl_Position.w);\n" +"}\n" +; +const char *matfx_env_frag_src = +"uniform sampler2D tex0;\n" +"uniform sampler2D tex1;\n" + +"uniform vec4 u_fxparams;\n" + +"#define shininess (u_fxparams.x)\n" +"#define disableFBA (u_fxparams.y)\n" + +"FSIN vec4 v_color;\n" +"FSIN vec4 v_envColor;\n" +"FSIN vec2 v_tex0;\n" +"FSIN vec2 v_tex1;\n" +"FSIN float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 pass1 = v_color;\n" +" pass1 *= texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n" + +" vec4 pass2 = v_envColor*shininess*texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y));\n" + +" pass1.rgb = mix(u_fogColor.rgb, pass1.rgb, v_fog);\n" +" pass2.rgb = mix(vec3(0.0, 0.0, 0.0), pass2.rgb, v_fog);\n" + +" float fba = max(pass1.a, disableFBA);\n" +" vec4 color;\n" +" color.rgb = pass1.rgb*pass1.a + pass2.rgb*fba;\n" +" color.a = pass1.a;\n" + +" DoAlphaTest(color.a);\n" + +" FRAGCOLOR(color);\n" +"}\n" +; diff --git a/src/gl/shaders/simple.frag b/src/gl/shaders/simple.frag new file mode 100644 index 0000000..34c1e43 --- /dev/null +++ b/src/gl/shaders/simple.frag @@ -0,0 +1,14 @@ +uniform sampler2D tex0; + +FSIN vec4 v_color; +FSIN vec2 v_tex0; +FSIN float v_fog; + +void +main(void) +{ + vec4 color = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y)); + color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog); + DoAlphaTest(color.a); + FRAGCOLOR(color); +} diff --git a/src/gl/shaders/simple_fs_gl.inc b/src/gl/shaders/simple_fs_gl.inc new file mode 100644 index 0000000..a9216ca --- /dev/null +++ b/src/gl/shaders/simple_fs_gl.inc @@ -0,0 +1,17 @@ +const char *simple_frag_src = +"uniform sampler2D tex0;\n" + +"FSIN vec4 v_color;\n" +"FSIN vec2 v_tex0;\n" +"FSIN float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 color = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n" +" color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);\n" +" DoAlphaTest(color.a);\n" +" FRAGCOLOR(color);\n" +"}\n" + +; diff --git a/src/gl/shaders/skin.vert b/src/gl/shaders/skin.vert new file mode 100644 index 0000000..7408542 --- /dev/null +++ b/src/gl/shaders/skin.vert @@ -0,0 +1,32 @@ +uniform mat4 u_boneMatrices[64]; + +VSIN(ATTRIB_POS) vec3 in_pos; + +VSOUT vec4 v_color; +VSOUT vec2 v_tex0; +VSOUT float v_fog; + +void +main(void) +{ + vec3 SkinVertex = vec3(0.0, 0.0, 0.0); + vec3 SkinNormal = vec3(0.0, 0.0, 0.0); + for(int i = 0; i < 4; i++){ + SkinVertex += (u_boneMatrices[int(in_indices[i])] * vec4(in_pos, 1.0)).xyz * in_weights[i]; + SkinNormal += (mat3(u_boneMatrices[int(in_indices[i])]) * in_normal) * in_weights[i]; + } + + vec4 Vertex = u_world * vec4(SkinVertex, 1.0); + gl_Position = u_proj * u_view * Vertex; + vec3 Normal = mat3(u_world) * SkinNormal; + + v_tex0 = in_tex0; + + v_color = in_color; + v_color.rgb += u_ambLight.rgb*surfAmbient; + v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse; + v_color = clamp(v_color, 0.0, 1.0); + v_color *= u_matColor; + + v_fog = DoFog(gl_Position.z); +} diff --git a/src/gl/shaders/skin_gl.inc b/src/gl/shaders/skin_gl.inc new file mode 100644 index 0000000..7d1268e --- /dev/null +++ b/src/gl/shaders/skin_gl.inc @@ -0,0 +1,34 @@ +const char *skin_vert_src = +"uniform mat4 u_boneMatrices[64];\n" + +"VSIN(ATTRIB_POS) vec3 in_pos;\n" + +"VSOUT vec4 v_color;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec3 SkinVertex = vec3(0.0, 0.0, 0.0);\n" +" vec3 SkinNormal = vec3(0.0, 0.0, 0.0);\n" +" for(int i = 0; i < 4; i++){\n" +" SkinVertex += (u_boneMatrices[int(in_indices[i])] * vec4(in_pos, 1.0)).xyz * in_weights[i];\n" +" SkinNormal += (mat3(u_boneMatrices[int(in_indices[i])]) * in_normal) * in_weights[i];\n" +" }\n" + +" vec4 Vertex = u_world * vec4(SkinVertex, 1.0);\n" +" gl_Position = u_proj * u_view * Vertex;\n" +" vec3 Normal = mat3(u_world) * SkinNormal;\n" + +" v_tex0 = in_tex0;\n" + +" v_color = in_color;\n" +" v_color.rgb += u_ambLight.rgb*surfAmbient;\n" +" v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse;\n" +" v_color = clamp(v_color, 0.0, 1.0);\n" +" v_color *= u_matColor;\n" + +" v_fog = DoFog(gl_Position.z);\n" +"}\n" +; |
