From a41eee9a721c643368eb92909684cecb95d6a15b Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 6 Apr 2012 14:07:52 +0200 Subject: [PATCH] specular lighting --- apps/openmw/mwrender/renderingmanager.cpp | 1 + files/water/water.cg | 17 +++++++++++++++-- files/water/water.material | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index afa54b30c..4b38cb148 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -406,6 +406,7 @@ void RenderingManager::skipAnimation (const MWWorld::Ptr& ptr) void RenderingManager::setSunColour(const Ogre::ColourValue& colour) { mSun->setDiffuseColour(colour); + mSun->setSpecularColour(colour); mTerrainManager->setDiffuse(colour); } diff --git a/files/water/water.cg b/files/water/water.cg index 188c37709..18ef0a757 100644 --- a/files/water/water.cg +++ b/files/water/water.cg @@ -37,6 +37,8 @@ void main_fp , in float iDepth : TEXCOORD2 , in float4 iEyeVector : TEXCOORD3 , uniform float renderTargetFlipping + , uniform float4 lightPosObjSpace0 + , uniform float4 lightSpecularColour0 , uniform sampler2D reflectionMap : register(s0) , uniform sampler2D refractionMap : register(s1) @@ -74,11 +76,22 @@ void main_fp // tangent to object space normal.xyz = normal.xzy; + iEyeVector.xyz = normalize(iEyeVector.xyz); + // fresnel - float facing = 1.0 - max(abs(dot(normalize(iEyeVector.xyz), normal.xyz)), 0); + float facing = 1.0 - max(abs(dot(iEyeVector.xyz, normal.xyz)), 0); float reflectionFactor = saturate(0.35 + 0.65 * pow(facing, 2)); - oColor.xyz = lerp(refraction.xyz, reflection.xyz, depth1 * reflectionFactor); + // specular + float3 lightDir = normalize(lightPosObjSpace0.xyz); // assumes that light 0 is a directional light + float3 halfVector = normalize(iEyeVector + lightDir); + float specular = pow(max(dot(normal.xyz, halfVector.xyz), 0), 64); + + float opacity = depth1 * saturate(reflectionFactor + specular); + + reflection.xyz += lightSpecularColour0.xyz * specular; + + oColor.xyz = lerp(refraction.xyz, reflection.xyz, opacity); float fogValue = saturate((iDepth - fogParams.y) * fogParams.w); oColor.xyz = lerp(oColor.xyz, fogColour, fogValue); diff --git a/files/water/water.material b/files/water/water.material index f21f929d4..d0cadfc09 100644 --- a/files/water/water.material +++ b/files/water/water.material @@ -54,6 +54,8 @@ material Water param_named_auto fogParams fog_params param_named_auto renderTargetFlipping render_target_flipping param_named_auto far far_clip_distance + param_named_auto lightPosObjSpace0 light_position_object_space 0 + param_named_auto lightSpecularColour0 light_specular_colour 0 } texture_unit reflectionMap