Permalink
Browse files

Add tiled light-index renderer.

  • Loading branch information...
1 parent a931ad7 commit 827daf859e751aaf01c7414ec8279f4c1e856bd5 @gimhael gimhael committed Feb 1, 2016
@@ -61,6 +61,9 @@ GLShader_liquid *gl_liquidShader = nullptr;
GLShader_volumetricFog *gl_volumetricFogShader = nullptr;
GLShader_motionblur *gl_motionblurShader = nullptr;
GLShader_ssao *gl_ssaoShader = nullptr;
+GLShader_depthtile1 *gl_depthtile1Shader = nullptr;
+GLShader_depthtile2 *gl_depthtile2Shader = nullptr;
+GLShader_lighttile *gl_lighttileShader = nullptr;
GLShader_fxaa *gl_fxaaShader = nullptr;
GLShaderManager gl_shaderManager;
@@ -459,6 +462,7 @@ std::string GLShaderManager::BuildGPUShaderText( Str::StringRef mainShaderNa
AddDefine( env, "M_PI", static_cast<float>( M_PI ) );
AddDefine( env, "MAX_SHADOWMAPS", MAX_SHADOWMAPS );
AddDefine( env, "MAX_REF_LIGHTS", MAX_REF_LIGHTS );
+ AddDefine( env, "TILE_SIZE", TILE_SIZE );
float fbufWidthScale = 1.0f / glConfig.vidWidth;
float fbufHeightScale = 1.0f / glConfig.vidHeight;
@@ -475,6 +479,7 @@ std::string GLShaderManager::BuildGPUShaderText( Str::StringRef mainShaderNa
}
AddDefine( env, "r_NPOTScale", npotWidthScale, npotHeightScale );
+ AddDefine( env, "r_tileStep", glState.tileStep[ 0 ], glState.tileStep[ 1 ] );
if ( glConfig.driverType == glDriverType_t::GLDRV_MESA )
AddDefine( env, "GLDRV_MESA", 1 );
@@ -1274,13 +1279,16 @@ GLShader_generic::GLShader_generic( GLShaderManager *manager ) :
u_Bones( this ),
u_VertexInterpolation( this ),
u_DepthScale( this ),
+ u_numLights( this ),
+ u_Lights( this ),
GLDeformStage( this ),
GLCompileMacro_USE_VERTEX_SKINNING( this ),
GLCompileMacro_USE_VERTEX_ANIMATION( this ),
GLCompileMacro_USE_VERTEX_SPRITE( this ),
GLCompileMacro_USE_TCGEN_ENVIRONMENT( this ),
GLCompileMacro_USE_TCGEN_LIGHTMAP( this ),
- GLCompileMacro_USE_DEPTH_FADE( this )
+ GLCompileMacro_USE_DEPTH_FADE( this ),
+ GLCompileMacro_USE_SHADER_LIGHTS( this )
{
}
@@ -1309,10 +1317,13 @@ GLShader_lightMapping::GLShader_lightMapping( GLShaderManager *manager ) :
u_ModelMatrix( this ),
u_ModelViewProjectionMatrix( this ),
u_DepthScale( this ),
+ u_numLights( this ),
+ u_Lights( this ),
GLDeformStage( this ),
GLCompileMacro_USE_NORMAL_MAPPING( this ),
GLCompileMacro_USE_PARALLAX_MAPPING( this ),
- GLCompileMacro_USE_GLOW_MAPPING( this )
+ GLCompileMacro_USE_GLOW_MAPPING( this ),
+ GLCompileMacro_USE_SHADER_LIGHTS( this )
{
}
@@ -1338,6 +1349,7 @@ void GLShader_lightMapping::SetShaderProgramUniforms( shaderProgram_t *shaderPro
glUniform1i( glGetUniformLocation( shaderProgram->program, "u_LightMap" ), 3 );
glUniform1i( glGetUniformLocation( shaderProgram->program, "u_DeluxeMap" ), 4 );
glUniform1i( glGetUniformLocation( shaderProgram->program, "u_GlowMap" ), 5 );
+ glUniform1i( glGetUniformLocation( shaderProgram->program, "u_LightTiles" ), 8 );
}
GLShader_vertexLighting_DBS_entity::GLShader_vertexLighting_DBS_entity( GLShaderManager *manager ) :
@@ -1357,13 +1369,16 @@ GLShader_vertexLighting_DBS_entity::GLShader_vertexLighting_DBS_entity( GLShader
u_EnvironmentInterpolation( this ),
u_LightGridOrigin( this ),
u_LightGridScale( this ),
+ u_numLights( this ),
+ u_Lights( this ),
GLDeformStage( this ),
GLCompileMacro_USE_VERTEX_SKINNING( this ),
GLCompileMacro_USE_VERTEX_ANIMATION( this ),
GLCompileMacro_USE_NORMAL_MAPPING( this ),
GLCompileMacro_USE_PARALLAX_MAPPING( this ),
GLCompileMacro_USE_REFLECTIVE_SPECULAR( this ),
- GLCompileMacro_USE_GLOW_MAPPING( this )
+ GLCompileMacro_USE_GLOW_MAPPING( this ),
+ GLCompileMacro_USE_SHADER_LIGHTS( this )
{
}
@@ -1391,6 +1406,7 @@ void GLShader_vertexLighting_DBS_entity::SetShaderProgramUniforms( shaderProgram
glUniform1i( glGetUniformLocation( shaderProgram->program, "u_GlowMap" ), 5 );
glUniform1i( glGetUniformLocation( shaderProgram->program, "u_LightGrid1" ), 6 );
glUniform1i( glGetUniformLocation( shaderProgram->program, "u_LightGrid2" ), 7 );
+ glUniform1i( glGetUniformLocation( shaderProgram->program, "u_LightTiles" ), 8 );
}
GLShader_vertexLighting_DBS_world::GLShader_vertexLighting_DBS_world( GLShaderManager *manager ) :
@@ -1413,10 +1429,13 @@ GLShader_vertexLighting_DBS_world::GLShader_vertexLighting_DBS_world( GLShaderMa
u_LightWrapAround( this ),
u_LightGridOrigin( this ),
u_LightGridScale( this ),
+ u_numLights( this ),
+ u_Lights( this ),
GLDeformStage( this ),
GLCompileMacro_USE_NORMAL_MAPPING( this ),
GLCompileMacro_USE_PARALLAX_MAPPING( this ),
- GLCompileMacro_USE_GLOW_MAPPING( this )
+ GLCompileMacro_USE_GLOW_MAPPING( this ),
+ GLCompileMacro_USE_SHADER_LIGHTS( this )
{
}
@@ -1441,6 +1460,7 @@ void GLShader_vertexLighting_DBS_world::SetShaderProgramUniforms( shaderProgram_
glUniform1i( glGetUniformLocation( shaderProgram->program, "u_GlowMap" ), 3 );
glUniform1i( glGetUniformLocation( shaderProgram->program, "u_LightGrid1" ), 6 );
glUniform1i( glGetUniformLocation( shaderProgram->program, "u_LightGrid2" ), 7 );
+ glUniform1i( glGetUniformLocation( shaderProgram->program, "u_LightTiles" ), 8 );
}
GLShader_forwardLighting_omniXYZ::GLShader_forwardLighting_omniXYZ( GLShaderManager *manager ):
@@ -1977,6 +1997,41 @@ void GLShader_ssao::SetShaderProgramUniforms( shaderProgram_t *shaderProgram )
glUniform1i( glGetUniformLocation( shaderProgram->program, "u_DepthMap" ), 0 );
}
+GLShader_depthtile1::GLShader_depthtile1( GLShaderManager *manager ) :
+ GLShader( "depthtile1", ATTR_POSITION, manager ),
+ u_zFar( this )
+{
+}
+
+void GLShader_depthtile1::SetShaderProgramUniforms( shaderProgram_t *shaderProgram )
+{
+ glUniform1i( glGetUniformLocation( shaderProgram->program, "u_DepthMap" ), 0 );
+}
+
+GLShader_depthtile2::GLShader_depthtile2( GLShaderManager *manager ) :
+ GLShader( "depthtile2", ATTR_POSITION, manager )
+{
+}
+
+void GLShader_depthtile2::SetShaderProgramUniforms( shaderProgram_t *shaderProgram )
+{
+ glUniform1i( glGetUniformLocation( shaderProgram->program, "u_DepthMap" ), 0 );
+}
+
+GLShader_lighttile::GLShader_lighttile( GLShaderManager *manager ) :
+ GLShader( "lighttile", ATTR_POSITION | ATTR_TEXCOORD, manager ),
+ u_ModelMatrix( this ),
+ u_numLights( this ),
+ u_lightLayer( this ),
+ u_Lights( this )
+{
+}
+
+void GLShader_lighttile::SetShaderProgramUniforms( shaderProgram_t *shaderProgram )
+{
+ glUniform1i( glGetUniformLocation( shaderProgram->program, "u_DepthMap" ), 0 );
+}
+
GLShader_fxaa::GLShader_fxaa( GLShaderManager *manager ) :
GLShader( "fxaa", ATTR_POSITION, manager )
{
@@ -711,10 +711,13 @@ class GLUniformBlock
void SetBuffer( GLuint buffer ) {
shaderProgram_t *p = _shader->GetProgram();
+ GLuint blockIndex = p->uniformBlockIndexes[ _locationIndex ];
ASSERT_EQ(p, glState.currentProgram);
- glBindBufferBase( GL_UNIFORM_BUFFER, p->uniformBlockIndexes[ _locationIndex ], buffer );
+ if( blockIndex != GL_INVALID_INDEX ) {
+ glBindBufferBase( GL_UNIFORM_BUFFER, blockIndex, buffer );
+ }
}
};
@@ -748,7 +751,8 @@ class GLCompileMacro
USE_SHADOWING,
LIGHT_DIRECTIONAL,
USE_GLOW_MAPPING,
- USE_DEPTH_FADE
+ USE_DEPTH_FADE,
+ USE_SHADER_LIGHTS
};
public:
@@ -1333,6 +1337,48 @@ class GLCompileMacro_USE_DEPTH_FADE :
}
};
+class GLCompileMacro_USE_SHADER_LIGHTS :
+ GLCompileMacro
+{
+public:
+ GLCompileMacro_USE_SHADER_LIGHTS( GLShader *shader ) :
+ GLCompileMacro( shader )
+ {
+ }
+
+ const char *GetName() const
+ {
+ return "USE_SHADER_LIGHTS";
+ }
+
+ EGLCompileMacro GetType() const
+ {
+ return USE_SHADER_LIGHTS;
+ }
+
+ void EnableMacro_USE_SHADER_LIGHTS()
+ {
+ EnableMacro();
+ }
+
+ void DisableMacro_USE_SHADER_LIGHTS()
+ {
+ DisableMacro();
+ }
+
+ void SetShaderLights( bool enable )
+ {
+ if ( enable )
+ {
+ EnableMacro();
+ }
+ else
+ {
+ DisableMacro();
+ }
+ }
+};
+
class u_ColorTextureMatrix :
GLUniformMatrix4f
{
@@ -2227,6 +2273,21 @@ class u_numLights :
}
};
+class u_lightLayer :
+ GLUniform1i
+{
+public:
+ u_lightLayer( GLShader *shader ) :
+ GLUniform1i( shader, "u_lightLayer" )
+ {
+ }
+
+ void SetUniform_lightLayer( int value )
+ {
+ this->SetValue( value );
+ }
+};
+
class u_Lights :
GLUniformBlock
{
@@ -2256,13 +2317,16 @@ class GLShader_generic :
public u_Bones,
public u_VertexInterpolation,
public u_DepthScale,
+ public u_numLights,
+ public u_Lights,
public GLDeformStage,
public GLCompileMacro_USE_VERTEX_SKINNING,
public GLCompileMacro_USE_VERTEX_ANIMATION,
public GLCompileMacro_USE_VERTEX_SPRITE,
public GLCompileMacro_USE_TCGEN_ENVIRONMENT,
public GLCompileMacro_USE_TCGEN_LIGHTMAP,
- public GLCompileMacro_USE_DEPTH_FADE
+ public GLCompileMacro_USE_DEPTH_FADE,
+ public GLCompileMacro_USE_SHADER_LIGHTS
{
public:
GLShader_generic( GLShaderManager *manager );
@@ -2284,10 +2348,13 @@ class GLShader_lightMapping :
public u_ModelMatrix,
public u_ModelViewProjectionMatrix,
public u_DepthScale,
+ public u_numLights,
+ public u_Lights,
public GLDeformStage,
public GLCompileMacro_USE_NORMAL_MAPPING,
public GLCompileMacro_USE_PARALLAX_MAPPING,
- public GLCompileMacro_USE_GLOW_MAPPING
+ public GLCompileMacro_USE_GLOW_MAPPING,
+ public GLCompileMacro_USE_SHADER_LIGHTS
{
public:
GLShader_lightMapping( GLShaderManager *manager );
@@ -2314,13 +2381,16 @@ class GLShader_vertexLighting_DBS_entity :
public u_EnvironmentInterpolation,
public u_LightGridOrigin,
public u_LightGridScale,
+ public u_numLights,
+ public u_Lights,
public GLDeformStage,
public GLCompileMacro_USE_VERTEX_SKINNING,
public GLCompileMacro_USE_VERTEX_ANIMATION,
public GLCompileMacro_USE_NORMAL_MAPPING,
public GLCompileMacro_USE_PARALLAX_MAPPING,
public GLCompileMacro_USE_REFLECTIVE_SPECULAR,
- public GLCompileMacro_USE_GLOW_MAPPING
+ public GLCompileMacro_USE_GLOW_MAPPING,
+ public GLCompileMacro_USE_SHADER_LIGHTS
{
public:
GLShader_vertexLighting_DBS_entity( GLShaderManager *manager );
@@ -2347,10 +2417,13 @@ class GLShader_vertexLighting_DBS_world :
public u_LightWrapAround,
public u_LightGridOrigin,
public u_LightGridScale,
+ public u_numLights,
+ public u_Lights,
public GLDeformStage,
public GLCompileMacro_USE_NORMAL_MAPPING,
public GLCompileMacro_USE_PARALLAX_MAPPING,
- public GLCompileMacro_USE_GLOW_MAPPING
+ public GLCompileMacro_USE_GLOW_MAPPING,
+ public GLCompileMacro_USE_SHADER_LIGHTS
{
public:
GLShader_vertexLighting_DBS_world( GLShaderManager *manager );
@@ -2751,6 +2824,35 @@ class GLShader_ssao :
void SetShaderProgramUniforms( shaderProgram_t *shaderProgram );
};
+class GLShader_depthtile1 :
+ public GLShader,
+ public u_zFar
+{
+public:
+ GLShader_depthtile1( GLShaderManager *manager );
+ void SetShaderProgramUniforms( shaderProgram_t *shaderProgram );
+};
+
+class GLShader_depthtile2 :
+ public GLShader
+{
+public:
+ GLShader_depthtile2( GLShaderManager *manager );
+ void SetShaderProgramUniforms( shaderProgram_t *shaderProgram );
+};
+
+class GLShader_lighttile :
+ public GLShader,
+ public u_ModelMatrix,
+ public u_numLights,
+ public u_lightLayer,
+ public u_Lights
+{
+public:
+ GLShader_lighttile( GLShaderManager *manager );
+ void SetShaderProgramUniforms( shaderProgram_t *shaderProgram );
+};
+
class GLShader_fxaa :
public GLShader
{
@@ -2790,6 +2892,9 @@ extern GLShader_liquid *gl_liquidShader;
extern GLShader_volumetricFog *gl_volumetricFogShader;
extern GLShader_motionblur *gl_motionblurShader;
extern GLShader_ssao *gl_ssaoShader;
+extern GLShader_depthtile1 *gl_depthtile1Shader;
+extern GLShader_depthtile2 *gl_depthtile2Shader;
+extern GLShader_lighttile *gl_lighttileShader;
extern GLShader_fxaa *gl_fxaaShader;
extern GLShaderManager gl_shaderManager;
Oops, something went wrong.

0 comments on commit 827daf8

Please sign in to comment.