fixes for gl3

This commit is contained in:
aap
2020-04-26 19:33:43 +02:00
parent 43190a51f7
commit 09b0b36e7d
36 changed files with 858 additions and 647 deletions

View File

@@ -1,4 +1,9 @@
all: im2d_gl3.inc im3d_gl3.inc simple_vs_gl3.inc simple_fs_gl3.inc matfx_gl3.inc skin_gl3.inc
all: header_vs.inc im2d_gl3.inc im3d_gl3.inc default_vs_gl3.inc simple_fs_gl3.inc matfx_gl3.inc skin_gl3.inc
header_vs.inc: header.vert
(echo 'const char *header_vert_src =';\
sed 's/..*/"&\\n"/' header.vert;\
echo ';') >header_vs.inc
im2d_gl3.inc: im2d.vert
(echo 'const char *im2d_vert_src =';\
@@ -10,10 +15,10 @@ im3d_gl3.inc: im3d.vert
sed 's/..*/"&\\n"/' im3d.vert;\
echo ';') >im3d_gl3.inc
simple_vs_gl3.inc: simple.vert
(echo 'const char *simple_vert_src =';\
sed 's/..*/"&\\n"/' simple.vert;\
echo ';') >simple_vs_gl3.inc
default_vs_gl3.inc: default.vert
(echo 'const char *default_vert_src =';\
sed 's/..*/"&\\n"/' default.vert;\
echo ';') >default_vs_gl3.inc
simple_fs_gl3.inc: simple.frag
(echo 'const char *simple_frag_src =';\

View File

@@ -0,0 +1,48 @@
layout(location = 0) in vec3 in_pos;
layout(location = 1) in vec3 in_normal;
layout(location = 2) in vec4 in_color;
layout(location = 3) in vec2 in_tex0;
out vec4 v_color;
out vec2 v_tex0;
out 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);
}

View File

@@ -0,0 +1,50 @@
const char *default_vert_src =
"layout(location = 0) in vec3 in_pos;\n"
"layout(location = 1) in vec3 in_normal;\n"
"layout(location = 2) in vec4 in_color;\n"
"layout(location = 3) in vec2 in_tex0;\n"
"out vec4 v_color;\n"
"out vec2 v_tex0;\n"
"out 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"
;

View File

@@ -0,0 +1,88 @@
#version 330
layout(std140) uniform State
{
int u_alphaTest;
float u_alphaRef;
float u_fogStart;
float u_fogEnd;
float u_fogRange;
float u_fogDisable;
vec4 u_fogColor;
};
layout(std140) uniform Scene
{
mat4 u_proj;
mat4 u_view;
};
#define MAX_LIGHTS 8
struct Light {
float enabled;
float radius;
float minusCosAngle;
float hardSpot;
vec4 position;
vec4 direction;
vec4 color;
};
layout(std140) uniform Object
{
mat4 u_world;
vec4 u_ambLight;
Light u_directLights[MAX_LIGHTS];
Light u_pointLights[MAX_LIGHTS];
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) // outside of cone
l = 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

View File

@@ -0,0 +1,89 @@
const char *header_vert_src =
"#version 330\n"
"layout(std140) uniform State\n"
"{\n"
" int u_alphaTest;\n"
" float u_alphaRef;\n"
" float u_fogStart;\n"
" float u_fogEnd;\n"
" float u_fogRange;\n"
" float u_fogDisable;\n"
" vec4 u_fogColor;\n"
"};\n"
"layout(std140) uniform Scene\n"
"{\n"
" mat4 u_proj;\n"
" mat4 u_view;\n"
"};\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"
"layout(std140) uniform Object\n"
"{\n"
" mat4 u_world;\n"
" vec4 u_ambLight;\n"
" Light u_directLights[MAX_LIGHTS];\n"
" Light u_pointLights[MAX_LIGHTS];\n"
" Light u_spotLights[MAX_LIGHTS];\n"
"};\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) // outside of cone\n"
" l = 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";

View File

