mirror of https://github.com/aap/librw.git
forgot half the files
This commit is contained in:
parent
6c7d811096
commit
0fec15b06b
|
@ -0,0 +1,40 @@
|
|||
all: header_vs.inc im2d_gl2.inc im3d_gl2.inc default_vs_gl2.inc simple_fs_gl2.inc matfx_gl2.inc skin_gl2.inc
|
||||
|
||||
header_vs.inc: header.vert
|
||||
(echo 'const char *header_vert_src =';\
|
||||
sed 's/..*/"&\\n"/' header.vert;\
|
||||
echo ';') >header_vs.inc
|
||||
|
||||
im2d_gl2.inc: im2d.vert
|
||||
(echo 'const char *im2d_vert_src =';\
|
||||
sed 's/..*/"&\\n"/' im2d.vert;\
|
||||
echo ';') >im2d_gl2.inc
|
||||
|
||||
im3d_gl2.inc: im3d.vert
|
||||
(echo 'const char *im3d_vert_src =';\
|
||||
sed 's/..*/"&\\n"/' im3d.vert;\
|
||||
echo ';') >im3d_gl2.inc
|
||||
|
||||
default_vs_gl2.inc: default.vert
|
||||
(echo 'const char *default_vert_src =';\
|
||||
sed 's/..*/"&\\n"/' default.vert;\
|
||||
echo ';') >default_vs_gl2.inc
|
||||
|
||||
simple_fs_gl2.inc: simple.frag
|
||||
(echo 'const char *simple_frag_src =';\
|
||||
sed 's/..*/"&\\n"/' simple.frag;\
|
||||
echo ';') >simple_fs_gl2.inc
|
||||
|
||||
matfx_gl2.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_gl2.inc
|
||||
|
||||
skin_gl2.inc: skin.vert
|
||||
(echo 'const char *skin_vert_src =';\
|
||||
sed 's/..*/"&\\n"/' skin.vert;\
|
||||
echo ';') >skin_gl2.inc
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
attribute vec3 in_pos;
|
||||
attribute vec3 in_normal;
|
||||
attribute vec4 in_color;
|
||||
attribute vec2 in_tex0;
|
||||
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_tex0;
|
||||
varying float v_fog;
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
vec4 V = u_world * vec4(in_pos, 1.0);
|
||||
gl_Position = u_proj * u_view * V;
|
||||
vec3 N = mat3(u_world) * in_normal;
|
||||
|
||||
v_tex0 = in_tex0;
|
||||
|
||||
v_color = in_color;
|
||||
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
||||
|
||||
#ifdef DIRECTIONALS
|
||||
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||
if(u_directLights[i].enabled == 0.0)
|
||||
break;
|
||||
v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;
|
||||
}
|
||||
#endif
|
||||
#ifdef POINTLIGHTS
|
||||
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||
if(u_pointLights[i].enabled == 0.0)
|
||||
break;
|
||||
v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;
|
||||
}
|
||||
#endif
|
||||
#ifdef SPOTLIGHTS
|
||||
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||
if(u_spotLights[i].enabled == 0.0)
|
||||
break;
|
||||
v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;
|
||||
}
|
||||
#endif
|
||||
|
||||
v_color = clamp(v_color, 0.0f, 1.0);
|
||||
v_color *= u_matColor;
|
||||
|
||||
v_fog = DoFog(gl_Position.w);
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
const char *default_vert_src =
|
||||
"attribute vec3 in_pos;\n"
|
||||
"attribute vec3 in_normal;\n"
|
||||
"attribute vec4 in_color;\n"
|
||||
"attribute vec2 in_tex0;\n"
|
||||
|
||||
"varying vec4 v_color;\n"
|
||||
"varying vec2 v_tex0;\n"
|
||||
"varying float v_fog;\n"
|
||||
|
||||
"void\n"
|
||||
"main(void)\n"
|
||||
"{\n"
|
||||
" vec4 V = u_world * vec4(in_pos, 1.0);\n"
|
||||
" gl_Position = u_proj * u_view * V;\n"
|
||||
" vec3 N = mat3(u_world) * in_normal;\n"
|
||||
|
||||
" v_tex0 = in_tex0;\n"
|
||||
|
||||
" v_color = in_color;\n"
|
||||
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
||||
|
||||
"#ifdef DIRECTIONALS\n"
|
||||
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||
" if(u_directLights[i].enabled == 0.0)\n"
|
||||
" break;\n"
|
||||
" v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
"#ifdef POINTLIGHTS\n"
|
||||
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||
" if(u_pointLights[i].enabled == 0.0)\n"
|
||||
" break;\n"
|
||||
" v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
"#ifdef SPOTLIGHTS\n"
|
||||
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||
" if(u_spotLights[i].enabled == 0.0)\n"
|
||||
" break;\n"
|
||||
" v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
|
||||
" v_color = clamp(v_color, 0.0f, 1.0);\n"
|
||||
" v_color *= u_matColor;\n"
|
||||
|
||||
" v_fog = DoFog(gl_Position.w);\n"
|
||||
"}\n"
|
||||
;
|
|
@ -0,0 +1,77 @@
|
|||
// State
|
||||
uniform float u_fogStart;
|
||||
uniform float u_fogEnd;
|
||||
uniform float u_fogRange;
|
||||
uniform float u_fogDisable;
|
||||
//uniform vec4 u_fogColor;
|
||||
|
||||
// Scene
|
||||
uniform mat4 u_proj;
|
||||
uniform mat4 u_view;
|
||||
|
||||
#define MAX_LIGHTS 8
|
||||
struct Light {
|
||||
float enabled;
|
||||
float radius;
|
||||
float minusCosAngle;
|
||||
float hardSpot;
|
||||
vec4 position;
|
||||
vec4 direction;
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
// Object
|
||||
uniform mat4 u_world;
|
||||
uniform vec4 u_ambLight;
|
||||
uniform Light u_directLights[MAX_LIGHTS];
|
||||
uniform Light u_pointLights[MAX_LIGHTS];
|
||||
uniform Light u_spotLights[MAX_LIGHTS];
|
||||
|
||||
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 DoDirLight(Light L, vec3 N)
|
||||
{
|
||||
float l = max(0.0, dot(N, -L.direction.xyz));
|
||||
return l*L.color.rgb;
|
||||
}
|
||||
|
||||
vec3 DoPointLight(Light L, vec3 V, vec3 N)
|
||||
{
|
||||
// As on PS2
|
||||
vec3 dir = V - L.position.xyz;
|
||||
float dist = length(dir);
|
||||
float atten = max(0.0, (1.0 - dist/L.radius));
|
||||
float l = max(0.0, dot(N, -normalize(dir)));
|
||||
return l*L.color.rgb*atten;
|
||||
}
|
||||
|
||||
vec3 DoSpotLight(Light L, vec3 V, vec3 N)
|
||||
{
|
||||
// As on PS2
|
||||
vec3 dir = V - L.position.xyz;
|
||||
float dist = length(dir);
|
||||
float atten = max(0.0, (1.0 - dist/L.radius));
|
||||
dir /= dist;
|
||||
float l = max(0.0, dot(N, -dir));
|
||||
float pcos = dot(dir, L.direction.xyz); // cos to point
|
||||
float ccos = -L.minusCosAngle;
|
||||
float falloff = (pcos-ccos)/(1.0-ccos);
|
||||
if(falloff < 0.0) // outside of cone
|
||||
l = 0.0;
|
||||
l *= max(falloff, L.hardSpot);
|
||||
return l*L.color.xyz*atten;
|
||||
}
|
||||
|
||||
float DoFog(float w)
|
||||
{
|
||||
return clamp((w - u_fogEnd)*u_fogRange, u_fogDisable, 1.0);
|
||||
}
|
||||
|
||||
#define DIRECTIONALS
|
||||
//#define POINTLIGHTS
|
||||
//#define SPOTLIGHTS
|
|
@ -0,0 +1,79 @@
|
|||
const char *header_vert_src =
|
||||
"// State\n"
|
||||
"uniform float u_fogStart;\n"
|
||||
"uniform float u_fogEnd;\n"
|
||||
"uniform float u_fogRange;\n"
|
||||
"uniform float u_fogDisable;\n"
|
||||
"//uniform vec4 u_fogColor;\n"
|
||||
|
||||
"// Scene\n"
|
||||
"uniform mat4 u_proj;\n"
|
||||
"uniform mat4 u_view;\n"
|
||||
|
||||
"#define MAX_LIGHTS 8\n"
|
||||
"struct Light {\n"
|
||||
" float enabled;\n"
|
||||
" float radius;\n"
|
||||
" float minusCosAngle;\n"
|
||||
" float hardSpot;\n"
|
||||
" vec4 position;\n"
|
||||
" vec4 direction;\n"
|
||||
" vec4 color;\n"
|
||||
"};\n"
|
||||
|
||||
"// Object\n"
|
||||
"uniform mat4 u_world;\n"
|
||||
"uniform vec4 u_ambLight;\n"
|
||||
"uniform Light u_directLights[MAX_LIGHTS];\n"
|
||||
"uniform Light u_pointLights[MAX_LIGHTS];\n"
|
||||
"uniform Light u_spotLights[MAX_LIGHTS];\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 DoDirLight(Light L, vec3 N)\n"
|
||||
"{\n"
|
||||
" float l = max(0.0, dot(N, -L.direction.xyz));\n"
|
||||
" return l*L.color.rgb;\n"
|
||||
"}\n"
|
||||
|
||||
"vec3 DoPointLight(Light L, vec3 V, vec3 N)\n"
|
||||
"{\n"
|
||||
" // As on PS2\n"
|
||||
" vec3 dir = V - L.position.xyz;\n"
|
||||
" float dist = length(dir);\n"
|
||||
" float atten = max(0.0, (1.0 - dist/L.radius));\n"
|
||||
" float l = max(0.0, dot(N, -normalize(dir)));\n"
|
||||
" return l*L.color.rgb*atten;\n"
|
||||
"}\n"
|
||||
|
||||
"vec3 DoSpotLight(Light L, vec3 V, vec3 N)\n"
|
||||
"{\n"
|
||||
" // As on PS2\n"
|
||||
" vec3 dir = V - L.position.xyz;\n"
|
||||
" float dist = length(dir);\n"
|
||||
" float atten = max(0.0, (1.0 - dist/L.radius));\n"
|
||||
" dir /= dist;\n"
|
||||
" float l = max(0.0, dot(N, -dir));\n"
|
||||
" float pcos = dot(dir, L.direction.xyz); // cos to point\n"
|
||||
" float ccos = -L.minusCosAngle;\n"
|
||||
" float falloff = (pcos-ccos)/(1.0-ccos);\n"
|
||||
" if(falloff < 0.0) // outside of cone\n"
|
||||
" l = 0.0;\n"
|
||||
" l *= max(falloff, L.hardSpot);\n"
|
||||
" return l*L.color.xyz*atten;\n"
|
||||
"}\n"
|
||||
|
||||
"float DoFog(float w)\n"
|
||||
"{\n"
|
||||
" return clamp((w - u_fogEnd)*u_fogRange, u_fogDisable, 1.0);\n"
|
||||
"}\n"
|
||||
|
||||
"#define DIRECTIONALS\n"
|
||||
"//#define POINTLIGHTS\n"
|
||||
"//#define SPOTLIGHTS\n"
|
||||
;
|
|
@ -0,0 +1,25 @@
|
|||
uniform vec4 u_xform;
|
||||
|
||||
attribute vec4 in_pos;
|
||||
attribute vec4 in_color;
|
||||
attribute vec2 in_tex0;
|
||||
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_tex0;
|
||||
varying 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.z);
|
||||
gl_Position.xyz *= gl_Position.w;
|
||||
v_color = in_color;
|
||||
//v_color.r = 0.0;
|
||||
//v_color.g = 0.0;
|
||||
//v_color.b = 0.0;
|
||||
//v_color.a = 1.0;
|
||||
//v_fog = 1.0;
|
||||
v_tex0 = in_tex0;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
const char *im2d_vert_src =
|
||||
"uniform vec4 u_xform;\n"
|
||||
|
||||
"attribute vec4 in_pos;\n"
|
||||
"attribute vec4 in_color;\n"
|
||||
"attribute vec2 in_tex0;\n"
|
||||
|
||||
"varying vec4 v_color;\n"
|
||||
"varying vec2 v_tex0;\n"
|
||||
"varying 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.z);\n"
|
||||
" gl_Position.xyz *= gl_Position.w;\n"
|
||||
" v_color = in_color;\n"
|
||||
"//v_color.r = 0.0;\n"
|
||||
"//v_color.g = 0.0;\n"
|
||||
"//v_color.b = 0.0;\n"
|
||||
"//v_color.a = 1.0;\n"
|
||||
"//v_fog = 1.0;\n"
|
||||
" v_tex0 = in_tex0;\n"
|
||||
"}\n"
|
||||
;
|
|
@ -0,0 +1,18 @@
|
|||
attribute vec3 in_pos;
|
||||
attribute vec4 in_color;
|
||||
attribute vec2 in_tex0;
|
||||
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_tex0;
|
||||
varying float v_fog;
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
vec4 V = u_world * vec4(in_pos, 1.0);
|
||||
vec4 cV = u_view * V;
|
||||
gl_Position = u_proj * cV;
|
||||
v_color = in_color;
|
||||
v_tex0 = in_tex0;
|
||||
v_fog = DoFog(gl_Position.w);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
const char *im3d_vert_src =
|
||||
"attribute vec3 in_pos;\n"
|
||||
"attribute vec4 in_color;\n"
|
||||
"attribute vec2 in_tex0;\n"
|
||||
|
||||
"varying vec4 v_color;\n"
|
||||
"varying vec2 v_tex0;\n"
|
||||
"varying float v_fog;\n"
|
||||
|
||||
"void\n"
|
||||
"main(void)\n"
|
||||
"{\n"
|
||||
" vec4 V = u_world * vec4(in_pos, 1.0);\n"
|
||||
" vec4 cV = u_view * V;\n"
|
||||
" gl_Position = u_proj * cV;\n"
|
||||
" v_color = in_color;\n"
|
||||
" v_tex0 = in_tex0;\n"
|
||||
" v_fog = DoFog(gl_Position.w);\n"
|
||||
"}\n"
|
||||
;
|
|
@ -0,0 +1,55 @@
|
|||
uniform vec2 u_alphaRef;
|
||||
|
||||
uniform float u_fogStart;
|
||||
uniform float u_fogEnd;
|
||||
uniform float u_fogRange;
|
||||
uniform float u_fogDisable;
|
||||
uniform vec4 u_fogColor;
|
||||
|
||||
uniform sampler2D tex0;
|
||||
uniform sampler2D tex1;
|
||||
|
||||
uniform float u_coefficient;
|
||||
uniform vec4 u_colorClamp;
|
||||
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_tex0;
|
||||
varying vec2 v_tex1;
|
||||
varying float v_fog;
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
vec4 color;
|
||||
|
||||
vec4 pass1 = v_color;
|
||||
vec4 envColor = pass1; // TODO: colorClamp
|
||||
pass1 *= texture2D(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));
|
||||
|
||||
vec4 pass2 = envColor*u_coefficient*texture2D(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);
|
||||
|
||||
color.rgb = pass1.rgb*pass1.a + pass2.rgb;
|
||||
color.a = pass1.a;
|
||||
|
||||
if(color.a < u_alphaRef.x || color.a >= u_alphaRef.y)
|
||||
discard;
|
||||
/*
|
||||
switch(u_alphaTest){
|
||||
default:
|
||||
case 0: break;
|
||||
case 1:
|
||||
if(color.a < u_alphaRef)
|
||||
discard;
|
||||
break;
|
||||
case 2:
|
||||
if(color.a >= u_alphaRef)
|
||||
discard;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
uniform mat4 u_texMatrix;
|
||||
|
||||
attribute vec3 in_pos;
|
||||
attribute vec3 in_normal;
|
||||
attribute vec4 in_color;
|
||||
attribute vec2 in_tex0;
|
||||
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_tex0;
|
||||
varying vec2 v_tex1;
|
||||
varying float v_fog;
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
vec4 V = u_world * vec4(in_pos, 1.0);
|
||||
gl_Position = u_proj * u_view * V;
|
||||
vec3 N = mat3(u_world) * in_normal;
|
||||
|
||||
v_tex0 = in_tex0;
|
||||
v_tex1 = (u_texMatrix * vec4(N, 1.0)).xy;
|
||||
|
||||
v_color = in_color;
|
||||
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
||||
|
||||
#ifdef DIRECTIONALS
|
||||
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||
if(u_directLights[i].enabled == 0.0)
|
||||
break;
|
||||
v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;
|
||||
}
|
||||
#endif
|
||||
#ifdef POINTLIGHTS
|
||||
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||
if(u_pointLights[i].enabled == 0.0)
|
||||
break;
|
||||
v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;
|
||||
}
|
||||
#endif
|
||||
#ifdef SPOTLIGHTS
|
||||
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||
if(u_spotLights[i].enabled == 0.0)
|
||||
break;
|
||||
v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;
|
||||
}
|
||||
#endif
|
||||
|
||||
v_color = clamp(v_color, 0.0f, 1.0);
|
||||
v_color *= u_matColor;
|
||||
|
||||
v_fog = DoFog(gl_Position.w);
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
const char *matfx_env_vert_src =
|
||||
"uniform mat4 u_texMatrix;\n"
|
||||
|
||||
"attribute vec3 in_pos;\n"
|
||||
"attribute vec3 in_normal;\n"
|
||||
"attribute vec4 in_color;\n"
|
||||
"attribute vec2 in_tex0;\n"
|
||||
|
||||
"varying vec4 v_color;\n"
|
||||
"varying vec2 v_tex0;\n"
|
||||
"varying vec2 v_tex1;\n"
|
||||
"varying float v_fog;\n"
|
||||
|
||||
"void\n"
|
||||
"main(void)\n"
|
||||
"{\n"
|
||||
" vec4 V = u_world * vec4(in_pos, 1.0);\n"
|
||||
" gl_Position = u_proj * u_view * V;\n"
|
||||
" vec3 N = mat3(u_world) * in_normal;\n"
|
||||
|
||||
" v_tex0 = in_tex0;\n"
|
||||
" v_tex1 = (u_texMatrix * vec4(N, 1.0)).xy;\n"
|
||||
|
||||
" v_color = in_color;\n"
|
||||
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
||||
|
||||
"#ifdef DIRECTIONALS\n"
|
||||
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||
" if(u_directLights[i].enabled == 0.0)\n"
|
||||
" break;\n"
|
||||
" v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
"#ifdef POINTLIGHTS\n"
|
||||
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||
" if(u_pointLights[i].enabled == 0.0)\n"
|
||||
" break;\n"
|
||||
" v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
"#ifdef SPOTLIGHTS\n"
|
||||
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||
" if(u_spotLights[i].enabled == 0.0)\n"
|
||||
" break;\n"
|
||||
" v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
|
||||
" v_color = clamp(v_color, 0.0f, 1.0);\n"
|
||||
" v_color *= u_matColor;\n"
|
||||
|
||||
" v_fog = DoFog(gl_Position.w);\n"
|
||||
"}\n"
|
||||
;
|
||||
const char *matfx_env_frag_src =
|
||||
"uniform vec2 u_alphaRef;\n"
|
||||
|
||||
"uniform float u_fogStart;\n"
|
||||
"uniform float u_fogEnd;\n"
|
||||
"uniform float u_fogRange;\n"
|
||||
"uniform float u_fogDisable;\n"
|
||||
"uniform vec4 u_fogColor;\n"
|
||||
|
||||
"uniform sampler2D tex0;\n"
|
||||
"uniform sampler2D tex1;\n"
|
||||
|
||||
"uniform float u_coefficient;\n"
|
||||
"uniform vec4 u_colorClamp;\n"
|
||||
|
||||
"varying vec4 v_color;\n"
|
||||
"varying vec2 v_tex0;\n"
|
||||
"varying vec2 v_tex1;\n"
|
||||
"varying float v_fog;\n"
|
||||
|
||||
"void\n"
|
||||
"main(void)\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
|
||||
" vec4 pass1 = v_color;\n"
|
||||
" vec4 envColor = pass1; // TODO: colorClamp\n"
|
||||
" pass1 *= texture2D(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n"
|
||||
|
||||
" vec4 pass2 = envColor*u_coefficient*texture2D(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"
|
||||
|
||||
" color.rgb = pass1.rgb*pass1.a + pass2.rgb;\n"
|
||||
" color.a = pass1.a;\n"
|
||||
|
||||
" if(color.a < u_alphaRef.x || color.a >= u_alphaRef.y)\n"
|
||||
" discard;\n"
|
||||
"/*\n"
|
||||
" switch(u_alphaTest){\n"
|
||||
" default:\n"
|
||||
" case 0: break;\n"
|
||||
" case 1:\n"
|
||||
" if(color.a < u_alphaRef)\n"
|
||||
" discard;\n"
|
||||
" break;\n"
|
||||
" case 2:\n"
|
||||
" if(color.a >= u_alphaRef)\n"
|
||||
" discard;\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
"*/\n"
|
||||
|
||||
" gl_FragColor = color;\n"
|
||||
"}\n"
|
||||
;
|
|
@ -0,0 +1,40 @@
|
|||
uniform vec2 u_alphaRef;
|
||||
|
||||
uniform float u_fogStart;
|
||||
uniform float u_fogEnd;
|
||||
uniform float u_fogRange;
|
||||
uniform float u_fogDisable;
|
||||
uniform vec4 u_fogColor;
|
||||
|
||||
uniform sampler2D tex0;
|
||||
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_tex0;
|
||||
varying float v_fog;
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
vec4 color;
|
||||
color = v_color*texture2D(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));
|
||||
color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);
|
||||
if(color.a < u_alphaRef.x || color.a >= u_alphaRef.y)
|
||||
discard;
|
||||
/*
|
||||
switch(u_alphaTest){
|
||||
default:
|
||||
case 0: break;
|
||||
case 1:
|
||||
if(color.a < u_alphaRef)
|
||||
discard;
|
||||
break;
|
||||
case 2:
|
||||
if(color.a >= u_alphaRef)
|
||||
discard;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
const char *simple_frag_src =
|
||||
"uniform vec2 u_alphaRef;\n"
|
||||
|
||||
"uniform float u_fogStart;\n"
|
||||
"uniform float u_fogEnd;\n"
|
||||
"uniform float u_fogRange;\n"
|
||||
"uniform float u_fogDisable;\n"
|
||||
"uniform vec4 u_fogColor;\n"
|
||||
|
||||
"uniform sampler2D tex0;\n"
|
||||
|
||||
"varying vec4 v_color;\n"
|
||||
"varying vec2 v_tex0;\n"
|
||||
"varying float v_fog;\n"
|
||||
|
||||
"void\n"
|
||||
"main(void)\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" color = v_color*texture2D(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n"
|
||||
" color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);\n"
|
||||
" if(color.a < u_alphaRef.x || color.a >= u_alphaRef.y)\n"
|
||||
" discard;\n"
|
||||
"/*\n"
|
||||
" switch(u_alphaTest){\n"
|
||||
" default:\n"
|
||||
" case 0: break;\n"
|
||||
" case 1:\n"
|
||||
" if(color.a < u_alphaRef)\n"
|
||||
" discard;\n"
|
||||
" break;\n"
|
||||
" case 2:\n"
|
||||
" if(color.a >= u_alphaRef)\n"
|
||||
" discard;\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
"*/\n"
|
||||
|
||||
" gl_FragColor = color;\n"
|
||||
"}\n"
|
||||
|
||||
;
|
|
@ -0,0 +1,57 @@
|
|||
uniform mat4 u_boneMatrices[64];
|
||||
|
||||
attribute vec3 in_pos;
|
||||
attribute vec3 in_normal;
|
||||
attribute vec4 in_color;
|
||||
attribute vec2 in_tex0;
|
||||
attribute vec4 in_weights;
|
||||
attribute vec4 in_indices;
|
||||
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_tex0;
|
||||
varying 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 V = u_world * vec4(SkinVertex, 1.0);
|
||||
gl_Position = u_proj * u_view * V;
|
||||
vec3 N = mat3(u_world) * SkinNormal;
|
||||
|
||||
v_color = in_color;
|
||||
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
||||
|
||||
#ifdef DIRECTIONALS
|
||||
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||
if(u_directLights[i].enabled == 0.0)
|
||||
break;
|
||||
v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;
|
||||
}
|
||||
#endif
|
||||
#ifdef POINTLIGHTS
|
||||
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||
if(u_pointLights[i].enabled == 0.0)
|
||||
break;
|
||||
v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;
|
||||
}
|
||||
#endif
|
||||
#ifdef SPOTLIGHTS
|
||||
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||
if(u_spotLights[i].enabled == 0.0)
|
||||
break;
|
||||
v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;
|
||||
}
|
||||
#endif
|
||||
v_color *= u_matColor;
|
||||
|
||||
v_tex0 = in_tex0;
|
||||
|
||||
v_fog = DoFog(gl_Position.z);
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
const char *skin_vert_src =
|
||||
"uniform mat4 u_boneMatrices[64];\n"
|
||||
|
||||
"attribute vec3 in_pos;\n"
|
||||
"attribute vec3 in_normal;\n"
|
||||
"attribute vec4 in_color;\n"
|
||||
"attribute vec2 in_tex0;\n"
|
||||
"attribute vec4 in_weights;\n"
|
||||
"attribute vec4 in_indices;\n"
|
||||
|
||||
"varying vec4 v_color;\n"
|
||||
"varying vec2 v_tex0;\n"
|
||||
"varying 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 V = u_world * vec4(SkinVertex, 1.0);\n"
|
||||
" gl_Position = u_proj * u_view * V;\n"
|
||||
" vec3 N = mat3(u_world) * SkinNormal;\n"
|
||||
|
||||
" v_color = in_color;\n"
|
||||
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
||||
|
||||
"#ifdef DIRECTIONALS\n"
|
||||
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||
" if(u_directLights[i].enabled == 0.0)\n"
|
||||
" break;\n"
|
||||
" v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
"#ifdef POINTLIGHTS\n"
|
||||
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||
" if(u_pointLights[i].enabled == 0.0)\n"
|
||||
" break;\n"
|
||||
" v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
"#ifdef SPOTLIGHTS\n"
|
||||
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||
" if(u_spotLights[i].enabled == 0.0)\n"
|
||||
" break;\n"
|
||||
" v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
" v_color *= u_matColor;\n"
|
||||
|
||||
" v_tex0 = in_tex0;\n"
|
||||
|
||||
" v_fog = DoFog(gl_Position.z);\n"
|
||||
"}\n"
|
||||
;
|
Loading…
Reference in New Issue