From 78a67a03fadca08ec268dccce1b419e4b1e377e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ko=C5=BCuchowski?= Date: Tue, 19 May 2020 17:14:17 +0200 Subject: [PATCH] Back to uniform med/high shaders. Allowed more brightness control --- src/shaders/ShipMaterialP2.hlsl | 15 +++++++++++---- src/shaders/ShipMaterialP3.hlsl | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/shaders/ShipMaterialP2.hlsl b/src/shaders/ShipMaterialP2.hlsl index 3dfa58d..afb465b 100644 --- a/src/shaders/ShipMaterialP2.hlsl +++ b/src/shaders/ShipMaterialP2.hlsl @@ -16,6 +16,16 @@ bool UseNormalMap; static const float3 lDir = float3(0,0,1); +float3 getLightContribution(float3 Normal) +{ + float diffuse = saturate(dot(Normal, lDir)); + float3 Reflect = normalize(4.0 * diffuse * Normal - lDir); + float specFac = saturate(dot(Reflect, lDir)); + float specular = pow(specFac, SpecularExponent); + + return clamp(diffuse + specular, 0.25, 1); +} + float4 pixelMain ( float2 TexCoords : TEXCOORD0, @@ -48,10 +58,7 @@ float4 pixelMain albedoColor = lerp(albedoColor, tex2D(EnvMapSampler, refCoords), 0.5); } - - float diffuse = clamp(dot(Normal, lDir), 0.25, 1); - float3 finalLightColor = diffuse + (AmbientColor / 4); - + float3 finalLightColor = getLightContribution(Normal) + (AmbientColor / 3); float4 finalColor = saturate(albedoColor * float4(finalLightColor.xyz, 1.0)); finalColor.a = saturate(DiffuseTint.a); diff --git a/src/shaders/ShipMaterialP3.hlsl b/src/shaders/ShipMaterialP3.hlsl index 47af01f..afb465b 100644 --- a/src/shaders/ShipMaterialP3.hlsl +++ b/src/shaders/ShipMaterialP3.hlsl @@ -20,7 +20,7 @@ float3 getLightContribution(float3 Normal) { float diffuse = saturate(dot(Normal, lDir)); float3 Reflect = normalize(4.0 * diffuse * Normal - lDir); - float specFac = clamp(dot(Reflect, lDir),0, 0.97); + float specFac = saturate(dot(Reflect, lDir)); float specular = pow(specFac, SpecularExponent); return clamp(diffuse + specular, 0.25, 1); @@ -58,7 +58,7 @@ float4 pixelMain albedoColor = lerp(albedoColor, tex2D(EnvMapSampler, refCoords), 0.5); } - float3 finalLightColor = getLightContribution(Normal) + (AmbientColor / 4); + float3 finalLightColor = getLightContribution(Normal) + (AmbientColor / 3); float4 finalColor = saturate(albedoColor * float4(finalLightColor.xyz, 1.0)); finalColor.a = saturate(DiffuseTint.a);