@@ -1,16 +1,3 @@
#version 330
layout(std140) uniform State
{
int u_alphaTest;
float u_alphaRef;
int u_fogEnable;
float u_fogStart;
float u_fogEnd;
vec4 u_fogColor;
};
uniform vec4 u_xform;
layout(location = 0) in vec4 in_pos;
@@ -26,8 +13,8 @@ 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_tex0 = in_tex0;
v_fog = clamp((gl_Position.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
}

View File

@@ -1,17 +1,4 @@
const char *im2d_vert_src =
"#version 330\n"
"layout(std140) uniform State\n"
"{\n"
" int u_alphaTest;\n"
" float u_alphaRef;\n"
" int u_fogEnable;\n"
" float u_fogStart;\n"
" float u_fogEnd;\n"
" vec4 u_fogColor;\n"
"};\n"
"uniform vec4 u_xform;\n"
"layout(location = 0) in vec4 in_pos;\n"
@@ -27,9 +14,9 @@ const char *im2d_vert_src =
"{\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_tex0 = in_tex0;\n"
" v_fog = clamp((gl_Position.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);\n"
"}\n"
;

View File

@@ -1,27 +1,3 @@
#version 330
layout(std140) uniform State
{
int u_alphaTest;
float u_alphaRef;
int u_fogEnable;
float u_fogStart;
float u_fogEnd;
vec4 u_fogColor;
};
layout(std140) uniform Scene
{
mat4 u_proj;
mat4 u_view;
};
layout(std140) uniform Object
{
mat4 u_world;
};
layout(location = 0) in vec3 in_pos;
layout(location = 2) in vec4 in_color;
layout(location = 3) in vec2 in_tex0;
@@ -38,5 +14,5 @@ main(void)
gl_Position = u_proj * cV;
v_color = in_color;
v_tex0 = in_tex0;
v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
v_fog = DoFog(gl_Position.w);
}

View File

@@ -1,28 +1,4 @@
const char *im3d_vert_src =
"#version 330\n"
"layout(std140) uniform State\n"
"{\n"
" int u_alphaTest;\n"
" float u_alphaRef;\n"
" int u_fogEnable;\n"
" float u_fogStart;\n"
" float u_fogEnd;\n"
" vec4 u_fogColor;\n"
"};\n"
"layout(std140) uniform Scene\n"
"{\n"
" mat4 u_proj;\n"
" mat4 u_view;\n"
"};\n"
"layout(std140) uniform Object\n"
"{\n"
" mat4 u_world;\n"
"};\n"
"layout(location = 0) in vec3 in_pos;\n"
"layout(location = 2) in vec4 in_color;\n"
"layout(location = 3) in vec2 in_tex0;\n"
@@ -35,10 +11,10 @@ const char *im3d_vert_src =
"main(void)\n"
"{\n"
" vec4 V = u_world * vec4(in_pos, 1.0);\n"
" vec4 cV = u_view * V; \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 = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);\n"
" v_fog = DoFog(gl_Position.w);\n"
"}\n"
;

View File

@@ -4,20 +4,38 @@ layout(std140) uniform State
{
int u_alphaTest;
float u_alphaRef;
// fog etc.
float u_fogStart;
float u_fogEnd;
float u_fogRange;
float u_fogDisable;
vec4 u_fogColor;
};
uniform sampler2D tex;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform float u_coefficient;
in vec4 v_color;
in vec2 v_tex0;
in vec2 v_tex1;
in float v_fog;
out vec4 color;
void
main(void)
{
color = v_color*texture(tex, vec2(v_tex0.x, v_tex0.y));
vec4 pass1 = v_color;
vec4 envColor = pass1; // TODO: colorClamp
pass1 *= texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));
vec4 pass2 = envColor*u_coefficient*texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y));
color.rgb = pass1.rgb*pass1.a + pass2.rgb;
color.a = pass1.a;
switch(u_alphaTest){
default:
case 0: break;
@@ -31,4 +49,3 @@ main(void)
break;
}
}

View File

@@ -1,33 +1,4 @@
#version 330
layout(std140) uniform Scene
{
mat4 u_proj;
mat4 u_view;
};
#define MAX_LIGHTS 8
struct Light {
vec4 position;
vec4 direction;
vec4 color;
float radius;
float minusCosAngle;
};
layout(std140) uniform Object
{
mat4 u_world;
vec4 u_ambLight;
int u_numLights;
Light u_lights[MAX_LIGHTS];
};
uniform vec4 u_matColor;
uniform vec4 u_surfaceProps; // amb, spec, diff, extra
uniform mat4 u_texMatrix;
uniform float u_coefficient;
layout(location = 0) in vec3 in_pos;
layout(location = 1) in vec3 in_normal;
@@ -36,6 +7,8 @@ layout(location = 3) in vec2 in_tex0;
out vec4 v_color;
out vec2 v_tex0;
out vec2 v_tex1;
out float v_fog;
void
main(void)
@@ -44,15 +17,36 @@ main(void)
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;
for(int i = 0; i < u_numLights; i++){
float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));
v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;
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;
}
v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;
#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_color *= u_coefficient;
vec3 cN = mat3(u_view) * in_normal;
v_tex0 = (u_texMatrix * vec4(cN, 1.0)).xy;
v_fog = DoFog(gl_Position.w);
}

