diff --git a/WickedEngine/envMapPS.hlsl b/WickedEngine/envMapPS.hlsl index 24990fe14..4fc421af0 100644 --- a/WickedEngine/envMapPS.hlsl +++ b/WickedEngine/envMapPS.hlsl @@ -3,23 +3,23 @@ #define DIRECTIONALLIGHT_SOFT #include "dirLightHF.hlsli" +#include "objectHF.hlsli" + float4 main(PSIn input) : SV_TARGET { - float4 baseColor = g_xMat_diffuseColor; + OBJECT_PS_MAKE_COMMON - input.tex *= g_xMat_texMulAdd.xy; - input.tex += g_xMat_texMulAdd.zw; - - if (g_xMat_hasTex) { - baseColor *= texture_0.Sample(sampler_aniso_wrap, input.tex.xy); - } - baseColor.rgb *= input.instanceColor; + OBJECT_PS_NORMALMAPPING - //float lighting = dirLight(input.pos3D, input.nor, baseColor); - //lighting = saturate(dot(input.nor.xyz, g_xDirLight_direction.xyz)); - //baseColor.rgb *= lighting; + OBJECT_PS_SPECULARMAPPING - ALPHATEST(baseColor.a) + OBJECT_PS_DEGAMMA - return baseColor*(1 + g_xMat_emissive); + OBJECT_PS_DIRECTIONALLIGHT + + OBJECT_PS_GAMMA + + OBJECT_PS_FOG + + OBJECT_PS_OUT_FORWARD } \ No newline at end of file diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli index e728004da..7fbc303fa 100644 --- a/WickedEngine/objectHF.hlsli +++ b/WickedEngine/objectHF.hlsli @@ -11,6 +11,7 @@ #include "depthConvertHF.hlsli" #include "fogHF.hlsli" #include "globalsHF.hlsli" +#include "dirLightHF.hlsli" // DEFINITIONS ////////////////// @@ -80,7 +81,6 @@ inline void PlanarReflection(in float2 UV, in float2 reflectionUV, in float3 N, [branch]if (g_xMat_hasRef) { float colorMat = xReflectionMap.SampleLevel(sampler_aniso_wrap, UV, 0).r; - //normal = normalize(lerp(normal, PSIn.nor, pow(abs(colorMat.x), 0.02f))); float4 colorReflection = xReflection.SampleLevel(sampler_linear_clamp, reflectionUV + N.xz, 0); baseColor.rgb = lerp(baseColor.rgb, colorReflection.rgb, colorMat); } @@ -123,11 +123,13 @@ inline void EnvironmentReflection(in float3 N, in float3 V, in float3 P, in floa color.rgb += envCol.rgb * specularColor.rgb * metalness; } -inline void DirectionalLight(in float3 N, in float3 V, in float4 specularColor, inout float4 baseColor) +inline void DirectionalLight(in float3 P, in float3 N, in float3 V, in float4 specularColor, inout float4 baseColor) { - float3 light = saturate(dot(g_xWorld_SunDir.xyz, N)); + float3 light; + //light = dirLight(P, N, baseColor); + light = saturate(dot(N, g_xDirLight_direction.xyz)); light = clamp(light, g_xWorld_Ambient.rgb, 1); - baseColor.rgb *= light*g_xWorld_SunColor.rgb; + baseColor.rgb *= g_xWorld_SunColor.rgb * light; applySpecular(baseColor, g_xWorld_SunColor, N, V, g_xWorld_SunDir.xyz, 1, g_xMat_specular_power, specularColor.a, 0); } @@ -135,26 +137,30 @@ inline void DirectionalLight(in float3 N, in float3 V, in float4 specularColor, // MACROS //////////// -#define OBJECT_PS_MAKE \ - float3 N = normalize(PSIn.nor); \ - float3 P = PSIn.pos3D; \ +#define OBJECT_PS_MAKE_COMMON \ + float3 N = normalize(input.nor); \ + float3 P = input.pos3D; \ float3 V = normalize(P - g_xCamera_CamPos); \ float roughness = 1 - (g_xMat_specular_power / 128.0f); \ float metalness = g_xMat_metallic; \ - float2 UV = PSIn.tex * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw; \ + float2 UV = input.tex * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw; \ float4 specularColor = g_xMat_specular; \ - float2 refUV = float2(1, -1)*PSIn.ReflectionMapSamplingPos.xy / PSIn.ReflectionMapSamplingPos.w / 2.0f + 0.5f; \ - float2 ScreenCoord = float2(1, -1) * PSIn.pos2D.xy / PSIn.pos2D.w / 2.0f + 0.5f; \ - float2 ScreenCoordPrev = float2(1, -1)*PSIn.pos2DPrev.xy / PSIn.pos2DPrev.w / 2.0f + 0.5f; \ - float lineardepth = PSIn.pos2D.z; \ - float depth = PSIn.pos2D.z / PSIn.pos2D.w; \ float3 bumpColor = 0; \ - float4 baseColor = g_xMat_diffuseColor * float4(PSIn.instanceColor, 1); \ + float4 baseColor = g_xMat_diffuseColor * float4(input.instanceColor, 1); \ BaseColorMapping(UV, baseColor); \ - ALPHATEST(baseColor.a) + ALPHATEST(baseColor.a) \ + float depth = input.pos.z; + + +#define OBJECT_PS_MAKE \ + OBJECT_PS_MAKE_COMMON \ + float lineardepth = input.pos2D.z; \ + float2 refUV = float2(1, -1)*input.ReflectionMapSamplingPos.xy / input.ReflectionMapSamplingPos.w / 2.0f + 0.5f;\ + float2 ScreenCoord = float2(1, -1) * input.pos2D.xy / input.pos2D.w / 2.0f + 0.5f; \ + float2 ScreenCoordPrev = float2(1, -1)*input.pos2DPrev.xy / input.pos2DPrev.w / 2.0f + 0.5f; #define OBJECT_PS_DITHER \ - clip(dither(PSIn.pos.xy) - PSIn.dither); \ + clip(dither(input.pos.xy) - input.dither); \ #define OBJECT_PS_NORMALMAPPING \ NormalMapping(UV, V, N, bumpColor); @@ -166,10 +172,10 @@ inline void DirectionalLight(in float3 N, in float3 V, in float4 specularColor, EnvironmentReflection(N, V, P, roughness, metalness, specularColor, baseColor); #define OBJECT_PS_PLANARREFLECTIONS \ - PlanarReflection(PSIn.tex, refUV, N, baseColor); + PlanarReflection(input.tex, refUV, N, baseColor); #define OBJECT_PS_REFRACTION \ - Refraction(ScreenCoord, PSIn.nor2D, bumpColor, baseColor); + Refraction(ScreenCoord, input.nor2D, bumpColor, baseColor); #define OBJECT_PS_DEGAMMA \ baseColor = pow(abs(baseColor), GAMMA); @@ -181,13 +187,13 @@ inline void DirectionalLight(in float3 N, in float3 V, in float4 specularColor, baseColor.rgb = applyFog(baseColor.rgb, getFog(getLinearDepth(depth))); #define OBJECT_PS_DIRECTIONALLIGHT \ - DirectionalLight(N, V, specularColor, baseColor); + DirectionalLight(P, N, V, specularColor, baseColor); #define OBJECT_PS_OUT_GBUFFER \ bool unshaded = g_xMat_shadeless; \ float properties = unshaded ? RT_UNSHADED : 0.0f; \ PixelOutputType Out = (PixelOutputType)0; \ - Out.col = float4(baseColor.rgb*(1 + g_xMat_emissive)*PSIn.ao, 1); \ + Out.col = float4(baseColor.rgb*(1 + g_xMat_emissive)*input.ao, 1); \ Out.nor = float4(N.xyz, properties); \ Out.vel = float4(ScreenCoord - ScreenCoordPrev, g_xMat_specular_power, specularColor.a); \ return Out; diff --git a/WickedEngine/objectPS.hlsl b/WickedEngine/objectPS.hlsl index 0f4265bd6..79a008f80 100644 --- a/WickedEngine/objectPS.hlsl +++ b/WickedEngine/objectPS.hlsl @@ -1,6 +1,6 @@ #include "objectHF.hlsli" -PixelOutputType main(PixelInputType PSIn) +PixelOutputType main(PixelInputType input) { OBJECT_PS_DITHER diff --git a/WickedEngine/objectPS_blackout.hlsl b/WickedEngine/objectPS_blackout.hlsl index 4e0269c93..e8da8d65c 100644 --- a/WickedEngine/objectPS_blackout.hlsl +++ b/WickedEngine/objectPS_blackout.hlsl @@ -2,7 +2,7 @@ -float4 main(PixelInputType PSIn) : SV_TARGET +float4 main(PixelInputType input) : SV_TARGET { OBJECT_PS_MAKE diff --git a/WickedEngine/objectPS_forwardSimple.hlsl b/WickedEngine/objectPS_forwardSimple.hlsl index d7c476044..eedd8abda 100644 --- a/WickedEngine/objectPS_forwardSimple.hlsl +++ b/WickedEngine/objectPS_forwardSimple.hlsl @@ -1,6 +1,6 @@ #include "objectHF.hlsli" -float4 main(PixelInputType PSIn) : SV_TARGET +float4 main(PixelInputType input) : SV_TARGET { OBJECT_PS_DITHER diff --git a/WickedEngine/objectPS_textureonly.hlsl b/WickedEngine/objectPS_textureonly.hlsl index 0476ce429..c302257e0 100644 --- a/WickedEngine/objectPS_textureonly.hlsl +++ b/WickedEngine/objectPS_textureonly.hlsl @@ -2,7 +2,7 @@ -float4 main(PixelInputType PSIn) : SV_TARGET +float4 main(PixelInputType input) : SV_TARGET { OBJECT_PS_DITHER diff --git a/WickedEngine/objectPS_transparent.hlsl b/WickedEngine/objectPS_transparent.hlsl index ce152cc00..1be7ab8de 100644 --- a/WickedEngine/objectPS_transparent.hlsl +++ b/WickedEngine/objectPS_transparent.hlsl @@ -1,7 +1,7 @@ #include "objectHF.hlsli" -float4 main( PixelInputType PSIn) : SV_TARGET +float4 main( PixelInputType input) : SV_TARGET { OBJECT_PS_MAKE diff --git a/WickedEngine/waterPS.hlsl b/WickedEngine/waterPS.hlsl index 4f03a791f..b524790a2 100644 --- a/WickedEngine/waterPS.hlsl +++ b/WickedEngine/waterPS.hlsl @@ -5,7 +5,7 @@ #include "specularHF.hlsli" #include "globals.hlsli" -float4 main(PixelInputType PSIn) : SV_TARGET +float4 main(PixelInputType input) : SV_TARGET { OBJECT_PS_MAKE @@ -19,9 +19,9 @@ float4 main(PixelInputType PSIn) : SV_TARGET float2 bumpColor1=0; float2 bumpColor2=0; if(g_xMat_hasNor){ - float3x3 tangentFrame = compute_tangent_frame(N, V, -PSIn.tex); - bumpColor0 = 2.0f * xNormalMap.Sample(sampler_aniso_wrap,PSIn.tex - g_xMat_texMulAdd.ww).rg - 1.0f; - bumpColor1 = 2.0f * xNormalMap.Sample(sampler_aniso_wrap,PSIn.tex + g_xMat_texMulAdd.zw).rg - 1.0f; + float3x3 tangentFrame = compute_tangent_frame(N, V, -input.tex); + bumpColor0 = 2.0f * xNormalMap.Sample(sampler_aniso_wrap,input.tex - g_xMat_texMulAdd.ww).rg - 1.0f; + bumpColor1 = 2.0f * xNormalMap.Sample(sampler_aniso_wrap,input.tex + g_xMat_texMulAdd.zw).rg - 1.0f; bumpColor2 = xWaterRipples.Sample(sampler_aniso_wrap,ScreenCoord).rg; bumpColor= float3( bumpColor0+bumpColor1+bumpColor2,1 ) * g_xMat_refractionIndex; N = normalize(mul(normalize(bumpColor), tangentFrame)); @@ -29,7 +29,7 @@ float4 main(PixelInputType PSIn) : SV_TARGET //REFLECTION - float2 RefTex = float2(1, -1)*PSIn.ReflectionMapSamplingPos.xy / PSIn.ReflectionMapSamplingPos.w / 2.0f + 0.5f; + float2 RefTex = float2(1, -1)*input.ReflectionMapSamplingPos.xy / input.ReflectionMapSamplingPos.w / 2.0f + 0.5f; float4 reflectiveColor = xReflection.SampleLevel(sampler_linear_mirror,RefTex+bumpColor.rg,0);