From eee6eeeaf3afea5f076856f3f79ae0afc42b25cf Mon Sep 17 00:00:00 2001 From: turanszkij Date: Wed, 10 Feb 2016 23:20:06 +0100 Subject: [PATCH] objectshader refactor - part 2 --- WickedEngine/WickedEngine.vcxproj.filters | 18 +-- WickedEngine/dirLightHF.hlsli | 4 +- WickedEngine/lightHF.hlsli | 6 +- WickedEngine/objectHF.hlsli | 53 +++++++-- WickedEngine/objectPS.hlsl | 4 +- WickedEngine/objectPS_blackout.hlsl | 8 +- WickedEngine/objectPS_forwardSimple.hlsl | 66 ++--------- WickedEngine/objectPS_simplest.hlsl | 2 +- WickedEngine/objectPS_textureonly.hlsl | 13 +-- WickedEngine/objectPS_transparent.hlsl | 76 ++----------- WickedEngine/objectVS10.hlsl | 2 +- WickedEngine/objectVS_reflection.hlsl | 2 +- WickedEngine/pointLightPS.hlsl | 4 +- WickedEngine/specularHF.hlsli | 24 +--- WickedEngine/spotLightPS.hlsl | 4 +- WickedEngine/waterPS.hlsl | 133 ++++++++-------------- WickedEngine/wiRenderer.cpp | 22 ++-- WickedEngine/wiVersion.cpp | 2 +- 18 files changed, 153 insertions(+), 290 deletions(-) diff --git a/WickedEngine/WickedEngine.vcxproj.filters b/WickedEngine/WickedEngine.vcxproj.filters index ef194810b..587e7b2f3 100644 --- a/WickedEngine/WickedEngine.vcxproj.filters +++ b/WickedEngine/WickedEngine.vcxproj.filters @@ -1858,9 +1858,6 @@ shaders\headers - - shaders\headers - shaders\headers @@ -1913,6 +1910,9 @@ shaders\object + + shaders\lighting + @@ -1983,12 +1983,6 @@ shaders - - shaders - - - shaders - shaders\grass @@ -2178,6 +2172,12 @@ shaders\object + + shaders\object + + + shaders\object + diff --git a/WickedEngine/dirLightHF.hlsli b/WickedEngine/dirLightHF.hlsli index 52c070f5f..f487abab3 100644 --- a/WickedEngine/dirLightHF.hlsli +++ b/WickedEngine/dirLightHF.hlsli @@ -88,8 +88,8 @@ inline float dirLight(in float3 pos3D, in float3 normal, inout float4 color, in // MACROS #define DEFERRED_DIRLIGHT_MAIN \ - float lighting = dirLight(pos3D,normal,color,toonshaded); \ + float lighting = dirLight(P,N,color,toonshaded); \ color.rgb *= lighting; \ - applySpecular(color, color*lighting, normal, eyevector, g_xDirLight_direction.xyz, 1, specular_power, specular, toonshaded); + applySpecular(color, color*lighting, N, V, g_xDirLight_direction.xyz, 1, specular_power, specular, toonshaded); #endif // _DIRLIGHT_HF_ \ No newline at end of file diff --git a/WickedEngine/lightHF.hlsli b/WickedEngine/lightHF.hlsli index 9cac5627a..da3b3d3a0 100644 --- a/WickedEngine/lightHF.hlsli +++ b/WickedEngine/lightHF.hlsli @@ -33,10 +33,10 @@ static const float specularMaximumIntensity = 1; float4 material = texture_gbuffer2.SampleLevel(sampler_point_clamp,screenPos,0); \ float specular = material.w*specularMaximumIntensity; \ uint specular_power = material.z; \ - float3 normal = norU.xyz; \ + float3 N = norU.xyz; \ bool toonshaded = isToon(norU.w); \ - float3 pos3D = getPosition(screenPos, depth); \ - float3 eyevector = normalize(g_xCamera_CamPos - pos3D.xyz); + float3 P = getPosition(screenPos, depth); \ + float3 V = normalize(P - g_xCamera_CamPos); #define DEFERREDLIGHT_RETURN \ return max(unshaded? 1 : color, 0.0f); diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli index a6073d33b..e728004da 100644 --- a/WickedEngine/objectHF.hlsli +++ b/WickedEngine/objectHF.hlsli @@ -37,7 +37,7 @@ struct PixelInputType float ao : AMBIENT_OCCLUSION; nointerpolation float dither : DITHER; nointerpolation float3 instanceColor : INSTANCECOLOR; - float3 nor2D : NORMAL2D; + float2 nor2D : NORMAL2D; }; struct PixelOutputType @@ -58,11 +58,10 @@ inline void BaseColorMapping(in float2 UV, inout float4 baseColor) } } -inline void NormalMapping(in float2 UV, in float3 V, inout float3 N) +inline void NormalMapping(in float2 UV, in float3 V, inout float3 N, inout float3 bumpColor) { if (g_xMat_hasNor) { - float3 bumpColor = 0; float4 nortex = xNormalMap.Sample(sampler_aniso_wrap, UV); float3x3 tangentFrame = compute_tangent_frame(N, V, -UV); bumpColor = 2.0f * nortex.rgb - 1.0f; @@ -87,6 +86,14 @@ inline void PlanarReflection(in float2 UV, in float2 reflectionUV, in float3 N, } } +inline void Refraction(in float2 ScreenCoord, in float2 normal2D, in float3 bumpColor, inout float4 baseColor) +{ + float2 perturbatedRefrTexCoords = ScreenCoord.xy + (normal2D + bumpColor.rg) * g_xMat_refractionIndex; + float4 refractiveColor = (xRefraction.SampleLevel(sampler_linear_clamp, perturbatedRefrTexCoords, 0)); + baseColor.rgb = lerp(refractiveColor.rgb, baseColor.rgb, baseColor.a); + baseColor.a = 1; +} + // #define ENVMAP_CAMERA_BLEND inline void EnvironmentReflection(in float3 N, in float3 V, in float3 P, in float roughness, in float metalness, in float4 specularColor, inout float4 color) @@ -116,6 +123,14 @@ 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) +{ + float3 light = saturate(dot(g_xWorld_SunDir.xyz, N)); + light = clamp(light, g_xWorld_Ambient.rgb, 1); + baseColor.rgb *= light*g_xWorld_SunColor.rgb; + applySpecular(baseColor, g_xWorld_SunColor, N, V, g_xWorld_SunDir.xyz, 1, g_xMat_specular_power, specularColor.a, 0); +} + // MACROS //////////// @@ -131,16 +146,18 @@ inline void EnvironmentReflection(in float3 N, in float3 V, in float3 P, in floa 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 depth = PSIn.pos.z / PSIn.pos.w; \ + 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); \ - BaseColorMapping(UV, baseColor); - -#define OBJECT_PS_MISC \ - clip(dither(PSIn.pos.xy) - PSIn.dither); \ + BaseColorMapping(UV, baseColor); \ ALPHATEST(baseColor.a) +#define OBJECT_PS_DITHER \ + clip(dither(PSIn.pos.xy) - PSIn.dither); \ + #define OBJECT_PS_NORMALMAPPING \ - NormalMapping(UV, V, N); + NormalMapping(UV, V, N, bumpColor); #define OBJECT_PS_SPECULARMAPPING \ SpecularMapping(UV, specularColor); @@ -151,6 +168,21 @@ inline void EnvironmentReflection(in float3 N, in float3 V, in float3 P, in floa #define OBJECT_PS_PLANARREFLECTIONS \ PlanarReflection(PSIn.tex, refUV, N, baseColor); +#define OBJECT_PS_REFRACTION \ + Refraction(ScreenCoord, PSIn.nor2D, bumpColor, baseColor); + +#define OBJECT_PS_DEGAMMA \ + baseColor = pow(abs(baseColor), GAMMA); + +#define OBJECT_PS_GAMMA \ + baseColor = pow(abs(baseColor*(1 + g_xMat_emissive)), INV_GAMMA); + +#define OBJECT_PS_FOG \ + baseColor.rgb = applyFog(baseColor.rgb, getFog(getLinearDepth(depth))); + +#define OBJECT_PS_DIRECTIONALLIGHT \ + DirectionalLight(N, V, specularColor, baseColor); + #define OBJECT_PS_OUT_GBUFFER \ bool unshaded = g_xMat_shadeless; \ float properties = unshaded ? RT_UNSHADED : 0.0f; \ @@ -160,4 +192,7 @@ inline void EnvironmentReflection(in float3 N, in float3 V, in float3 P, in floa Out.vel = float4(ScreenCoord - ScreenCoordPrev, g_xMat_specular_power, specularColor.a); \ return Out; +#define OBJECT_PS_OUT_FORWARD \ + return baseColor; + #endif // _OBJECTSHADER_HF_ \ No newline at end of file diff --git a/WickedEngine/objectPS.hlsl b/WickedEngine/objectPS.hlsl index 4a5296873..0f4265bd6 100644 --- a/WickedEngine/objectPS.hlsl +++ b/WickedEngine/objectPS.hlsl @@ -2,9 +2,9 @@ PixelOutputType main(PixelInputType PSIn) { - OBJECT_PS_MAKE + OBJECT_PS_DITHER - OBJECT_PS_MISC + OBJECT_PS_MAKE OBJECT_PS_NORMALMAPPING diff --git a/WickedEngine/objectPS_blackout.hlsl b/WickedEngine/objectPS_blackout.hlsl index dbff4c82a..4e0269c93 100644 --- a/WickedEngine/objectPS_blackout.hlsl +++ b/WickedEngine/objectPS_blackout.hlsl @@ -4,13 +4,7 @@ float4 main(PixelInputType PSIn) : SV_TARGET { - float4 baseColor = float4(0,0,0,0); - - if(g_xMat_hasTex) { - baseColor = xTextureMap.Sample(sampler_aniso_wrap,PSIn.tex); - } - - ALPHATEST(baseColor.a) + OBJECT_PS_MAKE return float4(0, 0, 0, 1); } \ No newline at end of file diff --git a/WickedEngine/objectPS_forwardSimple.hlsl b/WickedEngine/objectPS_forwardSimple.hlsl index 5d689516d..d7c476044 100644 --- a/WickedEngine/objectPS_forwardSimple.hlsl +++ b/WickedEngine/objectPS_forwardSimple.hlsl @@ -1,69 +1,23 @@ #include "objectHF.hlsli" - - float4 main(PixelInputType PSIn) : SV_TARGET { - clip(dither(PSIn.pos.xy) - PSIn.dither); + OBJECT_PS_DITHER - float4 baseColor = g_xMat_diffuseColor; - float depth = PSIn.pos2D.z; + OBJECT_PS_MAKE - PSIn.tex *= g_xMat_texMulAdd.xy; - PSIn.tex += g_xMat_texMulAdd.zw; + OBJECT_PS_NORMALMAPPING - if (g_xMat_hasTex) { - baseColor *= xTextureMap.Sample(sampler_aniso_wrap, PSIn.tex); - } - baseColor.rgb *= PSIn.instanceColor; + OBJECT_PS_SPECULARMAPPING - ALPHATEST(baseColor.a) + OBJECT_PS_DEGAMMA - if (!g_xMat_shadeless.x) - { - float4 spec = g_xMat_specular; - float3 normal = normalize(PSIn.nor); - float3 eyevector = normalize(g_xCamera_CamPos - PSIn.pos3D); + OBJECT_PS_DIRECTIONALLIGHT - baseColor = pow(abs(baseColor), GAMMA); - //NORMALMAP - float3 bumpColor = 0; - if (g_xMat_hasNor){ - float4 nortex = xNormalMap.Sample(sampler_aniso_wrap, PSIn.tex); - if (nortex.a>0){ - float3x3 tangentFrame = compute_tangent_frame(normal, eyevector, -PSIn.tex.xy); - bumpColor = 2.0f * nortex.rgb - 1.0f; - //bumpColor.g*=-1; - normal = normalize(mul(bumpColor, tangentFrame)); - } - } + OBJECT_PS_GAMMA + + OBJECT_PS_FOG - spec = lerp(spec, xSpecularMap.Sample(sampler_aniso_wrap, PSIn.tex).r, g_xMat_hasSpe); - - //ENVIROMENT MAP - float4 envCol = 0; - { - uint mip = 0; - float2 size; - float mipLevels; - texture_env_global.GetDimensions(mip, size.x, size.y, mipLevels); - - float3 ref = normalize(reflect(-eyevector, normal)); - envCol = texture_env_global.SampleLevel(sampler_linear_clamp, ref, (1 - smoothstep(0, 128, g_xMat_specular_power))*mipLevels); - baseColor = lerp(baseColor, envCol, g_xMat_metallic*spec); - } - - float3 light = saturate( dot(g_xWorld_SunDir.xyz,normalize(PSIn.nor)) ); - light=clamp(light, g_xWorld_Ambient.rgb,1); - baseColor.rgb *= light*g_xWorld_SunColor.rgb; - - applySpecular(baseColor, g_xWorld_SunColor, normal, eyevector, g_xWorld_SunDir.xyz, 1, g_xMat_specular_power, spec.a, 0); - - baseColor = pow(abs(baseColor*(1 + g_xMat_emissive)), INV_GAMMA); - - baseColor.rgb = applyFog(baseColor.rgb, getFog(getLinearDepth(depth / PSIn.pos2D.w))); - } - - return baseColor; + OBJECT_PS_OUT_FORWARD } diff --git a/WickedEngine/objectPS_simplest.hlsl b/WickedEngine/objectPS_simplest.hlsl index c0ea37cb0..5235d150f 100644 --- a/WickedEngine/objectPS_simplest.hlsl +++ b/WickedEngine/objectPS_simplest.hlsl @@ -4,6 +4,6 @@ float4 main(PixelInputType PSIn) : SV_TARGET { - return g_xMat_diffuseColor; + return g_xMat_diffuseColor * float4(PSIn.instanceColor,1); } diff --git a/WickedEngine/objectPS_textureonly.hlsl b/WickedEngine/objectPS_textureonly.hlsl index 34b55677e..0476ce429 100644 --- a/WickedEngine/objectPS_textureonly.hlsl +++ b/WickedEngine/objectPS_textureonly.hlsl @@ -4,18 +4,9 @@ float4 main(PixelInputType PSIn) : SV_TARGET { - float4 baseColor = g_xMat_diffuseColor; - - PSIn.tex *= g_xMat_texMulAdd.xy; - PSIn.tex += g_xMat_texMulAdd.zw; - - if(g_xMat_hasTex) { - baseColor *= xTextureMap.Sample(sampler_aniso_wrap,PSIn.tex); - } - baseColor.rgb *= PSIn.instanceColor; - - ALPHATEST(baseColor.a) + OBJECT_PS_DITHER + OBJECT_PS_MAKE return baseColor*(1 + g_xMat_emissive); } diff --git a/WickedEngine/objectPS_transparent.hlsl b/WickedEngine/objectPS_transparent.hlsl index 4d50146fc..ce152cc00 100644 --- a/WickedEngine/objectPS_transparent.hlsl +++ b/WickedEngine/objectPS_transparent.hlsl @@ -3,79 +3,23 @@ float4 main( PixelInputType PSIn) : SV_TARGET { - float3 normal = normalize(PSIn.nor); - //uint mat = PSIn.mat; - float4 spec = g_xMat_specular; - float4 baseColor = g_xMat_diffuseColor; + OBJECT_PS_MAKE - PSIn.tex *= g_xMat_texMulAdd.xy; - PSIn.tex += g_xMat_texMulAdd.zw; - - [branch]if(g_xMat_hasTex){ - baseColor *= xTextureMap.Sample(sampler_aniso_wrap, PSIn.tex); - } - baseColor.rgb *= PSIn.instanceColor; + OBJECT_PS_NORMALMAPPING - ALPHATEST(baseColor.a) + OBJECT_PS_REFRACTION - float3 eyevector = normalize(g_xCamera_CamPos - PSIn.pos3D); - float2 screenPos; - screenPos.x = PSIn.pos2D.x/PSIn.pos2D.w/2.0f + 0.5f; - screenPos.y = -PSIn.pos2D.y/PSIn.pos2D.w/2.0f + 0.5f; - + OBJECT_PS_DEGAMMA + OBJECT_PS_SPECULARMAPPING - //NORMALMAP - float3 bumpColor=0; - if(g_xMat_hasNor){ - float4 nortex = xNormalMap.Sample(sampler_aniso_wrap,PSIn.tex); - if(nortex.a>0){ - float3x3 tangentFrame = compute_tangent_frame(normal, eyevector, -PSIn.tex.xy); - bumpColor = 2.0f * nortex.rgb - 1.0f; - //bumpColor.g*=-1; - normal = normalize(mul(bumpColor, tangentFrame)); - } - } + OBJECT_PS_ENVIRONMENTMAPPING - + OBJECT_PS_DIRECTIONALLIGHT - //ENVIROMENT MAP - float4 envCol=0; - { - uint mip=0; - float2 size; - float mipLevels; - texture_env_global.GetDimensions(mip,size.x,size.y,mipLevels); + OBJECT_PS_GAMMA - float3 ref = normalize(reflect(-eyevector, normal)); - envCol = texture_env_global.SampleLevel(sampler_linear_clamp,ref,(1-smoothstep(0,128, g_xMat_specular_power))*mipLevels); - baseColor = lerp(baseColor,envCol, g_xMat_metallic*spec); - } - - - //REFRACTION - float2 perturbatedRefrTexCoords = screenPos.xy + (normalize(PSIn.nor2D).rg + bumpColor.rg) * g_xMat_refractionIndex; - float4 refractiveColor = (xRefraction.SampleLevel(sampler_linear_clamp, perturbatedRefrTexCoords, 0)); - baseColor.rgb=lerp(refractiveColor.rgb,baseColor.rgb,baseColor.a); - - baseColor.rgb=pow(abs(baseColor.rgb),GAMMA); - baseColor.a=1; - - float depth = PSIn.pos2D.z; - + OBJECT_PS_FOG - //SPECULAR - if(g_xMat_hasSpe && !g_xMat_shadeless){ - spec = xSpecularMap.Sample(sampler_aniso_wrap, PSIn.tex); - } - [branch]if(!g_xMat_shadeless.x){ - baseColor.rgb*=clamp( saturate( abs(dot(g_xWorld_SunDir.xyz,PSIn.nor)) * g_xWorld_SunColor.rgb ), g_xWorld_Ambient.rgb,1 ); - applySpecular(baseColor, g_xWorld_SunColor, normal, eyevector, g_xWorld_SunDir.xyz, 1, g_xMat_specular_power, spec.w, 0); - } - - baseColor.rgb = pow(abs(baseColor.rgb*(1 + g_xMat_emissive)), INV_GAMMA); - - baseColor.rgb = applyFog(baseColor.rgb,getFog(getLinearDepth(depth/PSIn.pos2D.w))); - - return baseColor; + OBJECT_PS_OUT_FORWARD } \ No newline at end of file diff --git a/WickedEngine/objectVS10.hlsl b/WickedEngine/objectVS10.hlsl index b517c552d..feaa9b7c5 100644 --- a/WickedEngine/objectVS10.hlsl +++ b/WickedEngine/objectVS10.hlsl @@ -47,7 +47,7 @@ PixelInputType main(Input input) Out.pos3D = pos.xyz; Out.tex = input.tex.xy; Out.nor = normalize(normal); - Out.nor2D = mul(Out.nor.xyz, (float3x3)g_xCamera_VP); + Out.nor2D = mul(Out.nor.xyz, (float3x3)g_xCamera_VP).xy; Out.ReflectionMapSamplingPos = mul(pos, g_xCamera_ReflVP); diff --git a/WickedEngine/objectVS_reflection.hlsl b/WickedEngine/objectVS_reflection.hlsl index 024ac92a8..b3774a18e 100644 --- a/WickedEngine/objectVS_reflection.hlsl +++ b/WickedEngine/objectVS_reflection.hlsl @@ -39,7 +39,7 @@ PixelInputType main(Input input) Out.pos3D = pos.xyz; Out.tex = input.tex.xy; Out.nor = normalize(normal); - Out.nor2D = float3(0,0,0); + Out.nor2D = float2(0,0); Out.ReflectionMapSamplingPos = float4(0,0,0,0); diff --git a/WickedEngine/pointLightPS.hlsl b/WickedEngine/pointLightPS.hlsl index 3dc9cbbbf..de2bca785 100644 --- a/WickedEngine/pointLightPS.hlsl +++ b/WickedEngine/pointLightPS.hlsl @@ -8,9 +8,9 @@ float4 main(VertexToPixel PSIn) : SV_TARGET float3 lightDir; float attenuation; - float lightInt = pointLight(pos3D, normal, lightDir, attenuation, toonshaded); + float lightInt = pointLight(P, N, lightDir, attenuation, toonshaded); color *= lightInt; - applySpecular(color, color * lightInt, normal, eyevector, lightDir, 1, specular_power, specular, toonshaded); + applySpecular(color, color * lightInt, N, V, lightDir, 1, specular_power, specular, toonshaded); color *= attenuation; DEFERREDLIGHT_RETURN diff --git a/WickedEngine/specularHF.hlsli b/WickedEngine/specularHF.hlsli index 1f711d190..d5c73c982 100644 --- a/WickedEngine/specularHF.hlsli +++ b/WickedEngine/specularHF.hlsli @@ -4,36 +4,18 @@ #include "toonHF.hlsli" #include "gammaHF.hlsli" -inline void applySpecular(inout float4 color, in float4 lightColor, in float3 normal, in float3 eyevector, in float3 lightDir +inline void applySpecular(inout float4 color, in float4 lightColor, in float3 N, in float3 V, in float3 lightDir , in float fresnelValue, in int specular_power, in float intensity, in bool toonshaded) { if(specular_power){ - //float3 reflectionVector = reflect(lightDir.xyz, normal.xyz); - //float spec = dot((reflectionVector), eyevector); - //spec = pow(saturate(-spec), specular_power)*intensity; - //color.rgb += (lightColor.rgb * spec); - //color.rgb*=1+spec; - ////color.a=spec; - - - float3 reflectionVector = normalize(lightDir.xyz + eyevector.xyz); - float spec = saturate( dot(reflectionVector, normal) ); + float3 reflectionVector = normalize(lightDir.xyz - V.xyz); + float spec = saturate( dot(reflectionVector, N) ); spec = pow(spec, specular_power)*intensity; if(toonshaded) toon(spec); color.rgb += (lightColor.rgb * spec); color.rgb*=pow(abs(1+spec),GAMMA); - - - //float3 h = normalize(lightDir.xyz + eyevector.xyz); // Half-vector. - //float specBase = saturate(dot(normal.xyz, h)); // Regular spec. - //float fresnel = 1.0 - dot(eyevector, h); // Caculate fresnel. - //fresnel = pow(fresnel, 5.0); - //fresnel += fresnelValue * (1.0 - fresnel); - //float finalSpec = pow(specBase, specular_power) * intensity * fresnel; - //color.rgb += lightColor.rgb * finalSpec; - //color.rgb *= 1+finalSpec; } } diff --git a/WickedEngine/spotLightPS.hlsl b/WickedEngine/spotLightPS.hlsl index 617301e59..2d33dfeb0 100644 --- a/WickedEngine/spotLightPS.hlsl +++ b/WickedEngine/spotLightPS.hlsl @@ -8,9 +8,9 @@ float4 main(VertexToPixel PSIn) : SV_TARGET float attenuation; float3 lightToPixel; - float lightInt = spotLight(pos3D, normal, attenuation, lightToPixel, toonshaded); + float lightInt = spotLight(P, N, attenuation, lightToPixel, toonshaded); color *= lightInt; - applySpecular(color, color * lightInt, normal, eyevector, lightToPixel, 1, specular_power, specular, toonshaded); + applySpecular(color, color * lightInt, N, V, lightToPixel, 1, specular_power, specular, toonshaded); color *= attenuation; DEFERREDLIGHT_RETURN diff --git a/WickedEngine/waterPS.hlsl b/WickedEngine/waterPS.hlsl index cc9844f71..4f03a791f 100644 --- a/WickedEngine/waterPS.hlsl +++ b/WickedEngine/waterPS.hlsl @@ -5,100 +5,63 @@ #include "specularHF.hlsli" #include "globals.hlsli" -//Texture2D xDepthMap:register(t7); -//Texture2D xRippleMap:register(t8); - -float4 main( PixelInputType PSIn) : SV_TARGET +float4 main(PixelInputType PSIn) : SV_TARGET { - PixelOutputType Out = (PixelOutputType)0; + OBJECT_PS_MAKE - float3 normal = normalize(PSIn.nor); - float4 spec = g_xMat_specular; - float4 baseColor = float4(0,0,0,1); + OBJECT_PS_SPECULARMAPPING + + + baseColor.a = 1; + + //NORMALMAP + float2 bumpColor0=0; + 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; + bumpColor2 = xWaterRipples.Sample(sampler_aniso_wrap,ScreenCoord).rg; + bumpColor= float3( bumpColor0+bumpColor1+bumpColor2,1 ) * g_xMat_refractionIndex; + N = normalize(mul(normalize(bumpColor), tangentFrame)); + } + + + //REFLECTION + float2 RefTex = float2(1, -1)*PSIn.ReflectionMapSamplingPos.xy / PSIn.ReflectionMapSamplingPos.w / 2.0f + 0.5f; + float4 reflectiveColor = xReflection.SampleLevel(sampler_linear_mirror,RefTex+bumpColor.rg,0); + - PSIn.tex *= g_xMat_texMulAdd.xy; - - float3 eyevector = normalize(g_xCamera_CamPos - PSIn.pos3D); - float2 screenPos; - screenPos.x = PSIn.pos2D.x/PSIn.pos2D.w/2.0f + 0.5f; - screenPos.y = -PSIn.pos2D.y/PSIn.pos2D.w/2.0f + 0.5f; + //REFRACTION + float2 perturbatedRefrTexCoords = ScreenCoord.xy + bumpColor.rg; + float refDepth = (texture_lineardepth.Sample(sampler_linear_mirror, ScreenCoord)); + float3 refractiveColor = xRefraction.SampleLevel(sampler_linear_mirror, perturbatedRefrTexCoords, 0).rgb; + float eyeDot = dot(N, -V); + float mod = saturate(0.05*(refDepth- lineardepth)); + float3 dullColor = lerp(refractiveColor, g_xMat_diffuseColor.rgb, saturate(eyeDot)); + refractiveColor = lerp(refractiveColor, dullColor, mod).rgb; + //FRESNEL TERM + float fresnelTerm = abs(eyeDot); + baseColor.rgb = lerp(reflectiveColor.rgb, refractiveColor, fresnelTerm); - - //NORMALMAP - float2 bumpColor0=0; - float2 bumpColor1=0; - float2 bumpColor2=0; - float3 bumpColor=0; - if(g_xMat_hasNor){ - float3x3 tangentFrame = compute_tangent_frame(normal, eyevector, -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; - bumpColor2 = xWaterRipples.Sample(sampler_aniso_wrap,screenPos).rg; - bumpColor= float3( bumpColor0+bumpColor1+bumpColor2,1 ) * g_xMat_refractionIndex; - normal = normalize(mul(normalize(bumpColor), tangentFrame)); - //normal = (bumpColor.x * PSIn.tan) + (bumpColor.y * PSIn.bin) + (bumpColor.z * PSIn.nor); - //normal = normalize(normal); - } - - - ////ENVIROMENT MAP - //float3 ref = (reflect(-eyevector, normal)); - //float3 skyColor = enviroTex.Sample(texSampler,ref).rgb; - - //REFLECTION - float2 RefTex; - RefTex.x = PSIn.ReflectionMapSamplingPos.x/PSIn.ReflectionMapSamplingPos.w/2.0f + 0.5f; - RefTex.y = -PSIn.ReflectionMapSamplingPos.y/PSIn.ReflectionMapSamplingPos.w/2.0f + 0.5f; - float4 reflectiveColor = xReflection.SampleLevel(sampler_linear_mirror,RefTex+bumpColor.rg,0); - - //reflectiveColor.rgb = lerp(skyColor, reflectiveColor.rgb, reflectiveColor.a); - - //REFRACTION - float2 perturbatedRefrTexCoords = screenPos.xy + bumpColor.rg; - float depth = PSIn.pos2D.z; - float refDepth = (texture_lineardepth.Sample(sampler_linear_mirror, screenPos)); - float3 refractiveColor = xRefraction.SampleLevel(sampler_linear_mirror, perturbatedRefrTexCoords, 0).rgb; - float eyeDot = dot(normal, eyevector); - float mod = saturate(0.05*(refDepth-depth)); - float3 dullColor = lerp(refractiveColor, g_xMat_diffuseColor.rgb, saturate(eyeDot)); - refractiveColor = lerp(refractiveColor, dullColor, mod).rgb; - - //FRESNEL TERM - float fresnelTerm = abs(eyeDot); - baseColor.rgb = lerp(reflectiveColor.rgb, refractiveColor, fresnelTerm); - - //DULL COLOR - baseColor.rgb = lerp(baseColor.rgb, g_xMat_diffuseColor.rgb, 0.16); - - baseColor.rgb=pow(abs(baseColor.rgb),GAMMA); + //DULL COLOR + baseColor.rgb = lerp(baseColor.rgb, g_xMat_diffuseColor.rgb, 0.16); - //SOFT EDGE - float fade = saturate(0.3* abs(refDepth-depth)); - baseColor.a*=fade; + //SOFT EDGE + float fade = saturate(0.3* abs(refDepth- lineardepth)); + baseColor.a*=fade; + + + OBJECT_PS_DEGAMMA - baseColor.rgb*= clamp( saturate( abs(dot(g_xWorld_SunDir.xyz,PSIn.nor)) *g_xWorld_SunColor.rgb ), g_xWorld_Ambient.rgb,1 ); - - //SPECULAR - if(g_xMat_hasSpe){ - spec = xSpecularMap.Sample(sampler_aniso_wrap, PSIn.tex); - } - /*float3 reflectionVector = reflect(xSun, normal); - float specR = dot(normalize(reflectionVector), eyevector); - specR = pow(abs(specR), specular_power)*spec.w; - baseColor.rgb += saturate(xSunColor.rgb) * specR;*/ - applySpecular(baseColor, g_xWorld_SunColor, normal, eyevector, g_xWorld_SunDir.xyz, 1, g_xMat_specular_power, spec.w, 0); + OBJECT_PS_DIRECTIONALLIGHT + OBJECT_PS_GAMMA - baseColor.rgb = pow(abs(baseColor.rgb*(1 + g_xMat_emissive)), INV_GAMMA); + OBJECT_PS_FOG - baseColor.rgb = applyFog(baseColor.rgb,getFog(getLinearDepth(depth/PSIn.pos2D.w))); - - //Out.col = saturate(baseColor); - //Out.nor = float4((normal),1); - //Out.spe = saturate(spec); - //Out.vel = float4(PSIn.vel*float3(-1,1,1),1); - - return baseColor; + OBJECT_PS_OUT_FORWARD } \ No newline at end of file diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 33536d01b..102716476 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -770,7 +770,7 @@ void wiRenderer::LoadBasicShaders() { "COLOR_DITHER", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, }; UINT numElements = ARRAYSIZE(layout); - VertexShaderInfo* vsinfo = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectVS10.cso", wiResourceManager::VERTEXSHADER, layout, numElements)); + VertexShaderInfo* vsinfo = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS10.cso", wiResourceManager::VERTEXSHADER, layout, numElements)); if (vsinfo != nullptr){ vertexShaders[VSTYPE_EFFECT10] = vsinfo->vertexShader; vertexLayouts[VLTYPE_EFFECT] = vsinfo->vertexLayout; @@ -811,8 +811,8 @@ void wiRenderer::LoadBasicShaders() } - vertexShaders[VSTYPE_EFFECT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader; - vertexShaders[VSTYPE_EFFECT_REFLECTION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectVS_reflection.cso", wiResourceManager::VERTEXSHADER))->vertexShader; + vertexShaders[VSTYPE_EFFECT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader; + vertexShaders[VSTYPE_EFFECT_REFLECTION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_reflection.cso", wiResourceManager::VERTEXSHADER))->vertexShader; vertexShaders[VSTYPE_DIRLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "dirLightVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader; vertexShaders[VSTYPE_POINTLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "pointLightVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader; vertexShaders[VSTYPE_SPOTLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "spotLightVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader; @@ -822,12 +822,12 @@ void wiRenderer::LoadBasicShaders() vertexShaders[VSTYPE_ENVMAP] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMapVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader; vertexShaders[VSTYPE_ENVMAP_SKY] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMap_skyVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader; - pixelShaders[PSTYPE_EFFECT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_EFFECT_TRANSPARENT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectPS_transparent.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_SIMPLEST] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectPS_simplest.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_EFFECT_FORWARDSIMPLE] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectPS_forwardSimple.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_BLACKOUT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectPS_blackout.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_TEXTUREONLY] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectPS_textureonly.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_EFFECT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_EFFECT_TRANSPARENT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_transparent.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_SIMPLEST] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_simplest.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_EFFECT_FORWARDSIMPLE] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forwardSimple.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_BLACKOUT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_blackout.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_TEXTUREONLY] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_textureonly.cso", wiResourceManager::PIXELSHADER)); pixelShaders[PSTYPE_DIRLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "dirLightPS.cso", wiResourceManager::PIXELSHADER)); pixelShaders[PSTYPE_DIRLIGHT_SOFT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "dirLightSoftPS.cso", wiResourceManager::PIXELSHADER)); pixelShaders[PSTYPE_POINTLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "pointLightPS.cso", wiResourceManager::PIXELSHADER)); @@ -861,8 +861,8 @@ void wiRenderer::LoadLineShaders() } void wiRenderer::LoadTessShaders() { - hullShaders[HSTYPE_EFFECT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectHS.cso", wiResourceManager::HULLSHADER)); - domainShaders[DSTYPE_EFFECT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "effectDS.cso", wiResourceManager::DOMAINSHADER)); + hullShaders[HSTYPE_EFFECT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectHS.cso", wiResourceManager::HULLSHADER)); + domainShaders[DSTYPE_EFFECT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectDS.cso", wiResourceManager::DOMAINSHADER)); } void wiRenderer::LoadSkyShaders() diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index dabc2f781..69cd3d411 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -7,7 +7,7 @@ namespace wiVersion // minor features, major bug fixes const int minor = 6; // minor bug fixes, alterations, refactors - const int revision = 7; + const int revision = 8; long GetVersion()