From af7cb4f3d5f10693075fdce229f98f1b1b7fe831 Mon Sep 17 00:00:00 2001 From: Turanszki Janos Date: Wed, 4 Nov 2020 20:34:56 +0100 Subject: [PATCH] improved cartoon shading --- WickedEngine/brdf.hlsli | 9 +++++++++ WickedEngine/lightingHF.hlsli | 16 ++++++++-------- WickedEngine/objectPS_cartoon.hlsl | 2 +- WickedEngine/objectPS_transparent_cartoon.hlsl | 2 +- WickedEngine/wiVersion.cpp | 2 +- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/WickedEngine/brdf.hlsli b/WickedEngine/brdf.hlsli index 5b6ba4f4a..cbd991167 100644 --- a/WickedEngine/brdf.hlsli +++ b/WickedEngine/brdf.hlsli @@ -76,6 +76,10 @@ struct Surface BdotV = dot(B, V); at = max(0, alphaRoughness * (1.0 + anisotropy)); ab = max(0, alphaRoughness * (1.0 - anisotropy)); + +#ifdef BRDF_CARTOON + F = smoothstep(0.05, 0.1, F); +#endif // BRDF_CARTOON } }; inline Surface CreateSurface( @@ -152,6 +156,11 @@ inline SurfaceToLight CreateSurfaceToLight(in Surface surface, in float3 L) surfaceToLight.TdotH = dot(surface.T, surfaceToLight.H); surfaceToLight.BdotH = dot(surface.B, surfaceToLight.H); +#ifdef BRDF_CARTOON + surfaceToLight.NdotL = smoothstep(0.005, 0.05, surfaceToLight.NdotL); + surfaceToLight.NdotH = smoothstep(0.98, 0.99, surfaceToLight.NdotH); +#endif // BRDF_CARTOON + return surfaceToLight; } diff --git a/WickedEngine/lightingHF.hlsli b/WickedEngine/lightingHF.hlsli index 12741079c..0a65e3f2b 100644 --- a/WickedEngine/lightingHF.hlsli +++ b/WickedEngine/lightingHF.hlsli @@ -5,6 +5,10 @@ #include "voxelConeTracingHF.hlsli" #include "skyHF.hlsli" +#ifdef BRDF_CARTOON +#define DISABLE_SOFT_SHADOWMAP +#endif // BRDF_CARTOON + struct LightingContribution { float diffuse; @@ -38,13 +42,6 @@ inline Lighting CreateLighting( // Combine the direct and indirect lighting into final contribution inline LightingPart CombineLighting(in Surface surface, in Lighting lighting) { -#ifdef LIGHTING_CARTOON - lighting.direct.diffuse = smoothstep(0.005, 0.05, lighting.direct.diffuse); - lighting.direct.specular = max(lighting.direct.specular.r, max(lighting.direct.specular.g, lighting.direct.specular.b)); - lighting.direct.specular = step(0.05, lighting.direct.specular); - lighting.indirect.specular = smoothstep(0.008, 0.098, lighting.indirect.specular); -#endif // LIGHTING_CARTOON - LightingPart result; result.diffuse = lighting.direct.diffuse + lighting.indirect.diffuse * surface.occlusion; result.specular = lighting.direct.specular + lighting.indirect.specular * surface.F * surface.occlusion; @@ -110,11 +107,14 @@ inline float shadowTrace(in Surface surface, in float3 L, in float dist) ray.TMin = 0.001; ray.TMax = dist; ray.Origin = surface.P + surface.N * 0.01; + ray.Direction = L; +#ifndef BRDF_CARTOON float seed = g_xFrame_FrameCount * 0.001f; float2 uv = surface.screenUV; float3 sampling_offset = float3(rand(seed, uv), rand(seed, uv), rand(seed, uv)) * 2 - 1; // todo: should be specific to light surface - ray.Direction = normalize(L + sampling_offset * 0.025f); + ray.Direction = normalize(ray.Direction + sampling_offset * 0.025f); +#endif // BRDF_CARTOON q.TraceRayInline(scene_acceleration_structure, 0, 0xFF, ray); q.Proceed(); diff --git a/WickedEngine/objectPS_cartoon.hlsl b/WickedEngine/objectPS_cartoon.hlsl index b4cf91b1d..46170a392 100644 --- a/WickedEngine/objectPS_cartoon.hlsl +++ b/WickedEngine/objectPS_cartoon.hlsl @@ -1,6 +1,6 @@ #define COMPILE_OBJECTSHADER_PS #define OUTPUT_GBUFFER #define TILEDFORWARD -#define LIGHTING_CARTOON +#define BRDF_CARTOON #include "objectHF.hlsli" diff --git a/WickedEngine/objectPS_transparent_cartoon.hlsl b/WickedEngine/objectPS_transparent_cartoon.hlsl index 6b51a068f..c9e76bddf 100644 --- a/WickedEngine/objectPS_transparent_cartoon.hlsl +++ b/WickedEngine/objectPS_transparent_cartoon.hlsl @@ -1,6 +1,6 @@ #define COMPILE_OBJECTSHADER_PS #define TILEDFORWARD #define TRANSPARENT -#define LIGHTING_CARTOON +#define BRDF_CARTOON #include "objectHF.hlsli" diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 53cae0ba1..63c30aa59 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates, breaking API changes const int minor = 49; // minor bug fixes, alterations, refactors, updates - const int revision = 9; + const int revision = 10; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);