1
0
forked from 0ad/0ad

Modified sky, minimap and healthbar renderers to use shaders, to fix a bug reported by historic_bruno

This was SVN commit r12551.
This commit is contained in:
myconid 2012-08-29 23:07:53 +00:00
parent fcf09598d9
commit 38c1a4c4a1
25 changed files with 451 additions and 20 deletions

View File

@ -0,0 +1,5 @@
!!ARBfp1.0
TEX result.color, fragment.texcoord[0], texture[0], 2D;
END

View File

@ -0,0 +1,13 @@
!!ARBvp1.0
ATTRIB position = vertex.position;
ATTRIB uv = vertex.texcoord[0];
DP4 result.position.x, state.matrix.mvp.row[0], position;
DP4 result.position.y, state.matrix.mvp.row[1], position;
DP4 result.position.z, state.matrix.mvp.row[2], position;
DP4 result.position.w, state.matrix.mvp.row[3], position;
MOV result.texcoord, uv;
END

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<program type="arb">
<vertex file="arb/foreground_overlay.vp">
<stream name="pos"/>
<stream name="uv0"/>
</vertex>
<fragment file="arb/foreground_overlay.fp">
<uniform name="baseTex" loc="0" type="sampler2D"/>
</fragment>
</program>

View File

@ -0,0 +1,33 @@
!!ARBfp1.0
#if MINIMAP_BASE
TEX result.color, fragment.texcoord[0], texture[0], 2D;
#endif
#if MINIMAP_LOS
TEMP tex;
TEMP temp;
TEX tex, fragment.texcoord[0], texture[0], 2D;
MOV temp.x, 1.0;
SUB temp.y, temp.x, tex.a;
MOV result.color.r, 0.0;
MOV result.color.g, 0.0;
MOV result.color.b, 0.0;
MOV result.color.a, temp.y;
#endif
#if MINIMAP_POINT
MOV result.color, fragment.color;
MOV result.color.w, 1.0;
#endif
#if MINIMAP_LINE
MOV result.color.r, 1.0;
MOV result.color.g, 0.3;
MOV result.color.b, 0.3;
MOV result.color.w, 1.0;
#endif
END

View File

@ -0,0 +1,29 @@
!!ARBvp1.0
TEMP position;
MOV position, vertex.position;
#if MINIMAP_POINT || MINIMAP_LINE
MOV position.z, 0.0;
#endif
MOV position.w, 1.0;
DP4 result.position.x, state.matrix.mvp.row[0], position;
DP4 result.position.y, state.matrix.mvp.row[1], position;
DP4 result.position.z, state.matrix.mvp.row[2], position;
DP4 result.position.w, state.matrix.mvp.row[3], position;
#if MINIMAP_BASE || MINIMAP_LOS
TEMP tex;
MOV tex, vertex.texcoord;
DP4 result.texcoord.x, state.matrix.texture[0].row[0], tex;
DP4 result.texcoord.y, state.matrix.texture[0].row[1], tex;
DP4 result.texcoord.z, state.matrix.texture[0].row[2], tex;
DP4 result.texcoord.w, state.matrix.texture[0].row[3], tex;
#endif
#if MINIMAP_POINT
MOV result.color, vertex.color;
#endif
END

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<program type="arb">
<vertex file="arb/minimap.vp">
<stream name="pos"/>
<stream name="color" if="MINIMAP_POINT"/>
</vertex>
<fragment file="arb/minimap.fp">
<uniform name="baseTex" loc="0" type="sampler2D" if="MINIMAP_BASE || MINIMAP_LOS"/>
</fragment>
</program>

View File

@ -0,0 +1,5 @@
!!ARBfp1.0
TEX result.color, fragment.texcoord[0], texture[0], 2D;
END

View File

@ -0,0 +1,13 @@
!!ARBvp1.0
ATTRIB position = vertex.position;
ATTRIB uv = vertex.texcoord[0];
DP4 result.position.x, state.matrix.mvp.row[0], position;
DP4 result.position.y, state.matrix.mvp.row[1], position;
DP4 result.position.z, state.matrix.mvp.row[2], position;
DP4 result.position.w, state.matrix.mvp.row[3], position;
MOV result.texcoord, uv;
END

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<program type="arb">
<vertex file="arb/sky.vp">
<stream name="pos"/>
</vertex>
<fragment file="arb/sky.fp">
<uniform name="baseTex" loc="0" type="sampler2D"/>
</fragment>
</program>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<effect>
<technique>
<require shaders="arb"/>
<pass shader="arb/foreground_overlay"/>
</technique>
<technique>
<require shaders="glsl"/>
<pass shader="glsl/foreground_overlay"/>
</technique>
</effect>

