Fixing a bug when albedo map transaprent but not quite loaded yet

This commit is contained in:
samcake 2016-03-15 17:01:26 -07:00
parent f30e8e9e0c
commit d58ac269ee
2 changed files with 25 additions and 13 deletions

View file

@ -147,7 +147,7 @@ bool NetworkGeometry::isLoadedWithTextures() const {
(material->lightmapTexture && !material->lightmapTexture->isLoaded())) { (material->lightmapTexture && !material->lightmapTexture->isLoaded())) {
return false; return false;
} }
if (material->albedoTexture) { if (material->albedoTexture && material->albedoTexture->getGPUTexture()) {
// Reset the materialKey transparentTexture key only, as it is albedoTexture-dependent // Reset the materialKey transparentTexture key only, as it is albedoTexture-dependent
const auto& usage = material->albedoTexture->getGPUTexture()->getUsage(); const auto& usage = material->albedoTexture->getGPUTexture()->getUsage();
bool isTransparentTexture = usage.isAlpha() && !usage.isAlphaMask(); bool isTransparentTexture = usage.isAlpha() && !usage.isAlphaMask();

View file

@ -20,7 +20,8 @@
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$> <$declareStandardCameraTransform()$>
uniform sampler2D albedoMap; <@include MaterialTextures.slh@>
<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$>
in vec2 _texCoord0; in vec2 _texCoord0;
in vec4 _position; in vec4 _position;
@ -31,16 +32,27 @@ in float _alpha;
out vec4 _fragColor; out vec4 _fragColor;
void main(void) { void main(void) {
vec4 albedo = texture(albedoMap, _texCoord0);
Material mat = getMaterial(); Material mat = getMaterial();
int matKey = getMaterialKey(mat);
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
vec3 albedo = getMaterialAlbedo(mat);
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
albedo *= _color;
float roughness = getMaterialRoughness(mat);
<$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>;
float metallic = getMaterialMetallic(mat);
vec3 emissive = getMaterialEmissive(mat);
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
vec3 fragPosition = _position.xyz; vec3 fragPosition = _position.xyz;
vec3 fragNormal = normalize(_normal); vec3 fragNormal = normalize(_normal);
vec3 fragAlbedo = getMaterialAlbedo(mat) * albedo.rgb * _color;
float fragMetallic = getMaterialMetallic(mat); float fragOpacity = getMaterialOpacity(mat) * albedoTex.a * _alpha;
vec3 fragEmissive = getMaterialEmissive(mat);
float fragRoughness = getMaterialRoughness(mat);
float fragOpacity = getMaterialOpacity(mat) * albedo.a * _alpha;
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
@ -50,9 +62,9 @@ void main(void) {
1.0, 1.0,
fragPosition, fragPosition,
fragNormal, fragNormal,
fragAlbedo, albedo,
fragMetallic, metallic,
fragEmissive, emissive,
fragRoughness), roughness),
fragOpacity); fragOpacity);
} }