mirror of
https://github.com/aap/librw.git
synced 2024-11-25 13:15:43 +00:00
lights for gles2
This commit is contained in:
parent
0fec15b06b
commit
57634dc46d
@ -18,29 +18,7 @@ main(void)
|
|||||||
|
|
||||||
v_color = in_color;
|
v_color = in_color;
|
||||||
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
||||||
|
v_color.rgb += DoDynamicLight(V.xyz, N)*surfDiffuse;
|
||||||
#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 = clamp(v_color, 0.0f, 1.0);
|
||||||
v_color *= u_matColor;
|
v_color *= u_matColor;
|
||||||
|
|
||||||
|
@ -19,29 +19,7 @@ const char *default_vert_src =
|
|||||||
|
|
||||||
" v_color = in_color;\n"
|
" v_color = in_color;\n"
|
||||||
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
||||||
|
" v_color.rgb += DoDynamicLight(V.xyz, N)*surfDiffuse;\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 = clamp(v_color, 0.0f, 1.0);\n"
|
||||||
" v_color *= u_matColor;\n"
|
" v_color *= u_matColor;\n"
|
||||||
|
|
||||||
|
@ -10,22 +10,14 @@ uniform mat4 u_proj;
|
|||||||
uniform mat4 u_view;
|
uniform mat4 u_view;
|
||||||
|
|
||||||
#define MAX_LIGHTS 8
|
#define MAX_LIGHTS 8
|
||||||
struct Light {
|
|
||||||
float enabled;
|
|
||||||
float radius;
|
|
||||||
float minusCosAngle;
|
|
||||||
float hardSpot;
|
|
||||||
vec4 position;
|
|
||||||
vec4 direction;
|
|
||||||
vec4 color;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Object
|
// Object
|
||||||
uniform mat4 u_world;
|
uniform mat4 u_world;
|
||||||
uniform vec4 u_ambLight;
|
uniform vec4 u_ambLight;
|
||||||
uniform Light u_directLights[MAX_LIGHTS];
|
uniform vec4 u_lightParams[MAX_LIGHTS]; // type, radius, minusCosAngle, hardSpot
|
||||||
uniform Light u_pointLights[MAX_LIGHTS];
|
uniform vec4 u_lightPosition[MAX_LIGHTS];
|
||||||
uniform Light u_spotLights[MAX_LIGHTS];
|
uniform vec4 u_lightDirection[MAX_LIGHTS];
|
||||||
|
uniform vec4 u_lightColor[MAX_LIGHTS];
|
||||||
|
|
||||||
uniform vec4 u_matColor;
|
uniform vec4 u_matColor;
|
||||||
uniform vec4 u_surfProps; // amb, spec, diff, extra
|
uniform vec4 u_surfProps; // amb, spec, diff, extra
|
||||||
@ -34,44 +26,45 @@ uniform vec4 u_surfProps; // amb, spec, diff, extra
|
|||||||
#define surfSpecular (u_surfProps.y)
|
#define surfSpecular (u_surfProps.y)
|
||||||
#define surfDiffuse (u_surfProps.z)
|
#define surfDiffuse (u_surfProps.z)
|
||||||
|
|
||||||
vec3 DoDirLight(Light L, vec3 N)
|
vec3 DoDynamicLight(vec3 V, vec3 N)
|
||||||
{
|
{
|
||||||
float l = max(0.0, dot(N, -L.direction.xyz));
|
vec3 color = vec3(0.0, 0.0, 0.0);
|
||||||
return l*L.color.rgb;
|
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||||
}
|
if(u_lightParams[i].x == 0.0)
|
||||||
|
break;
|
||||||
vec3 DoPointLight(Light L, vec3 V, vec3 N)
|
if(u_lightParams[i].x == 1.0){
|
||||||
{
|
// direct
|
||||||
// As on PS2
|
float l = max(0.0, dot(N, -u_lightDirection[i].xyz));
|
||||||
vec3 dir = V - L.position.xyz;
|
color += l*u_lightColor[i].rgb;
|
||||||
float dist = length(dir);
|
/*
|
||||||
float atten = max(0.0, (1.0 - dist/L.radius));
|
}else if(u_lightParams[i].x == 2.0){
|
||||||
float l = max(0.0, dot(N, -normalize(dir)));
|
// point
|
||||||
return l*L.color.rgb*atten;
|
vec3 dir = V - u_lightPosition[i].xyz;
|
||||||
}
|
float dist = length(dir);
|
||||||
|
float atten = max(0.0, (1.0 - dist/u_lightParams[i].y));
|
||||||
vec3 DoSpotLight(Light L, vec3 V, vec3 N)
|
float l = max(0.0, dot(N, -normalize(dir)));
|
||||||
{
|
color += l*u_lightColor[i].rgb*atten;
|
||||||
// As on PS2
|
}else if(u_lightParams[i].x == 3.0){
|
||||||
vec3 dir = V - L.position.xyz;
|
// spot
|
||||||
float dist = length(dir);
|
vec3 dir = V - u_lightPosition[i].xyz;
|
||||||
float atten = max(0.0, (1.0 - dist/L.radius));
|
float dist = length(dir);
|
||||||
dir /= dist;
|
float atten = max(0.0, (1.0 - dist/u_lightParams[i].y));
|
||||||
float l = max(0.0, dot(N, -dir));
|
dir /= dist;
|
||||||
float pcos = dot(dir, L.direction.xyz); // cos to point
|
float l = max(0.0, dot(N, -dir));
|
||||||
float ccos = -L.minusCosAngle;
|
float pcos = dot(dir, u_lightDirection[i].xyz); // cos to point
|
||||||
float falloff = (pcos-ccos)/(1.0-ccos);
|
float ccos = -u_lightParams[i].z;
|
||||||
if(falloff < 0.0) // outside of cone
|
float falloff = (pcos-ccos)/(1.0-ccos);
|
||||||
l = 0.0;
|
if(falloff < 0.0) // outside of cone
|
||||||
l *= max(falloff, L.hardSpot);
|
l = 0.0;
|
||||||
return l*L.color.xyz*atten;
|
l *= max(falloff, u_lightParams[i].w);
|
||||||
|
return l*u_lightColor[i].rgb*atten;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DoFog(float w)
|
float DoFog(float w)
|
||||||
{
|
{
|
||||||
return clamp((w - u_fogEnd)*u_fogRange, u_fogDisable, 1.0);
|
return clamp((w - u_fogEnd)*u_fogRange, u_fogDisable, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DIRECTIONALS
|
|
||||||
//#define POINTLIGHTS
|
|
||||||
//#define SPOTLIGHTS
|
|
||||||
|
@ -11,22 +11,14 @@ const char *header_vert_src =
|
|||||||
"uniform mat4 u_view;\n"
|
"uniform mat4 u_view;\n"
|
||||||
|
|
||||||
"#define MAX_LIGHTS 8\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"
|
"// Object\n"
|
||||||
"uniform mat4 u_world;\n"
|
"uniform mat4 u_world;\n"
|
||||||
"uniform vec4 u_ambLight;\n"
|
"uniform vec4 u_ambLight;\n"
|
||||||
"uniform Light u_directLights[MAX_LIGHTS];\n"
|
"uniform vec4 u_lightParams[MAX_LIGHTS]; // type, radius, minusCosAngle, hardSpot\n"
|
||||||
"uniform Light u_pointLights[MAX_LIGHTS];\n"
|
"uniform vec4 u_lightPosition[MAX_LIGHTS];\n"
|
||||||
"uniform Light u_spotLights[MAX_LIGHTS];\n"
|
"uniform vec4 u_lightDirection[MAX_LIGHTS];\n"
|
||||||
|
"uniform vec4 u_lightColor[MAX_LIGHTS];\n"
|
||||||
|
|
||||||
"uniform vec4 u_matColor;\n"
|
"uniform vec4 u_matColor;\n"
|
||||||
"uniform vec4 u_surfProps; // amb, spec, diff, extra\n"
|
"uniform vec4 u_surfProps; // amb, spec, diff, extra\n"
|
||||||
@ -35,45 +27,46 @@ const char *header_vert_src =
|
|||||||
"#define surfSpecular (u_surfProps.y)\n"
|
"#define surfSpecular (u_surfProps.y)\n"
|
||||||
"#define surfDiffuse (u_surfProps.z)\n"
|
"#define surfDiffuse (u_surfProps.z)\n"
|
||||||
|
|
||||||
"vec3 DoDirLight(Light L, vec3 N)\n"
|
"vec3 DoDynamicLight(vec3 V, vec3 N)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" float l = max(0.0, dot(N, -L.direction.xyz));\n"
|
" vec3 color = vec3(0.0, 0.0, 0.0);\n"
|
||||||
" return l*L.color.rgb;\n"
|
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||||
"}\n"
|
" if(u_lightParams[i].x == 0.0)\n"
|
||||||
|
" break;\n"
|
||||||
"vec3 DoPointLight(Light L, vec3 V, vec3 N)\n"
|
" if(u_lightParams[i].x == 1.0){\n"
|
||||||
"{\n"
|
" // direct\n"
|
||||||
" // As on PS2\n"
|
" float l = max(0.0, dot(N, -u_lightDirection[i].xyz));\n"
|
||||||
" vec3 dir = V - L.position.xyz;\n"
|
" color += l*u_lightColor[i].rgb;\n"
|
||||||
" float dist = length(dir);\n"
|
"/*\n"
|
||||||
" float atten = max(0.0, (1.0 - dist/L.radius));\n"
|
" }else if(u_lightParams[i].x == 2.0){\n"
|
||||||
" float l = max(0.0, dot(N, -normalize(dir)));\n"
|
" // point\n"
|
||||||
" return l*L.color.rgb*atten;\n"
|
" vec3 dir = V - u_lightPosition[i].xyz;\n"
|
||||||
"}\n"
|
" float dist = length(dir);\n"
|
||||||
|
" float atten = max(0.0, (1.0 - dist/u_lightParams[i].y));\n"
|
||||||
"vec3 DoSpotLight(Light L, vec3 V, vec3 N)\n"
|
" float l = max(0.0, dot(N, -normalize(dir)));\n"
|
||||||
"{\n"
|
" color += l*u_lightColor[i].rgb*atten;\n"
|
||||||
" // As on PS2\n"
|
" }else if(u_lightParams[i].x == 3.0){\n"
|
||||||
" vec3 dir = V - L.position.xyz;\n"
|
" // spot\n"
|
||||||
" float dist = length(dir);\n"
|
" vec3 dir = V - u_lightPosition[i].xyz;\n"
|
||||||
" float atten = max(0.0, (1.0 - dist/L.radius));\n"
|
" float dist = length(dir);\n"
|
||||||
" dir /= dist;\n"
|
" float atten = max(0.0, (1.0 - dist/u_lightParams[i].y));\n"
|
||||||
" float l = max(0.0, dot(N, -dir));\n"
|
" dir /= dist;\n"
|
||||||
" float pcos = dot(dir, L.direction.xyz); // cos to point\n"
|
" float l = max(0.0, dot(N, -dir));\n"
|
||||||
" float ccos = -L.minusCosAngle;\n"
|
" float pcos = dot(dir, u_lightDirection[i].xyz); // cos to point\n"
|
||||||
" float falloff = (pcos-ccos)/(1.0-ccos);\n"
|
" float ccos = -u_lightParams[i].z;\n"
|
||||||
" if(falloff < 0.0) // outside of cone\n"
|
" float falloff = (pcos-ccos)/(1.0-ccos);\n"
|
||||||
" l = 0.0;\n"
|
" if(falloff < 0.0) // outside of cone\n"
|
||||||
" l *= max(falloff, L.hardSpot);\n"
|
" l = 0.0;\n"
|
||||||
" return l*L.color.xyz*atten;\n"
|
" l *= max(falloff, u_lightParams[i].w);\n"
|
||||||
|
" return l*u_lightColor[i].rgb*atten;\n"
|
||||||
|
"*/\n"
|
||||||
|
" }\n"
|
||||||
|
" }\n"
|
||||||
|
" return color;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
|
||||||
"float DoFog(float w)\n"
|
"float DoFog(float w)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return clamp((w - u_fogEnd)*u_fogRange, u_fogDisable, 1.0);\n"
|
" return clamp((w - u_fogEnd)*u_fogRange, u_fogDisable, 1.0);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
|
||||||
"#define DIRECTIONALS\n"
|
|
||||||
"//#define POINTLIGHTS\n"
|
|
||||||
"//#define SPOTLIGHTS\n"
|
|
||||||
;
|
;
|
||||||
|
@ -16,10 +16,5 @@ main(void)
|
|||||||
v_fog = DoFog(gl_Position.z);
|
v_fog = DoFog(gl_Position.z);
|
||||||
gl_Position.xyz *= gl_Position.w;
|
gl_Position.xyz *= gl_Position.w;
|
||||||
v_color = in_color;
|
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;
|
v_tex0 = in_tex0;
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,6 @@ const char *im2d_vert_src =
|
|||||||
" v_fog = DoFog(gl_Position.z);\n"
|
" v_fog = DoFog(gl_Position.z);\n"
|
||||||
" gl_Position.xyz *= gl_Position.w;\n"
|
" gl_Position.xyz *= gl_Position.w;\n"
|
||||||
" v_color = in_color;\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"
|
" v_tex0 = in_tex0;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
;
|
;
|
||||||
|
@ -22,29 +22,7 @@ main(void)
|
|||||||
|
|
||||||
v_color = in_color;
|
v_color = in_color;
|
||||||
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
||||||
|
v_color.rgb += DoDynamicLight(V.xyz, N)*surfDiffuse;
|
||||||
#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 = clamp(v_color, 0.0f, 1.0);
|
||||||
v_color *= u_matColor;
|
v_color *= u_matColor;
|
||||||
|
|
||||||
|
@ -23,29 +23,7 @@ const char *matfx_env_vert_src =
|
|||||||
|
|
||||||
" v_color = in_color;\n"
|
" v_color = in_color;\n"
|
||||||
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
||||||
|
" v_color.rgb += DoDynamicLight(V.xyz, N)*surfDiffuse;\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 = clamp(v_color, 0.0f, 1.0);\n"
|
||||||
" v_color *= u_matColor;\n"
|
" v_color *= u_matColor;\n"
|
||||||
|
|
||||||
|
@ -25,33 +25,13 @@ main(void)
|
|||||||
gl_Position = u_proj * u_view * V;
|
gl_Position = u_proj * u_view * V;
|
||||||
vec3 N = mat3(u_world) * SkinNormal;
|
vec3 N = mat3(u_world) * SkinNormal;
|
||||||
|
|
||||||
|
v_tex0 = in_tex0;
|
||||||
|
|
||||||
v_color = in_color;
|
v_color = in_color;
|
||||||
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
||||||
|
v_color.rgb += DoDynamicLight(V.xyz, N)*surfDiffuse;
|
||||||
#ifdef DIRECTIONALS
|
v_color = clamp(v_color, 0.0f, 1.0);
|
||||||
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_color *= u_matColor;
|
||||||
|
|
||||||
v_tex0 = in_tex0;
|
|
||||||
|
|
||||||
v_fog = DoFog(gl_Position.z);
|
v_fog = DoFog(gl_Position.z);
|
||||||
}
|
}
|
||||||
|
@ -26,34 +26,14 @@ const char *skin_vert_src =
|
|||||||
" gl_Position = u_proj * u_view * V;\n"
|
" gl_Position = u_proj * u_view * V;\n"
|
||||||
" vec3 N = mat3(u_world) * SkinNormal;\n"
|
" vec3 N = mat3(u_world) * SkinNormal;\n"
|
||||||
|
|
||||||
|
" v_tex0 = in_tex0;\n"
|
||||||
|
|
||||||
" v_color = in_color;\n"
|
" v_color = in_color;\n"
|
||||||
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
||||||
|
" v_color.rgb += DoDynamicLight(V.xyz, N)*surfDiffuse;\n"
|
||||||
"#ifdef DIRECTIONALS\n"
|
" v_color = clamp(v_color, 0.0f, 1.0);\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_color *= u_matColor;\n"
|
||||||
|
|
||||||
" v_tex0 = in_tex0;\n"
|
|
||||||
|
|
||||||
" v_fog = DoFog(gl_Position.z);\n"
|
" v_fog = DoFog(gl_Position.z);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
;
|
;
|
||||||
|
@ -97,6 +97,16 @@ struct UniformObject
|
|||||||
UniformLight spotLights[MAX_LIGHTS];
|
UniformLight spotLights[MAX_LIGHTS];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct {
|
||||||
|
float type;
|
||||||
|
float radius;
|
||||||
|
float minusCosAngle;
|
||||||
|
float hardSpot;
|
||||||
|
} lightParams[MAX_LIGHTS];
|
||||||
|
V4d lightPosition[MAX_LIGHTS];
|
||||||
|
V4d lightDirection[MAX_LIGHTS];
|
||||||
|
RGBAf lightColor[MAX_LIGHTS];
|
||||||
|
|
||||||
const char *shaderDecl330 = "#version 330\n";
|
const char *shaderDecl330 = "#version 330\n";
|
||||||
const char *shaderDecl100es =
|
const char *shaderDecl100es =
|
||||||
"#version 100\n"\
|
"#version 100\n"\
|
||||||
@ -140,7 +150,10 @@ int32 u_view;
|
|||||||
// Object
|
// Object
|
||||||
int32 u_world;
|
int32 u_world;
|
||||||
int32 u_ambLight;
|
int32 u_ambLight;
|
||||||
// TODO: lights!
|
int32 u_lightParams;
|
||||||
|
int32 u_lightPosition;
|
||||||
|
int32 u_lightDirection;
|
||||||
|
int32 u_lightColor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32 u_matColor;
|
int32 u_matColor;
|
||||||
@ -681,6 +694,7 @@ setWorldMatrix(Matrix *mat)
|
|||||||
int32
|
int32
|
||||||
setLights(WorldLights *lightData)
|
setLights(WorldLights *lightData)
|
||||||
{
|
{
|
||||||
|
#ifndef RW_GLES2
|
||||||
int i, np, ns;
|
int i, np, ns;
|
||||||
Light *l;
|
Light *l;
|
||||||
int32 bits;
|
int32 bits;
|
||||||
@ -735,9 +749,70 @@ setLights(WorldLights *lightData)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
int i, n;
|
||||||
|
Light *l;
|
||||||
|
int32 bits;
|
||||||
|
|
||||||
|
uniformObject.ambLight = lightData->ambient;
|
||||||
|
|
||||||
|
bits = 0;
|
||||||
|
|
||||||
|
if(lightData->numAmbients)
|
||||||
|
bits |= VSLIGHT_AMBIENT;
|
||||||
|
|
||||||
|
n = 0;
|
||||||
|
for(i = 0; i < lightData->numDirectionals && i < 8; i++){
|
||||||
|
l = lightData->directionals[i];
|
||||||
|
lightParams[n].type = 1.0f;
|
||||||
|
lightColor[n] = l->color;
|
||||||
|
memcpy(&lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
|
||||||
|
bits |= VSLIGHT_POINT;
|
||||||
|
n++;
|
||||||
|
if(n >= MAX_LIGHTS)
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < lightData->numLocals; i++){
|
||||||
|
Light *l = lightData->locals[i];
|
||||||
|
|
||||||
|
switch(l->getType()){
|
||||||
|
case Light::POINT:
|
||||||
|
lightParams[n].type = 2.0f;
|
||||||
|
lightParams[n].radius = l->radius;
|
||||||
|
lightColor[n] = l->color;
|
||||||
|
memcpy(&lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d));
|
||||||
|
bits |= VSLIGHT_POINT;
|
||||||
|
n++;
|
||||||
|
if(n >= MAX_LIGHTS)
|
||||||
|
goto out;
|
||||||
|
break;
|
||||||
|
case Light::SPOT:
|
||||||
|
case Light::SOFTSPOT:
|
||||||
|
lightParams[n].type = 3.0f;
|
||||||
|
lightParams[n].minusCosAngle = l->minusCosAngle;
|
||||||
|
lightParams[n].radius = l->radius;
|
||||||
|
lightColor[n] = l->color;
|
||||||
|
memcpy(&lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d));
|
||||||
|
memcpy(&lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
|
||||||
|
// lower bound of falloff
|
||||||
|
if(l->getType() == Light::SOFTSPOT)
|
||||||
|
lightParams[n].hardSpot = 0.0f;
|
||||||
|
else
|
||||||
|
lightParams[n].hardSpot = 1.0f;
|
||||||
|
bits |= VSLIGHT_SPOT;
|
||||||
|
n++;
|
||||||
|
if(n >= MAX_LIGHTS)
|
||||||
|
goto out;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lightParams[n].type = 0.0f;
|
||||||
|
out:
|
||||||
|
#endif
|
||||||
objectDirty = 1;
|
objectDirty = 1;
|
||||||
return 0;
|
return bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -773,7 +848,10 @@ flushCache(void)
|
|||||||
if(objectDirty){
|
if(objectDirty){
|
||||||
glUniformMatrix4fv(U(u_world), 1, 0, (float*)&uniformObject.world);
|
glUniformMatrix4fv(U(u_world), 1, 0, (float*)&uniformObject.world);
|
||||||
glUniform4fv(U(u_ambLight), 1, (float*)&uniformObject.ambLight);
|
glUniform4fv(U(u_ambLight), 1, (float*)&uniformObject.ambLight);
|
||||||
// TODO: lights somehow
|
glUniform4fv(U(u_lightParams), MAX_LIGHTS, (float*)lightParams);
|
||||||
|
glUniform4fv(U(u_lightPosition), MAX_LIGHTS, (float*)lightPosition);
|
||||||
|
glUniform4fv(U(u_lightDirection), MAX_LIGHTS, (float*)lightDirection);
|
||||||
|
glUniform4fv(U(u_lightColor), MAX_LIGHTS, (float*)lightColor);
|
||||||
objectDirty = 0;
|
objectDirty = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1216,6 +1294,10 @@ initOpenGL(void)
|
|||||||
u_view = registerUniform("u_view");
|
u_view = registerUniform("u_view");
|
||||||
u_world = registerUniform("u_world");
|
u_world = registerUniform("u_world");
|
||||||
u_ambLight = registerUniform("u_ambLight");
|
u_ambLight = registerUniform("u_ambLight");
|
||||||
|
u_lightParams = registerUniform("u_lightParams");
|
||||||
|
u_lightPosition = registerUniform("u_lightPosition");
|
||||||
|
u_lightDirection = registerUniform("u_lightDirection");
|
||||||
|
u_lightColor = registerUniform("u_lightColor");
|
||||||
lastShaderUploaded = nil;
|
lastShaderUploaded = nil;
|
||||||
#else
|
#else
|
||||||
registerBlock("Scene");
|
registerBlock("Scene");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "../rwbase.h"
|
#include "../rwbase.h"
|
||||||
#include "../rwerror.h"
|
#include "../rwerror.h"
|
||||||
@ -31,8 +32,10 @@ registerUniform(const char *name)
|
|||||||
i = findUniform(name);
|
i = findUniform(name);
|
||||||
if(i >= 0) return i;
|
if(i >= 0) return i;
|
||||||
// TODO: print error
|
// TODO: print error
|
||||||
if(uniformRegistry.numUniforms+1 >= MAX_UNIFORMS)
|
if(uniformRegistry.numUniforms+1 >= MAX_UNIFORMS){
|
||||||
|
assert(0 && "no space for uniform");
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
uniformRegistry.uniformNames[uniformRegistry.numUniforms] = strdup(name);
|
uniformRegistry.uniformNames[uniformRegistry.numUniforms] = strdup(name);
|
||||||
return uniformRegistry.numUniforms++;
|
return uniformRegistry.numUniforms++;
|
||||||
}
|
}
|
||||||
@ -199,7 +202,7 @@ Shader::create(const char **vsrc, const char **fsrc)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef xxxRW_GLES2
|
#ifdef RW_GLES2
|
||||||
int numAttribs;
|
int numAttribs;
|
||||||
glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &numAttribs);
|
glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &numAttribs);
|
||||||
for(i = 0; i < numAttribs; i++){
|
for(i = 0; i < numAttribs; i++){
|
||||||
|
@ -5,7 +5,7 @@ namespace gl3 {
|
|||||||
|
|
||||||
// TODO: make this dynamic
|
// TODO: make this dynamic
|
||||||
enum {
|
enum {
|
||||||
MAX_UNIFORMS = 20,
|
MAX_UNIFORMS = 40,
|
||||||
MAX_BLOCKS = 20
|
MAX_BLOCKS = 20
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user