View File

@@ -1,34 +1,5 @@
const char *matfx_env_vert_src =
"#version 330\n"
"layout(std140) uniform Scene\n"
"{\n"
" mat4 u_proj;\n"
" mat4 u_view;\n"
"};\n"
"#define MAX_LIGHTS 8\n"
"struct Light {\n"
" vec4 position;\n"
" vec4 direction;\n"
" vec4 color;\n"
" float radius;\n"
" float minusCosAngle;\n"
"};\n"
"layout(std140) uniform Object\n"
"{\n"
" mat4 u_world;\n"
" vec4 u_ambLight;\n"
" int u_numLights;\n"
" Light u_lights[MAX_LIGHTS];\n"
"};\n"
"uniform vec4 u_matColor;\n"
"uniform vec4 u_surfaceProps; // amb, spec, diff, extra\n"
"uniform mat4 u_texMatrix;\n"
"uniform float u_coefficient;\n"
"layout(location = 0) in vec3 in_pos;\n"
"layout(location = 1) in vec3 in_normal;\n"
@@ -37,6 +8,8 @@ const char *matfx_env_vert_src =
"out vec4 v_color;\n"
"out vec2 v_tex0;\n"
"out vec2 v_tex1;\n"
"out float v_fog;\n"
"void\n"
"main(void)\n"
@@ -45,17 +18,38 @@ const char *matfx_env_vert_src =
" 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"
" for(int i = 0; i < u_numLights; i++){\n"
" float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));\n"
" v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;\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"
" v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;\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_color *= u_coefficient;\n"
" vec3 cN = mat3(u_view) * in_normal;\n"
" v_tex0 = (u_texMatrix * vec4(cN, 1.0)).xy;\n"
" v_fog = DoFog(gl_Position.w);\n"
"}\n"
;
const char *matfx_env_frag_src =
@@ -65,20 +59,38 @@ const char *matfx_env_frag_src =
"{\n"
" int u_alphaTest;\n"
" float u_alphaRef;\n"
" // fog etc.\n"
" float u_fogStart;\n"
" float u_fogEnd;\n"
" float u_fogRange;\n"
" float u_fogDisable;\n"
" vec4 u_fogColor;\n"
"};\n"
"uniform sampler2D tex;\n"
"uniform sampler2D tex0;\n"
"uniform sampler2D tex1;\n"
"uniform float u_coefficient;\n"
"in vec4 v_color;\n"
"in vec2 v_tex0;\n"
"in vec2 v_tex1;\n"
"in float v_fog;\n"
"out vec4 color;\n"
"void\n"
"main(void)\n"
"{\n"
" color = v_color*texture(tex, vec2(v_tex0.x, v_tex0.y));\n"
" vec4 pass1 = v_color;\n"
" vec4 envColor = pass1; // TODO: colorClamp\n"
" pass1 *= texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n"
" vec4 pass2 = envColor*u_coefficient*texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y));\n"
" color.rgb = pass1.rgb*pass1.a + pass2.rgb;\n"
" color.a = pass1.a;\n"
" switch(u_alphaTest){\n"
" default:\n"
" case 0: break;\n"
@@ -92,5 +104,4 @@ const char *matfx_env_frag_src =
" break;\n"
" }\n"
"}\n"
;

View File

