Skip to content

Commit 251db01

Browse files
Copilotriccardobl
andauthored
Fix SPTerrainLighting.frag missing SpecularMap support (#2654)
* Initial plan * Fix SPTerrainLighting to sample SpecularMap like MultiPass shader Co-authored-by: riccardobl <4943530+riccardobl@users.noreply.github.com> Agent-Logs-Url: https://github.com/jMonkeyEngine/jmonkeyengine/sessions/a30c94c1-aa2a-41dd-b8cd-4059e44d7611 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: riccardobl <4943530+riccardobl@users.noreply.github.com>
1 parent efcf2ff commit 251db01

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

jme3-terrain/src/main/resources/Common/MatDefs/Terrain/SPTerrainLighting.frag

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#import "Common/ShaderLib/Lighting.glsllib"
44

55
uniform float m_Shininess;
6+
#ifdef SPECULARMAP
7+
uniform sampler2D m_SpecularMap;
8+
#endif
69

710
varying vec4 AmbientSum;
811
varying vec4 DiffuseSum;
@@ -619,6 +622,20 @@ void main(){
619622
#endif
620623

621624

625+
//-----------------------
626+
// read shininess or specularColor from specularMap
627+
//-----------------------
628+
vec4 specularColor = vec4(1.0);
629+
float finalShininessValue = m_Shininess;
630+
#ifdef SPECULARMAP
631+
vec4 specularMapColor = texture2D(m_SpecularMap, texCoord);
632+
#ifdef USE_SPECULARMAP_AS_SHININESS
633+
finalShininessValue = specularMapColor.r; //assumes that specularMap is a gray-scale reflectivity/shininess map
634+
#else
635+
specularColor = specularMapColor;
636+
#endif
637+
#endif
638+
622639
//-----------------------
623640
// lighting calculations
624641
//-----------------------
@@ -655,9 +672,9 @@ void main(){
655672
vec3 viewDir = normalize(-vPos.xyz);
656673
#endif
657674

658-
vec2 light = computeLighting(normal, viewDir, lightDir.xyz, lightDir.w * spotFallOff, m_Shininess);
675+
vec2 light = computeLighting(normal, viewDir, lightDir.xyz, lightDir.w * spotFallOff, finalShininessValue);
659676
gl_FragColor.rgb += DiffuseSum.rgb * lightColor.rgb * diffuseColor.rgb * vec3(light.x) +
660-
SpecularSum.rgb * vec3(light.y);
677+
SpecularSum.rgb * specularColor.rgb * vec3(light.y);
661678
}
662679

663680
}

jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ MaterialDef Terrain Lighting {
238238
DIFFUSEMAP_11_SCALE : DiffuseMap_11_scale
239239

240240
USE_ALPHA : useDiffuseAlpha
241+
USE_SPECULARMAP_AS_SHININESS : useSpecularMapAsShininess
241242
}
242243
}
243244

0 commit comments

Comments
 (0)