Implemented texture scale and offset material parameters
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4024
This commit is contained in:
@@ -58,6 +58,12 @@ KRMaterial::KRMaterial(const char *szName) : KRResource(szName) {
|
|||||||
m_diffuseMap = "";
|
m_diffuseMap = "";
|
||||||
m_specularMap = "";
|
m_specularMap = "";
|
||||||
m_normalMap = "";
|
m_normalMap = "";
|
||||||
|
m_ambientMapOffset = KRVector2(0.0f, 0.0f);
|
||||||
|
m_specularMapOffset = KRVector2(0.0f, 0.0f);
|
||||||
|
m_diffuseMapOffset = KRVector2(0.0f, 0.0f);
|
||||||
|
m_ambientMapScale = KRVector2(1.0f, 1.0f);
|
||||||
|
m_specularMapScale = KRVector2(1.0f, 1.0f);
|
||||||
|
m_diffuseMapScale = KRVector2(1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRMaterial::~KRMaterial() {
|
KRMaterial::~KRMaterial() {
|
||||||
@@ -80,36 +86,44 @@ bool KRMaterial::save(const std::string& path) {
|
|||||||
fprintf(f, "Tr %f\n", m_tr);
|
fprintf(f, "Tr %f\n", m_tr);
|
||||||
fprintf(f, "Ns %f\n", m_ns);
|
fprintf(f, "Ns %f\n", m_ns);
|
||||||
if(m_ambientMap.size()) {
|
if(m_ambientMap.size()) {
|
||||||
fprintf(f, "map_Ka %s.pvr\n", m_ambientMap.c_str());
|
fprintf(f, "map_Ka %s.pvr -s %f %f -o %f %f\n", m_ambientMap.c_str(), m_ambientMapScale.x, m_ambientMapScale.y, m_ambientMapOffset.x, m_ambientMapOffset.y);
|
||||||
}
|
}
|
||||||
if(m_diffuseMap.size()) {
|
if(m_diffuseMap.size()) {
|
||||||
fprintf(f, "map_Kd %s.pvr\n", m_diffuseMap.c_str());
|
fprintf(f, "map_Kd %s.pvr -s %f %f -o %f %f\n", m_diffuseMap.c_str(), m_diffuseMapScale.x, m_diffuseMapScale.y, m_diffuseMapOffset.x, m_diffuseMapOffset.y);
|
||||||
}
|
}
|
||||||
if(m_specularMap.size()) {
|
if(m_specularMap.size()) {
|
||||||
fprintf(f, "map_Ks %s.pvr\n", m_specularMap.c_str());
|
fprintf(f, "map_Ks %s.pvr -s %f %f -o %f %f\n", m_specularMap.c_str(), m_specularMapScale.x, m_specularMapScale.y, m_specularMapOffset.x, m_specularMapOffset.y);
|
||||||
}
|
}
|
||||||
if(m_normalMap.size()) {
|
if(m_normalMap.size()) {
|
||||||
fprintf(f, "map_Normal %s.pvr\n", m_normalMap.c_str());
|
fprintf(f, "map_Normal %s.pvr -s %f %f -o %f %f\n", m_normalMap.c_str(), m_normalMapScale.x, m_normalMapScale.y, m_normalMapOffset.x, m_normalMapOffset.y);
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRMaterial::setAmbientMap(std::string texture_name) {
|
void KRMaterial::setAmbientMap(std::string texture_name, KRVector2 texture_scale, KRVector2 texture_offset) {
|
||||||
m_ambientMap = texture_name;
|
m_ambientMap = texture_name;
|
||||||
|
m_ambientMapScale = texture_scale;
|
||||||
|
m_ambientMapOffset = texture_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRMaterial::setDiffuseMap(std::string texture_name) {
|
void KRMaterial::setDiffuseMap(std::string texture_name, KRVector2 texture_scale, KRVector2 texture_offset) {
|
||||||
m_diffuseMap = texture_name;
|
m_diffuseMap = texture_name;
|
||||||
|
m_diffuseMapScale = texture_scale;
|
||||||
|
m_diffuseMapOffset = texture_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRMaterial::setSpecularMap(std::string texture_name) {
|
void KRMaterial::setSpecularMap(std::string texture_name, KRVector2 texture_scale, KRVector2 texture_offset) {
|
||||||
m_specularMap = texture_name;
|
m_specularMap = texture_name;
|
||||||
|
m_specularMapScale = texture_scale;
|
||||||
|
m_specularMapOffset = texture_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRMaterial::setNormalMap(std::string texture_name) {
|
void KRMaterial::setNormalMap(std::string texture_name, KRVector2 texture_scale, KRVector2 texture_offset) {
|
||||||
m_normalMap = texture_name;
|
m_normalMap = texture_name;
|
||||||
|
m_normalMapScale = texture_scale;
|
||||||
|
m_normalMapOffset = texture_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRMaterial::setAmbient(GLfloat r, GLfloat g, GLfloat b) {
|
void KRMaterial::setAmbient(GLfloat r, GLfloat g, GLfloat b) {
|
||||||
@@ -159,12 +173,19 @@ void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
|||||||
m_pSpecularMap = pTextureManager->getTexture(m_specularMap.c_str());
|
m_pSpecularMap = pTextureManager->getTexture(m_specularMap.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->bEnableDiffuseMap;
|
|
||||||
bool bNormalMap = m_pNormalMap != NULL && pCamera->bEnableNormalMap;
|
|
||||||
bool bSpecMap = m_pSpecularMap != NULL && pCamera->bEnableSpecMap;
|
|
||||||
|
|
||||||
if(!bSameMaterial) {
|
if(!bSameMaterial) {
|
||||||
KRShader *pShader = pShaderManager->getShader(pCamera, bDiffuseMap, bNormalMap, bSpecMap, cShadowBuffers, bShadowMap);
|
KRVector2 default_scale = KRVector2(1.0f, 1.0f);
|
||||||
|
KRVector2 default_offset = KRVector2(0.0f, 0.0f);
|
||||||
|
|
||||||
|
bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->bEnableDiffuseMap;
|
||||||
|
bool bNormalMap = m_pNormalMap != NULL && pCamera->bEnableNormalMap;
|
||||||
|
bool bSpecMap = m_pSpecularMap != NULL && pCamera->bEnableSpecMap;
|
||||||
|
|
||||||
|
KRShader *pShader = pShaderManager->getShader(pCamera, bDiffuseMap, bNormalMap, bSpecMap, cShadowBuffers, bShadowMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_normalMapScale != default_scale && bNormalMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_normalMapOffset != default_offset && bNormalMap);
|
||||||
|
|
||||||
bool bSameShader = strcmp(pShader->getKey(), szPrevShaderKey) == 0;
|
bool bSameShader = strcmp(pShader->getKey(), szPrevShaderKey) == 0;
|
||||||
if(!bSameShader) {
|
if(!bSameShader) {
|
||||||
@@ -176,11 +197,27 @@ void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
|||||||
bool bSameAmbient = false;
|
bool bSameAmbient = false;
|
||||||
bool bSameDiffuse = false;
|
bool bSameDiffuse = false;
|
||||||
bool bSameSpecular = false;
|
bool bSameSpecular = false;
|
||||||
|
bool bSameAmbientScale = false;
|
||||||
|
bool bSameDiffuseScale = false;
|
||||||
|
bool bSameSpecularScale = false;
|
||||||
|
bool bSameNormalScale = false;
|
||||||
|
bool bSameAmbientOffset = false;
|
||||||
|
bool bSameDiffuseOffset = false;
|
||||||
|
bool bSameSpecularOffset = false;
|
||||||
|
bool bSameNormalOffset = false;
|
||||||
|
|
||||||
if(*prevBoundMaterial && bSameShader) {
|
if(*prevBoundMaterial && bSameShader) {
|
||||||
bSameAmbient = (*prevBoundMaterial)->m_ka_r == m_ka_r && (*prevBoundMaterial)->m_ka_g == m_ka_g && (*prevBoundMaterial)->m_ka_b == m_ka_b;
|
bSameAmbient = (*prevBoundMaterial)->m_ka_r == m_ka_r && (*prevBoundMaterial)->m_ka_g == m_ka_g && (*prevBoundMaterial)->m_ka_b == m_ka_b;
|
||||||
bSameDiffuse = (*prevBoundMaterial)->m_kd_r == m_kd_r && (*prevBoundMaterial)->m_kd_g == m_kd_g && (*prevBoundMaterial)->m_kd_b == m_kd_b;
|
bSameDiffuse = (*prevBoundMaterial)->m_kd_r == m_kd_r && (*prevBoundMaterial)->m_kd_g == m_kd_g && (*prevBoundMaterial)->m_kd_b == m_kd_b;
|
||||||
bSameSpecular = (*prevBoundMaterial)->m_ks_r == m_ks_r && (*prevBoundMaterial)->m_ks_g == m_ks_g && (*prevBoundMaterial)->m_ks_b == m_ks_b;
|
bSameSpecular = (*prevBoundMaterial)->m_ks_r == m_ks_r && (*prevBoundMaterial)->m_ks_g == m_ks_g && (*prevBoundMaterial)->m_ks_b == m_ks_b;
|
||||||
|
bSameAmbientScale = (*prevBoundMaterial)->m_ambientMapScale == m_ambientMapScale;
|
||||||
|
bSameDiffuseScale = (*prevBoundMaterial)->m_diffuseMapScale == m_diffuseMapScale;
|
||||||
|
bSameSpecularScale = (*prevBoundMaterial)->m_specularMapScale == m_specularMapScale;
|
||||||
|
bSameNormalScale = (*prevBoundMaterial)->m_normalMapScale == m_normalMapScale;
|
||||||
|
bSameAmbientOffset = (*prevBoundMaterial)->m_ambientMapOffset == m_ambientMapOffset;
|
||||||
|
bSameDiffuseOffset = (*prevBoundMaterial)->m_diffuseMapOffset == m_diffuseMapOffset;
|
||||||
|
bSameSpecularOffset = (*prevBoundMaterial)->m_specularMapOffset == m_specularMapOffset;
|
||||||
|
bSameNormalOffset = (*prevBoundMaterial)->m_normalMapOffset == m_normalMapOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!bSameAmbient) {
|
if(!bSameAmbient) {
|
||||||
@@ -210,6 +247,54 @@ void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(bDiffuseMap && !bSameDiffuseScale && m_diffuseMapScale != default_scale) {
|
||||||
|
glUniform2f(
|
||||||
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE],
|
||||||
|
m_diffuseMapScale.x,
|
||||||
|
m_diffuseMapScale.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bSpecMap && !bSameSpecularScale && m_specularMapScale != default_scale) {
|
||||||
|
glUniform2f(
|
||||||
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SPECULARTEXTURE_SCALE],
|
||||||
|
m_specularMapScale.x,
|
||||||
|
m_specularMapScale.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bNormalMap && !bSameNormalScale && m_normalMapScale != default_scale) {
|
||||||
|
glUniform2f(
|
||||||
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_NORMALTEXTURE_SCALE],
|
||||||
|
m_normalMapScale.x,
|
||||||
|
m_normalMapScale.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bDiffuseMap && !bSameDiffuseOffset && m_diffuseMapOffset != default_offset) {
|
||||||
|
glUniform2f(
|
||||||
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_DIFFUSETEXTURE_OFFSET],
|
||||||
|
m_diffuseMapOffset.x,
|
||||||
|
m_diffuseMapOffset.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bSpecMap && !bSameSpecularOffset && m_specularMapOffset != default_offset) {
|
||||||
|
glUniform2f(
|
||||||
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SPECULARTEXTURE_OFFSET],
|
||||||
|
m_specularMapOffset.x,
|
||||||
|
m_specularMapOffset.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bNormalMap && !bSameNormalOffset && m_normalMapOffset != default_offset) {
|
||||||
|
glUniform2f(
|
||||||
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_NORMALTEXTURE_OFFSET],
|
||||||
|
m_normalMapOffset.x,
|
||||||
|
m_normalMapOffset.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], 1.0f - m_tr);
|
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], 1.0f - m_tr);
|
||||||
|
|
||||||
bool bSameDiffuseMap = false;
|
bool bSameDiffuseMap = false;
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ using std::list;
|
|||||||
#import "KRShader.h"
|
#import "KRShader.h"
|
||||||
#import "KRCamera.h"
|
#import "KRCamera.h"
|
||||||
#import "KRResource.h"
|
#import "KRResource.h"
|
||||||
|
#import "KRVector2.h"
|
||||||
|
|
||||||
class KRTextureManager;
|
class KRTextureManager;
|
||||||
|
|
||||||
@@ -57,10 +58,10 @@ public:
|
|||||||
virtual bool save(const std::string& path);
|
virtual bool save(const std::string& path);
|
||||||
|
|
||||||
|
|
||||||
void setAmbientMap(std::string texture_name);
|
void setAmbientMap(std::string texture_name, KRVector2 texture_scale, KRVector2 texture_offset);
|
||||||
void setDiffuseMap(std::string texture_name);
|
void setDiffuseMap(std::string texture_name, KRVector2 texture_scale, KRVector2 texture_offset);
|
||||||
void setSpecularMap(std::string texture_name);
|
void setSpecularMap(std::string texture_name, KRVector2 texture_scale, KRVector2 texture_offset);
|
||||||
void setNormalMap(std::string texture_name);
|
void setNormalMap(std::string texture_name, KRVector2 texture_scale, KRVector2 texture_offset);
|
||||||
void setAmbient(GLfloat r, GLfloat g, GLfloat b);
|
void setAmbient(GLfloat r, GLfloat g, GLfloat b);
|
||||||
void setDiffuse(GLfloat r, GLfloat g, GLfloat b);
|
void setDiffuse(GLfloat r, GLfloat g, GLfloat b);
|
||||||
void setSpecular(GLfloat r, GLfloat g, GLfloat b);
|
void setSpecular(GLfloat r, GLfloat g, GLfloat b);
|
||||||
@@ -88,6 +89,15 @@ private:
|
|||||||
std::string m_specularMap;
|
std::string m_specularMap;
|
||||||
std::string m_normalMap;
|
std::string m_normalMap;
|
||||||
|
|
||||||
|
KRVector2 m_ambientMapScale;
|
||||||
|
KRVector2 m_ambientMapOffset;
|
||||||
|
KRVector2 m_diffuseMapScale;
|
||||||
|
KRVector2 m_diffuseMapOffset;
|
||||||
|
KRVector2 m_specularMapScale;
|
||||||
|
KRVector2 m_specularMapOffset;
|
||||||
|
KRVector2 m_normalMapScale;
|
||||||
|
KRVector2 m_normalMapOffset;
|
||||||
|
|
||||||
GLfloat m_ka_r, m_ka_g, m_ka_b; // Ambient rgb
|
GLfloat m_ka_r, m_ka_g, m_ka_b; // Ambient rgb
|
||||||
GLfloat m_kd_r, m_kd_g, m_kd_b; // Diffuse rgb
|
GLfloat m_kd_r, m_kd_g, m_kd_b; // Diffuse rgb
|
||||||
GLfloat m_ks_r, m_ks_g, m_ks_b; // Specular rgb
|
GLfloat m_ks_r, m_ks_g, m_ks_b; // Specular rgb
|
||||||
|
|||||||
@@ -108,84 +108,120 @@ bool KRMaterialManager::loadFile(const char *szPath) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(szSymbol[0], "newmtl") == 0 && cSymbols >= 2) {
|
if(cSymbols > 0) {
|
||||||
|
|
||||||
pMaterial = new KRMaterial(szSymbol[1]);
|
if(strcmp(szSymbol[0], "newmtl") == 0 && cSymbols >= 2) {
|
||||||
m_materials[szSymbol[1]] = pMaterial;
|
|
||||||
} if(pMaterial != NULL) {
|
|
||||||
if(strcmp(szSymbol[0], "Ka") == 0) {
|
|
||||||
char *pScan2 = szSymbol[1];
|
|
||||||
double r = strtof(pScan2, &pScan2);
|
|
||||||
if(cSymbols == 2) {
|
|
||||||
pMaterial->setAmbient(r, r, r);
|
|
||||||
} else if(cSymbols == 4) {
|
|
||||||
pScan2 = szSymbol[2];
|
|
||||||
double g = strtof(pScan2, &pScan2);
|
|
||||||
pScan2 = szSymbol[3];
|
|
||||||
double b = strtof(pScan2, &pScan2);
|
|
||||||
pMaterial->setAmbient(r, g, b);
|
|
||||||
}
|
|
||||||
} else if(strcmp(szSymbol[0], "Kd") == 0) {
|
|
||||||
char *pScan2 = szSymbol[1];
|
|
||||||
double r = strtof(pScan2, &pScan2);
|
|
||||||
if(cSymbols == 2) {
|
|
||||||
pMaterial->setDiffuse(r, r, r);
|
|
||||||
} else if(cSymbols == 4) {
|
|
||||||
pScan2 = szSymbol[2];
|
|
||||||
double g = strtof(pScan2, &pScan2);
|
|
||||||
pScan2 = szSymbol[3];
|
|
||||||
double b = strtof(pScan2, &pScan2);
|
|
||||||
pMaterial->setDiffuse(r, g, b);
|
|
||||||
}
|
|
||||||
} else if(strcmp(szSymbol[0], "Ks") == 0) {
|
|
||||||
char *pScan2 = szSymbol[1];
|
|
||||||
double r = strtof(pScan2, &pScan2);
|
|
||||||
if(cSymbols == 2) {
|
|
||||||
pMaterial->setSpecular(r, r, r);
|
|
||||||
} else if(cSymbols == 4) {
|
|
||||||
pScan2 = szSymbol[2];
|
|
||||||
double g = strtof(pScan2, &pScan2);
|
|
||||||
pScan2 = szSymbol[3];
|
|
||||||
double b = strtof(pScan2, &pScan2);
|
|
||||||
pMaterial->setSpecular(r, g, b);
|
|
||||||
}
|
|
||||||
} else if(strcmp(szSymbol[0], "Tr") == 0) {
|
|
||||||
char *pScan2 = szSymbol[1];
|
|
||||||
double a = strtof(pScan2, &pScan2);
|
|
||||||
pMaterial->setTransparency(a);
|
|
||||||
} else if(strcmp(szSymbol[0], "Ns") == 0) {
|
|
||||||
char *pScan2 = szSymbol[1];
|
|
||||||
double a = strtof(pScan2, &pScan2);
|
|
||||||
pMaterial->setShininess(a);
|
|
||||||
} else if(strncmp(szSymbol[0], "map", 3) == 0) {
|
|
||||||
// Truncate file extension
|
|
||||||
char *pScan2 = szSymbol[1];
|
|
||||||
char *pLastPeriod = NULL;
|
|
||||||
while(*pScan2 != '\0') {
|
|
||||||
if(*pScan2 == '.') {
|
|
||||||
pLastPeriod = pScan2;
|
|
||||||
}
|
|
||||||
pScan2++;
|
|
||||||
}
|
|
||||||
if(pLastPeriod) {
|
|
||||||
*pLastPeriod = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
pMaterial = new KRMaterial(szSymbol[1]);
|
||||||
|
m_materials[szSymbol[1]] = pMaterial;
|
||||||
|
}
|
||||||
|
if(pMaterial != NULL) {
|
||||||
|
if(strcmp(szSymbol[0], "Ka") == 0) {
|
||||||
|
char *pScan2 = szSymbol[1];
|
||||||
|
double r = strtof(pScan2, &pScan2);
|
||||||
|
if(cSymbols == 2) {
|
||||||
|
pMaterial->setAmbient(r, r, r);
|
||||||
|
} else if(cSymbols == 4) {
|
||||||
|
pScan2 = szSymbol[2];
|
||||||
|
double g = strtof(pScan2, &pScan2);
|
||||||
|
pScan2 = szSymbol[3];
|
||||||
|
double b = strtof(pScan2, &pScan2);
|
||||||
|
pMaterial->setAmbient(r, g, b);
|
||||||
|
}
|
||||||
|
} else if(strcmp(szSymbol[0], "Kd") == 0) {
|
||||||
|
char *pScan2 = szSymbol[1];
|
||||||
|
double r = strtof(pScan2, &pScan2);
|
||||||
|
if(cSymbols == 2) {
|
||||||
|
pMaterial->setDiffuse(r, r, r);
|
||||||
|
} else if(cSymbols == 4) {
|
||||||
|
pScan2 = szSymbol[2];
|
||||||
|
double g = strtof(pScan2, &pScan2);
|
||||||
|
pScan2 = szSymbol[3];
|
||||||
|
double b = strtof(pScan2, &pScan2);
|
||||||
|
pMaterial->setDiffuse(r, g, b);
|
||||||
|
}
|
||||||
|
} else if(strcmp(szSymbol[0], "Ks") == 0) {
|
||||||
|
char *pScan2 = szSymbol[1];
|
||||||
|
double r = strtof(pScan2, &pScan2);
|
||||||
|
if(cSymbols == 2) {
|
||||||
|
pMaterial->setSpecular(r, r, r);
|
||||||
|
} else if(cSymbols == 4) {
|
||||||
|
pScan2 = szSymbol[2];
|
||||||
|
double g = strtof(pScan2, &pScan2);
|
||||||
|
pScan2 = szSymbol[3];
|
||||||
|
double b = strtof(pScan2, &pScan2);
|
||||||
|
pMaterial->setSpecular(r, g, b);
|
||||||
|
}
|
||||||
|
} else if(strcmp(szSymbol[0], "Tr") == 0) {
|
||||||
|
char *pScan2 = szSymbol[1];
|
||||||
|
double a = strtof(pScan2, &pScan2);
|
||||||
|
pMaterial->setTransparency(a);
|
||||||
|
} else if(strcmp(szSymbol[0], "Ns") == 0) {
|
||||||
|
char *pScan2 = szSymbol[1];
|
||||||
|
double a = strtof(pScan2, &pScan2);
|
||||||
|
pMaterial->setShininess(a);
|
||||||
|
} else if(strncmp(szSymbol[0], "map", 3) == 0) {
|
||||||
|
// Truncate file extension
|
||||||
|
char *pScan2 = szSymbol[1];
|
||||||
|
char *pLastPeriod = NULL;
|
||||||
|
while(*pScan2 != '\0') {
|
||||||
|
if(*pScan2 == '.') {
|
||||||
|
pLastPeriod = pScan2;
|
||||||
|
}
|
||||||
|
pScan2++;
|
||||||
|
}
|
||||||
|
if(pLastPeriod) {
|
||||||
|
*pLastPeriod = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
KRVector2 texture_scale = KRVector2(1.0f, 1.0f);
|
||||||
|
KRVector2 texture_offset = KRVector2(0.0f, 0.0f);
|
||||||
|
|
||||||
|
int iScanSymbol = 2;
|
||||||
|
int iScaleParam = -1;
|
||||||
|
int iOffsetParam = -1;
|
||||||
|
while(iScanSymbol < cSymbols) {
|
||||||
|
if(strcmp(szSymbol[iScanSymbol], "-s") == 0) {
|
||||||
|
// Scale
|
||||||
|
iScaleParam = 0;
|
||||||
|
iOffsetParam = -1;
|
||||||
|
} else if(strcmp(szSymbol[iScanSymbol], "-o") == 0) {
|
||||||
|
// Offset
|
||||||
|
iOffsetParam = 0;
|
||||||
|
iScaleParam = -1;
|
||||||
|
} else {
|
||||||
|
char *pScan3 = szSymbol[iScanSymbol];
|
||||||
|
double v = strtof(pScan3, &pScan3);
|
||||||
|
if(iScaleParam == 0) {
|
||||||
|
texture_scale.x = v;
|
||||||
|
iScaleParam++;
|
||||||
|
} else if(iScaleParam == 1) {
|
||||||
|
texture_scale.y = v;
|
||||||
|
iScaleParam++;
|
||||||
|
} else if(iOffsetParam == 0) {
|
||||||
|
texture_offset.x = v;
|
||||||
|
iOffsetParam++;
|
||||||
|
} else if(iOffsetParam == 1) {
|
||||||
|
texture_offset.y = v;
|
||||||
|
iOffsetParam++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iScanSymbol++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strcmp(szSymbol[0], "map_Ka") == 0) {
|
||||||
|
pMaterial->setAmbientMap(szSymbol[1], texture_scale, texture_offset);
|
||||||
|
} else if(strcmp(szSymbol[0], "map_Kd") == 0) {
|
||||||
|
pMaterial->setDiffuseMap(szSymbol[1], texture_scale, texture_offset);
|
||||||
|
} else if(strcmp(szSymbol[0], "map_Ks") == 0) {
|
||||||
|
pMaterial->setSpecularMap(szSymbol[1], texture_scale, texture_offset);
|
||||||
|
} else if(strcmp(szSymbol[0], "map_Normal") == 0) {
|
||||||
|
pMaterial->setNormalMap(szSymbol[1], texture_scale, texture_offset);
|
||||||
|
}
|
||||||
|
|
||||||
if(strcmp(szSymbol[0], "map_Ka") == 0) {
|
|
||||||
pMaterial->setAmbientMap(szSymbol[1]);
|
|
||||||
} else if(strcmp(szSymbol[0], "map_Kd") == 0) {
|
|
||||||
pMaterial->setDiffuseMap(szSymbol[1]);
|
|
||||||
} else if(strcmp(szSymbol[0], "map_Ks") == 0) {
|
|
||||||
pMaterial->setSpecularMap(szSymbol[1]);
|
|
||||||
} else if(strcmp(szSymbol[0], "map_Normal") == 0) {
|
|
||||||
pMaterial->setNormalMap(szSymbol[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -320,24 +320,38 @@ void KRMesh::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uv
|
|||||||
KRVector2 source_uva = uva[iVertex];
|
KRVector2 source_uva = uva[iVertex];
|
||||||
pVertex->uva.u = source_uva.x;
|
pVertex->uva.u = source_uva.x;
|
||||||
pVertex->uva.v = source_uva.y;
|
pVertex->uva.v = source_uva.y;
|
||||||
|
} else {
|
||||||
|
pVertex->uva.u = 0.0;
|
||||||
|
pVertex->uva.v = 0.0;
|
||||||
}
|
}
|
||||||
if(uvb.size() > iVertex) {
|
if(uvb.size() > iVertex) {
|
||||||
KRVector2 source_uvb = uvb[iVertex];
|
KRVector2 source_uvb = uvb[iVertex];
|
||||||
pVertex->uvb.u = source_uvb.x;
|
pVertex->uvb.u = source_uvb.x;
|
||||||
pVertex->uvb.v = source_uvb.y;
|
pVertex->uvb.v = source_uvb.y;
|
||||||
|
} else {
|
||||||
|
pVertex->uvb.u = 0.0;
|
||||||
|
pVertex->uvb.v = 0.0;
|
||||||
}
|
}
|
||||||
if(normals.size() > iVertex) {
|
if(normals.size() > iVertex) {
|
||||||
KRVector3 source_normal = normals[iVertex];
|
KRVector3 source_normal = normals[iVertex];
|
||||||
pVertex->normal.x = source_normal.x;
|
pVertex->normal.x = source_normal.x;
|
||||||
pVertex->normal.y = source_normal.y;
|
pVertex->normal.y = source_normal.y;
|
||||||
pVertex->normal.z = source_normal.z;
|
pVertex->normal.z = source_normal.z;
|
||||||
|
} else {
|
||||||
|
pVertex->normal.x = 0.0f;
|
||||||
|
pVertex->normal.y = 0.0f;
|
||||||
|
pVertex->normal.z = 0.0f;
|
||||||
}
|
}
|
||||||
if(tangents.size() > iVertex) {
|
if(tangents.size() > iVertex) {
|
||||||
KRVector3 source_tangent = tangents[iVertex];
|
KRVector3 source_tangent = tangents[iVertex];
|
||||||
pVertex->tangent.x = source_tangent.x;
|
pVertex->tangent.x = source_tangent.x;
|
||||||
pVertex->tangent.y = source_tangent.y;
|
pVertex->tangent.y = source_tangent.y;
|
||||||
pVertex->tangent.z = source_tangent.z;
|
pVertex->tangent.z = source_tangent.z;
|
||||||
}
|
} else {
|
||||||
|
pVertex->tangent.x = 0.0f;
|
||||||
|
pVertex->tangent.y = 0.0f;
|
||||||
|
pVertex->tangent.z = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
pVertex++;
|
pVertex++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -509,9 +509,20 @@ void LoadMesh(std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeom
|
|||||||
printf("Error! Multiple diffuse textures not supported.\n");
|
printf("Error! Multiple diffuse textures not supported.\n");
|
||||||
} else if(texture_count == 1) {
|
} else if(texture_count == 1) {
|
||||||
KFbxTexture* pTexture = KFbxCast <KFbxTexture> (pProperty.GetSrcObject(KFbxTexture::ClassId,0));
|
KFbxTexture* pTexture = KFbxCast <KFbxTexture> (pProperty.GetSrcObject(KFbxTexture::ClassId,0));
|
||||||
|
assert(!pTexture->GetSwapUV());
|
||||||
|
assert(pTexture->GetCroppingTop() == 0);
|
||||||
|
assert(pTexture->GetCroppingLeft() == 0);
|
||||||
|
assert(pTexture->GetCroppingRight() == 0);
|
||||||
|
assert(pTexture->GetCroppingBottom() == 0);
|
||||||
|
assert(pTexture->GetWrapModeU() == KFbxTexture::eREPEAT);
|
||||||
|
assert(pTexture->GetWrapModeV() == KFbxTexture::eREPEAT);
|
||||||
|
assert(pTexture->GetRotationU() == 0.0f);
|
||||||
|
assert(pTexture->GetRotationV() == 0.0f);
|
||||||
|
assert(pTexture->GetRotationW() == 0.0f);
|
||||||
|
|
||||||
KFbxFileTexture *pFileTexture = KFbxCast<KFbxFileTexture>(pTexture);
|
KFbxFileTexture *pFileTexture = KFbxCast<KFbxFileTexture>(pTexture);
|
||||||
if(pFileTexture) {
|
if(pFileTexture) {
|
||||||
new_material->setDiffuseMap(KRResource::GetFileBase(pFileTexture->GetFileName()));
|
new_material->setDiffuseMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -528,7 +539,7 @@ void LoadMesh(std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeom
|
|||||||
KFbxTexture* pTexture = KFbxCast <KFbxTexture> (pProperty.GetSrcObject(KFbxTexture::ClassId,0));
|
KFbxTexture* pTexture = KFbxCast <KFbxTexture> (pProperty.GetSrcObject(KFbxTexture::ClassId,0));
|
||||||
KFbxFileTexture *pFileTexture = KFbxCast<KFbxFileTexture>(pTexture);
|
KFbxFileTexture *pFileTexture = KFbxCast<KFbxFileTexture>(pTexture);
|
||||||
if(pFileTexture) {
|
if(pFileTexture) {
|
||||||
new_material->setSpecularMap(KRResource::GetFileBase(pFileTexture->GetFileName()));
|
new_material->setSpecularMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -545,7 +556,7 @@ void LoadMesh(std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeom
|
|||||||
KFbxTexture* pTexture = KFbxCast <KFbxTexture> (pProperty.GetSrcObject(KFbxTexture::ClassId,0));
|
KFbxTexture* pTexture = KFbxCast <KFbxTexture> (pProperty.GetSrcObject(KFbxTexture::ClassId,0));
|
||||||
KFbxFileTexture *pFileTexture = KFbxCast<KFbxFileTexture>(pTexture);
|
KFbxFileTexture *pFileTexture = KFbxCast<KFbxFileTexture>(pTexture);
|
||||||
if(pFileTexture) {
|
if(pFileTexture) {
|
||||||
new_material->setNormalMap(KRResource::GetFileBase(pFileTexture->GetFileName()));
|
new_material->setNormalMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,16 @@ KRShader::KRShader(char *szKey, std::string options, const GLchar *szVertShaderS
|
|||||||
m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE] = glGetUniformLocation(m_iProgram, "diffuseTexture");
|
m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE] = glGetUniformLocation(m_iProgram, "diffuseTexture");
|
||||||
m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE] = glGetUniformLocation(m_iProgram, "specularTexture");
|
m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE] = glGetUniformLocation(m_iProgram, "specularTexture");
|
||||||
m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE] = glGetUniformLocation(m_iProgram, "normalTexture");
|
m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE] = glGetUniformLocation(m_iProgram, "normalTexture");
|
||||||
|
|
||||||
|
m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "diffuseTexture_Scale");
|
||||||
|
m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "specularTexture_Scale");
|
||||||
|
m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "normalTexture_Scale");
|
||||||
|
m_uniforms[KRENGINE_UNIFORM_AMBIENTTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "ambientTexture_Scale");
|
||||||
|
m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "diffuseTexture_Offset");
|
||||||
|
m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "specularTexture_Offset");
|
||||||
|
m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "normalTexture_Offset");
|
||||||
|
m_uniforms[KRENGINE_UNIFORM_AMBIENTTEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "ambientTexture_Offset");
|
||||||
|
|
||||||
m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1] = glGetUniformLocation(m_iProgram, "shadowTexture1");
|
m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1] = glGetUniformLocation(m_iProgram, "shadowTexture1");
|
||||||
m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] = glGetUniformLocation(m_iProgram, "shadowTexture2");
|
m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] = glGetUniformLocation(m_iProgram, "shadowTexture2");
|
||||||
m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] = glGetUniformLocation(m_iProgram, "shadowTexture3");
|
m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] = glGetUniformLocation(m_iProgram, "shadowTexture3");
|
||||||
|
|||||||
@@ -74,6 +74,14 @@ public:
|
|||||||
KRENGINE_UNIFORM_DIFFUSETEXTURE,
|
KRENGINE_UNIFORM_DIFFUSETEXTURE,
|
||||||
KRENGINE_UNIFORM_SPECULARTEXTURE,
|
KRENGINE_UNIFORM_SPECULARTEXTURE,
|
||||||
KRENGINE_UNIFORM_NORMALTEXTURE,
|
KRENGINE_UNIFORM_NORMALTEXTURE,
|
||||||
|
KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE,
|
||||||
|
KRENGINE_UNIFORM_SPECULARTEXTURE_SCALE,
|
||||||
|
KRENGINE_UNIFORM_NORMALTEXTURE_SCALE,
|
||||||
|
KRENGINE_UNIFORM_AMBIENTTEXTURE_SCALE,
|
||||||
|
KRENGINE_UNIFORM_DIFFUSETEXTURE_OFFSET,
|
||||||
|
KRENGINE_UNIFORM_SPECULARTEXTURE_OFFSET,
|
||||||
|
KRENGINE_UNIFORM_NORMALTEXTURE_OFFSET,
|
||||||
|
KRENGINE_UNIFORM_AMBIENTTEXTURE_OFFSET,
|
||||||
KRENGINE_UNIFORM_SHADOWMVP1,
|
KRENGINE_UNIFORM_SHADOWMVP1,
|
||||||
KRENGINE_UNIFORM_SHADOWMVP2,
|
KRENGINE_UNIFORM_SHADOWMVP2,
|
||||||
KRENGINE_UNIFORM_SHADOWMVP3,
|
KRENGINE_UNIFORM_SHADOWMVP3,
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ KRShaderManager::~KRShaderManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KRShader *KRShaderManager::getShader(KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, int iShadowQuality, bool bShadowMap) {
|
KRShader *KRShaderManager::getShader(KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, int iShadowQuality, bool bShadowMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset) {
|
||||||
|
|
||||||
char szKey[128];
|
char szKey[128];
|
||||||
sprintf(szKey, "%d_%d_%d_%d_%d_%d_%d_%d_%d_%d", pCamera->bEnablePerPixel, bDiffuseMap, bNormalMap, bSpecMap, pCamera->bDebugPSSM, iShadowQuality, /*pCamera->dAmbientR, pCamera->dAmbientG, pCamera->dAmbientB, pCamera->dSunR, pCamera->dSunG, pCamera->dSunB, */pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular, bShadowMap);
|
sprintf(szKey, "%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d", pCamera->bEnablePerPixel, bDiffuseMap, bNormalMap, bSpecMap, pCamera->bDebugPSSM, iShadowQuality, /*pCamera->dAmbientR, pCamera->dAmbientG, pCamera->dAmbientB, pCamera->dSunR, pCamera->dSunG, pCamera->dSunB, */pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular, bShadowMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -73,6 +73,12 @@ KRShader *KRShaderManager::getShader(KRCamera *pCamera, bool bDiffuseMap, bool b
|
|||||||
stream << "\n#define HAS_NORMAL_MAP " << (bNormalMap ? "1" : "0");
|
stream << "\n#define HAS_NORMAL_MAP " << (bNormalMap ? "1" : "0");
|
||||||
stream << "\n#define HAS_SPEC_MAP " << (bSpecMap ? "1" : "0");
|
stream << "\n#define HAS_SPEC_MAP " << (bSpecMap ? "1" : "0");
|
||||||
stream << "\n#define HAS_SHADOW_MAP " << (bShadowMap ? "1" : "0");
|
stream << "\n#define HAS_SHADOW_MAP " << (bShadowMap ? "1" : "0");
|
||||||
|
stream << "\n#define HAS_NORMAL_MAP_SCALE " << (bNormalMapScale ? "1" : "0");
|
||||||
|
stream << "\n#define HAS_SPEC_MAP_SCALE " << (bSpecMapScale ? "1" : "0");
|
||||||
|
stream << "\n#define HAS_DIFFUSE_MAP_SCALE " << (bDiffuseMapScale ? "1" : "0");
|
||||||
|
stream << "\n#define HAS_NORMAL_MAP_OFFSET " << (bNormalMapOffset ? "1" : "0");
|
||||||
|
stream << "\n#define HAS_SPEC_MAP_OFFSET " << (bSpecMapOffset ? "1" : "0");
|
||||||
|
stream << "\n#define HAS_DIFFUSE_MAP_OFFSET " << (bDiffuseMapOffset ? "1" : "0");
|
||||||
stream << "\n#define ENABLE_PER_PIXEL " << (pCamera->bEnablePerPixel ? "1" : "0");
|
stream << "\n#define ENABLE_PER_PIXEL " << (pCamera->bEnablePerPixel ? "1" : "0");
|
||||||
stream << "\n#define DEBUG_PSSM " << (pCamera->bDebugPSSM ? "1" : "0");
|
stream << "\n#define DEBUG_PSSM " << (pCamera->bDebugPSSM ? "1" : "0");
|
||||||
stream << "\n#define SHADOW_QUALITY " << iShadowQuality;
|
stream << "\n#define SHADOW_QUALITY " << iShadowQuality;
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
KRShaderManager(const GLchar *szVertShaderSource, const GLchar *szFragShaderSource);
|
KRShaderManager(const GLchar *szVertShaderSource, const GLchar *szFragShaderSource);
|
||||||
~KRShaderManager();
|
~KRShaderManager();
|
||||||
|
|
||||||
KRShader *getShader(KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, int iShadowQuality, bool bShadowMap);
|
KRShader *getShader(KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, int iShadowQuality, bool bShadowMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, KRShader *> m_shaders;
|
std::map<std::string, KRShader *> m_shaders;
|
||||||
|
|||||||
@@ -22,4 +22,12 @@ KRVector2::KRVector2(float X, float Y) {
|
|||||||
|
|
||||||
KRVector2::~KRVector2() {
|
KRVector2::~KRVector2() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator== (KRVector2 &v1, KRVector2 &v2) {
|
||||||
|
return v1.x == v2.x && v1.y == v2.y;
|
||||||
|
|
||||||
|
}
|
||||||
|
bool operator!= (KRVector2 &v1, KRVector2 &v2) {
|
||||||
|
return !(v1 == v2);
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,9 @@ public:
|
|||||||
KRVector2(float X, float Y);
|
KRVector2(float X, float Y);
|
||||||
~KRVector2();
|
~KRVector2();
|
||||||
|
|
||||||
|
friend bool operator== (KRVector2 &v1, KRVector2 &v2);
|
||||||
|
friend bool operator!= (KRVector2 &v1, KRVector2 &v2);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -118,3 +118,11 @@ KRVector3 KRVector3::cross(const KRVector3 &vec) const
|
|||||||
z * vec.x - x * vec.z,
|
z * vec.x - x * vec.z,
|
||||||
x * vec.y - y * vec.x);
|
x * vec.y - y * vec.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator== (KRVector3 &v1, KRVector3 &v2) {
|
||||||
|
return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!= (KRVector3 &v1, KRVector3 &v2) {
|
||||||
|
return !(v1 == v2);
|
||||||
|
}
|
||||||
@@ -49,7 +49,8 @@ public:
|
|||||||
|
|
||||||
KRVector3(const KRVector3& p);
|
KRVector3(const KRVector3& p);
|
||||||
KRVector3& operator = ( const KRVector3& p );
|
KRVector3& operator = ( const KRVector3& p );
|
||||||
|
friend bool operator== (KRVector3 &v1, KRVector3 &v2);
|
||||||
|
friend bool operator!= (KRVector3 &v1, KRVector3 &v2);
|
||||||
|
|
||||||
//calculate and return the magnitude of this vector
|
//calculate and return the magnitude of this vector
|
||||||
float GetMagnitude();
|
float GetMagnitude();
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ varying highp vec4 shadowMapCoord3;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || HAS_SPEC_MAP == 1
|
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || HAS_SPEC_MAP == 1
|
||||||
varying mediump vec2 texCoord;
|
varying highp vec2 texCoord;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_NORMAL_MAP == 0 && ENABLE_PER_PIXEL == 1
|
#if HAS_NORMAL_MAP == 0 && ENABLE_PER_PIXEL == 1
|
||||||
@@ -80,11 +80,30 @@ varying mediump float lamberFactor;
|
|||||||
varying mediump float specularFactor;
|
varying mediump float specularFactor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if (HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
||||||
|
varying highp vec2 normal_uv;
|
||||||
|
#else
|
||||||
|
#define normal_uv texCoord
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (HAS_SPEC_MAP_OFFSET == 1|| HAS_SPEC_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
||||||
|
varying mediump vec2 spec_uv;
|
||||||
|
#else
|
||||||
|
#define spec_uv texCoord
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1
|
||||||
|
varying highp vec2 diffuse_uv;
|
||||||
|
#else
|
||||||
|
#define diffuse_uv texCoord
|
||||||
|
#endif
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
#if HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1
|
#if HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1
|
||||||
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
|
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
|
||||||
mediump vec3 normal = normalize(2.0 * texture2D(normalTexture,texCoord).rgb - 1.0);
|
mediump vec3 normal = normalize(2.0 * texture2D(normalTexture,normal_uv).rgb - 1.0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_PER_PIXEL == 1
|
#if ENABLE_PER_PIXEL == 1
|
||||||
@@ -96,7 +115,7 @@ void main()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_DIFFUSE_MAP == 1
|
#if HAS_DIFFUSE_MAP == 1
|
||||||
mediump vec4 diffuseMaterial = vec4(vec3(texture2D(diffuseTexture, texCoord)), material_alpha);
|
mediump vec4 diffuseMaterial = vec4(vec3(texture2D(diffuseTexture, diffuse_uv)), material_alpha);
|
||||||
#else
|
#else
|
||||||
mediump vec4 diffuseMaterial = vec4(vec3(1.0), material_alpha);
|
mediump vec4 diffuseMaterial = vec4(vec3(1.0), material_alpha);
|
||||||
#endif
|
#endif
|
||||||
@@ -175,8 +194,8 @@ void main()
|
|||||||
#if ENABLE_SPECULAR
|
#if ENABLE_SPECULAR
|
||||||
|
|
||||||
// -------------------- Add specular light --------------------
|
// -------------------- Add specular light --------------------
|
||||||
#if HAS_SPEC_MAP == 1
|
#if HAS_SPEC_MAP == 1
|
||||||
gl_FragColor += vec4(material_specular * vec3(texture2D(specularTexture, texCoord)) * specularFactor, 0.0);
|
gl_FragColor += vec4(material_specular * vec3(texture2D(specularTexture, spec_uv)) * specularFactor, 0.0);
|
||||||
#else
|
#else
|
||||||
gl_FragColor += vec4(material_specular * specularFactor, 0.0);
|
gl_FragColor += vec4(material_specular * specularFactor, 0.0);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ uniform mediump float material_shininess;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || HAS_SPEC_MAP == 1
|
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || HAS_SPEC_MAP == 1
|
||||||
varying mediump vec2 texCoord;
|
varying highp vec2 texCoord;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_SHADOW_MAP == 1
|
#if HAS_SHADOW_MAP == 1
|
||||||
@@ -59,6 +59,30 @@ varying mediump float lamberFactor;
|
|||||||
varying mediump float specularFactor;
|
varying mediump float specularFactor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP_SCALE == 1
|
||||||
|
uniform highp vec2 diffuseTexture_Scale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_NORMAL_MAP_SCALE == 1
|
||||||
|
uniform highp vec2 normalTexture_Scale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_SPEC_MAP_SCALE == 1
|
||||||
|
uniform highp vec2 specularTexture_Scale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_NORMAL_MAP_OFFSET == 1
|
||||||
|
uniform highp vec2 normalTexture_Offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_SPEC_MAP_OFFSET == 1
|
||||||
|
uniform highp vec2 specularTexture_Offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP_OFFSET == 1
|
||||||
|
uniform highp vec2 diffuseTexture_Offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_NORMAL_MAP == 0 && ENABLE_PER_PIXEL == 1
|
#if HAS_NORMAL_MAP == 0 && ENABLE_PER_PIXEL == 1
|
||||||
varying mediump vec3 normal;
|
varying mediump vec3 normal;
|
||||||
#endif
|
#endif
|
||||||
@@ -75,6 +99,18 @@ varying highp vec4 shadowMapCoord2;
|
|||||||
varying highp vec4 shadowMapCoord3;
|
varying highp vec4 shadowMapCoord3;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
||||||
|
varying highp vec2 normal_uv;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (HAS_SPEC_MAP_OFFSET == 1|| HAS_SPEC_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
||||||
|
varying highp vec2 spec_uv;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1
|
||||||
|
varying highp vec2 diffuse_uv;
|
||||||
|
#endif
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Transform position
|
// Transform position
|
||||||
@@ -87,6 +123,52 @@ void main()
|
|||||||
texCoord = myUV.st;
|
texCoord = myUV.st;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Scaled and translated normal map UV's
|
||||||
|
#if (HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
||||||
|
normal_uv = texCoord;
|
||||||
|
|
||||||
|
#if HAS_NORMAL_MAP_OFFSET == 1
|
||||||
|
normal_uv + normalTexture_Offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_NORMAL_MAP_SCALE == 1
|
||||||
|
normal_uv *= normalTexture_Scale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Scaled and translated diffuse map UV's
|
||||||
|
#if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1
|
||||||
|
diffuse_uv = texCoord;
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP_OFFSET == 1
|
||||||
|
diffuse_uv + diffuseTexture_Offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP_SCALE == 1
|
||||||
|
diffuse_uv *= diffuseTexture_Scale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Scaled and translated specular map UV's
|
||||||
|
#if (HAS_SPEC_MAP_OFFSET == 1 || HAS_SPEC_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
||||||
|
spec_uv = texCoord;
|
||||||
|
#if HAS_SPEC_MAP_OFFSET == 1
|
||||||
|
spec_uv + specularTexture_Offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_SPEC_MAP_SCALE == 1
|
||||||
|
spec_uv *= specularTexture_Scale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if HAS_SHADOW_MAP == 1
|
#if HAS_SHADOW_MAP == 1
|
||||||
// Pass shadow UV co-ordinates
|
// Pass shadow UV co-ordinates
|
||||||
shadowCoord = shadowuv.st;
|
shadowCoord = shadowuv.st;
|
||||||
|
|||||||
@@ -127,7 +127,7 @@
|
|||||||
//m_scene.addInstance(pModelManager->getModel("fachwerkhaus12"), KRMat4());
|
//m_scene.addInstance(pModelManager->getModel("fachwerkhaus12"), KRMat4());
|
||||||
//m_scene.addInstance(pModelManager->getModel("ballroom"), KRMat4());
|
//m_scene.addInstance(pModelManager->getModel("ballroom"), KRMat4());
|
||||||
//m_scene.addInstance(pModelManager->getModel("HoganCombined"), KRMat4());
|
//m_scene.addInstance(pModelManager->getModel("HoganCombined"), KRMat4());
|
||||||
m_scene.addInstance(pModelManager->getModel("polySurface12848"), KRMat4(), "PillarLightmap1k");
|
m_scene.addInstance(pModelManager->getModel("polySurface12848"), KRMat4(), "PillarLightmap2k");
|
||||||
|
|
||||||
[renderEngine setNearZ: 25.0];
|
[renderEngine setNearZ: 25.0];
|
||||||
[renderEngine setFarZ: 5000.0];
|
[renderEngine setFarZ: 5000.0];
|
||||||
|
|||||||
Reference in New Issue
Block a user