Skip to content

Commit

Permalink
Ignore if loading specular or normal map fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik committed May 26, 2022
1 parent f2326a4 commit cad3809
Showing 1 changed file with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,46 +83,46 @@ public boolean load(Path texturePack) {
@Override
public boolean load(String file, Path texturePack) {
boolean loaded = super.load(file, texturePack);
String specularFormat = System.getProperty("chunky.pbr.specular", "labpbr");
if (specularFormat.equals("oldpbr") || specularFormat.equals("labpbr")) {
try (InputStream in = Files.newInputStream(texturePack.resolve(file + "_s.png"))) {
// LabPBR uses the alpha channel for the emission map
// Some resource packs use the blue channel (Red=Smoothness, Green=Metalness, Blue=Emission)
// (In BSL, this option is called "Old PBR + Emissive")
if (specularFormat.equals("oldpbr")) {
OldPbrSpecularMap specular = new OldPbrSpecularMap(getTextureOrFirstFrame(in));
texture.setEmissionMap(specular.hasEmission() ? specular : EmissionMap.EMPTY);
texture.setReflectanceMap(specular.hasReflectance() ? specular : ReflectanceMap.EMPTY);
texture.setRoughnessMap(specular.hasRoughness() ? specular : RoughnessMap.EMPTY);
texture.setMetalnessMap(MetalnessMap.EMPTY);
} else if (specularFormat.equals("labpbr")) {
LabPbrSpecularMap specular = new LabPbrSpecularMap(getTextureOrFirstFrame(in));
texture.setEmissionMap(specular.hasEmission() ? specular : EmissionMap.EMPTY);
texture.setReflectanceMap(specular.hasReflectance() ? specular : ReflectanceMap.EMPTY);
texture.setRoughnessMap(specular.hasRoughness() ? specular : RoughnessMap.EMPTY);
texture.setMetalnessMap(specular.hasMetalness() ? specular : MetalnessMap.EMPTY);

try {
String specularFormat = System.getProperty("chunky.pbr.specular", "labpbr");
if (specularFormat.equals("oldpbr") || specularFormat.equals("labpbr")) {
try (InputStream in = Files.newInputStream(texturePack.resolve(file + "_s.png"))) {
// LabPBR uses the alpha channel for the emission map
// Some resource packs use the blue channel (Red=Smoothness, Green=Metalness, Blue=Emission)
// (In BSL, this option is called "Old PBR + Emissive")
if (specularFormat.equals("oldpbr")) {
OldPbrSpecularMap specular = new OldPbrSpecularMap(getTextureOrFirstFrame(in));
texture.setEmissionMap(specular.hasEmission() ? specular : EmissionMap.EMPTY);
texture.setReflectanceMap(specular.hasReflectance() ? specular : ReflectanceMap.EMPTY);
texture.setRoughnessMap(specular.hasRoughness() ? specular : RoughnessMap.EMPTY);
texture.setMetalnessMap(MetalnessMap.EMPTY);
} else if (specularFormat.equals("labpbr")) {
LabPbrSpecularMap specular = new LabPbrSpecularMap(getTextureOrFirstFrame(in));
texture.setEmissionMap(specular.hasEmission() ? specular : EmissionMap.EMPTY);
texture.setReflectanceMap(specular.hasReflectance() ? specular : ReflectanceMap.EMPTY);
texture.setRoughnessMap(specular.hasRoughness() ? specular : RoughnessMap.EMPTY);
texture.setMetalnessMap(specular.hasMetalness() ? specular : MetalnessMap.EMPTY);
}
}
} catch (IOException e) {
// Safe to ignore
texture.setEmissionMap(EmissionMap.EMPTY);
texture.setReflectanceMap(ReflectanceMap.EMPTY);
texture.setRoughnessMap(RoughnessMap.EMPTY);
texture.setMetalnessMap(MetalnessMap.EMPTY);
}
} catch (IOException e) {
// Safe to ignore
}

String normalFormat = System.getProperty("chunky.pbr.normal", "");
if (normalFormat.equals("oldpbr") || normalFormat.equals("labpbr")) {
try (InputStream in = Files.newInputStream(texturePack.resolve(file + "_n.png"))) {
if (normalFormat.equals("oldpbr")) {
texture.setNormalMap(new OldPbrNormalMap(getTextureOrFirstFrame(in)));
} else if (normalFormat.equals("labpbr")) {
texture.setNormalMap(new LabPbrNormalMap(getTextureOrFirstFrame(in)));
try {
String normalFormat = System.getProperty("chunky.pbr.normal", "");
if (normalFormat.equals("oldpbr") || normalFormat.equals("labpbr")) {
try (InputStream in = Files.newInputStream(texturePack.resolve(file + "_n.png"))) {
if (normalFormat.equals("oldpbr")) {
texture.setNormalMap(new OldPbrNormalMap(getTextureOrFirstFrame(in)));
} else if (normalFormat.equals("labpbr")) {
texture.setNormalMap(new LabPbrNormalMap(getTextureOrFirstFrame(in)));
}
}
} catch (IOException e) {
// Safe to ignore
texture.setNormalMap(null);
}
} catch (IOException e) {
// Safe to ignore
}

return loaded;
Expand Down

0 comments on commit cad3809

Please sign in to comment.