Skip to content

Commit

Permalink
com.unity.render-pipelines.core@2.0.4-preview
Browse files Browse the repository at this point in the history
## [2.0.4-preview]

### Improvements
- Improved volume UI & styling

### Changed
- Moved root files into folders for easier maintenance
  • Loading branch information
Unity Technologies committed Jul 10, 2019
1 parent 3087272 commit f04a7ce
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 8 deletions.
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CoreRP/Editor/Debugging/DebugWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DebugWindow>();
Expand Down
7 changes: 5 additions & 2 deletions CoreRP/Editor/Shadow/ShadowCascadeSplitGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
61 changes: 61 additions & 0 deletions CoreRP/ShaderLibrary/BSDF.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions CoreRP/ShaderLibrary/CommonLighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
68 changes: 66 additions & 2 deletions CoreRP/ShaderLibrary/ImageBasedLighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 * <N,L> dw} =
// Integral{(F0 + (1 - F0) * (1 - <V,H>)^5) * (BSDF / F) * <N,L> dw} =
// (1 - F0) * Integral{(1 - <V,H>)^5 * (BSDF / F) * <N,L> dw} + F0 * Integral{(BSDF / F) * <N,L> 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)
Expand Down
7 changes: 7 additions & 0 deletions CoreRP/Shadow/ShadowBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit f04a7ce

Please sign in to comment.