Skip to content

Fix SPTerrainLighting.frag missing SpecularMap support#2654

Open
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-spterrainlighting-specularmap
Open

Fix SPTerrainLighting.frag missing SpecularMap support#2654
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-spterrainlighting-specularmap

Conversation

Copy link
Contributor

Copilot AI commented Mar 22, 2026

SPTerrainLighting.frag hardcoded m_Shininess and ignored SpecularMap/useSpecularMapAsShininess entirely, causing terrain materials that rely on those parameters to silently lose specular response when the SinglePass technique is active.

Changes

  • SPTerrainLighting.frag: Added m_SpecularMap uniform declaration under #ifdef SPECULARMAP. Before the per-light loop, now computes specularColor (default vec4(1.0)) and finalShininessValue (default m_Shininess) by sampling the specular map — using .r as shininess when USE_SPECULARMAP_AS_SHININESS is set, otherwise as a specular color multiplier. Loop updated to pass finalShininessValue to computeLighting and apply specularColor.rgb to the specular contribution.

  • TerrainLighting.j3md: Added USE_SPECULARMAP_AS_SHININESS : useSpecularMapAsShininess to the SinglePass technique's Defines block — it was already wired in the MultiPass technique but absent here.

The SinglePass shader now mirrors the MultiPass (TerrainLighting.frag) specular logic exactly:

vec4 specularColor = vec4(1.0);
float finalShininessValue = m_Shininess;
#ifdef SPECULARMAP
  vec4 specularMapColor = texture2D(m_SpecularMap, texCoord);
  #ifdef USE_SPECULARMAP_AS_SHININESS
    finalShininessValue = specularMapColor.r;
  #else
    specularColor = specularMapColor;
  #endif
#endif
// ...
vec2 light = computeLighting(normal, viewDir, lightDir.xyz, lightDir.w * spotFallOff, finalShininessValue);
gl_FragColor.rgb += DiffuseSum.rgb * lightColor.rgb * diffuseColor.rgb * vec3(light.x) +
                    SpecularSum.rgb * specularColor.rgb * vec3(light.y);
Original prompt

This section details on the original issue you should resolve

<issue_title>SPTerrainLighting does not sample SpecularMap</issue_title>
<issue_description>
Changing the default here makes Common/MatDefs/Terrain/TerrainLighting.j3md pick its LightMode SinglePass technique by default (jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md:179-240). That path still does not implement terrain specular maps: SPTerrainLighting.frag never samples m_SpecularMap and always uses m_Shininess directly (jme3-terrain/src/main/resources/Common/MatDefs/Terrain/SPTerrainLighting.frag:5,649-651), whereas the current MultiPass shader applies both SpecularMap and useSpecularMapAsShininess (jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag:642-651). Any existing terrain material that relies on those parameters will therefore lose its specular response after this default flips, even though the app never opted into single-pass lighting.

Originally posted by @chatgpt-codex-connector[bot] in #2652 (comment)
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix SPTerrainLighting to sample SpecularMap Fix SPTerrainLighting.frag missing SpecularMap support Mar 22, 2026
Copilot AI requested a review from riccardobl March 22, 2026 14:16
@riccardobl riccardobl requested a review from yaRnMcDonuts March 22, 2026 14:19
@riccardobl
Copy link
Member

I’ve never used the jME terrain system, so I’m not sure whether this PR is solid.
@yaRnMcDonuts, when you have some time, could you take a look? You might have better insight than I do.

@riccardobl riccardobl marked this pull request as ready for review March 22, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SPTerrainLighting does not sample SpecularMap

2 participants