View File

@ -3,7 +3,9 @@
<technique>
<require shaders="glsl"/>
<pass shader="glsl/los_interp"/>
<pass shader="glsl/los_interp">
<blend src="src_alpha" dst="one_minus_src_alpha"/>
</pass>
</technique>
</effect>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<effect>
<technique>
<require shaders="arb"/>
<pass shader="arb/minimap"/>
</technique>
<technique>
<require shaders="glsl"/>
<pass shader="glsl/minimap"/>
</technique>
</effect>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<effect>
<technique>
<require shaders="arb"/>
<pass shader="arb/sky"/>
</technique>
<technique>
<require shaders="glsl"/>
<pass shader="glsl/sky"/>
</technique>
</effect>

View File

@ -0,0 +1,9 @@
#version 110
uniform sampler2D baseTex;
varying vec2 v_tex;
void main()
{
gl_FragColor = texture2D(baseTex, v_tex);
}

View File

@ -0,0 +1,11 @@
#version 110
varying vec2 v_tex;
attribute vec3 a_vertex;
attribute vec2 a_uv0;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(a_vertex, 1.0);
v_tex = a_uv0;
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<program type="glsl">
<vertex file="glsl/foreground_overlay.vs">
<stream name="pos"/>
<stream name="uv0"/>
<attrib name="a_vertex" semantics="gl_Vertex"/>
<attrib name="a_uv0" semantics="gl_MultiTexCoord0"/>
</vertex>
<fragment file="glsl/foreground_overlay.fs"/>
</program>

View File

@ -0,0 +1,29 @@
#version 110
#if MINIMAP_BASE || MINIMAP_LOS
uniform sampler2D baseTex;
varying vec2 v_tex;
#endif
#if MINIMAP_POINT
varying vec3 color;
#endif
void main()
{
#if MINIMAP_BASE
gl_FragColor = texture2D(baseTex, v_tex);
#endif
#if MINIMAP_LOS
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0 - texture2D(baseTex, v_tex).a);
#endif
#if MINIMAP_POINT
gl_FragColor = vec4(color, 1.0);
#endif
#if MINIMAP_LINE
gl_FragColor = vec4(1.0, 0.3, 0.3, 1.0);
#endif
}

View File