@@ -5,13 +5,14 @@ layout(std140) uniform State
int u_alphaTest;
float u_alphaRef;
int u_fogEnable;
float u_fogStart;
float u_fogEnd;
float u_fogRange;
float u_fogDisable;
vec4 u_fogColor;
};
uniform sampler2D tex;
uniform sampler2D tex0;
in vec4 v_color;
in vec2 v_tex0;
@@ -22,9 +23,8 @@ out vec4 color;
void
main(void)
{
color = v_color*texture(tex, vec2(v_tex0.x, v_tex0.y));
if(u_fogEnable != 0)
color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);
color = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));
color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);
switch(u_alphaTest){
default:
case 0: break;

View File

@@ -1,68 +0,0 @@
#version 330
layout(std140) uniform State
{
int u_alphaTest;
float u_alphaRef;
int u_fogEnable;
float u_fogStart;
float u_fogEnd;
vec4 u_fogColor;
};
layout(std140) uniform Scene
{
mat4 u_proj;
mat4 u_view;
};
#define MAX_LIGHTS 8
struct Light {
vec4 position;
vec4 direction;
vec4 color;
float radius;
float minusCosAngle;
};
layout(std140) uniform Object
{
mat4 u_world;
vec4 u_ambLight;
int u_numLights;
Light u_lights[MAX_LIGHTS];
};
uniform vec4 u_matColor;
uniform vec4 u_surfaceProps; // amb, spec, diff, extra
layout(location = 0) in vec3 in_pos;
layout(location = 1) in vec3 in_normal;
layout(location = 2) in vec4 in_color;
layout(location = 3) in vec2 in_tex0;
out vec4 v_color;
out vec2 v_tex0;
out 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;
vec3 N = mat3(u_world) * in_normal;
v_color = in_color;
for(int i = 0; i < u_numLights; i++){
float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));
v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;
}
v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;
v_color *= u_matColor;
v_tex0 = in_tex0;
v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
}

View File

@@ -6,13 +6,14 @@ const char *simple_frag_src =
" int u_alphaTest;\n"
" float u_alphaRef;\n"
" int u_fogEnable;\n"
" float u_fogStart;\n"
" float u_fogEnd;\n"
" float u_fogRange;\n"
" float u_fogDisable;\n"
" vec4 u_fogColor;\n"
"};\n"
"uniform sampler2D tex;\n"
"uniform sampler2D tex0;\n"
"in vec4 v_color;\n"
"in vec2 v_tex0;\n"
@@ -23,9 +24,8 @@ const char *simple_frag_src =
"void\n"
"main(void)\n"
"{\n"
" color = v_color*texture(tex, vec2(v_tex0.x, v_tex0.y));\n"
" if(u_fogEnable != 0)\n"
" color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);\n"
" 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"
" switch(u_alphaTest){\n"
" default:\n"
" case 0: break;\n"

View File

@@ -1,72 +0,0 @@
const char *simple_vert_src =
"#version 330\n"
"layout(std140) uniform State\n"
"{\n"
" int u_alphaTest;\n"
" float u_alphaRef;\n"
" int u_fogEnable;\n"
" float u_fogStart;\n"
" float u_fogEnd;\n"
" vec4 u_fogColor;\n"
"};\n"
"layout(std140) uniform Scene\n"
"{\n"
" mat4 u_proj;\n"
" mat4 u_view;\n"
"};\n"
"#define MAX_LIGHTS 8\n"
"struct Light {\n"
" vec4 position;\n"
" vec4 direction;\n"
" vec4 color;\n"
" float radius;\n"
" float minusCosAngle;\n"
"};\n"
"layout(std140) uniform Object\n"
"{\n"
" mat4 u_world;\n"
" vec4 u_ambLight;\n"
" int u_numLights;\n"
" Light u_lights[MAX_LIGHTS];\n"
"};\n"
"uniform vec4 u_matColor;\n"
"uniform vec4 u_surfaceProps; // amb, spec, diff, extra\n"
"layout(location = 0) in vec3 in_pos;\n"
"layout(location = 1) in vec3 in_normal;\n"
"layout(location = 2) in vec4 in_color;\n"
"layout(location = 3) in vec2 in_tex0;\n"
"out vec4 v_color;\n"
"out vec2 v_tex0;\n"
"out float v_fog;\n"
"void\n"
"main(void)\n"
"{\n"
" vec3 lightdir = vec3(1.0, 1.0, -1.0);\n"
" vec4 V = u_world * vec4(in_pos, 1.0);\n"
" vec4 cV = u_view * V; \n"
" gl_Position = u_proj * cV;\n"
" vec3 N = mat3(u_world) * in_normal;\n"
" v_color = in_color;\n"
" for(int i = 0; i < u_numLights; i++){\n"
" float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));\n"
" v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;\n"
" }\n"
" v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;\n"
" v_color *= u_matColor;\n"
" v_tex0 = in_tex0;\n"
" v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);\n"
"}\n"
;

View File

