fix: Fix rancor/hutt transparency issues

This commit is contained in:
Vsevolod Kremianskii 2020-08-23 22:27:28 +07:00
parent 13fb08e3b5
commit f6ccbb75d1
7 changed files with 54 additions and 4 deletions

View file

@ -39,6 +39,7 @@ void ModelMesh::initGL() {
if (_lightmap) _lightmap->initGL();
if (_envmap) _envmap->initGL();
if (_bumpyShiny) _bumpyShiny->initGL();
if (_bumpmap) _bumpmap->initGL();
}
void ModelMesh::render(const shared_ptr<Texture> &diffuseOverride) const {
@ -62,6 +63,10 @@ void ModelMesh::render(const shared_ptr<Texture> &diffuseOverride) const {
glActiveTexture(GL_TEXTURE3);
_bumpyShiny->bind();
}
if (_bumpmap) {
glActiveTexture(GL_TEXTURE4);
_bumpmap->bind();
}
GLint blendSrcRgb, blendSrcAlpha, blendDstRgb, blendDstAlpha;
if (additive) {
@ -78,6 +83,10 @@ void ModelMesh::render(const shared_ptr<Texture> &diffuseOverride) const {
glBlendFuncSeparate(blendSrcRgb, blendDstRgb, blendSrcAlpha, blendDstAlpha);
}
if (_bumpmap) {
glActiveTexture(GL_TEXTURE4);
_bumpmap->unbind();
}
if (_bumpyShiny) {
glActiveTexture(GL_TEXTURE3);
_bumpyShiny->unbind();
@ -125,6 +134,10 @@ bool ModelMesh::hasBumpyShinyTexture() const {
return static_cast<bool>(_bumpyShiny);
}
bool ModelMesh::hasBumpmapTexture() const {
return static_cast<bool>(_bumpmap);
}
const shared_ptr<Texture> &ModelMesh::diffuseTexture() const {
return _diffuse;
}

View file

@ -52,6 +52,7 @@ public:
bool hasEnvmapTexture() const;
bool hasLightmapTexture() const;
bool hasBumpyShinyTexture() const;
bool hasBumpmapTexture() const;
const std::shared_ptr<Texture> &diffuseTexture() const;
@ -61,6 +62,7 @@ private:
std::shared_ptr<Texture> _envmap;
std::shared_ptr<Texture> _lightmap;
std::shared_ptr<Texture> _bumpyShiny;
std::shared_ptr<Texture> _bumpmap;
friend class resources::MdlFile;
};

View file

@ -321,6 +321,9 @@ void ModelInstance::render(const ModelNode &node, const glm::mat4 &transform, bo
if (mesh->hasBumpyShinyTexture()) {
shaders.setUniform("bumpyShiny", 3);
}
if (mesh->hasBumpmapTexture()) {
shaders.setUniform("bumpmap", 4);
}
if (skeletal) {
shaders.setUniform("absTransform", node.absoluteTransform());
@ -355,13 +358,16 @@ ShaderProgram ModelInstance::getShaderProgram(const ModelMesh &mesh, bool skelet
bool hasEnvmap = mesh.hasEnvmapTexture();
bool hasLightmap = mesh.hasLightmapTexture();
bool hasBumpyShiny = mesh.hasBumpyShinyTexture();
bool hasBumpmap = mesh.hasBumpmapTexture();
if (skeletal) {
if (hasEnvmap && !hasLightmap && !hasBumpyShiny) {
if (hasEnvmap && !hasLightmap && !hasBumpyShiny && !hasBumpmap) {
program = ShaderProgram::SkeletalDiffuseEnvmap;
} else if (hasBumpyShiny && !hasEnvmap && !hasLightmap) {
} else if (hasBumpyShiny && !hasEnvmap && !hasLightmap && !hasBumpmap) {
program = ShaderProgram::SkeletalDiffuseBumpyShiny;
} else if (!hasEnvmap && !hasLightmap && !hasBumpyShiny) {
} else if (hasBumpmap && !hasEnvmap && !hasLightmap && !hasBumpyShiny) {
program = ShaderProgram::SkeletalDiffuseBumpmap;
} else if (!hasEnvmap && !hasLightmap && !hasBumpyShiny && !hasBumpmap) {
program = ShaderProgram::SkeletalDiffuse;
}
} else {

View file

@ -276,6 +276,28 @@ static const GLchar kDiffuseLightmapBumpyShinyFragmentShader[] = "#version 330\n
color = vec4(objectColor.rgb, alpha * objectColor.a);\n\
}";
static const GLchar kDiffuseBumpmapFragmentShader[] = "#version 330\n\
\n\
uniform sampler2D diffuse;\n\
uniform sampler2D bumpmap;\n\
uniform vec3 cameraPosition;\n\
uniform float alpha;\n\
\n\
in vec3 fragPosition;\n\
in vec3 fragNormal;\n\
in vec2 fragTexCoords;\n\
in vec2 fragLightmapCoords;\n\
\n\
out vec4 color;\n\
\n\
void main() {\n\
vec4 diffuseSample = texture(diffuse, fragTexCoords);\n\
vec4 bumpmapSample = texture(bumpmap, fragTexCoords);\n\
\n\
vec4 objectColor = diffuseSample;\n\
color = vec4(objectColor.rgb, alpha);\n\
}";
static const GLchar kTextFragmentShader[] = "#version 330\n\
\n\
uniform sampler2D font;\n\
@ -305,6 +327,7 @@ void ShaderManager::initGL() {
initShader(ShaderName::FragmentDiffuseLightmap, GL_FRAGMENT_SHADER, kDiffuseLightmapFragmentShader);
initShader(ShaderName::FragmentDiffuseLightmapEnvmap, GL_FRAGMENT_SHADER, kDiffuseLightmapEnvmapFragmentShader);
initShader(ShaderName::FragmentDiffuseLightmapBumpyShiny, GL_FRAGMENT_SHADER, kDiffuseLightmapBumpyShinyFragmentShader);
initShader(ShaderName::FragmentDiffuseBumpmap, GL_FRAGMENT_SHADER, kDiffuseBumpmapFragmentShader);
initShader(ShaderName::FragmentText, GL_FRAGMENT_SHADER, kTextFragmentShader);
initProgram(ShaderProgram::BasicWhite, ShaderName::VertexBasic, ShaderName::FragmentWhite);
@ -317,6 +340,7 @@ void ShaderManager::initGL() {
initProgram(ShaderProgram::SkeletalDiffuse, ShaderName::VertexSkeletal, ShaderName::FragmentDiffuse);
initProgram(ShaderProgram::SkeletalDiffuseEnvmap, ShaderName::VertexSkeletal, ShaderName::FragmentDiffuseEnvmap);
initProgram(ShaderProgram::SkeletalDiffuseBumpyShiny, ShaderName::VertexSkeletal, ShaderName::FragmentDiffuseBumpyShiny);
initProgram(ShaderProgram::SkeletalDiffuseBumpmap, ShaderName::VertexSkeletal, ShaderName::FragmentDiffuseBumpmap);
initProgram(ShaderProgram::GUIText, ShaderName::VertexGUI, ShaderName::FragmentText);
}

View file

@ -39,6 +39,7 @@ enum class ShaderProgram {
SkeletalDiffuse,
SkeletalDiffuseEnvmap,
SkeletalDiffuseBumpyShiny,
SkeletalDiffuseBumpmap,
GUIText
};
@ -75,6 +76,7 @@ private:
FragmentDiffuseLightmap,
FragmentDiffuseLightmapEnvmap,
FragmentDiffuseLightmapBumpyShiny,
FragmentDiffuseBumpmap,
FragmentText
};

View file

@ -33,7 +33,7 @@ enum class TextureType {
Diffuse,
Lightmap,
EnvironmentMap,
BumpMap,
Bumpmap,
GUI,
Cursor
};

View file

@ -442,6 +442,9 @@ unique_ptr<ModelMesh> MdlFile::readMesh() {
if (!features.bumpyShinyTexture.empty()) {
mesh->_bumpyShiny = resources.findTexture(features.bumpyShinyTexture, TextureType::EnvironmentMap);
}
if (!features.bumpMapTexture.empty()) {
mesh->_bumpmap = resources.findTexture(features.bumpMapTexture, TextureType::Bumpmap);
}
}
}
if (!lightmap.empty()) {