@ -0,0 +1,33 @@
#version 110
#if MINIMAP_BASE || MINIMAP_LOS
attribute vec3 a_vertex;
varying vec2 v_tex;
#endif
#if MINIMAP_POINT
attribute vec2 a_vertex;
attribute vec3 a_color;
varying vec3 color;
#endif
#if MINIMAP_LINE
attribute vec2 a_vertex;
#endif
void main()
{
#if MINIMAP_BASE || MINIMAP_LOS
gl_Position = gl_ModelViewProjectionMatrix * vec4(a_vertex, 1.0);
v_tex = gl_TextureMatrix[0] * gl_MultiTexCoord0;
#endif
#if MINIMAP_POINT
gl_Position = gl_ModelViewProjectionMatrix * vec4(a_vertex, 0.0, 1.0);
color = a_color;
#endif
#if MINIMAP_LINE
gl_Position = gl_ModelViewProjectionMatrix * vec4(a_vertex, 0.0, 1.0);
#endif
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<program type="glsl">
<vertex file="glsl/minimap.vs">
<stream name="pos"/>
<stream name="color" if="MINIMAP_POINT"/>
<attrib name="a_vertex" semantics="gl_Vertex"/>
<attrib name="a_color" semantics="gl_Color" if="MINIMAP_POINT"/>
</vertex>
<fragment file="glsl/minimap.fs"/>
</program>

View File

@ -0,0 +1,9 @@
#version 110
uniform sampler2D baseTex;
varying vec2 v_tex;
void main()
{
gl_FragColor = texture2D(baseTex, v_tex);
}

View File

@ -0,0 +1,11 @@
#version 110
varying vec2 v_tex;
attribute vec3 a_vertex;
attribute vec2 a_uv0;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(a_vertex, 1.0);
v_tex = gl_MultiTexCoord0;
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<program type="glsl">
<vertex file="glsl/sky.vs">
<stream name="pos"/>
<attrib name="a_vertex" semantics="gl_Vertex"/>
</vertex>
<fragment file="glsl/sky.fs"/>
</program>

View File

@ -326,6 +326,23 @@ void CMiniMap::Draw()
// Disable depth updates to prevent apparent z-fighting-related issues
// with some drivers causing units to get drawn behind the texture
glDepthMask(0);
CShaderProgramPtr shader;
CShaderTechniquePtr tech;
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
CShaderDefines defines;
defines.Add("MINIMAP_BASE", "1");
tech = g_Renderer.GetShaderManager().LoadEffect(CStrIntern("minimap"), g_Renderer.GetSystemShaderDefines(), defines);
tech->BeginPass();
shader = tech->GetShader();
}
else
{
shader = g_Renderer.GetShaderManager().LoadProgram("fixed:dummy", CShaderDefines());
shader->Bind();
}
const float x = m_CachedActualSize.left, y = m_CachedActualSize.bottom;
const float x2 = m_CachedActualSize.right, y2 = m_CachedActualSize.top;
@ -334,7 +351,10 @@ void CMiniMap::Draw()
const float angle = GetAngle();
// Draw the main textured quad
g_Renderer.BindTexture(0, m_TerrainTexture);
//g_Renderer.BindTexture(0, m_TerrainTexture);
shader->BindTexture("baseTex", m_TerrainTexture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@ -343,7 +363,10 @@ void CMiniMap::Draw()
// Draw territory boundaries
CTerritoryTexture& territoryTexture = g_Game->GetView()->GetTerritoryTexture();
territoryTexture.BindTexture(0);
shader->BindTexture("baseTex", territoryTexture.GetTexture());
//territoryTexture.BindTexture(0);
glEnable(GL_BLEND);
glMatrixMode(GL_TEXTURE);
glLoadMatrixf(territoryTexture.GetMinimapTextureMatrix());
@ -359,7 +382,21 @@ void CMiniMap::Draw()
// Draw the LOS quad in black, using alpha values from the LOS texture
CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture();
losTexture.BindTexture(0);
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
tech->EndPass();
CShaderDefines defines;
defines.Add("MINIMAP_LOS", "1");
tech = g_Renderer.GetShaderManager().LoadEffect(CStrIntern("minimap"), g_Renderer.GetSystemShaderDefines(), defines);
tech->BeginPass();
shader = tech->GetShader();
}
shader->BindTexture("baseTex", losTexture.GetTexture());
//losTexture.BindTexture(0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PRIMARY_COLOR_ARB);
@ -382,7 +419,18 @@ void CMiniMap::Draw()
glMatrixMode(GL_MODELVIEW);
glDisable(GL_BLEND);
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
tech->EndPass();
CShaderDefines defines;
defines.Add("MINIMAP_POINT", "1");
tech = g_Renderer.GetShaderManager().LoadEffect(CStrIntern("minimap"), g_Renderer.GetSystemShaderDefines(), defines);
tech->BeginPass();
shader = tech->GetShader();
}
// Set up the matrix for drawing points and lines
glPushMatrix();
glTranslatef(x, y, z);
@ -430,8 +478,8 @@ void CMiniMap::Draw()
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(MinimapUnitVertex), &vertexArray[0].x);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(MinimapUnitVertex), &vertexArray[0].r);
shader->VertexPointer(2, GL_FLOAT, sizeof(MinimapUnitVertex), &vertexArray[0].x);
shader->ColorPointer(4, GL_UNSIGNED_BYTE, sizeof(MinimapUnitVertex), &vertexArray[0].r);
glDrawArrays(GL_POINTS, 0, (GLsizei)vertexArray.size());
@ -440,16 +488,35 @@ void CMiniMap::Draw()
}
PROFILE_END("minimap units");
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
tech->EndPass();
CShaderDefines defines;
defines.Add("MINIMAP_LINE", "1");
tech = g_Renderer.GetShaderManager().LoadEffect(CStrIntern("minimap"), g_Renderer.GetSystemShaderDefines(), defines);
tech->BeginPass();
shader = tech->GetShader();
}
DrawViewRect();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
tech->EndPass();
}
else
{
shader->Unbind();
}
// Reset everything back to normal
glPointSize(1.0f);

View File