@@ -1,41 +1,4 @@
#version 330
layout(std140) uniform State
{
int u_alphaTest;
float u_alphaRef;
int u_fogEnable;
float u_fogStart;
float u_fogEnd;
vec4 u_fogColor;
};
layout(std140) uniform Scene
{
mat4 u_proj;
mat4 u_view;
};
#define MAX_LIGHTS 8
struct Light {
vec4 position;
vec4 direction;
vec4 color;
float radius;
float minusCosAngle;
};
layout(std140) uniform Object
{
mat4 u_world;
vec4 u_ambLight;
int u_numLights;
Light u_lights[MAX_LIGHTS];
};
uniform vec4 u_matColor;
uniform vec4 u_surfaceProps; // amb, spec, diff, extra
uniform mat4 u_boneMatrices[64];
layout(location = 0) in vec3 in_pos;
layout(location = 1) in vec3 in_normal;
@@ -44,8 +7,6 @@ layout(location = 3) in vec2 in_tex0;
layout(location = 11) in vec4 in_weights;
layout(location = 12) in vec4 in_indices;
uniform mat4 u_boneMatrices[64];
out vec4 v_color;
out vec2 v_tex0;
out float v_fog;
@@ -53,26 +14,44 @@ out float v_fog;
void
main(void)
{
mat4 m = u_boneMatrices[int(in_indices[0])] * in_weights[0];
m += u_boneMatrices[int(in_indices[1])] * in_weights[1];
m += u_boneMatrices[int(in_indices[2])] * in_weights[2];
m += u_boneMatrices[int(in_indices[3])] * in_weights[3];
mat4 world = u_world * m;
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 = world * vec4(in_pos, 1.0);
vec4 cV = u_view * V;
gl_Position = u_proj * cV;
vec3 N = mat3(world) * in_normal;
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;
for(int i = 0; i < u_numLights; i++){
float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));
v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;
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;
}
v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;
#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 = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
v_fog = DoFog(gl_Position.z);
}

View File

@@ -1,42 +1,5 @@
const char *skin_vert_src =
"#version 330\n"
"layout(std140) uniform State\n"
"{\n"
" int u_alphaTest;\n"
" float u_alphaRef;\n"
" int u_fogEnable;\n"
" float u_fogStart;\n"
" float u_fogEnd;\n"
" vec4 u_fogColor;\n"
"};\n"
"layout(std140) uniform Scene\n"
"{\n"
" mat4 u_proj;\n"
" mat4 u_view;\n"
"};\n"
"#define MAX_LIGHTS 8\n"
"struct Light {\n"
" vec4 position;\n"
" vec4 direction;\n"
" vec4 color;\n"
" float radius;\n"
" float minusCosAngle;\n"
"};\n"
"layout(std140) uniform Object\n"
"{\n"
" mat4 u_world;\n"
" vec4 u_ambLight;\n"
" int u_numLights;\n"
" Light u_lights[MAX_LIGHTS];\n"
"};\n"
"uniform vec4 u_matColor;\n"
"uniform vec4 u_surfaceProps; // amb, spec, diff, extra\n"
"uniform mat4 u_boneMatrices[64];\n"
"layout(location = 0) in vec3 in_pos;\n"
"layout(location = 1) in vec3 in_normal;\n"
@@ -45,8 +8,6 @@ const char *skin_vert_src =
"layout(location = 11) in vec4 in_weights;\n"
"layout(location = 12) in vec4 in_indices;\n"
"uniform mat4 u_boneMatrices[64];\n"
"out vec4 v_color;\n"
"out vec2 v_tex0;\n"
"out float v_fog;\n"
@@ -54,27 +15,45 @@ const char *skin_vert_src =
"void\n"
"main(void)\n"
"{\n"
" mat4 m = u_boneMatrices[int(in_indices[0])] * in_weights[0];\n"
" m += u_boneMatrices[int(in_indices[1])] * in_weights[1];\n"
" m += u_boneMatrices[int(in_indices[2])] * in_weights[2];\n"
" m += u_boneMatrices[int(in_indices[3])] * in_weights[3];\n"
" mat4 world = u_world * m;\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 = world * vec4(in_pos, 1.0);\n"
" vec4 cV = u_view * V; \n"
" gl_Position = u_proj * cV;\n"
" vec3 N = mat3(world) * in_normal;\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"
" for(int i = 0; i < u_numLights; i++){\n"
" float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));\n"
" v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;\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"
" v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;\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 = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);\n"
" v_fog = DoFog(gl_Position.z);\n"
"}\n"
;