Support separate specular maps

This commit is contained in:
scrawl 2014-01-07 18:05:44 +01:00
parent 90b55c8d4b
commit d97615d5d8
2 changed files with 28 additions and 4 deletions

View file

@ -8,6 +8,7 @@ material openmw_objects_base
diffuseMap black.png diffuseMap black.png
normalMap normalMap
emissiveMap emissiveMap
specMap
darkMap darkMap
use_emissive_map false use_emissive_map false
use_detail_map false use_detail_map false
@ -44,6 +45,7 @@ material openmw_objects_base
emissiveMap $emissiveMap emissiveMap $emissiveMap
detailMap $detailMap detailMap $detailMap
diffuseMap $diffuseMap diffuseMap $diffuseMap
specMap $specMap
darkMap $darkMap darkMap $darkMap
env_map $env_map env_map $env_map
env_map_color $env_map_color env_map_color $env_map_color
@ -108,6 +110,11 @@ material openmw_objects_base
colour_op add colour_op add
} }
texture_unit specMap
{
direct_texture $specMap
}
texture_unit shadowMap0 texture_unit shadowMap0
{ {
content_type shadow content_type shadow

View file

@ -14,11 +14,14 @@
#define NEED_DEPTH #define NEED_DEPTH
#endif #endif
#define SPECULAR 1
#define NORMAL_MAP @shPropertyHasValue(normalMap) #define NORMAL_MAP @shPropertyHasValue(normalMap)
#define EMISSIVE_MAP @shPropertyHasValue(emissiveMap) #define EMISSIVE_MAP @shPropertyHasValue(emissiveMap)
#define DETAIL_MAP @shPropertyHasValue(detailMap) #define DETAIL_MAP @shPropertyHasValue(detailMap)
#define DIFFUSE_MAP @shPropertyHasValue(diffuseMap) #define DIFFUSE_MAP @shPropertyHasValue(diffuseMap)
#define DARK_MAP @shPropertyHasValue(darkMap) #define DARK_MAP @shPropertyHasValue(darkMap)
#define SPEC_MAP @shPropertyHasValue(specMap) && SPECULAR
#define PARALLAX @shPropertyBool(use_parallax) #define PARALLAX @shPropertyBool(use_parallax)
#define PARALLAX_SCALE 0.04 #define PARALLAX_SCALE 0.04
@ -38,8 +41,6 @@
#define ENV_MAP @shPropertyBool(env_map) #define ENV_MAP @shPropertyBool(env_map)
#define SPECULAR 1
#define NEED_NORMAL (!VERTEX_LIGHTING || ENV_MAP) || SPECULAR #define NEED_NORMAL (!VERTEX_LIGHTING || ENV_MAP) || SPECULAR
#ifdef SH_VERTEX_SHADER #ifdef SH_VERTEX_SHADER
@ -273,6 +274,10 @@
shUniform(float3, env_map_color) @shUniformProperty3f(env_map_color, env_map_color) shUniform(float3, env_map_color) @shUniformProperty3f(env_map_color, env_map_color)
#endif #endif
#if SPEC_MAP
shSampler2D(specMap)
#endif
#if ENV_MAP || SPECULAR || PARALLAX #if ENV_MAP || SPECULAR || PARALLAX
shUniform(float3, cameraPosObjSpace) @shAutoConstant(cameraPosObjSpace, camera_position_object_space) shUniform(float3, cameraPosObjSpace) @shAutoConstant(cameraPosObjSpace, camera_position_object_space)
#endif #endif
@ -511,8 +516,20 @@
float NdotL = max(dot(normal, light0Dir), 0); float NdotL = max(dot(normal, light0Dir), 0);
float3 halfVec = normalize (light0Dir + eyeDir); float3 halfVec = normalize (light0Dir + eyeDir);
float3 specular = pow(max(dot(normal, halfVec), 0), matShininess) * lightSpec0 * matSpec; float shininess = matShininess;
shOutputColour(0).xyz += specular * shadow * diffuse.a; #if SPEC_MAP
float4 specTex = shSample(specMap, UV.xy);
shininess *= (specTex.a);
#endif
float3 specular = pow(max(dot(normal, halfVec), 0), shininess) * lightSpec0 * matSpec;
#if SPEC_MAP
specular *= specTex.xyz;
#else
specular *= diffuse.a;
#endif
shOutputColour(0).xyz += specular * shadow;
#endif #endif
#if FOG #if FOG