@ -573,15 +573,29 @@ void OverlayRenderer::RenderForegroundOverlays(const CCamera& viewCamera)
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
CShaderProgramPtr shader;
CShaderTechniquePtr tech;
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
tech = g_Renderer.GetShaderManager().LoadEffect("foreground_overlay");
tech->BeginPass();
shader = tech->GetShader();
}
else
{
shader = g_Renderer.GetShaderManager().LoadProgram("fixed:dummy", CShaderDefines());
shader->Bind();
}
float uvs[8] = { 0,0, 1,0, 1,1, 0,1 };
glTexCoordPointer(2, GL_FLOAT, sizeof(float)*2, &uvs);
shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, sizeof(float)*2, &uvs[0]);
for (size_t i = 0; i < m->sprites.size(); ++i)
{
SOverlaySprite* sprite = m->sprites[i];
sprite->m_Texture->Bind();
shader->BindTexture("baseTex", sprite->m_Texture);
CVector3D pos[4] = {
sprite->m_Position + right*sprite->m_X0 + up*sprite->m_Y0,
@ -590,12 +604,21 @@ void OverlayRenderer::RenderForegroundOverlays(const CCamera& viewCamera)
sprite->m_Position + right*sprite->m_X0 + up*sprite->m_Y1
};
glVertexPointer(3, GL_FLOAT, sizeof(float)*3, &pos[0].X);
shader->VertexPointer(3, GL_FLOAT, sizeof(float)*3, &pos[0].X);
glDrawArrays(GL_QUADS, 0, (GLsizei)4);
g_Renderer.GetStats().m_DrawCalls++;
g_Renderer.GetStats().m_OverlayTris += 2;
}
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
tech->EndPass();
}
else
{
shader->Unbind();
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

View File

@ -39,6 +39,7 @@
#include "graphics/Camera.h"
#include "graphics/LightEnv.h"
#include "graphics/ShaderManager.h"
#include "graphics/TextureManager.h"
@ -140,9 +141,6 @@ void SkyManager::RenderSky()
glDepthMask( GL_FALSE );
pglActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@ -158,9 +156,24 @@ void SkyManager::RenderSky()
// Distance to draw the faces at
const float D = 2000.0;
CShaderProgramPtr shader;
CShaderTechniquePtr skytech;
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
skytech = g_Renderer.GetShaderManager().LoadEffect("sky_simple");
skytech->BeginPass();
shader = skytech->GetShader();
}
else
{
shader = g_Renderer.GetShaderManager().LoadProgram("fixed:dummy", CShaderDefines());
shader->Bind();
}
// Front face (positive Z)
m_SkyTexture[FRONT]->Bind();
shader->BindTexture("baseTex", m_SkyTexture[FRONT]);
glBegin( GL_QUADS );
glTexCoord2f( 0, 1 );
glVertex3f( -D, -D, +D );
@ -173,7 +186,7 @@ void SkyManager::RenderSky()
glEnd();
// Back face (negative Z)
m_SkyTexture[BACK]->Bind();
shader->BindTexture("baseTex", m_SkyTexture[BACK]);
glBegin( GL_QUADS );
glTexCoord2f( 1, 1 );
glVertex3f( -D, -D, -D );
@ -186,7 +199,7 @@ void SkyManager::RenderSky()
glEnd();
// Right face (negative X)
m_SkyTexture[RIGHT]->Bind();
shader->BindTexture("baseTex", m_SkyTexture[RIGHT]);
glBegin( GL_QUADS );
glTexCoord2f( 0, 1 );
glVertex3f( -D, -D, -D );
@ -199,7 +212,7 @@ void SkyManager::RenderSky()
glEnd();
// Left face (positive X)
m_SkyTexture[LEFT]->Bind();
shader->BindTexture("baseTex", m_SkyTexture[LEFT]);
glBegin( GL_QUADS );
glTexCoord2f( 1, 1 );
glVertex3f( +D, -D, -D );
@ -212,7 +225,7 @@ void SkyManager::RenderSky()
glEnd();
// Top face (positive Y)
m_SkyTexture[TOP]->Bind();
shader->BindTexture("baseTex", m_SkyTexture[TOP]);
glBegin( GL_QUADS );
glTexCoord2f( 1, 0 );
glVertex3f( +D, +D, -D );
@ -223,6 +236,15 @@ void SkyManager::RenderSky()
glTexCoord2f( 1, 1 );
glVertex3f( +D, +D, +D );
glEnd();
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
skytech->EndPass();
}
else
{
shader->Unbind();
}
glPopMatrix();