diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag index 6905b7f926..457cb05460 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag @@ -84,6 +84,10 @@ varying vec3 wPosition; #ifdef LIGHTMAP uniform sampler2D m_LightMap; #endif + +#ifdef AO_STRENGTH + uniform float m_AoStrength; +#endif #if defined(NORMALMAP) || defined(PARALLAXMAP) uniform sampler2D m_NormalMap; @@ -230,6 +234,12 @@ void main(){ ao = aoRoughnessMetallicValue.rrr; #endif + #ifdef AO_STRENGTH + ao = 1.0 + m_AoStrength * (ao - 1.0); + // sanity check + ao = clamp(ao, 0.0, 1.0); + #endif + float ndotv = max( dot( normal, viewDir ),0.0); for( int i = 0;i < NB_LIGHTS; i+=3){ vec4 lightColor = g_LightData[i]; diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md index 633e57c508..71db77abea 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md @@ -68,6 +68,10 @@ MaterialDef PBR Lighting { // Set to Use Lightmap Texture2D LightMap + // A scalar multiplier controlling the amount of occlusion applied. + // A value of `0.0` means no occlusion. A value of `1.0` means full occlusion. + Float AoStrength + // Set to use TexCoord2 for the lightmap sampling Boolean SeparateTexCoord // the light map is a grayscale ao map, only the r channel will be read. @@ -159,6 +163,7 @@ MaterialDef PBR Lighting { VERTEX_COLOR : UseVertexColor AO_MAP: LightMapAsAOMap AO_PACKED_IN_MR_MAP : AoPackedInMRMap + AO_STRENGTH : AoStrength NUM_MORPH_TARGETS: NumberOfMorphTargets NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers HORIZON_FADE: HorizonFade diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java index 11e934666e..d652ad4289 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java @@ -667,6 +667,12 @@ public Material readMaterial(int materialIndex) throws IOException { } else { adapter.setParam("occlusionTexture", readTexture(matData.getAsJsonObject("occlusionTexture"))); } + + Float occlusionStrength = occlusionJson != null ? getAsFloat(occlusionJson, "strength") : null; + if (occlusionStrength != null) { + adapter.setParam("occlusionStrength", occlusionStrength); + } + adapter.setParam("emissiveTexture", readTexture(matData.getAsJsonObject("emissiveTexture"))); return adapter.getMaterial(); diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBRMaterialAdapter.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBRMaterialAdapter.java index b184c402d8..ebbb03ec9d 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBRMaterialAdapter.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBRMaterialAdapter.java @@ -41,6 +41,7 @@ public abstract class PBRMaterialAdapter extends MaterialAdapter { public PBRMaterialAdapter() { addParamMapping("normalTexture", "NormalMap"); addParamMapping("occlusionTexture", "LightMap"); + addParamMapping("occlusionStrength", "AoStrength"); addParamMapping("emissiveTexture", "EmissiveMap"); addParamMapping("emissiveFactor", "Emissive"); addParamMapping("alphaMode", "alpha");