diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 3e297c0..0000000 --- a/.npmignore +++ /dev/null @@ -1 +0,0 @@ -sub-package.* \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ab92139..bb8abee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [2.0.4-preview] ### Improvements - Improved volume UI & styling diff --git a/CoreRP/Editor/Debugging/DebugWindow.cs b/CoreRP/Editor/Debugging/DebugWindow.cs index 47632b0..5287280 100644 --- a/CoreRP/Editor/Debugging/DebugWindow.cs +++ b/CoreRP/Editor/Debugging/DebugWindow.cs @@ -99,7 +99,7 @@ static void RebuildTypeMaps() s_TypeMapDirty = false; } - [MenuItem("Window/General/Render Pipeline Debug", priority = CoreUtils.editMenuPriority2)] + [MenuItem("Window/General/Render Pipeline Debug", priority = 112)] // 112 is hardcoded number given by the UxTeam to fit correctly in the Windows menu static void Init() { var window = GetWindow(); diff --git a/CoreRP/Editor/Shadow/ShadowCascadeSplitGUI.cs b/CoreRP/Editor/Shadow/ShadowCascadeSplitGUI.cs index 6b07465..c7aeee3 100644 --- a/CoreRP/Editor/Shadow/ShadowCascadeSplitGUI.cs +++ b/CoreRP/Editor/Shadow/ShadowCascadeSplitGUI.cs @@ -63,18 +63,21 @@ public DragCache(int activePartition, float normalizedPartitionSize, Vector2 cur */ public static void HandleCascadeSliderGUI(ref float[] normalizedCascadePartitions) { - EditorGUILayout.LabelField("Cascade splits"); - + EditorGUILayout.BeginHorizontal(); + GUILayout.Space(EditorGUI.indentLevel * 15f); // get the inspector width since we need it while drawing the partition rects. // Only way currently is to reserve the block in the layout using GetRect(), and then immediately drawing the empty box // to match the call to GetRect. // From this point on, we move to non-layout based code. + var sliderRect = GUILayoutUtility.GetRect(GUIContent.none , s_CascadeSliderBG , GUILayout.Height(kSliderbarTopMargin + kSliderbarHeight + kSliderbarBottomMargin) , GUILayout.ExpandWidth(true)); GUI.Box(sliderRect, GUIContent.none); + EditorGUILayout.EndHorizontal(); + float currentX = sliderRect.x; float cascadeBoxStartY = sliderRect.y + kSliderbarTopMargin; float cascadeSliderWidth = sliderRect.width - (normalizedCascadePartitions.Length * kPartitionHandleWidth); diff --git a/CoreRP/ShaderLibrary/BSDF.hlsl b/CoreRP/ShaderLibrary/BSDF.hlsl index feec380..63d5e87 100644 --- a/CoreRP/ShaderLibrary/BSDF.hlsl +++ b/CoreRP/ShaderLibrary/BSDF.hlsl @@ -460,4 +460,65 @@ real3 EvalIridescence(real eta_1, real cosTheta1, real iridescenceThickness, rea return I; } +//----------------------------------------------------------------------------- +// Cloth +//----------------------------------------------------------------------------- + +// Ref: https://knarkowicz.wordpress.com/2018/01/04/cloth-shading/ +real D_CharlieNoPI(real NdotH, real roughness) +{ + float invR = rcp(roughness); + float cos2h = NdotH * NdotH; + float sin2h = 1.0 - cos2h; + // Note: We have sin^2 so multiply by 0.5 to cancel it + return (2.0 + invR) * PositivePow(sin2h, invR * 0.5) / 2.0; +} + +real D_Charlie(real NdotH, real roughness) +{ + return INV_PI * D_CharlieNoPI(NdotH, roughness); +} + +real CharlieL(real x, real r) +{ + r = saturate(r); + r = (1. - r * r); + + float a = lerp(25.3245, 21.5473, r); + float b = lerp(3.32435, 3.82987, r); + float c = lerp(0.16801, 0.19823, r); + float d = lerp(-1.27393, -1.97760, r); + float e = lerp(-4.85967, -4.32054, r); + + return a / (1. + b * PositivePow(x, c)) + d * x + e; +} + +// Note: This version don't include the softening of the paper: Production Friendly Microfacet Sheen BRDF +real V_Charlie(real NdotL, real NdotV, real roughness) +{ + real lambdaV = NdotV < 0.5 ? exp(CharlieL(NdotV, roughness)) : exp(2.0 * CharlieL(0.5, roughness) - CharlieL(1.0 - NdotV, roughness)); + real lambdaL = NdotL < 0.5 ? exp(CharlieL(NdotL, roughness)) : exp(2.0 * CharlieL(0.5, roughness) - CharlieL(1.0 - NdotL, roughness)); + + return 1.0 / ((1.0 + lambdaV + lambdaL) * (4.0 * NdotV * NdotL)); +} + +// We use V_Ashikhmin instead of V_Charlie in practice for game due to the cost of V_Charlie +real V_Ashikhmin(real NdotL, real NdotV) +{ + // Use soft visibility term introduce in: Crafting a Next-Gen Material Pipeline for The Order : 1886 + return 1.0 / (4.0 * (NdotL + NdotV - NdotL * NdotV)); +} + +// A diffuse term use with cloth done by tech artist - empirical +real ClothLambertNoPI(real roughness) +{ + return lerp(1.0, 0.5, roughness); +} + +real ClothLambert(real roughness) +{ + return INV_PI * ClothLambertNoPI(roughness); +} + + #endif // UNITY_BSDF_INCLUDED diff --git a/CoreRP/ShaderLibrary/CommonLighting.hlsl b/CoreRP/ShaderLibrary/CommonLighting.hlsl index 8954f1c..2604f18 100644 --- a/CoreRP/ShaderLibrary/CommonLighting.hlsl +++ b/CoreRP/ShaderLibrary/CommonLighting.hlsl @@ -277,6 +277,17 @@ float ClampNdotV(float NdotV) return max(NdotV, 0.0001); } +// return usual BSDF angle +void GetBSDFAngle(float3 V, float3 L, float NdotL, float unclampNdotV, out float LdotV, out float NdotH, out float LdotH, out float clampNdotV, out float invLenLV) +{ + // Optimized math. Ref: PBR Diffuse Lighting for GGX + Smith Microsurfaces (slide 114). + LdotV = dot(L, V); + invLenLV = rsqrt(max(2.0 * LdotV + 2.0, FLT_EPS)); // invLenLV = rcp(length(L + V)), clamp to avoid rsqrt(0) = NaN + NdotH = saturate((NdotL + unclampNdotV) * invLenLV); // Do not clamp NdotV here + LdotH = saturate(invLenLV * LdotV + invLenLV); + clampNdotV = ClampNdotV(unclampNdotV); +} + // Inputs: normalized normal and view vectors. // Outputs: front-facing normal, and the new non-negative value of the cosine of the view angle. // Important: call Orthonormalize() on the tangent and recompute the bitangent afterwards. diff --git a/CoreRP/ShaderLibrary/ImageBasedLighting.hlsl b/CoreRP/ShaderLibrary/ImageBasedLighting.hlsl index c17e726..e1f6dcf 100644 --- a/CoreRP/ShaderLibrary/ImageBasedLighting.hlsl +++ b/CoreRP/ShaderLibrary/ImageBasedLighting.hlsl @@ -317,7 +317,7 @@ void ImportanceSampleAnisoGGX(real2 u, #if !defined SHADER_API_GLES // Ref: Listing 18 in "Moving Frostbite to PBR" + https://knarkowicz.wordpress.com/2014/12/27/analytical-dfg-term-for-ibl/ -real4 IntegrateGGXAndDisneyFGD(real3 V, real3 N, real roughness, uint sampleCount = 8192) +real4 IntegrateGGXAndDisneyDiffuseFGD(real3 V, real3 N, real roughness, uint sampleCount = 8192) { real NdotV = ClampNdotV(dot(N, V)); real4 acc = real4(0.0, 0.0, 0.0, 0.0); @@ -370,7 +370,71 @@ real4 IntegrateGGXAndDisneyFGD(real3 V, real3 N, real roughness, uint sampleCoun } #else // Not supported due to lack of random library in GLES 2 -#define IntegrateGGXAndDisneyFGD ERROR_ON_UNSUPPORTED_FUNCTION(IntegrateGGXAndDisneyFGD) +#define IntegrateGGXAndDisneyDiffuseFGD ERROR_ON_UNSUPPORTED_FUNCTION(IntegrateGGXAndDisneyDiffuseFGD) +#endif + +#if !defined SHADER_API_GLES +real4 IntegrateCharlieAndClothLambertFGD(real3 V, real3 N, real roughness, uint sampleCount = 8192) +{ + real NdotV = ClampNdotV(dot(N, V)); + real4 acc = real4(0.0, 0.0, 0.0, 0.0); + // Add some jittering on Hammersley2d + real2 randNum = InitRandom(V.xy * 0.5 + 0.5); + + real3x3 localToWorld = GetLocalFrame(N); + + for (uint i = 0; i < sampleCount; ++i) + { + real2 u = frac(randNum + Hammersley2d(i, sampleCount)); + + real NdotL; + real weightOverPdf; + + // Ref: Production Friendly Microfacet Sheen BRDF + // Paper recommend plain uniform sampling of upper hemisphere instead of importance sampling for Charlie + real3 localL = SampleHemisphereUniform(u.x, u.y); + real3 L = mul(localL, localToWorld); + NdotL = saturate(dot(N, L)); + + if (NdotL > 0.0) + { + // Sampling weight for each sample + // pdf = 1 / 2PI + // weight = fr * (N.L) with fr = CharlieV * CharlieD / PI + // weight over pdf is: + // weightOverPdf = (CharlieV * CharlieD / PI) * (N.L) / (1 / 2PI) + // weightOverPdf = 2 * CharlieV * CharlieD * (N.L) + real3 H = normalize(V + L); + real NdotH = dot(N, H); + // Note: we use V_Charlie and not the approx when computing FGD texture as we can afford it + weightOverPdf = 2.0 * V_Charlie(NdotL, NdotV, roughness) * D_CharlieNoPI(NdotH, roughness) * NdotL; + + // Integral{BSDF * dw} = + // Integral{(F0 + (1 - F0) * (1 - )^5) * (BSDF / F) * dw} = + // (1 - F0) * Integral{(1 - )^5 * (BSDF / F) * dw} + F0 * Integral{(BSDF / F) * dw}= + // (1 - F0) * x + F0 * y = lerp(x, y, F0) + real VdotH = dot(V, H); + acc.x += weightOverPdf * pow(1 - VdotH, 5); + acc.y += weightOverPdf; + } + + // for cloth Lambert we still use a Cosine importance sampling + ImportanceSampleLambert(u, localToWorld, L, NdotL, weightOverPdf); + + if (NdotL > 0.0) + { + real clothLambert = ClothLambertNoPI(roughness); + acc.z += clothLambert * weightOverPdf; + } + } + + acc /= sampleCount; + + return acc; +} +#else +// Not supported due to lack of random library in GLES 2 +#define IntegrateCharlieAndClothLambertFGD ERROR_ON_UNSUPPORTED_FUNCTION(IntegrateCharlieAndClothLambertFGD) #endif uint GetIBLRuntimeFilterSampleCount(uint mipLevel) diff --git a/CoreRP/Shadow/ShadowBase.cs b/CoreRP/Shadow/ShadowBase.cs index 6ada2ee..5cf0b9a 100644 --- a/CoreRP/Shadow/ShadowBase.cs +++ b/CoreRP/Shadow/ShadowBase.cs @@ -9,9 +9,16 @@ namespace UnityEngine.Experimental.Rendering public class ShadowInitParameters { public const int kDefaultShadowAtlasSize = 4096; + public const int kDefaultMaxPointLightShadows = 6; + public const int kDefaultMaxSpotLightShadows = 12; + public const int kDefaultMaxDirectionalLightShadows = 1; public int shadowAtlasWidth = kDefaultShadowAtlasSize; public int shadowAtlasHeight = kDefaultShadowAtlasSize; + + public int maxPointLightShadows = kDefaultMaxPointLightShadows; + public int maxSpotLightShadows = kDefaultMaxSpotLightShadows; + public int maxDirectionalLightShadows = kDefaultMaxDirectionalLightShadows; } // Class used to pass parameters to the shadow system on a per frame basis. diff --git a/package.json b/package.json index 2f56029..a4ff1c3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.render-pipelines.core", "description": "Core library for Unity render pipelines.", - "version": "2.0.3-preview", + "version": "2.0.4-preview", "unity": "2018.2", "displayName": "Render Pipeline Core Library", "dependencies": {