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..7313d0ecc1 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag @@ -89,6 +89,9 @@ varying vec3 wPosition; uniform sampler2D m_NormalMap; varying vec4 wTangent; #endif +#ifdef NORMALSCALE + uniform float m_NormalScale; +#endif varying vec3 wNormal; #ifdef DISCARD_ALPHA @@ -170,7 +173,11 @@ void main(){ //as it's compliant with normal maps generated with blender. //see http://hub.jmonkeyengine.org/forum/topic/parallax-mapping-fundamental-bug/#post-256898 //for more explanation. - vec3 normal = normalize((normalHeight.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0))); + #ifdef NORMALSCALE + vec3 normal = normalize((normalHeight.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)) * vec3(m_NormalScale, m_NormalScale, 1.0)); + #else + vec3 normal = normalize((normalHeight.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0))); + #endif normal = normalize(tbnMat * normal); //normal = normalize(normal * inverse(tbnMat)); #else 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..37b5df5d15 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md @@ -38,6 +38,8 @@ MaterialDef PBR Lighting { // Normal map Texture2D NormalMap -LINEAR + // The scalar parameter applied to each normal vector of the normal map + Float NormalScale //The type of normal map: -1.0 (DirectX), 1.0 (OpenGl) Float NormalType : -1.0 @@ -138,6 +140,7 @@ MaterialDef PBR Lighting { Defines { BASECOLORMAP : BaseColorMap NORMALMAP : NormalMap + NORMALSCALE : NormalScale METALLICMAP : MetallicMap ROUGHNESSMAP : RoughnessMap EMISSIVEMAP : EmissiveMap 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..bdd3119f3c 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2022 jMonkeyEngine + * Copyright (c) 2009-2023 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -659,6 +659,12 @@ public Material readMaterial(int materialIndex) throws IOException { adapter.setParam("normalTexture", normal); if (normal != null) { useNormalsFlag = true; + + JsonObject normalTexture = matData.getAsJsonObject("normalTexture"); + Float normalScale = getAsFloat(normalTexture, "scale"); + if (normalScale != null) { + adapter.setParam("normalScale", normalScale); + } } JsonObject occlusionJson = matData.getAsJsonObject("occlusionTexture"); Integer occlusionIndex = occlusionJson != null ? getAsInteger(occlusionJson, "index") : null; diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/MaterialAdapter.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/MaterialAdapter.java index ee7219efcb..cb2639dc8f 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/MaterialAdapter.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/MaterialAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2020 jMonkeyEngine + * Copyright (c) 2009-2023 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -50,7 +50,7 @@ */ public abstract class MaterialAdapter { - private Map paramsMapping = new HashMap<>(); + private final Map paramsMapping = new HashMap<>(); private Material mat; private AssetManager assetManager; 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..a1e1cabe21 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2020 jMonkeyEngine + * Copyright (c) 2009-2023 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ public abstract class PBRMaterialAdapter extends MaterialAdapter { public PBRMaterialAdapter() { addParamMapping("normalTexture", "NormalMap"); + addParamMapping("normalScale", "NormalScale"); addParamMapping("occlusionTexture", "LightMap"); addParamMapping("emissiveTexture", "EmissiveMap"); addParamMapping("emissiveFactor", "Emissive");