Skip to content

Commit

Permalink
Add reflectivity/shininess support to TerrainLighting.frag (#2306)
Browse files Browse the repository at this point in the history
* 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.

* 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

* Update TerrainLighting.frag

* Update TerrainLighting.frag
  • Loading branch information
yaRnMcDonuts authored Sep 5, 2024
1 parent 6709ee8 commit d71feba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -634,16 +638,27 @@ void main(){
vec3 normal = vNormal;
#endif

//-----------------------
// 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 specularMapColor = texture2D(m_SpecularMap, texCoord);
#ifdef USE_SPECULARMAP_AS_SHININESS
finalShininessValue = specularMapColor.r; //assumes that specularMap is a gray-scale reflectivity/shininess map)
#else
specularColor = specularMapColor;
#endif
#endif

//-----------------------
// lighting calculations
//-----------------------
vec4 lightDir = vLightDir;
lightDir.xyz = normalize(lightDir.xyz);

vec2 light = computeLighting(normal, vViewDir.xyz, lightDir.xyz,lightDir.w*spotFallOff,m_Shininess);

vec4 specularColor = vec4(1.0);
vec2 light = computeLighting(normal, vViewDir.xyz, lightDir.xyz,lightDir.w*spotFallOff,finalShininessValue);

//--------------------------
// final color calculations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ MaterialDef Terrain Lighting {

// The glow color of the object
Color GlowColor

// Use diffuse alpha when mixing
Boolean useSpecularMapAsShininess

}

Technique {
Expand Down Expand Up @@ -167,6 +171,7 @@ MaterialDef Terrain Lighting {
DIFFUSEMAP_11_SCALE : DiffuseMap_11_scale

USE_ALPHA : useDiffuseAlpha
USE_SPECULARMAP_AS_SHININESS : useSpecularMapAsShininess
}
}

Expand Down

0 comments on commit d71feba

Please sign in to comment.