mirror of
https://github.com/ioquake/ioq3.git
synced 2024-11-10 07:11:46 +00:00
Various shader fixes and optimizations.
This commit is contained in:
parent
b269acac94
commit
d635193e19
5 changed files with 558 additions and 452 deletions
File diff suppressed because it is too large
Load diff
|
@ -718,7 +718,7 @@ enum
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
GENERICDEF_USE_DEFORM_VERTEXES = 0x0001,
|
GENERICDEF_USE_DEFORM_VERTEXES = 0x0001,
|
||||||
GENERICDEF_USE_TCGEN = 0x0002,
|
GENERICDEF_USE_TCGEN_AND_TCMOD = 0x0002,
|
||||||
GENERICDEF_USE_VERTEX_ANIMATION = 0x0004,
|
GENERICDEF_USE_VERTEX_ANIMATION = 0x0004,
|
||||||
GENERICDEF_USE_FOG = 0x0008,
|
GENERICDEF_USE_FOG = 0x0008,
|
||||||
GENERICDEF_USE_RGBAGEN = 0x0010,
|
GENERICDEF_USE_RGBAGEN = 0x0010,
|
||||||
|
@ -729,19 +729,34 @@ enum
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
LIGHTDEF_USE_LIGHTMAP = 0x0001,
|
FOGDEF_USE_DEFORM_VERTEXES = 0x0001,
|
||||||
LIGHTDEF_USE_LIGHT_VECTOR = 0x0002,
|
FOGDEF_USE_VERTEX_ANIMATION = 0x0002,
|
||||||
LIGHTDEF_USE_LIGHT_VERTEX = 0x0003,
|
FOGDEF_ALL = 0x0003,
|
||||||
LIGHTDEF_LIGHTTYPE_MASK = 0x0003,
|
FOGDEF_COUNT = 0x0004,
|
||||||
LIGHTDEF_USE_NORMALMAP = 0x0004,
|
};
|
||||||
LIGHTDEF_USE_SPECULARMAP = 0x0008,
|
|
||||||
LIGHTDEF_USE_DELUXEMAP = 0x0010,
|
enum
|
||||||
LIGHTDEF_USE_PARALLAXMAP = 0x0020,
|
{
|
||||||
LIGHTDEF_USE_SHADOWMAP = 0x0040,
|
DLIGHTDEF_USE_DEFORM_VERTEXES = 0x0001,
|
||||||
LIGHTDEF_TCGEN_ENVIRONMENT = 0x0080,
|
DLIGHTDEF_ALL = 0x0001,
|
||||||
LIGHTDEF_ENTITY = 0x0100,
|
DLIGHTDEF_COUNT = 0x0002,
|
||||||
LIGHTDEF_ALL = 0x01FF,
|
};
|
||||||
LIGHTDEF_COUNT = 0x0200
|
|
||||||
|
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
|
enum
|
||||||
|
@ -769,8 +784,8 @@ typedef struct shaderProgram_s
|
||||||
// uniform parameters
|
// uniform parameters
|
||||||
int numUniforms;
|
int numUniforms;
|
||||||
GLint *uniforms;
|
GLint *uniforms;
|
||||||
GLint *uniformTypes;
|
char *uniformTypes; // max 127 uniform types
|
||||||
int *uniformBufferOffsets;
|
short *uniformBufferOffsets; // max 32767/64=511 uniforms
|
||||||
char *uniformBuffer;
|
char *uniformBuffer;
|
||||||
} shaderProgram_t;
|
} shaderProgram_t;
|
||||||
|
|
||||||
|
@ -839,6 +854,7 @@ enum
|
||||||
GENERIC_UNIFORM_SPECULARMAP,
|
GENERIC_UNIFORM_SPECULARMAP,
|
||||||
GENERIC_UNIFORM_SHADOWMAP,
|
GENERIC_UNIFORM_SHADOWMAP,
|
||||||
GENERIC_UNIFORM_DIFFUSETEXMATRIX,
|
GENERIC_UNIFORM_DIFFUSETEXMATRIX,
|
||||||
|
GENERIC_UNIFORM_DIFFUSETEXOFFTURB,
|
||||||
//GENERIC_UNIFORM_NORMALTEXMATRIX,
|
//GENERIC_UNIFORM_NORMALTEXMATRIX,
|
||||||
//GENERIC_UNIFORM_SPECULARTEXMATRIX,
|
//GENERIC_UNIFORM_SPECULARTEXMATRIX,
|
||||||
GENERIC_UNIFORM_TEXTURE1ENV,
|
GENERIC_UNIFORM_TEXTURE1ENV,
|
||||||
|
@ -1863,8 +1879,8 @@ typedef struct {
|
||||||
//
|
//
|
||||||
shaderProgram_t genericShader[GENERICDEF_COUNT];
|
shaderProgram_t genericShader[GENERICDEF_COUNT];
|
||||||
shaderProgram_t textureColorShader;
|
shaderProgram_t textureColorShader;
|
||||||
shaderProgram_t fogShader;
|
shaderProgram_t fogShader[FOGDEF_COUNT];
|
||||||
shaderProgram_t dlightallShader;
|
shaderProgram_t dlightShader[DLIGHTDEF_COUNT];
|
||||||
shaderProgram_t lightallShader[LIGHTDEF_COUNT];
|
shaderProgram_t lightallShader[LIGHTDEF_COUNT];
|
||||||
shaderProgram_t shadowmapShader;
|
shaderProgram_t shadowmapShader;
|
||||||
shaderProgram_t pshadowShader;
|
shaderProgram_t pshadowShader;
|
||||||
|
|
|
@ -363,7 +363,7 @@ static void ProjectDlightTexture( void ) {
|
||||||
radius = dl->radius;
|
radius = dl->radius;
|
||||||
scale = 1.0f / radius;
|
scale = 1.0f / radius;
|
||||||
|
|
||||||
sp = &tr.dlightallShader;
|
sp = &tr.dlightShader[deformGen == DGEN_NONE ? 0 : 1];
|
||||||
|
|
||||||
backEnd.pc.c_dlightDraws++;
|
backEnd.pc.c_dlightDraws++;
|
||||||
|
|
||||||
|
@ -397,10 +397,10 @@ static void ProjectDlightTexture( void ) {
|
||||||
// include GLS_DEPTHFUNC_EQUAL so alpha tested surfaces don't add light
|
// include GLS_DEPTHFUNC_EQUAL so alpha tested surfaces don't add light
|
||||||
// where they aren't rendered
|
// where they aren't rendered
|
||||||
if ( dl->additive ) {
|
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 {
|
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)
|
if (tess.multiDrawPrimitives)
|
||||||
|
@ -462,12 +462,12 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
|
||||||
case CGEN_EXACT_VERTEX_LIT:
|
case CGEN_EXACT_VERTEX_LIT:
|
||||||
baseColor[0] =
|
baseColor[0] =
|
||||||
baseColor[1] =
|
baseColor[1] =
|
||||||
baseColor[2] = 1.0f;
|
baseColor[2] =
|
||||||
baseColor[3] = 0.0f;
|
baseColor[3] = 0.0f;
|
||||||
|
|
||||||
vertColor[0] =
|
vertColor[0] =
|
||||||
vertColor[1] =
|
vertColor[1] =
|
||||||
vertColor[2] = 0.0f;
|
vertColor[2] =
|
||||||
vertColor[3] = 1.0f;
|
vertColor[3] = 1.0f;
|
||||||
break;
|
break;
|
||||||
case CGEN_CONST:
|
case CGEN_CONST:
|
||||||
|
@ -495,13 +495,13 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
|
||||||
case CGEN_VERTEX_LIT:
|
case CGEN_VERTEX_LIT:
|
||||||
baseColor[0] =
|
baseColor[0] =
|
||||||
baseColor[1] =
|
baseColor[1] =
|
||||||
baseColor[2] = tr.identityLight;
|
baseColor[2] =
|
||||||
baseColor[3] = 0.0f;
|
baseColor[3] = 0.0f;
|
||||||
|
|
||||||
vertColor[0] =
|
vertColor[0] =
|
||||||
vertColor[1] =
|
vertColor[1] =
|
||||||
vertColor[2] = 0.0f;
|
vertColor[2] =
|
||||||
vertColor[3] = 1.0f;
|
vertColor[3] = tr.identityLight;
|
||||||
break;
|
break;
|
||||||
case CGEN_ONE_MINUS_VERTEX:
|
case CGEN_ONE_MINUS_VERTEX:
|
||||||
baseColor[0] =
|
baseColor[0] =
|
||||||
|
@ -850,7 +850,14 @@ static void ForwardDlight( void ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputeTexMatrix( pStage, TB_DIFFUSEMAP, matrix );
|
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
|
// draw
|
||||||
|
@ -926,7 +933,7 @@ static void ForwardSunlight( void ) {
|
||||||
{
|
{
|
||||||
shaderStage_t *pStage = input->xstages[stage];
|
shaderStage_t *pStage = input->xstages[stage];
|
||||||
shaderProgram_t *sp;
|
shaderProgram_t *sp;
|
||||||
//vec4_t vector;
|
vec4_t vector;
|
||||||
matrix_t matrix;
|
matrix_t matrix;
|
||||||
|
|
||||||
if ( !pStage )
|
if ( !pStage )
|
||||||
|
@ -1046,7 +1053,14 @@ static void ForwardSunlight( void ) {
|
||||||
GL_BindToTMU(tr.screenShadowImage, TB_SHADOWMAP);
|
GL_BindToTMU(tr.screenShadowImage, TB_SHADOWMAP);
|
||||||
|
|
||||||
ComputeTexMatrix( pStage, TB_DIFFUSEMAP, matrix );
|
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
|
// draw
|
||||||
|
@ -1155,13 +1169,25 @@ static void RB_FogPass( void ) {
|
||||||
vec4_t color;
|
vec4_t color;
|
||||||
vec4_t fogDistanceVector, fogDepthVector = {0, 0, 0, 0};
|
vec4_t fogDistanceVector, fogDepthVector = {0, 0, 0, 0};
|
||||||
float eyeT = 0;
|
float eyeT = 0;
|
||||||
shaderProgram_t *sp = &tr.fogShader;
|
shaderProgram_t *sp;
|
||||||
|
|
||||||
int deformGen;
|
int deformGen;
|
||||||
vec5_t deformParams;
|
vec5_t deformParams;
|
||||||
|
|
||||||
ComputeDeformValues(&deformGen, 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++;
|
backEnd.pc.c_fogDraws++;
|
||||||
|
|
||||||
GLSL_BindProgram(sp);
|
GLSL_BindProgram(sp);
|
||||||
|
@ -1415,7 +1441,15 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputeTexMatrix( pStage, TB_DIFFUSEMAP, matrix );
|
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);
|
GLSL_SetUniformInt(sp, GENERIC_UNIFORM_TCGEN0, pStage->bundle[0].tcGen);
|
||||||
if (pStage->bundle[0].tcGen == TCGEN_VECTOR)
|
if (pStage->bundle[0].tcGen == TCGEN_VECTOR)
|
||||||
|
|
|
@ -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");
|
//ri.Printf(PRINT_ALL, ".\n");
|
||||||
|
|
|
@ -440,7 +440,7 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
shaderProgram_t *sp = &tr.lightallShader[0];
|
shaderProgram_t *sp = &tr.lightallShader[0];
|
||||||
matrix_t matrix;
|
vec4_t vector;
|
||||||
|
|
||||||
GLSL_VertexAttribsState(ATTR_POSITION | ATTR_TEXCOORD);
|
GLSL_VertexAttribsState(ATTR_POSITION | ATTR_TEXCOORD);
|
||||||
GLSL_BindProgram(sp);
|
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;
|
color[3] = 0.0f;
|
||||||
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_VERTCOLOR, color);
|
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_VERTCOLOR, color);
|
||||||
|
|
||||||
Matrix16Identity(matrix);
|
VectorSet4(vector, 1.0, 0.0, 0.0, 1.0);
|
||||||
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_DIFFUSETEXMATRIX, matrix);
|
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);
|
R_DrawElementsVBO(tess.numIndexes - tess.firstIndex, tess.firstIndex, tess.minIndex, tess.maxIndex);
|
||||||
|
|
Loading…
Reference in a new issue