mirror of https://github.com/aap/librw.git
made gl3 UBOs optional; also tried other snake oil
This commit is contained in:
parent
57634dc46d
commit
2d6ca32102
|
@ -1,10 +1,15 @@
|
||||||
all: header_vs.inc im2d_gl2.inc im3d_gl2.inc default_vs_gl2.inc simple_fs_gl2.inc matfx_gl2.inc skin_gl2.inc
|
all: header_vs.inc header_fs.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
|
header_vs.inc: header.vert
|
||||||
(echo 'const char *header_vert_src =';\
|
(echo 'const char *header_vert_src =';\
|
||||||
sed 's/..*/"&\\n"/' header.vert;\
|
sed 's/..*/"&\\n"/' header.vert;\
|
||||||
echo ';') >header_vs.inc
|
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_gl2.inc: im2d.vert
|
im2d_gl2.inc: im2d.vert
|
||||||
(echo 'const char *im2d_vert_src =';\
|
(echo 'const char *im2d_vert_src =';\
|
||||||
sed 's/..*/"&\\n"/' im2d.vert;\
|
sed 's/..*/"&\\n"/' im2d.vert;\
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
uniform vec2 u_alphaRef;
|
||||||
|
|
||||||
|
uniform float u_fogStart;
|
||||||
|
uniform float u_fogEnd;
|
||||||
|
uniform float u_fogRange;
|
||||||
|
uniform float u_fogDisable;
|
||||||
|
uniform vec4 u_fogColor;
|
||||||
|
|
||||||
|
void DoAlphaTest(float a)
|
||||||
|
{
|
||||||
|
if(a < u_alphaRef.x || a >= u_alphaRef.y)
|
||||||
|
discard;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
const char *header_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"
|
||||||
|
|
||||||
|
"void DoAlphaTest(float a)\n"
|
||||||
|
"{\n"
|
||||||
|
" if(a < u_alphaRef.x || a >= u_alphaRef.y)\n"
|
||||||
|
" discard;\n"
|
||||||
|
"}\n"
|
||||||
|
;
|
|
@ -1,11 +1,3 @@
|
||||||
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 tex0;
|
||||||
uniform sampler2D tex1;
|
uniform sampler2D tex1;
|
||||||
|
|
||||||
|
@ -34,22 +26,7 @@ main(void)
|
||||||
color.rgb = pass1.rgb*pass1.a + pass2.rgb;
|
color.rgb = pass1.rgb*pass1.a + pass2.rgb;
|
||||||
color.a = pass1.a;
|
color.a = pass1.a;
|
||||||
|
|
||||||
if(color.a < u_alphaRef.x || color.a >= u_alphaRef.y)
|
DoAlphaTest(color.a);
|
||||||
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;
|
gl_FragColor = color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,14 +31,6 @@ const char *matfx_env_vert_src =
|
||||||
"}\n"
|
"}\n"
|
||||||
;
|
;
|
||||||
const char *matfx_env_frag_src =
|
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 tex0;\n"
|
||||||
"uniform sampler2D tex1;\n"
|
"uniform sampler2D tex1;\n"
|
||||||
|
|
||||||
|
@ -67,22 +59,7 @@ const char *matfx_env_frag_src =
|
||||||
" color.rgb = pass1.rgb*pass1.a + pass2.rgb;\n"
|
" color.rgb = pass1.rgb*pass1.a + pass2.rgb;\n"
|
||||||
" color.a = pass1.a;\n"
|
" color.a = pass1.a;\n"
|
||||||
|
|
||||||
" if(color.a < u_alphaRef.x || color.a >= u_alphaRef.y)\n"
|
" DoAlphaTest(color.a);\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"
|
" gl_FragColor = color;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
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 tex0;
|
||||||
|
|
||||||
varying vec4 v_color;
|
varying vec4 v_color;
|
||||||
|
@ -18,23 +10,7 @@ main(void)
|
||||||
vec4 color;
|
vec4 color;
|
||||||
color = v_color*texture2D(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));
|
color = v_color*texture2D(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));
|
||||||
color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);
|
color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);
|
||||||
if(color.a < u_alphaRef.x || color.a >= u_alphaRef.y)
|
DoAlphaTest(color.a);
|
||||||
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;
|
gl_FragColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,4 @@
|
||||||
const char *simple_frag_src =
|
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"
|
"uniform sampler2D tex0;\n"
|
||||||
|
|
||||||
"varying vec4 v_color;\n"
|
"varying vec4 v_color;\n"
|
||||||
|
@ -19,23 +11,7 @@ const char *simple_frag_src =
|
||||||
" vec4 color;\n"
|
" vec4 color;\n"
|
||||||
" color = v_color*texture2D(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\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"
|
" color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);\n"
|
||||||
" if(color.a < u_alphaRef.x || color.a >= u_alphaRef.y)\n"
|
" DoAlphaTest(color.a);\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"
|
" gl_FragColor = color;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
|
||||||
|
|
|
@ -58,10 +58,13 @@ struct GlGlobals
|
||||||
const char *winTitle;
|
const char *winTitle;
|
||||||
} glGlobals;
|
} glGlobals;
|
||||||
|
|
||||||
|
int32 alphaFunc;
|
||||||
|
float32 alphaRef;
|
||||||
|
|
||||||
struct UniformState
|
struct UniformState
|
||||||
{
|
{
|
||||||
int32 alphaFunc;
|
float32 alphaRefLow;
|
||||||
float32 alphaRef;
|
float32 alphaRefHigh;
|
||||||
float32 fogStart;
|
float32 fogStart;
|
||||||
float32 fogEnd;
|
float32 fogEnd;
|
||||||
|
|
||||||
|
@ -78,35 +81,23 @@ struct UniformScene
|
||||||
float32 view[16];
|
float32 view[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UniformLight
|
|
||||||
{
|
|
||||||
float32 enabled, radius, minusCosAngle, hardSpot;
|
|
||||||
V3d position; int32 pad0;
|
|
||||||
V3d direction; int32 pad1;
|
|
||||||
RGBAf color;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MAX_LIGHTS 8
|
#define MAX_LIGHTS 8
|
||||||
|
|
||||||
struct UniformObject
|
struct UniformObject
|
||||||
{
|
{
|
||||||
RawMatrix world;
|
RawMatrix world;
|
||||||
RGBAf ambLight;
|
RGBAf ambLight;
|
||||||
UniformLight directLights[MAX_LIGHTS];
|
struct {
|
||||||
UniformLight pointLights[MAX_LIGHTS];
|
float type;
|
||||||
UniformLight spotLights[MAX_LIGHTS];
|
float radius;
|
||||||
|
float minusCosAngle;
|
||||||
|
float hardSpot;
|
||||||
|
} lightParams[MAX_LIGHTS];
|
||||||
|
V4d lightPosition[MAX_LIGHTS];
|
||||||
|
V4d lightDirection[MAX_LIGHTS];
|
||||||
|
RGBAf lightColor[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"\
|
||||||
|
@ -125,8 +116,13 @@ const char *shaderDecl = shaderDecl100es;
|
||||||
const char *shaderDecl = shaderDecl330;
|
const char *shaderDecl = shaderDecl330;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// this needs a define in the shaders as well!
|
||||||
|
//#define RW_GL_USE_UBOS
|
||||||
|
|
||||||
#ifndef RW_GLES2
|
#ifndef RW_GLES2
|
||||||
static GLuint vao;
|
static GLuint vao;
|
||||||
|
#endif
|
||||||
|
#ifdef RW_GL_USE_UBOS
|
||||||
static GLuint ubo_state, ubo_scene, ubo_object;
|
static GLuint ubo_state, ubo_scene, ubo_object;
|
||||||
#endif
|
#endif
|
||||||
static GLuint whitetex;
|
static GLuint whitetex;
|
||||||
|
@ -134,7 +130,7 @@ static UniformState uniformState;
|
||||||
static UniformScene uniformScene;
|
static UniformScene uniformScene;
|
||||||
static UniformObject uniformObject;
|
static UniformObject uniformObject;
|
||||||
|
|
||||||
#ifdef RW_GLES2
|
#ifndef RW_GL_USE_UBOS
|
||||||
// State
|
// State
|
||||||
int32 u_alphaRef;
|
int32 u_alphaRef;
|
||||||
int32 u_fogStart;
|
int32 u_fogStart;
|
||||||
|
@ -271,8 +267,8 @@ setAlphaTest(bool32 enable)
|
||||||
if(rwStateCache.alphaTestEnable != enable){
|
if(rwStateCache.alphaTestEnable != enable){
|
||||||
rwStateCache.alphaTestEnable = enable;
|
rwStateCache.alphaTestEnable = enable;
|
||||||
shaderfunc = rwStateCache.alphaTestEnable ? rwStateCache.alphaFunc : ALPHAALWAYS;
|
shaderfunc = rwStateCache.alphaTestEnable ? rwStateCache.alphaFunc : ALPHAALWAYS;
|
||||||
if(uniformState.alphaFunc != shaderfunc){
|
if(alphaFunc != shaderfunc){
|
||||||
uniformState.alphaFunc = shaderfunc;
|
alphaFunc = shaderfunc;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,8 +281,8 @@ setAlphaTestFunction(uint32 function)
|
||||||
if(rwStateCache.alphaFunc != function){
|
if(rwStateCache.alphaFunc != function){
|
||||||
rwStateCache.alphaFunc = function;
|
rwStateCache.alphaFunc = function;
|
||||||
shaderfunc = rwStateCache.alphaTestEnable ? rwStateCache.alphaFunc : ALPHAALWAYS;
|
shaderfunc = rwStateCache.alphaTestEnable ? rwStateCache.alphaFunc : ALPHAALWAYS;
|
||||||
if(uniformState.alphaFunc != shaderfunc){
|
if(alphaFunc != shaderfunc){
|
||||||
uniformState.alphaFunc = shaderfunc;
|
alphaFunc = shaderfunc;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -560,8 +556,8 @@ setRenderState(int32 state, void *pvalue)
|
||||||
setAlphaTestFunction(value);
|
setAlphaTestFunction(value);
|
||||||
break;
|
break;
|
||||||
case ALPHATESTREF:
|
case ALPHATESTREF:
|
||||||
if(uniformState.alphaRef != value/255.0f){
|
if(alphaRef != value/255.0f){
|
||||||
uniformState.alphaRef = value/255.0f;
|
alphaRef = value/255.0f;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -627,7 +623,7 @@ getRenderState(int32 state)
|
||||||
val = rwStateCache.alphaFunc;
|
val = rwStateCache.alphaFunc;
|
||||||
break;
|
break;
|
||||||
case ALPHATESTREF:
|
case ALPHATESTREF:
|
||||||
val = (uint32)(uniformState.alphaRef*255.0f);
|
val = (uint32)(alphaRef*255.0f);
|
||||||
break;
|
break;
|
||||||
case GSALPHATEST:
|
case GSALPHATEST:
|
||||||
val = rwStateCache.gsalpha;
|
val = rwStateCache.gsalpha;
|
||||||
|
@ -645,8 +641,8 @@ static void
|
||||||
resetRenderState(void)
|
resetRenderState(void)
|
||||||
{
|
{
|
||||||
rwStateCache.alphaFunc = ALPHAGREATEREQUAL;
|
rwStateCache.alphaFunc = ALPHAGREATEREQUAL;
|
||||||
uniformState.alphaFunc = 0;
|
alphaFunc = 0;
|
||||||
uniformState.alphaRef = 10.0f/255.0f;
|
alphaRef = 10.0f/255.0f;
|
||||||
uniformState.fogDisable = 1.0f;
|
uniformState.fogDisable = 1.0f;
|
||||||
uniformState.fogStart = 0.0f;
|
uniformState.fogStart = 0.0f;
|
||||||
uniformState.fogEnd = 0.0f;
|
uniformState.fogEnd = 0.0f;
|
||||||
|
@ -694,62 +690,6 @@ setWorldMatrix(Matrix *mat)
|
||||||
int32
|
int32
|
||||||
setLights(WorldLights *lightData)
|
setLights(WorldLights *lightData)
|
||||||
{
|
{
|
||||||
#ifndef RW_GLES2
|
|
||||||
int i, np, ns;
|
|
||||||
Light *l;
|
|
||||||
int32 bits;
|
|
||||||
|
|
||||||
uniformObject.ambLight = lightData->ambient;
|
|
||||||
memset(uniformObject.directLights, 0, sizeof(uniformObject.directLights));
|
|
||||||
memset(uniformObject.pointLights, 0, sizeof(uniformObject.pointLights));
|
|
||||||
memset(uniformObject.spotLights, 0, sizeof(uniformObject.spotLights));
|
|
||||||
|
|
||||||
bits = 0;
|
|
||||||
|
|
||||||
for(i = 0; i < lightData->numDirectionals && i < 8; i++){
|
|
||||||
l = lightData->directionals[i];
|
|
||||||
uniformObject.directLights[i].enabled = 1.0f;
|
|
||||||
uniformObject.directLights[i].color = l->color;
|
|
||||||
uniformObject.directLights[i].direction = l->getFrame()->getLTM()->at;
|
|
||||||
bits |= VSLIGHT_POINT;
|
|
||||||
}
|
|
||||||
|
|
||||||
np = 0;
|
|
||||||
ns = 0;
|
|
||||||
for(i = 0; i < lightData->numLocals; i++){
|
|
||||||
l = lightData->locals[i];
|
|
||||||
switch(l->getType()){
|
|
||||||
case Light::POINT:
|
|
||||||
if(np >= 8)
|
|
||||||
continue;
|
|
||||||
uniformObject.pointLights[np].enabled = 1.0f;
|
|
||||||
uniformObject.pointLights[np].color = l->color;
|
|
||||||
uniformObject.pointLights[np].position = l->getFrame()->getLTM()->pos;
|
|
||||||
uniformObject.pointLights[np].radius = l->radius;
|
|
||||||
np++;
|
|
||||||
bits |= VSLIGHT_POINT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Light::SPOT:
|
|
||||||
case Light::SOFTSPOT:
|
|
||||||
if(np >= 8)
|
|
||||||
continue;
|
|
||||||
uniformObject.spotLights[ns].enabled = 1.0f;
|
|
||||||
uniformObject.spotLights[ns].color = l->color;
|
|
||||||
uniformObject.spotLights[ns].position = l->getFrame()->getLTM()->pos;
|
|
||||||
uniformObject.spotLights[ns].direction = l->getFrame()->getLTM()->at;
|
|
||||||
uniformObject.spotLights[ns].radius = l->radius;
|
|
||||||
uniformObject.spotLights[ns].minusCosAngle = l->minusCosAngle;
|
|
||||||
if(l->getType() == Light::SOFTSPOT)
|
|
||||||
uniformObject.spotLights[ns].hardSpot = 0.0f;
|
|
||||||
else
|
|
||||||
uniformObject.spotLights[ns].hardSpot = 1.0f;
|
|
||||||
ns++;
|
|
||||||
bits |= VSLIGHT_SPOT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
int i, n;
|
int i, n;
|
||||||
Light *l;
|
Light *l;
|
||||||
int32 bits;
|
int32 bits;
|
||||||
|
@ -764,9 +704,9 @@ setLights(WorldLights *lightData)
|
||||||
n = 0;
|
n = 0;
|
||||||
for(i = 0; i < lightData->numDirectionals && i < 8; i++){
|
for(i = 0; i < lightData->numDirectionals && i < 8; i++){
|
||||||
l = lightData->directionals[i];
|
l = lightData->directionals[i];
|
||||||
lightParams[n].type = 1.0f;
|
uniformObject.lightParams[n].type = 1.0f;
|
||||||
lightColor[n] = l->color;
|
uniformObject.lightColor[n] = l->color;
|
||||||
memcpy(&lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
|
memcpy(&uniformObject.lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
|
||||||
bits |= VSLIGHT_POINT;
|
bits |= VSLIGHT_POINT;
|
||||||
n++;
|
n++;
|
||||||
if(n >= MAX_LIGHTS)
|
if(n >= MAX_LIGHTS)
|
||||||
|
@ -778,10 +718,10 @@ setLights(WorldLights *lightData)
|
||||||
|
|
||||||
switch(l->getType()){
|
switch(l->getType()){
|
||||||
case Light::POINT:
|
case Light::POINT:
|
||||||
lightParams[n].type = 2.0f;
|
uniformObject.lightParams[n].type = 2.0f;
|
||||||
lightParams[n].radius = l->radius;
|
uniformObject.lightParams[n].radius = l->radius;
|
||||||
lightColor[n] = l->color;
|
uniformObject.lightColor[n] = l->color;
|
||||||
memcpy(&lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d));
|
memcpy(&uniformObject.lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d));
|
||||||
bits |= VSLIGHT_POINT;
|
bits |= VSLIGHT_POINT;
|
||||||
n++;
|
n++;
|
||||||
if(n >= MAX_LIGHTS)
|
if(n >= MAX_LIGHTS)
|
||||||
|
@ -789,17 +729,17 @@ setLights(WorldLights *lightData)
|
||||||
break;
|
break;
|
||||||
case Light::SPOT:
|
case Light::SPOT:
|
||||||
case Light::SOFTSPOT:
|
case Light::SOFTSPOT:
|
||||||
lightParams[n].type = 3.0f;
|
uniformObject.lightParams[n].type = 3.0f;
|
||||||
lightParams[n].minusCosAngle = l->minusCosAngle;
|
uniformObject.lightParams[n].minusCosAngle = l->minusCosAngle;
|
||||||
lightParams[n].radius = l->radius;
|
uniformObject.lightParams[n].radius = l->radius;
|
||||||
lightColor[n] = l->color;
|
uniformObject.lightColor[n] = l->color;
|
||||||
memcpy(&lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d));
|
memcpy(&uniformObject.lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d));
|
||||||
memcpy(&lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
|
memcpy(&uniformObject.lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
|
||||||
// lower bound of falloff
|
// lower bound of falloff
|
||||||
if(l->getType() == Light::SOFTSPOT)
|
if(l->getType() == Light::SOFTSPOT)
|
||||||
lightParams[n].hardSpot = 0.0f;
|
uniformObject.lightParams[n].hardSpot = 0.0f;
|
||||||
else
|
else
|
||||||
lightParams[n].hardSpot = 1.0f;
|
uniformObject.lightParams[n].hardSpot = 1.0f;
|
||||||
bits |= VSLIGHT_SPOT;
|
bits |= VSLIGHT_SPOT;
|
||||||
n++;
|
n++;
|
||||||
if(n >= MAX_LIGHTS)
|
if(n >= MAX_LIGHTS)
|
||||||
|
@ -808,9 +748,8 @@ setLights(WorldLights *lightData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lightParams[n].type = 0.0f;
|
uniformObject.lightParams[n].type = 0.0f;
|
||||||
out:
|
out:
|
||||||
#endif
|
|
||||||
objectDirty = 1;
|
objectDirty = 1;
|
||||||
return bits;
|
return bits;
|
||||||
}
|
}
|
||||||
|
@ -834,10 +773,10 @@ Shader *lastShaderUploaded;
|
||||||
void
|
void
|
||||||
flushCache(void)
|
flushCache(void)
|
||||||
{
|
{
|
||||||
#ifdef RW_GLES2
|
#ifndef RW_GL_USE_UBOS
|
||||||
#define U(i) currentShader->uniformLocations[i]
|
#define U(i) currentShader->uniformLocations[i]
|
||||||
|
|
||||||
// TODO: this is probably a stupid way to do it with gl2
|
// TODO: this is probably a stupid way to do it without UBOs
|
||||||
if(lastShaderUploaded != currentShader){
|
if(lastShaderUploaded != currentShader){
|
||||||
lastShaderUploaded = currentShader;
|
lastShaderUploaded = currentShader;
|
||||||
objectDirty = 1;
|
objectDirty = 1;
|
||||||
|
@ -848,10 +787,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);
|
||||||
glUniform4fv(U(u_lightParams), MAX_LIGHTS, (float*)lightParams);
|
glUniform4fv(U(u_lightParams), MAX_LIGHTS, (float*)uniformObject.lightParams);
|
||||||
glUniform4fv(U(u_lightPosition), MAX_LIGHTS, (float*)lightPosition);
|
glUniform4fv(U(u_lightPosition), MAX_LIGHTS, (float*)uniformObject.lightPosition);
|
||||||
glUniform4fv(U(u_lightDirection), MAX_LIGHTS, (float*)lightDirection);
|
glUniform4fv(U(u_lightDirection), MAX_LIGHTS, (float*)uniformObject.lightDirection);
|
||||||
glUniform4fv(U(u_lightColor), MAX_LIGHTS, (float*)lightColor);
|
glUniform4fv(U(u_lightColor), MAX_LIGHTS, (float*)uniformObject.lightColor);
|
||||||
objectDirty = 0;
|
objectDirty = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -867,16 +806,16 @@ flushCache(void)
|
||||||
uniformState.fogEnd = rwStateCache.fogEnd;
|
uniformState.fogEnd = rwStateCache.fogEnd;
|
||||||
uniformState.fogRange = 1.0f/(rwStateCache.fogStart - rwStateCache.fogEnd);
|
uniformState.fogRange = 1.0f/(rwStateCache.fogStart - rwStateCache.fogEnd);
|
||||||
|
|
||||||
switch(uniformState.alphaFunc){
|
switch(alphaFunc){
|
||||||
case ALPHAALWAYS:
|
case ALPHAALWAYS:
|
||||||
default:
|
default:
|
||||||
glUniform2f(U(u_alphaRef), -1000.0f, 1000.0f);
|
glUniform2f(U(u_alphaRef), -1000.0f, 1000.0f);
|
||||||
break;
|
break;
|
||||||
case ALPHAGREATEREQUAL:
|
case ALPHAGREATEREQUAL:
|
||||||
glUniform2f(U(u_alphaRef), uniformState.alphaRef, 1000.0f);
|
glUniform2f(U(u_alphaRef), alphaRef, 1000.0f);
|
||||||
break;
|
break;
|
||||||
case ALPHALESS:
|
case ALPHALESS:
|
||||||
glUniform2f(U(u_alphaRef), -1000.0f, uniformState.alphaRef);
|
glUniform2f(U(u_alphaRef), -1000.0f, alphaRef);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,24 +829,39 @@ flushCache(void)
|
||||||
#else
|
#else
|
||||||
if(objectDirty){
|
if(objectDirty){
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, ubo_object);
|
glBindBuffer(GL_UNIFORM_BUFFER, ubo_object);
|
||||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(UniformObject),
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformObject), nil, GL_STREAM_DRAW);
|
||||||
&uniformObject);
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformObject), &uniformObject, GL_STREAM_DRAW);
|
||||||
objectDirty = 0;
|
objectDirty = 0;
|
||||||
}
|
}
|
||||||
if(sceneDirty){
|
if(sceneDirty){
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, ubo_scene);
|
glBindBuffer(GL_UNIFORM_BUFFER, ubo_scene);
|
||||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(UniformScene),
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformScene), nil, GL_STREAM_DRAW);
|
||||||
&uniformScene);
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformScene), &uniformScene, GL_STREAM_DRAW);
|
||||||
sceneDirty = 0;
|
sceneDirty = 0;
|
||||||
}
|
}
|
||||||
if(stateDirty){
|
if(stateDirty){
|
||||||
|
switch(alphaFunc){
|
||||||
|
case ALPHAALWAYS:
|
||||||
|
default:
|
||||||
|
uniformState.alphaRefLow = -1000.0f;
|
||||||
|
uniformState.alphaRefHigh = 1000.0f;
|
||||||
|
break;
|
||||||
|
case ALPHAGREATEREQUAL:
|
||||||
|
uniformState.alphaRefLow = alphaRef;
|
||||||
|
uniformState.alphaRefHigh = 1000.0f;
|
||||||
|
break;
|
||||||
|
case ALPHALESS:
|
||||||
|
uniformState.alphaRefLow = -1000.0f;
|
||||||
|
uniformState.alphaRefHigh = alphaRef;
|
||||||
|
break;
|
||||||
|
}
|
||||||
uniformState.fogDisable = rwStateCache.fogEnable ? 0.0f : 1.0f;
|
uniformState.fogDisable = rwStateCache.fogEnable ? 0.0f : 1.0f;
|
||||||
uniformState.fogStart = rwStateCache.fogStart;
|
uniformState.fogStart = rwStateCache.fogStart;
|
||||||
uniformState.fogEnd = rwStateCache.fogEnd;
|
uniformState.fogEnd = rwStateCache.fogEnd;
|
||||||
uniformState.fogRange = 1.0f/(rwStateCache.fogStart - rwStateCache.fogEnd);
|
uniformState.fogRange = 1.0f/(rwStateCache.fogStart - rwStateCache.fogEnd);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, ubo_state);
|
glBindBuffer(GL_UNIFORM_BUFFER, ubo_state);
|
||||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(UniformState),
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformState), nil, GL_STREAM_DRAW);
|
||||||
&uniformState);
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformState), &uniformState, GL_STREAM_DRAW);
|
||||||
stateDirty = 0;
|
stateDirty = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1283,7 +1237,7 @@ stopGLFW(void)
|
||||||
static int
|
static int
|
||||||
initOpenGL(void)
|
initOpenGL(void)
|
||||||
{
|
{
|
||||||
#ifdef RW_GLES2
|
#ifndef RW_GL_USE_UBOS
|
||||||
u_alphaRef = registerUniform("u_alphaRef");
|
u_alphaRef = registerUniform("u_alphaRef");
|
||||||
u_fogStart = registerUniform("u_fogStart");
|
u_fogStart = registerUniform("u_fogStart");
|
||||||
u_fogEnd = registerUniform("u_fogEnd");
|
u_fogEnd = registerUniform("u_fogEnd");
|
||||||
|
@ -1322,26 +1276,28 @@ initOpenGL(void)
|
||||||
#ifndef RW_GLES2
|
#ifndef RW_GLES2
|
||||||
glGenVertexArrays(1, &vao);
|
glGenVertexArrays(1, &vao);
|
||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RW_GL_USE_UBOS
|
||||||
glGenBuffers(1, &ubo_state);
|
glGenBuffers(1, &ubo_state);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, ubo_state);
|
glBindBuffer(GL_UNIFORM_BUFFER, ubo_state);
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, gl3::findBlock("State"), ubo_state);
|
glBindBufferBase(GL_UNIFORM_BUFFER, gl3::findBlock("State"), ubo_state);
|
||||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformState), &uniformState,
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformState), &uniformState,
|
||||||
GL_DYNAMIC_DRAW);
|
GL_STREAM_DRAW);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
|
|
||||||
glGenBuffers(1, &ubo_scene);
|
glGenBuffers(1, &ubo_scene);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, ubo_scene);
|
glBindBuffer(GL_UNIFORM_BUFFER, ubo_scene);
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, gl3::findBlock("Scene"), ubo_scene);
|
glBindBufferBase(GL_UNIFORM_BUFFER, gl3::findBlock("Scene"), ubo_scene);
|
||||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformScene), &uniformScene,
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformScene), &uniformScene,
|
||||||
GL_DYNAMIC_DRAW);
|
GL_STREAM_DRAW);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
|
|
||||||
glGenBuffers(1, &ubo_object);
|
glGenBuffers(1, &ubo_object);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, ubo_object);
|
glBindBuffer(GL_UNIFORM_BUFFER, ubo_object);
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, gl3::findBlock("Object"), ubo_object);
|
glBindBufferBase(GL_UNIFORM_BUFFER, gl3::findBlock("Object"), ubo_object);
|
||||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformObject), &uniformObject,
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformObject), &uniformObject,
|
||||||
GL_DYNAMIC_DRAW);
|
GL_STREAM_DRAW);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1353,7 +1309,7 @@ initOpenGL(void)
|
||||||
#include "shaders/simple_fs_gl3.inc"
|
#include "shaders/simple_fs_gl3.inc"
|
||||||
#endif
|
#endif
|
||||||
const char *vs[] = { shaderDecl, header_vert_src, default_vert_src, nil };
|
const char *vs[] = { shaderDecl, header_vert_src, default_vert_src, nil };
|
||||||
const char *fs[] = { shaderDecl, simple_frag_src, nil };
|
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
|
||||||
defaultShader = Shader::create(vs, fs);
|
defaultShader = Shader::create(vs, fs);
|
||||||
assert(defaultShader);
|
assert(defaultShader);
|
||||||
|
|
||||||
|
|
|
@ -58,20 +58,18 @@ openIm2D(void)
|
||||||
#include "shaders/simple_fs_gl3.inc"
|
#include "shaders/simple_fs_gl3.inc"
|
||||||
#endif
|
#endif
|
||||||
const char *vs[] = { shaderDecl, header_vert_src, im2d_vert_src, nil };
|
const char *vs[] = { shaderDecl, header_vert_src, im2d_vert_src, nil };
|
||||||
const char *fs[] = { shaderDecl, simple_frag_src, nil };
|
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
|
||||||
im2dShader = Shader::create(vs, fs);
|
im2dShader = Shader::create(vs, fs);
|
||||||
assert(im2dShader);
|
assert(im2dShader);
|
||||||
|
|
||||||
glGenBuffers(1, &im2DIbo);
|
glGenBuffers(1, &im2DIbo);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im2DIbo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im2DIbo);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2,
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2, nil, GL_STREAM_DRAW);
|
||||||
nil, GL_DYNAMIC_DRAW);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
glGenBuffers(1, &im2DVbo);
|
glGenBuffers(1, &im2DVbo);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, im2DVbo);
|
glBindBuffer(GL_ARRAY_BUFFER, im2DVbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im2DVertex),
|
glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im2DVertex), nil, GL_STREAM_DRAW);
|
||||||
nil, GL_DYNAMIC_DRAW);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,8 +111,8 @@ im2DRenderPrimitive(PrimitiveType primType, void *vertices, int32 numVertices)
|
||||||
cam = (Camera*)engine->currentCamera;
|
cam = (Camera*)engine->currentCamera;
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, im2DVbo);
|
glBindBuffer(GL_ARRAY_BUFFER, im2DVbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(Im2DVertex),
|
glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im2DVertex), nil, GL_STREAM_DRAW);
|
||||||
vertices, GL_DYNAMIC_DRAW);
|
glBufferSubData(GL_ARRAY_BUFFER, 0, numVertices*sizeof(Im2DVertex), vertices);
|
||||||
|
|
||||||
xform[0] = 2.0f/cam->frameBuffer->width;
|
xform[0] = 2.0f/cam->frameBuffer->width;
|
||||||
xform[1] = -2.0f/cam->frameBuffer->height;
|
xform[1] = -2.0f/cam->frameBuffer->height;
|
||||||
|
@ -142,12 +140,12 @@ im2DRenderIndexedPrimitive(PrimitiveType primType,
|
||||||
|
|
||||||
// TODO: fixed size
|
// TODO: fixed size
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im2DIbo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im2DIbo);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices*2,
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2, nil, GL_STREAM_DRAW);
|
||||||
indices, GL_DYNAMIC_DRAW);
|
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, numIndices*2, indices);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, im2DVbo);
|
glBindBuffer(GL_ARRAY_BUFFER, im2DVbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(Im2DVertex),
|
glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im2DVertex), nil, GL_STREAM_DRAW);
|
||||||
vertices, GL_DYNAMIC_DRAW);
|
glBufferSubData(GL_ARRAY_BUFFER, 0, numVertices*sizeof(Im2DVertex), vertices);
|
||||||
|
|
||||||
xform[0] = 2.0f/cam->frameBuffer->width;
|
xform[0] = 2.0f/cam->frameBuffer->width;
|
||||||
xform[1] = -2.0f/cam->frameBuffer->height;
|
xform[1] = -2.0f/cam->frameBuffer->height;
|
||||||
|
@ -192,20 +190,18 @@ openIm3D(void)
|
||||||
#include "shaders/simple_fs_gl3.inc"
|
#include "shaders/simple_fs_gl3.inc"
|
||||||
#endif
|
#endif
|
||||||
const char *vs[] = { shaderDecl, header_vert_src, im3d_vert_src, nil };
|
const char *vs[] = { shaderDecl, header_vert_src, im3d_vert_src, nil };
|
||||||
const char *fs[] = { shaderDecl, simple_frag_src, nil };
|
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
|
||||||
im3dShader = Shader::create(vs, fs);
|
im3dShader = Shader::create(vs, fs);
|
||||||
assert(im3dShader);
|
assert(im3dShader);
|
||||||
|
|
||||||
glGenBuffers(1, &im3DIbo);
|
glGenBuffers(1, &im3DIbo);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im3DIbo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im3DIbo);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2,
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2, nil, GL_STREAM_DRAW);
|
||||||
nil, GL_DYNAMIC_DRAW);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
glGenBuffers(1, &im3DVbo);
|
glGenBuffers(1, &im3DVbo);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, im3DVbo);
|
glBindBuffer(GL_ARRAY_BUFFER, im3DVbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im3DVertex),
|
glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im3DVertex), nil, GL_STREAM_DRAW);
|
||||||
nil, GL_DYNAMIC_DRAW);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,8 +230,8 @@ im3DTransform(void *vertices, int32 numVertices, Matrix *world, uint32 flags)
|
||||||
|
|
||||||
// TODO: fixed size
|
// TODO: fixed size
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, im3DVbo);
|
glBindBuffer(GL_ARRAY_BUFFER, im3DVbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(Im3DVertex),
|
glBufferData(GL_ARRAY_BUFFER, STARTVERTICES*sizeof(Im3DVertex), nil, GL_STREAM_DRAW);
|
||||||
vertices, GL_DYNAMIC_DRAW);
|
glBufferSubData(GL_ARRAY_BUFFER, 0, numVertices*sizeof(Im3DVertex), vertices);
|
||||||
setAttribPointers(im3dattribDesc, 3);
|
setAttribPointers(im3dattribDesc, 3);
|
||||||
num3DVertices = numVertices;
|
num3DVertices = numVertices;
|
||||||
}
|
}
|
||||||
|
@ -248,21 +244,19 @@ im3DRenderPrimitive(PrimitiveType primType)
|
||||||
flushCache();
|
flushCache();
|
||||||
glDrawArrays(primTypeMap[primType], 0, num3DVertices);
|
glDrawArrays(primTypeMap[primType], 0, num3DVertices);
|
||||||
disableAttribPointers(im3dattribDesc, 3);
|
disableAttribPointers(im3dattribDesc, 3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
im3DRenderIndexedPrimitive(PrimitiveType primType, void *indices, int32 numIndices)
|
im3DRenderIndexedPrimitive(PrimitiveType primType, void *indices, int32 numIndices)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im3DIbo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im3DIbo);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices*2,
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, STARTINDICES*2, nil, GL_STREAM_DRAW);
|
||||||
indices, GL_DYNAMIC_DRAW);
|
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, numIndices*2, indices);
|
||||||
|
|
||||||
flushCache();
|
flushCache();
|
||||||
glDrawElements(primTypeMap[primType], numIndices,
|
glDrawElements(primTypeMap[primType], numIndices,
|
||||||
GL_UNSIGNED_SHORT, nil);
|
GL_UNSIGNED_SHORT, nil);
|
||||||
disableAttribPointers(im3dattribDesc, 3);
|
disableAttribPointers(im3dattribDesc, 3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -47,7 +47,7 @@ matfxOpen(void *o, int32, int32)
|
||||||
#include "shaders/matfx_gl3.inc"
|
#include "shaders/matfx_gl3.inc"
|
||||||
#endif
|
#endif
|
||||||
const char *vs[] = { shaderDecl, header_vert_src, matfx_env_vert_src, nil };
|
const char *vs[] = { shaderDecl, header_vert_src, matfx_env_vert_src, nil };
|
||||||
const char *fs[] = { shaderDecl, matfx_env_frag_src, nil };
|
const char *fs[] = { shaderDecl, header_frag_src, matfx_env_frag_src, nil };
|
||||||
envShader = Shader::create(vs, fs);
|
envShader = Shader::create(vs, fs);
|
||||||
assert(envShader);
|
assert(envShader);
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,10 @@ namespace gl3 {
|
||||||
|
|
||||||
#ifdef RW_GLES2
|
#ifdef RW_GLES2
|
||||||
#include "gl2_shaders/header_vs.inc"
|
#include "gl2_shaders/header_vs.inc"
|
||||||
|
#include "gl2_shaders/header_fs.inc"
|
||||||
#else
|
#else
|
||||||
#include "shaders/header_vs.inc"
|
#include "shaders/header_vs.inc"
|
||||||
|
#include "shaders/header_fs.inc"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
UniformRegistry uniformRegistry;
|
UniformRegistry uniformRegistry;
|
||||||
|
@ -202,7 +204,7 @@ Shader::create(const char **vsrc, const char **fsrc)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RW_GLES2
|
#ifdef xxxRW_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++){
|
||||||
|
|
|
@ -45,7 +45,7 @@ skinOpen(void *o, int32, int32)
|
||||||
#include "shaders/skin_gl3.inc"
|
#include "shaders/skin_gl3.inc"
|
||||||
#endif
|
#endif
|
||||||
const char *vs[] = { shaderDecl, header_vert_src, skin_vert_src, nil };
|
const char *vs[] = { shaderDecl, header_vert_src, skin_vert_src, nil };
|
||||||
const char *fs[] = { shaderDecl, simple_frag_src, nil };
|
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
|
||||||
skinShader = Shader::create(vs, fs);
|
skinShader = Shader::create(vs, fs);
|
||||||
assert(skinShader);
|
assert(skinShader);
|
||||||
|
|
||||||
|
|
|
@ -164,6 +164,7 @@ enum
|
||||||
|
|
||||||
extern const char *shaderDecl; // #version stuff
|
extern const char *shaderDecl; // #version stuff
|
||||||
extern const char *header_vert_src;
|
extern const char *header_vert_src;
|
||||||
|
extern const char *header_frag_src;
|
||||||
|
|
||||||
// per Scene
|
// per Scene
|
||||||
void setProjectionMatrix(float32*);
|
void setProjectionMatrix(float32*);
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
all: header_vs.inc im2d_gl3.inc im3d_gl3.inc default_vs_gl3.inc simple_fs_gl3.inc matfx_gl3.inc skin_gl3.inc
|
all: header_vs.inc header_fs.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
|
header_vs.inc: header.vert
|
||||||
(echo 'const char *header_vert_src =';\
|
(echo 'const char *header_vert_src =';\
|
||||||
sed 's/..*/"&\\n"/' header.vert;\
|
sed 's/..*/"&\\n"/' header.vert;\
|
||||||
echo ';') >header_vs.inc
|
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_gl3.inc: im2d.vert
|
im2d_gl3.inc: im2d.vert
|
||||||
(echo 'const char *im2d_vert_src =';\
|
(echo 'const char *im2d_vert_src =';\
|
||||||
sed 's/..*/"&\\n"/' im2d.vert;\
|
sed 's/..*/"&\\n"/' im2d.vert;\
|
||||||
|
|
|
@ -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"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifdef USE_UBOS
|
||||||
|
layout(std140) uniform State
|
||||||
|
{
|
||||||
|
vec2 u_alphaRef;
|
||||||
|
|
||||||
|
float u_fogStart;
|
||||||
|
float u_fogEnd;
|
||||||
|
float u_fogRange;
|
||||||
|
float u_fogDisable;
|
||||||
|
vec4 u_fogColor;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
//uniform int u_alphaTest;
|
||||||
|
//uniform float u_alphaRef;
|
||||||
|
uniform vec2 u_alphaRef;
|
||||||
|
|
||||||
|
uniform float u_fogStart;
|
||||||
|
uniform float u_fogEnd;
|
||||||
|
uniform float u_fogRange;
|
||||||
|
uniform float u_fogDisable;
|
||||||
|
uniform vec4 u_fogColor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void DoAlphaTest(float a)
|
||||||
|
{
|
||||||
|
if(a < u_alphaRef.x || a >= u_alphaRef.y)
|
||||||
|
discard;
|
||||||
|
}
|
|
@ -1,7 +1,12 @@
|
||||||
|
|
||||||
|
#define DIRECTIONALS
|
||||||
|
//#define POINTLIGHTS
|
||||||
|
//#define SPOTLIGHTS
|
||||||
|
|
||||||
|
#ifdef USE_UBOS
|
||||||
layout(std140) uniform State
|
layout(std140) uniform State
|
||||||
{
|
{
|
||||||
int u_alphaTest;
|
vec2 u_alphaRef;
|
||||||
float u_alphaRef;
|
|
||||||
|
|
||||||
float u_fogStart;
|
float u_fogStart;
|
||||||
float u_fogEnd;
|
float u_fogEnd;
|
||||||
|
@ -9,32 +14,47 @@ layout(std140) uniform State
|
||||||
float u_fogDisable;
|
float u_fogDisable;
|
||||||
vec4 u_fogColor;
|
vec4 u_fogColor;
|
||||||
};
|
};
|
||||||
|
#else
|
||||||
|
uniform vec2 u_alphaRef;
|
||||||
|
|
||||||
|
uniform float u_fogStart;
|
||||||
|
uniform float u_fogEnd;
|
||||||
|
uniform float u_fogRange;
|
||||||
|
uniform float u_fogDisable;
|
||||||
|
uniform vec4 u_fogColor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_UBOS
|
||||||
layout(std140) uniform Scene
|
layout(std140) uniform Scene
|
||||||
{
|
{
|
||||||
mat4 u_proj;
|
mat4 u_proj;
|
||||||
mat4 u_view;
|
mat4 u_view;
|
||||||
};
|
};
|
||||||
|
#else
|
||||||
|
uniform mat4 u_proj;
|
||||||
|
uniform mat4 u_view;
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MAX_LIGHTS 8
|
#define MAX_LIGHTS 8
|
||||||
struct Light {
|
|
||||||
float enabled;
|
|
||||||
float radius;
|
|
||||||
float minusCosAngle;
|
|
||||||
float hardSpot;
|
|
||||||
vec4 position;
|
|
||||||
vec4 direction;
|
|
||||||
vec4 color;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
#ifdef USE_UBOS
|
||||||
layout(std140) uniform Object
|
layout(std140) uniform Object
|
||||||
{
|
{
|
||||||
mat4 u_world;
|
mat4 u_world;
|
||||||
vec4 u_ambLight;
|
vec4 u_ambLight;
|
||||||
Light u_directLights[MAX_LIGHTS];
|
vec4 u_lightParams[MAX_LIGHTS]; // type, radius, minusCosAngle, hardSpot
|
||||||
Light u_pointLights[MAX_LIGHTS];
|
vec4 u_lightPosition[MAX_LIGHTS];
|
||||||
Light u_spotLights[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_matColor;
|
||||||
uniform vec4 u_surfProps; // amb, spec, diff, extra
|
uniform vec4 u_surfProps; // amb, spec, diff, extra
|
||||||
|
@ -43,44 +63,52 @@ 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)
|
#ifdef DIRECTIONALS
|
||||||
{
|
if(u_lightParams[i].x == 1.0){
|
||||||
// As on PS2
|
// direct
|
||||||
vec3 dir = V - L.position.xyz;
|
float l = max(0.0, dot(N, -u_lightDirection[i].xyz));
|
||||||
float dist = length(dir);
|
color += l*u_lightColor[i].rgb;
|
||||||
float atten = max(0.0, (1.0 - dist/L.radius));
|
}else
|
||||||
float l = max(0.0, dot(N, -normalize(dir)));
|
#endif
|
||||||
return l*L.color.rgb*atten;
|
#ifdef POINTLIGHTS
|
||||||
}
|
if(u_lightParams[i].x == 2.0){
|
||||||
|
// point
|
||||||
vec3 DoSpotLight(Light L, vec3 V, vec3 N)
|
vec3 dir = V - u_lightPosition[i].xyz;
|
||||||
{
|
float dist = length(dir);
|
||||||
// As on PS2
|
float atten = max(0.0, (1.0 - dist/u_lightParams[i].y));
|
||||||
vec3 dir = V - L.position.xyz;
|
float l = max(0.0, dot(N, -normalize(dir)));
|
||||||
float dist = length(dir);
|
color += l*u_lightColor[i].rgb*atten;
|
||||||
float atten = max(0.0, (1.0 - dist/L.radius));
|
}else
|
||||||
dir /= dist;
|
#endif
|
||||||
float l = max(0.0, dot(N, -dir));
|
#ifdef SPOTLIGHTS
|
||||||
float pcos = dot(dir, L.direction.xyz); // cos to point
|
if(u_lightParams[i].x == 3.0){
|
||||||
float ccos = -L.minusCosAngle;
|
// spot
|
||||||
float falloff = (pcos-ccos)/(1.0-ccos);
|
vec3 dir = V - u_lightPosition[i].xyz;
|
||||||
if(falloff < 0.0) // outside of cone
|
float dist = length(dir);
|
||||||
l = 0.0;
|
float atten = max(0.0, (1.0 - dist/u_lightParams[i].y));
|
||||||
l *= max(falloff, L.hardSpot);
|
dir /= dist;
|
||||||
return l*L.color.xyz*atten;
|
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)
|
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
|
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
const char *header_frag_src =
|
||||||
|
"#ifdef USE_UBOS\n"
|
||||||
|
"layout(std140) uniform State\n"
|
||||||
|
"{\n"
|
||||||
|
" vec2 u_alphaRef;\n"
|
||||||
|
|
||||||
|
" float u_fogStart;\n"
|
||||||
|
" float u_fogEnd;\n"
|
||||||
|
" float u_fogRange;\n"
|
||||||
|
" float u_fogDisable;\n"
|
||||||
|
" vec4 u_fogColor;\n"
|
||||||
|
"};\n"
|
||||||
|
"#else\n"
|
||||||
|
"//uniform int u_alphaTest;\n"
|
||||||
|
"//uniform float u_alphaRef;\n"
|
||||||
|
"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"
|
||||||
|
"#endif\n"
|
||||||
|
|
||||||
|
"void DoAlphaTest(float a)\n"
|
||||||
|
"{\n"
|
||||||
|
" if(a < u_alphaRef.x || a >= u_alphaRef.y)\n"
|
||||||
|
" discard;\n"
|
||||||
|
"}\n"
|
||||||
|
;
|
|
@ -1,8 +1,13 @@
|
||||||
const char *header_vert_src =
|
const char *header_vert_src =
|
||||||
|
|
||||||
|
"#define DIRECTIONALS\n"
|
||||||
|
"//#define POINTLIGHTS\n"
|
||||||
|
"//#define SPOTLIGHTS\n"
|
||||||
|
|
||||||
|
"#ifdef USE_UBOS\n"
|
||||||
"layout(std140) uniform State\n"
|
"layout(std140) uniform State\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int u_alphaTest;\n"
|
" vec2 u_alphaRef;\n"
|
||||||
" float u_alphaRef;\n"
|
|
||||||
|
|
||||||
" float u_fogStart;\n"
|
" float u_fogStart;\n"
|
||||||
" float u_fogEnd;\n"
|
" float u_fogEnd;\n"
|
||||||
|
@ -10,32 +15,47 @@ const char *header_vert_src =
|
||||||
" float u_fogDisable;\n"
|
" float u_fogDisable;\n"
|
||||||
" vec4 u_fogColor;\n"
|
" vec4 u_fogColor;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
|
"#else\n"
|
||||||
|
"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"
|
||||||
|
"#endif\n"
|
||||||
|
|
||||||
|
"#ifdef USE_UBOS\n"
|
||||||
"layout(std140) uniform Scene\n"
|
"layout(std140) uniform Scene\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" mat4 u_proj;\n"
|
" mat4 u_proj;\n"
|
||||||
" mat4 u_view;\n"
|
" mat4 u_view;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
|
"#else\n"
|
||||||
|
"uniform mat4 u_proj;\n"
|
||||||
|
"uniform mat4 u_view;\n"
|
||||||
|
"#endif\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"
|
|
||||||
|
|
||||||
|
"#ifdef USE_UBOS\n"
|
||||||
"layout(std140) uniform Object\n"
|
"layout(std140) uniform Object\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" mat4 u_world;\n"
|
" mat4 u_world;\n"
|
||||||
" vec4 u_ambLight;\n"
|
" vec4 u_ambLight;\n"
|
||||||
" Light u_directLights[MAX_LIGHTS];\n"
|
" vec4 u_lightParams[MAX_LIGHTS]; // type, radius, minusCosAngle, hardSpot\n"
|
||||||
" Light u_pointLights[MAX_LIGHTS];\n"
|
" vec4 u_lightPosition[MAX_LIGHTS];\n"
|
||||||
" Light u_spotLights[MAX_LIGHTS];\n"
|
" vec4 u_lightDirection[MAX_LIGHTS];\n"
|
||||||
|
" vec4 u_lightColor[MAX_LIGHTS];\n"
|
||||||
"};\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_matColor;\n"
|
||||||
"uniform vec4 u_surfProps; // amb, spec, diff, extra\n"
|
"uniform vec4 u_surfProps; // amb, spec, diff, extra\n"
|
||||||
|
@ -44,45 +64,53 @@ 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"
|
"#ifdef DIRECTIONALS\n"
|
||||||
"{\n"
|
" if(u_lightParams[i].x == 1.0){\n"
|
||||||
" // As on PS2\n"
|
" // direct\n"
|
||||||
" vec3 dir = V - L.position.xyz;\n"
|
" float l = max(0.0, dot(N, -u_lightDirection[i].xyz));\n"
|
||||||
" float dist = length(dir);\n"
|
" color += l*u_lightColor[i].rgb;\n"
|
||||||
" float atten = max(0.0, (1.0 - dist/L.radius));\n"
|
" }else\n"
|
||||||
" float l = max(0.0, dot(N, -normalize(dir)));\n"
|
"#endif\n"
|
||||||
" return l*L.color.rgb*atten;\n"
|
"#ifdef POINTLIGHTS\n"
|
||||||
"}\n"
|
" if(u_lightParams[i].x == 2.0){\n"
|
||||||
|
" // point\n"
|
||||||
"vec3 DoSpotLight(Light L, vec3 V, vec3 N)\n"
|
" vec3 dir = V - u_lightPosition[i].xyz;\n"
|
||||||
"{\n"
|
" float dist = length(dir);\n"
|
||||||
" // As on PS2\n"
|
" float atten = max(0.0, (1.0 - dist/u_lightParams[i].y));\n"
|
||||||
" vec3 dir = V - L.position.xyz;\n"
|
" float l = max(0.0, dot(N, -normalize(dir)));\n"
|
||||||
" float dist = length(dir);\n"
|
" color += l*u_lightColor[i].rgb*atten;\n"
|
||||||
" float atten = max(0.0, (1.0 - dist/L.radius));\n"
|
" }else\n"
|
||||||
" dir /= dist;\n"
|
"#endif\n"
|
||||||
" float l = max(0.0, dot(N, -dir));\n"
|
"#ifdef SPOTLIGHTS\n"
|
||||||
" float pcos = dot(dir, L.direction.xyz); // cos to point\n"
|
" if(u_lightParams[i].x == 3.0){\n"
|
||||||
" float ccos = -L.minusCosAngle;\n"
|
" // spot\n"
|
||||||
" float falloff = (pcos-ccos)/(1.0-ccos);\n"
|
" vec3 dir = V - u_lightPosition[i].xyz;\n"
|
||||||
" if(falloff < 0.0) // outside of cone\n"
|
" float dist = length(dir);\n"
|
||||||
" l = 0.0;\n"
|
" float atten = max(0.0, (1.0 - dist/u_lightParams[i].y));\n"
|
||||||
" l *= max(falloff, L.hardSpot);\n"
|
" dir /= dist;\n"
|
||||||
" return l*L.color.xyz*atten;\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"
|
"}\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"
|
|
||||||
;
|
;
|
||||||
|
|
|
@ -1,15 +1,3 @@
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
uniform sampler2D tex0;
|
uniform sampler2D tex0;
|
||||||
uniform sampler2D tex1;
|
uniform sampler2D tex1;
|
||||||
|
|
||||||
|
@ -38,16 +26,5 @@ main(void)
|
||||||
color.rgb = pass1.rgb*pass1.a + pass2.rgb;
|
color.rgb = pass1.rgb*pass1.a + pass2.rgb;
|
||||||
color.a = pass1.a;
|
color.a = pass1.a;
|
||||||
|
|
||||||
switch(u_alphaTest){
|
DoAlphaTest(color.a);
|
||||||
default:
|
|
||||||
case 0: break;
|
|
||||||
case 1:
|
|
||||||
if(color.a < u_alphaRef)
|
|
||||||
discard;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if(color.a >= u_alphaRef)
|
|
||||||
discard;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
|
||||||
|
@ -53,18 +31,6 @@ const char *matfx_env_vert_src =
|
||||||
"}\n"
|
"}\n"
|
||||||
;
|
;
|
||||||
const char *matfx_env_frag_src =
|
const char *matfx_env_frag_src =
|
||||||
"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"
|
|
||||||
|
|
||||||
"uniform sampler2D tex0;\n"
|
"uniform sampler2D tex0;\n"
|
||||||
"uniform sampler2D tex1;\n"
|
"uniform sampler2D tex1;\n"
|
||||||
|
|
||||||
|
@ -93,17 +59,6 @@ const char *matfx_env_frag_src =
|
||||||
" color.rgb = pass1.rgb*pass1.a + pass2.rgb;\n"
|
" color.rgb = pass1.rgb*pass1.a + pass2.rgb;\n"
|
||||||
" color.a = pass1.a;\n"
|
" color.a = pass1.a;\n"
|
||||||
|
|
||||||
" switch(u_alphaTest){\n"
|
" DoAlphaTest(color.a);\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"
|
"}\n"
|
||||||
;
|
;
|
||||||
|
|
|
@ -1,15 +1,3 @@
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
uniform sampler2D tex0;
|
uniform sampler2D tex0;
|
||||||
|
|
||||||
in vec4 v_color;
|
in vec4 v_color;
|
||||||
|
@ -23,17 +11,6 @@ main(void)
|
||||||
{
|
{
|
||||||
color = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));
|
color = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));
|
||||||
color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);
|
color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);
|
||||||
switch(u_alphaTest){
|
DoAlphaTest(color.a);
|
||||||
default:
|
|
||||||
case 0: break;
|
|
||||||
case 1:
|
|
||||||
if(color.a < u_alphaRef)
|
|
||||||
discard;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if(color.a >= u_alphaRef)
|
|
||||||
discard;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,4 @@
|
||||||
const char *simple_frag_src =
|
const char *simple_frag_src =
|
||||||
"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"
|
|
||||||
|
|
||||||
"uniform sampler2D tex0;\n"
|
"uniform sampler2D tex0;\n"
|
||||||
|
|
||||||
"in vec4 v_color;\n"
|
"in vec4 v_color;\n"
|
||||||
|
@ -24,18 +12,7 @@ const char *simple_frag_src =
|
||||||
"{\n"
|
"{\n"
|
||||||
" color = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\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"
|
" color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);\n"
|
||||||
" switch(u_alphaTest){\n"
|
" DoAlphaTest(color.a);\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"
|
"}\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"
|
||||||
;
|
;
|
||||||
|
|
Loading…
Reference in New Issue