From d97615d5d87604caeffc1ad303e0ef6ea510680d Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 7 Jan 2014 18:05:44 +0100 Subject: [PATCH] Support separate specular maps --- files/materials/objects.mat | 7 +++++++ files/materials/objects.shader | 25 +++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/files/materials/objects.mat b/files/materials/objects.mat index 751b51243..2281226b0 100644 --- a/files/materials/objects.mat +++ b/files/materials/objects.mat @@ -8,6 +8,7 @@ material openmw_objects_base diffuseMap black.png normalMap emissiveMap + specMap darkMap use_emissive_map false use_detail_map false @@ -44,6 +45,7 @@ material openmw_objects_base emissiveMap $emissiveMap detailMap $detailMap diffuseMap $diffuseMap + specMap $specMap darkMap $darkMap env_map $env_map env_map_color $env_map_color @@ -107,6 +109,11 @@ material openmw_objects_base anim_texture2 textures\magicitem\caust.dds 32 2 colour_op add } + + texture_unit specMap + { + direct_texture $specMap + } texture_unit shadowMap0 { diff --git a/files/materials/objects.shader b/files/materials/objects.shader index 93368f1f6..ed75babdd 100644 --- a/files/materials/objects.shader +++ b/files/materials/objects.shader @@ -14,11 +14,14 @@ #define NEED_DEPTH #endif +#define SPECULAR 1 + #define NORMAL_MAP @shPropertyHasValue(normalMap) #define EMISSIVE_MAP @shPropertyHasValue(emissiveMap) #define DETAIL_MAP @shPropertyHasValue(detailMap) #define DIFFUSE_MAP @shPropertyHasValue(diffuseMap) #define DARK_MAP @shPropertyHasValue(darkMap) +#define SPEC_MAP @shPropertyHasValue(specMap) && SPECULAR #define PARALLAX @shPropertyBool(use_parallax) #define PARALLAX_SCALE 0.04 @@ -38,8 +41,6 @@ #define ENV_MAP @shPropertyBool(env_map) -#define SPECULAR 1 - #define NEED_NORMAL (!VERTEX_LIGHTING || ENV_MAP) || SPECULAR #ifdef SH_VERTEX_SHADER @@ -273,6 +274,10 @@ shUniform(float3, env_map_color) @shUniformProperty3f(env_map_color, env_map_color) #endif +#if SPEC_MAP + shSampler2D(specMap) +#endif + #if ENV_MAP || SPECULAR || PARALLAX shUniform(float3, cameraPosObjSpace) @shAutoConstant(cameraPosObjSpace, camera_position_object_space) #endif @@ -511,8 +516,20 @@ float NdotL = max(dot(normal, light0Dir), 0); float3 halfVec = normalize (light0Dir + eyeDir); - float3 specular = pow(max(dot(normal, halfVec), 0), matShininess) * lightSpec0 * matSpec; - shOutputColour(0).xyz += specular * shadow * diffuse.a; + float shininess = matShininess; +#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 #if FOG