Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what normal scale is supposed to achieve exactly, but it seems very strange to have vec3(m_NormalScale, m_NormalScale, 1.0) with the z component left as 1.0. That isn't how scalars are normally applied.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex128 you mean that usually the m_NormalScale should also apply to the Z component like this?
vec3(m_NormalScale, m_NormalScale, m_NormalScale)

BTW, the link in the comment (http://hub.jmonkeyengine.org/forum/topic/parallax-mapping-fundamental-bug/#post-256898) is broken

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, having all components be m_NormalScale seems like it should be correct.

#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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -138,6 +140,7 @@ MaterialDef PBR Lighting {
Defines {
BASECOLORMAP : BaseColorMap
NORMALMAP : NormalMap
NORMALSCALE : NormalScale
METALLICMAP : MetallicMap
ROUGHNESSMAP : RoughnessMap
EMISSIVEMAP : EmissiveMap
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -50,7 +50,7 @@
*/
public abstract class MaterialAdapter {

private Map<String, String> paramsMapping = new HashMap<>();
private final Map<String, String> paramsMapping = new HashMap<>();
private Material mat;
private AssetManager assetManager;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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");
Expand Down