Skip to content

Add support for AoStrength in PBRLighting & GltfLoader #1981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down