Permalink
Browse files

Add support for loading specular maps. Not supported in shader yet. T…

…he SPECULARMAP

directive must be added after the NORMALMAP directive in the PIE file.
  • Loading branch information...
1 parent 823cf08 commit 45d2737e3cc854866329cc3d1ac0432c5460a635 @perim perim committed Sep 1, 2013
@@ -7,9 +7,11 @@ varying vec3 normal, lightDir, eyeVec;
uniform sampler2D Texture0; // diffuse
uniform sampler2D Texture1; // tcmask
uniform sampler2D Texture2; // normal map
+uniform sampler2D Texture3; // specular map
uniform vec4 teamcolour; // the team colour of the model
uniform int tcmask; // whether a tcmask texture exists for the model
uniform int normalmap; // whether a normal map exists for the model
+uniform int specularmap; // whether a specular map exists for the model
uniform int fogEnabled; // whether fog is enabled
uniform bool ecmEffect; // whether ECM special effect is enabled
uniform float graphicsCycle; // a periodically cycling value for special effects
View
@@ -37,6 +37,7 @@ iIMDShape::iIMDShape()
texpage = iV_TEX_INVALID;
tcmaskpage = iV_TEX_INVALID;
normalpage = iV_TEX_INVALID;
+ specularpage = iV_TEX_INVALID;
numFrames = 0;
}
@@ -663,7 +663,7 @@ iIMDShape *iV_ProcessIMD( const char **ppFileData, const char *FileDataEnd )
{
const char *pFileName = GetLastResourceFilename(); // Last loaded filename
const char *pFileData = *ppFileData;
- char buffer[PATH_MAX], texfile[PATH_MAX], normalfile[PATH_MAX];
+ char buffer[PATH_MAX], texfile[PATH_MAX], normalfile[PATH_MAX], specfile[PATH_MAX];
int cnt, nlevels;
iIMDShape *shape, *psShape;
UDWORD level;
@@ -672,6 +672,7 @@ iIMDShape *iV_ProcessIMD( const char **ppFileData, const char *FileDataEnd )
bool bTextured = false;
memset(normalfile, 0, sizeof(normalfile));
+ memset(specfile, 0, sizeof(specfile));
if (sscanf(pFileData, "%255s %d%n", buffer, &imd_version, &cnt) != 2)
{
@@ -789,7 +790,46 @@ iIMDShape *iV_ProcessIMD( const char **ppFileData, const char *FileDataEnd )
}
sstrcat(normalfile, ".png");
- /* -Now- read in LEVELS directive */
+ /* Now read in LEVELS directive */
+ if (sscanf(pFileData, "%255s %d%n", buffer, &nlevels, &cnt) != 2)
+ {
+ debug(LOG_ERROR, "iV_ProcessIMD %s bad levels info: %s", pFileName, buffer);
+ return NULL;
+ }
+ pFileData += cnt;
+ }
+
+ if (strncmp(buffer, "SPECULARMAP", 11) == 0)
+ {
+ char ch, texType[PATH_MAX];
+ int i;
+
+ /* the first parameter for textures is always ignored; which is why we ignore
+ * nlevels read in above */
+ ch = *pFileData++;
+
+ // Run up to the dot or till the buffer is filled. Leave room for the extension.
+ for (i = 0; i < PATH_MAX-5 && (ch = *pFileData++) != '\0' && ch != '.'; ++i)
+ {
+ specfile[i] = ch;
+ }
+ specfile[i] = '\0';
+
+ if (sscanf(pFileData, "%255s%n", texType, &cnt) != 1)
+ {
+ debug(LOG_ERROR, "%s specular map info corrupt: %s", pFileName, buffer);
+ return NULL;
+ }
+ pFileData += cnt;
+
+ if (strcmp(texType, "png") != 0)
+ {
+ debug(LOG_ERROR, "%s: only png specular maps supported", pFileName);
+ return NULL;
+ }
+ sstrcat(specfile, ".png");
+
+ /* Try -again- to read in LEVELS directive */
if (sscanf(pFileData, "%255s %d%n", buffer, &nlevels, &cnt) != 2)
{
debug(LOG_ERROR, "iV_ProcessIMD %s bad levels info: %s", pFileName, buffer);
@@ -830,20 +870,30 @@ iIMDShape *iV_ProcessIMD( const char **ppFileData, const char *FileDataEnd )
{
int texpage = iV_GetTexture(texfile);
int normalpage = iV_TEX_INVALID;
+ int specpage = iV_TEX_INVALID;
+
+ ASSERT_OR_RETURN(NULL, texpage >= 0, "%s could not load tex page %s", pFileName, texfile);
if (normalfile[0] != '\0')
{
- debug(LOG_WARNING, "Loading normal map %s for %s", normalfile, pFileName);
+ debug(LOG_TEXTURE, "Loading normal map %s for %s", normalfile, pFileName);
normalpage = iV_GetTexture(normalfile);
+ ASSERT_OR_RETURN(NULL, normalpage >= 0, "%s could not load tex page %s", pFileName, normalfile);
}
- ASSERT_OR_RETURN(NULL, texpage >= 0, "%s could not load tex page %s", pFileName, texfile);
+ if (specfile[0] != '\0')
+ {
+ debug(LOG_TEXTURE, "Loading specular map %s for %s", specfile, pFileName);
+ specpage = iV_GetTexture(specfile);
+ ASSERT_OR_RETURN(NULL, specpage >= 0, "%s could not load tex page %s", pFileName, specfile);
+ }
// assign tex pages and flags to all levels
for (psShape = shape; psShape != NULL; psShape = psShape->next)
{
psShape->texpage = texpage;
psShape->normalpage = normalpage;
+ psShape->specularpage = specpage;
psShape->flags = imd_flags;
}
@@ -98,6 +98,7 @@ struct iIMDShape
int texpage;
int tcmaskpage;
int normalpage;
+ int specularpage;
int sradius, radius;
Vector3i min, max;
@@ -38,7 +38,7 @@
static GLuint shaderProgram[SHADER_MAX];
static GLfloat shaderStretch = 0;
-static GLint locTeam, locStretch, locTCMask, locFog, locNormalMap, locEcm, locTime;
+static GLint locTeam, locStretch, locTCMask, locFog, locNormalMap, locSpecularMap, locEcm, locTime;
static SHADER_MODE currentShaderMode = SHADER_NONE;
unsigned int pieStateCount = 0; // Used in pie_GetResetCounts
static RENDER_STATE rendStates;
@@ -333,20 +333,23 @@ void pie_ActivateShader(SHADER_MODE shaderMode, iIMDShape* shape, PIELIGHT teamc
{
int maskpage = shape->tcmaskpage;
int normalpage = shape->normalpage;
+ int specularpage = shape->specularpage;
GLfloat colour4f[4];
if (shaderMode != currentShaderMode)
{
- GLint locTex0, locTex1, locTex2;
+ GLint locTex0, locTex1, locTex2, locTex3;
glUseProgram(shaderProgram[shaderMode]);
locTex0 = glGetUniformLocation(shaderProgram[shaderMode], "Texture0");
locTex1 = glGetUniformLocation(shaderProgram[shaderMode], "Texture1");
locTex2 = glGetUniformLocation(shaderProgram[shaderMode], "Texture2");
+ locTex3 = glGetUniformLocation(shaderProgram[shaderMode], "Texture3");
locTeam = glGetUniformLocation(shaderProgram[shaderMode], "teamcolour");
locStretch = glGetUniformLocation(shaderProgram[shaderMode], "stretch");
locTCMask = glGetUniformLocation(shaderProgram[shaderMode], "tcmask");
locNormalMap = glGetUniformLocation(shaderProgram[shaderMode], "normalmap");
+ locSpecularMap = glGetUniformLocation(shaderProgram[shaderMode], "specularmap");
locFog = glGetUniformLocation(shaderProgram[shaderMode], "fogEnabled");
locEcm = glGetUniformLocation(shaderProgram[shaderMode], "ecmEffect");
locTime = glGetUniformLocation(shaderProgram[shaderMode], "graphicsCycle");
@@ -355,6 +358,7 @@ void pie_ActivateShader(SHADER_MODE shaderMode, iIMDShape* shape, PIELIGHT teamc
glUniform1i(locTex0, 0);
glUniform1i(locTex1, 1);
glUniform1i(locTex2, 2);
+ glUniform1i(locTex3, 3);
// These do not change during our drawing pass
glUniform1i(locFog, rendStates.fog);
@@ -377,6 +381,10 @@ void pie_ActivateShader(SHADER_MODE shaderMode, iIMDShape* shape, PIELIGHT teamc
{
glUniform1i(locNormalMap, normalpage != iV_TEX_INVALID);
}
+ if (locSpecularMap >= 0)
+ {
+ glUniform1i(locSpecularMap, specularpage != iV_TEX_INVALID);
+ }
if (locEcm >= 0)
{
glUniform1i(locEcm, ecmState);
@@ -392,6 +400,11 @@ void pie_ActivateShader(SHADER_MODE shaderMode, iIMDShape* shape, PIELIGHT teamc
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, pie_Texture(normalpage));
}
+ if (specularpage != iV_TEX_INVALID)
+ {
+ glActiveTexture(GL_TEXTURE3);
+ glBindTexture(GL_TEXTURE_2D, pie_Texture(specularpage));
+ }
glActiveTexture(GL_TEXTURE0);
#ifdef _DEBUG

0 comments on commit 45d2737

Please sign in to comment.