Various shader fixes and optimizations.

This commit is contained in:
James Canete 2012-11-14 10:56:31 +00:00
parent b269acac94
commit d635193e19
5 changed files with 558 additions and 452 deletions

File diff suppressed because it is too large Load diff

View file

@ -718,7 +718,7 @@ enum
enum
{
GENERICDEF_USE_DEFORM_VERTEXES = 0x0001,
GENERICDEF_USE_TCGEN = 0x0002,
GENERICDEF_USE_TCGEN_AND_TCMOD = 0x0002,
GENERICDEF_USE_VERTEX_ANIMATION = 0x0004,
GENERICDEF_USE_FOG = 0x0008,
GENERICDEF_USE_RGBAGEN = 0x0010,
@ -729,19 +729,34 @@ enum
enum
{
LIGHTDEF_USE_LIGHTMAP = 0x0001,
LIGHTDEF_USE_LIGHT_VECTOR = 0x0002,
LIGHTDEF_USE_LIGHT_VERTEX = 0x0003,
LIGHTDEF_LIGHTTYPE_MASK = 0x0003,
LIGHTDEF_USE_NORMALMAP = 0x0004,
LIGHTDEF_USE_SPECULARMAP = 0x0008,
LIGHTDEF_USE_DELUXEMAP = 0x0010,
LIGHTDEF_USE_PARALLAXMAP = 0x0020,
LIGHTDEF_USE_SHADOWMAP = 0x0040,
LIGHTDEF_TCGEN_ENVIRONMENT = 0x0080,
LIGHTDEF_ENTITY = 0x0100,
LIGHTDEF_ALL = 0x01FF,
LIGHTDEF_COUNT = 0x0200
FOGDEF_USE_DEFORM_VERTEXES = 0x0001,
FOGDEF_USE_VERTEX_ANIMATION = 0x0002,
FOGDEF_ALL = 0x0003,
FOGDEF_COUNT = 0x0004,
};
enum
{
DLIGHTDEF_USE_DEFORM_VERTEXES = 0x0001,
DLIGHTDEF_ALL = 0x0001,
DLIGHTDEF_COUNT = 0x0002,
};
enum
{
LIGHTDEF_USE_LIGHTMAP = 0x0001,
LIGHTDEF_USE_LIGHT_VECTOR = 0x0002,
LIGHTDEF_USE_LIGHT_VERTEX = 0x0003,
LIGHTDEF_LIGHTTYPE_MASK = 0x0003,
LIGHTDEF_ENTITY = 0x0004,
LIGHTDEF_USE_TCGEN_AND_TCMOD = 0x0008,
LIGHTDEF_USE_NORMALMAP = 0x0010,
LIGHTDEF_USE_SPECULARMAP = 0x0020,
LIGHTDEF_USE_DELUXEMAP = 0x0040,
LIGHTDEF_USE_PARALLAXMAP = 0x0080,
LIGHTDEF_USE_SHADOWMAP = 0x0100,
LIGHTDEF_ALL = 0x01FF,
LIGHTDEF_COUNT = 0x0200
};
enum
@ -769,8 +784,8 @@ typedef struct shaderProgram_s
// uniform parameters
int numUniforms;
GLint *uniforms;
GLint *uniformTypes;
int *uniformBufferOffsets;
char *uniformTypes; // max 127 uniform types
short *uniformBufferOffsets; // max 32767/64=511 uniforms
char *uniformBuffer;
} shaderProgram_t;
@ -839,6 +854,7 @@ enum
GENERIC_UNIFORM_SPECULARMAP,
GENERIC_UNIFORM_SHADOWMAP,
GENERIC_UNIFORM_DIFFUSETEXMATRIX,
GENERIC_UNIFORM_DIFFUSETEXOFFTURB,
//GENERIC_UNIFORM_NORMALTEXMATRIX,
//GENERIC_UNIFORM_SPECULARTEXMATRIX,
GENERIC_UNIFORM_TEXTURE1ENV,
@ -1863,8 +1879,8 @@ typedef struct {
//
shaderProgram_t genericShader[GENERICDEF_COUNT];
shaderProgram_t textureColorShader;
shaderProgram_t fogShader;
shaderProgram_t dlightallShader;
shaderProgram_t fogShader[FOGDEF_COUNT];
shaderProgram_t dlightShader[DLIGHTDEF_COUNT];
shaderProgram_t lightallShader[LIGHTDEF_COUNT];
shaderProgram_t shadowmapShader;
shaderProgram_t pshadowShader;

View file

@ -363,7 +363,7 @@ static void ProjectDlightTexture( void ) {
radius = dl->radius;
scale = 1.0f / radius;
sp = &tr.dlightallShader;
sp = &tr.dlightShader[deformGen == DGEN_NONE ? 0 : 1];
backEnd.pc.c_dlightDraws++;
@ -397,10 +397,10 @@ static void ProjectDlightTexture( void ) {
// include GLS_DEPTHFUNC_EQUAL so alpha tested surfaces don't add light
// where they aren't rendered
if ( dl->additive ) {
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL );
GL_State( GLS_ATEST_GT_0 | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL );
}
else {
GL_State( GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL );
GL_State( GLS_ATEST_GT_0 | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL );
}
if (tess.multiDrawPrimitives)
@ -462,12 +462,12 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
case CGEN_EXACT_VERTEX_LIT:
baseColor[0] =
baseColor[1] =
baseColor[2] = 1.0f;
baseColor[2] =
baseColor[3] = 0.0f;
vertColor[0] =
vertColor[1] =
vertColor[2] = 0.0f;
vertColor[2] =
vertColor[3] = 1.0f;
break;
case CGEN_CONST:
@ -495,13 +495,13 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
case CGEN_VERTEX_LIT:
baseColor[0] =
baseColor[1] =
baseColor[2] = tr.identityLight;
baseColor[2] =
baseColor[3] = 0.0f;
vertColor[0] =
vertColor[1] =
vertColor[2] = 0.0f;
vertColor[3] = 1.0f;
vertColor[2] =
vertColor[3] = tr.identityLight;
break;
case CGEN_ONE_MINUS_VERTEX:
baseColor[0] =
@ -850,7 +850,14 @@ static void ForwardDlight( void ) {
}
ComputeTexMatrix( pStage, TB_DIFFUSEMAP, matrix );
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_DIFFUSETEXMATRIX, matrix);
VectorSet4(vector, matrix[0], matrix[1], matrix[4], matrix[5]);
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_DIFFUSETEXMATRIX, vector);
VectorSet4(vector, matrix[8], matrix[9], matrix[12], matrix[13]);
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_DIFFUSETEXOFFTURB, vector);
GLSL_SetUniformInt(sp, GENERIC_UNIFORM_TCGEN0, pStage->bundle[0].tcGen);
//
// draw
@ -926,7 +933,7 @@ static void ForwardSunlight( void ) {
{
shaderStage_t *pStage = input->xstages[stage];
shaderProgram_t *sp;
//vec4_t vector;
vec4_t vector;
matrix_t matrix;
if ( !pStage )
@ -1046,7 +1053,14 @@ static void ForwardSunlight( void ) {
GL_BindToTMU(tr.screenShadowImage, TB_SHADOWMAP);
ComputeTexMatrix( pStage, TB_DIFFUSEMAP, matrix );
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_DIFFUSETEXMATRIX, matrix);
VectorSet4(vector, matrix[0], matrix[1], matrix[4], matrix[5]);
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_DIFFUSETEXMATRIX, vector);
VectorSet4(vector, matrix[8], matrix[9], matrix[12], matrix[13]);
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_DIFFUSETEXOFFTURB, vector);
GLSL_SetUniformInt(sp, GENERIC_UNIFORM_TCGEN0, pStage->bundle[0].tcGen);
//
// draw
@ -1155,13 +1169,25 @@ static void RB_FogPass( void ) {
vec4_t color;
vec4_t fogDistanceVector, fogDepthVector = {0, 0, 0, 0};
float eyeT = 0;
shaderProgram_t *sp = &tr.fogShader;
shaderProgram_t *sp;
int deformGen;
vec5_t deformParams;
ComputeDeformValues(&deformGen, deformParams);
{
int index = 0;
if (deformGen |= DGEN_NONE)
index |= FOGDEF_USE_DEFORM_VERTEXES;
if (glState.vertexAttribsInterpolation)
index |= FOGDEF_USE_VERTEX_ANIMATION;
sp = &tr.fogShader[index];
}
backEnd.pc.c_fogDraws++;
GLSL_BindProgram(sp);
@ -1415,7 +1441,15 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
}
ComputeTexMatrix( pStage, TB_DIFFUSEMAP, matrix );
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_DIFFUSETEXMATRIX, matrix);
{
vec4_t vector;
VectorSet4(vector, matrix[0], matrix[1], matrix[4], matrix[5]);
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_DIFFUSETEXMATRIX, vector);
VectorSet4(vector, matrix[8], matrix[9], matrix[12], matrix[13]);
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_DIFFUSETEXOFFTURB, vector);
}
GLSL_SetUniformInt(sp, GENERIC_UNIFORM_TCGEN0, pStage->bundle[0].tcGen);
if (pStage->bundle[0].tcGen == TCGEN_VECTOR)

View file

@ -2234,9 +2234,9 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse,
}
}
if (environment)
if (environment || diffuse->bundle[0].numTexMods)
{
defs |= LIGHTDEF_TCGEN_ENVIRONMENT;
defs |= LIGHTDEF_USE_TCGEN_AND_TCMOD;
}
//ri.Printf(PRINT_ALL, ".\n");

View file

@ -440,7 +440,7 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
*/
{
shaderProgram_t *sp = &tr.lightallShader[0];
matrix_t matrix;
vec4_t vector;
GLSL_VertexAttribsState(ATTR_POSITION | ATTR_TEXCOORD);
GLSL_BindProgram(sp);
@ -459,8 +459,11 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
color[3] = 0.0f;
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_VERTCOLOR, color);
Matrix16Identity(matrix);
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_DIFFUSETEXMATRIX, matrix);
VectorSet4(vector, 1.0, 0.0, 0.0, 1.0);
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_DIFFUSETEXMATRIX, vector);
VectorSet4(vector, 0.0, 0.0, 0.0, 0.0);
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_DIFFUSETEXOFFTURB, vector);
}
R_DrawElementsVBO(tess.numIndexes - tess.firstIndex, tess.firstIndex, tess.minIndex, tess.maxIndex);