From d3847d3ea0078ea0376c52d47dd3873828487085 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Wed, 21 Aug 2024 17:07:10 -0400 Subject: [PATCH 1/4] Add reflectivity/shininess support to TerrainLighting.frag Uses the (previously unused) SpecularMap as a gray-scale texture for painting shininess/reflectivity on the whole terrain. --- .../Common/MatDefs/Terrain/TerrainLighting.frag | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag index f2ca013fc7..adcf027884 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag @@ -3,6 +3,10 @@ #import "Common/ShaderLib/Lighting.glsllib" uniform float m_Shininess; +#ifdef SPECULARMAP + uniform sampler2D m_SpecularMap; +#endif + uniform vec4 g_LightDirection; varying vec4 AmbientSum; @@ -634,6 +638,15 @@ void main(){ vec3 normal = vNormal; #endif + //----------------------- + // read shininess from specularMap (possibly want to create a new texture called ShininessMap insetad, since this isn't really what specular is for. but specularMap isn't used elsewhere in this shader anyways, so this doesn't break anything doing it like this) + //----------------------- + #ifdef SPECULARMAP + vec4 specularColor = texture2D(m_SpecularMap, texCoord); + float finalShininessValue = specularColor.r; //assumes that specularMap is a gray-scale reflectivity/shininess map) + #else + float finalShininessValue = m_Shininess; + #endif //----------------------- // lighting calculations @@ -641,7 +654,7 @@ void main(){ vec4 lightDir = vLightDir; lightDir.xyz = normalize(lightDir.xyz); - vec2 light = computeLighting(normal, vViewDir.xyz, lightDir.xyz,lightDir.w*spotFallOff,m_Shininess); + vec2 light = computeLighting(normal, vViewDir.xyz, lightDir.xyz,lightDir.w*spotFallOff,finalShininessValue); vec4 specularColor = vec4(1.0); From edea7053a5589d8cd9cf63e25684478a35a5cccd Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Thu, 22 Aug 2024 01:58:17 -0400 Subject: [PATCH 2/4] Update TerrainLighting.j3md add USE_SPECULARMAP_AS_SHININESS define to make this PR cleaner, and allow the SpecularMap to be used as regular specularColor if USE_SPECULARMAP_AS_SHININESS is not true/defined --- .../resources/Common/MatDefs/Terrain/TerrainLighting.j3md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md index 341ef1c683..4eb9c8d7a2 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md @@ -103,6 +103,10 @@ MaterialDef Terrain Lighting { // The glow color of the object Color GlowColor + + // Use diffuse alpha when mixing + Boolean useSpecularMapAsShininess + } Technique { @@ -167,6 +171,7 @@ MaterialDef Terrain Lighting { DIFFUSEMAP_11_SCALE : DiffuseMap_11_scale USE_ALPHA : useDiffuseAlpha + USE_SPECULARMAP_AS_SHININESS : useSpecularMapAsShininess } } From 62ba20ba5e8a19b39765f1d0b04e56f690fd4540 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Thu, 22 Aug 2024 02:03:36 -0400 Subject: [PATCH 3/4] Update TerrainLighting.frag --- .../MatDefs/Terrain/TerrainLighting.frag | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag index adcf027884..ad020ced74 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag @@ -639,13 +639,17 @@ void main(){ #endif //----------------------- - // read shininess from specularMap (possibly want to create a new texture called ShininessMap insetad, since this isn't really what specular is for. but specularMap isn't used elsewhere in this shader anyways, so this doesn't break anything doing it like this) - //----------------------- + // read shininess or specularColor from specularMap (possibly want to create a new texture called ShininessMap if there is ever a need to have both a specularMap and reflectivityMap) + //----------------------- + vec4 specularColor = vec4(1.0); + float finalShininessValue = m_Shininess; #ifdef SPECULARMAP - vec4 specularColor = texture2D(m_SpecularMap, texCoord); - float finalShininessValue = specularColor.r; //assumes that specularMap is a gray-scale reflectivity/shininess map) - #else - float finalShininessValue = m_Shininess; + vec4 specularMapColor = texture2D(m_SpecularMap, texCoord); + #ifdef USE_SPECULARMAP_AS_SHININESS + finalShininessValue = specularColor.r; //assumes that specularMap is a gray-scale reflectivity/shininess map) + #else + specularColor = specularMapColor; + #endif #endif //----------------------- @@ -656,8 +660,6 @@ void main(){ vec2 light = computeLighting(normal, vViewDir.xyz, lightDir.xyz,lightDir.w*spotFallOff,finalShininessValue); - vec4 specularColor = vec4(1.0); - //-------------------------- // final color calculations //-------------------------- From 8f4b0c9ce887f0095969d5879f4acd31ed8b2468 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Thu, 22 Aug 2024 02:10:13 -0400 Subject: [PATCH 4/4] Update TerrainLighting.frag --- .../main/resources/Common/MatDefs/Terrain/TerrainLighting.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag index ad020ced74..8125982303 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag @@ -646,7 +646,7 @@ void main(){ #ifdef SPECULARMAP vec4 specularMapColor = texture2D(m_SpecularMap, texCoord); #ifdef USE_SPECULARMAP_AS_SHININESS - finalShininessValue = specularColor.r; //assumes that specularMap is a gray-scale reflectivity/shininess map) + finalShininessValue = specularMapColor.r; //assumes that specularMap is a gray-scale reflectivity/shininess map) #else specularColor = specularMapColor; #endif