Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reflectivity/shininess support to TerrainLighting.frag #2306

Merged
merged 4 commits into from
Sep 5, 2024
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 @@ -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
Loading