Skip to content

Commit

Permalink
Apply BOTD v1.1 SRP Diff
Browse files Browse the repository at this point in the history
  • Loading branch information
0lento committed Aug 6, 2018
1 parent 3582e18 commit a969c38
Show file tree
Hide file tree
Showing 61 changed files with 3,191 additions and 142 deletions.
Expand Up @@ -70,11 +70,15 @@ public void Repaint()
m_Inspector.Repaint();
}

internal void Init(VolumeComponent target, Editor inspector)
//custom-begin: malte: context reference for exposed property resolver
internal void Init(VolumeComponent target, UnityEngine.Object context, Editor inspector)
//custom-end
{
this.target = target;
m_Inspector = inspector;
serializedObject = new SerializedObject(target);
//custom-begin: malte: context reference for exposed property resolver
serializedObject = new SerializedObject(target, context);
//custom-end
activeProperty = serializedObject.FindProperty("active");
OnEnable();
}
Expand Down
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand Down Expand Up @@ -88,7 +88,9 @@ void CreateEditor(VolumeComponent component, SerializedProperty property, int in
editorType = typeof(VolumeComponentEditor);

var editor = (VolumeComponentEditor)Activator.CreateInstance(editorType);
editor.Init(component, m_BaseEditor);
//custom-begin: malte: context reference for exposed property resolver
editor.Init(component, m_SerializedObject.context, m_BaseEditor);
//custom-end
editor.baseProperty = property.Copy();

if (forceOpen)
Expand Down
Expand Up @@ -6,6 +6,9 @@ namespace UnityEditor.Experimental.Rendering
[CustomEditor(typeof(Volume))]
sealed class VolumeEditor : Editor
{
//custom-begin: malte: context reference for exposed property resolver
SerializedProperty m_Context;
//custom-end
SerializedProperty m_IsGlobal;
SerializedProperty m_BlendRadius;
SerializedProperty m_Weight;
Expand All @@ -27,6 +30,9 @@ VolumeProfile profileRef
void OnEnable()
{
var o = new PropertyFetcher<Volume>(serializedObject);
//custom-begin: malte: context reference for exposed property resolver
m_Context = o.Find(x => x.context);
//custom-end
m_IsGlobal = o.Find(x => x.isGlobal);
m_BlendRadius = o.Find(x => x.blendDistance);
m_Weight = o.Find(x => x.weight);
Expand All @@ -48,13 +54,18 @@ void RefreshEffectListEditor(VolumeProfile asset)
m_ComponentList.Clear();

if (asset != null)
m_ComponentList.Init(asset, new SerializedObject(asset));
//custom-begin: malte: context reference for exposed property resolver
m_ComponentList.Init(asset, new SerializedObject(asset, actualTarget.context));
//custom-end
}

public override void OnInspectorGUI()
{
serializedObject.Update();

//custom-begin: malte: context reference for exposed property resolver
EditorGUILayout.ObjectField(m_Context, typeof(IExposedPropertyTable));
//custom-end
EditorGUILayout.PropertyField(m_IsGlobal);

if (!m_IsGlobal.boolValue) // Blend radius is not needed for global volumes
Expand Down
Expand Up @@ -219,6 +219,26 @@ real GetSpecularOcclusionFromAmbientOcclusion(real NdotV, real ambientOcclusion,
return saturate(PositivePow(NdotV + ambientOcclusion, exp2(-16.0 * roughness - 1.0)) - 1.0 + ambientOcclusion);
}

//forest-begin: lightmap occlusion
float3 SampleBakedGI(float3 positionWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap, float skyOcclusion, float grassOcclusion, float treeOcclusion);

float4 _LightmapOcclusionLuminanceMode;
float4 _LightmapOcclusionScalePowerReflStrengthSpecStrength;

float GetSpecularOcclusionFromLightmapLuminance(float3 V, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap)
{
#if !defined(LIGHTMAP_ON) && !defined(DYNAMICLIGHTMAP_ON)
return 1.0;
#endif

float3 lookupVector = _LightmapOcclusionLuminanceMode.w == 0 ? normalWS : reflect(-V, normalWS);;
float3 bakedGI = SampleBakedGI(float3(0, 0, 0), lookupVector, uvStaticLightmap, uvDynamicLightmap, 1.f, 1.f, 1.f);
float lightmapOcclusion = dot(bakedGI, _LightmapOcclusionLuminanceMode.rgb);
lightmapOcclusion = pow(saturate(lightmapOcclusion * _LightmapOcclusionScalePowerReflStrengthSpecStrength.x), _LightmapOcclusionScalePowerReflStrengthSpecStrength.y);
return lerp(1.f, lightmapOcclusion, _LightmapOcclusionScalePowerReflStrengthSpecStrength.z);
}
//forest-end

// ref: Practical Realtime Strategies for Accurate Indirect Occlusion
// Update ambient occlusion to colored ambient occlusion based on statitics of how light is bouncing in an object and with the albedo of the object
real3 GTAOMultiBounce(real visibility, real3 albedo)
Expand Down
31 changes: 31 additions & 0 deletions com.unity.render-pipelines.core/CoreRP/Shadow/Shadow.cs
Expand Up @@ -15,6 +15,17 @@ namespace UnityEngine.Experimental.Rendering
// Standard shadow map atlas implementation using one large shadow map
public class ShadowAtlas : ShadowmapBase, IDisposable
{
//forest-begin: Staggered Cascades
public delegate TResult Func<T1, T2, T3, T4, T5, TResult>(T1 arg, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
public delegate TResult Func<T1, T2, T3, T4, T5, T6, TResult>(T1 arg, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
public delegate TResult Func<T1, T2, T3, T4, T5, T6, T7, TResult>(T1 arg, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);

public struct StaggeredOutput { public bool valid; public Matrix4x4 view; public Matrix4x4 proj; public Vector3 position; }
public static event Func<uint, uint, Matrix4x4, Matrix4x4, Vector3, Vector3, StaggeredOutput> OnIsStaggered;
public static event Func<uint, uint, bool> OnShouldRenderShadows;
public static event Func<ScriptableRenderContext, CullResults, uint, uint, bool> OnRenderShadows;
//forest-end:

public const uint k_MaxCascadesInShader = 4;
protected readonly int m_TempDepthId;
protected readonly int m_ZClipId;
Expand Down Expand Up @@ -385,6 +396,18 @@ override public bool Reserve(FrameId frameId, Camera camera, bool cameraRelative
else if (sr.shadowType == GPUShadowType.Directional)
{
vp = ShadowUtils.ExtractDirectionalLightMatrix(lights[sr.index], key.faceIdx, cascadeCnt, cascadeRatios, nearPlaneOffset, width, height, out ce.current.view, out ce.current.proj, out devproj, out invvp, out ce.current.lightDir, out ce.current.splitData, m_CullResults, (int)sr.index);
//forest-begin: Staggered Cascades
if(OnIsStaggered != null) {
var staggered = OnIsStaggered(key.faceIdx, k_MaxCascadesInShader, ce.current.view, ce.current.proj, camera.transform.position, ce.current.lightDir);
if(staggered.valid) {
ce.current.view = staggered.view;
ce.current.proj = staggered.proj;
devproj = GL.GetGPUProjectionMatrix(ce.current.proj, false);
ShadowUtils.InvertOrthographic(ref devproj, ref ce.current.view, out invvp);
vp = devproj * ce.current.view;
}
}
//forest-end:
m_TmpSplits[key.faceIdx] = ce.current.splitData.cullingSphere;
if (ce.current.splitData.cullingSphere.w != float.NegativeInfinity)
{
Expand Down Expand Up @@ -645,6 +668,11 @@ override public void Update(FrameId frameId, ScriptableRenderContext renderConte
if (!cullResults.GetShadowCasterBounds(m_EntryCache[i].key.visibleIdx, out bounds))
continue;

//forest-begin: Staggered Cascades
if(OnShouldRenderShadows != null && !OnShouldRenderShadows(m_EntryCache[i].key.faceIdx, k_MaxCascadesInShader))
continue;
//forest-end:

uint entrySlice = m_EntryCache[i].current.slice;
if (entrySlice != curSlice)
{
Expand Down Expand Up @@ -686,7 +714,10 @@ override public void Update(FrameId frameId, ScriptableRenderContext renderConte
renderContext.ExecuteCommandBuffer(cmd);
cmd.Clear();

//forest-begin: Staggered Cascades
if(OnRenderShadows == null || !OnRenderShadows(renderContext, cullResults, m_EntryCache[i].key.faceIdx, k_MaxCascadesInShader))
renderContext.DrawShadows(ref dss); // <- if this was a call on the commandbuffer we would get away with using just once commandbuffer for the entire shadowmap, instead of one per face
//forest-end:
}

// post update
Expand Down
6 changes: 5 additions & 1 deletion com.unity.render-pipelines.core/CoreRP/Shadow/ShadowBase.cs
@@ -1,4 +1,4 @@
using UnityEngine.Rendering;
using UnityEngine.Rendering;
using System;
using System.Collections.Generic;

Expand All @@ -16,6 +16,10 @@ public class ShadowInitParameters
public int shadowAtlasWidth = kDefaultShadowAtlasSize;
public int shadowAtlasHeight = kDefaultShadowAtlasSize;

//forest-begin: 16-bit shadows option
public bool shadowMap16Bit;
//forest-end:

public int maxPointLightShadows = kDefaultMaxPointLightShadows;
public int maxSpotLightShadows = kDefaultMaxSpotLightShadows;
public int maxDirectionalLightShadows = kDefaultMaxDirectionalLightShadows;
Expand Down
13 changes: 13 additions & 0 deletions com.unity.render-pipelines.core/CoreRP/Volume/Volume.cs
Expand Up @@ -5,6 +5,10 @@ namespace UnityEngine.Experimental.Rendering
[ExecuteInEditMode]
public class Volume : MonoBehaviour
{
//custom-begin: malte: context reference for exposed property resolver
public Object context;
//custom-end

[Tooltip("A global volume is applied to the whole scene.")]
public bool isGlobal = false;

Expand Down Expand Up @@ -111,6 +115,10 @@ void Update()
// TODO: Look into a better volume previsualization system
List<Collider> m_TempColliders;

//custom-begin: malte: hide collider gizmos
public bool hideColliderGizmos { get; set; }
//custom-end

void OnDrawGizmos()
{
if (m_TempColliders == null)
Expand All @@ -119,6 +127,11 @@ void OnDrawGizmos()
var colliders = m_TempColliders;
GetComponents(colliders);

//custom-begin: malte: hide collider gizmos
if (hideColliderGizmos)
return;
//custom-end

if (isGlobal || colliders == null)
return;

Expand Down
Expand Up @@ -65,7 +65,13 @@ public virtual void Override(VolumeComponent state, float interpFactor)
var toParam = parameters[i];

// Keep track of the override state for debugging purpose
stateParam.overrideState = toParam.overrideState;
//custom-begin: malte: allow partial overrides from many volumes in priority order
if (toParam.overrideState)
{
stateParam.overrideState = toParam.overrideState;
stateParam.Interp(stateParam, toParam, interpFactor);
}
//custom-end

if (toParam.overrideState)
stateParam.Interp(stateParam, toParam, interpFactor);
Expand Down
Expand Up @@ -288,14 +288,18 @@ public void Update(VolumeStack stack, Transform trigger, LayerMask layerMask)
float interpFactor = 1f;

if (blendDistSqr > 0f)
interpFactor = 1f - (closestDistanceSqr / blendDistSqr);
//custom-begin: malte: smoothstep blend
interpFactor = Mathf.SmoothStep(1f, 0f, closestDistanceSqr / blendDistSqr);
//custom-end

// No need to clamp01 the interpolation factor as it'll always be in [0;1[ range
OverrideData(stack, volume.profileRef.components, interpFactor * Mathf.Clamp01(volume.weight));
}
}

List<Volume> GrabVolumes(LayerMask mask)
//custom-begin: malte: debugging/visualizing volumes
public List<Volume> GrabVolumes(LayerMask mask)
//custom-end
{
List<Volume> list;

Expand Down
Expand Up @@ -286,7 +286,9 @@ public void Update(FrameSettings currentFrameSettings, PostProcessLayer postProc
m_ActualHeight = camera.pixelHeight;
var screenWidth = m_ActualWidth;
var screenHeight = m_ActualHeight;
#if !UNITY_SWITCH
//forest-begin: Added XboxOne to define around XR code
#if !UNITY_SWITCH && !UNITY_XBOXONE
//forest-end:
if (m_frameSettings.enableStereo)
{
screenWidth = XRSettings.eyeTextureWidth;
Expand Down
Expand Up @@ -15,6 +15,10 @@ sealed class Styles
public readonly GUIContent transmittancePreview2 = new GUIContent("Can be viewed as a cross section of a slab of material illuminated by white light from the left.");
public readonly GUIContent profileScatteringDistance = new GUIContent("Scattering Distance", "Determines the shape of the profile, and the blur radius of the filter per color channel. Alpha is ignored.");
public readonly GUIContent profileTransmissionTint = new GUIContent("Transmission tint", "Color which tints transmitted light. Alpha is ignored.");
//forest-begin: Tweakable transmission
public readonly GUIContent profileTransmissionDirectScale = new GUIContent("Direct Scale", "Tweak direct transmission contribution.");
public readonly GUIContent profileTransmissionIndirectScale = new GUIContent("Indirect Scale", "Tweak indirect transmission contribution.");
//forest-end:
public readonly GUIContent profileMaxRadius = new GUIContent("Max Radius", "Effective radius of the filter (in millimeters). The blur is energy-preserving, so a wide filter results in a large area with small contributions of individual samples. Reducing the distance increases the sharpness of the result.");
public readonly GUIContent texturingMode = new GUIContent("Texturing Mode", "Specifies when the diffuse texture should be applied.");
public readonly GUIContent[] texturingModeOptions = new GUIContent[2]
Expand Down
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
Expand All @@ -17,6 +17,10 @@ sealed class Profile

internal SerializedProperty scatteringDistance;
internal SerializedProperty transmissionTint;
//forest-begin: Tweakable transmission
internal SerializedProperty transmissionDirectScale;
internal SerializedProperty transmissionIndirectScale;
//forest-end:
internal SerializedProperty texturingMode;
internal SerializedProperty transmissionMode;
internal SerializedProperty thicknessRemap;
Expand Down Expand Up @@ -78,6 +82,10 @@ protected override void OnEnable()

scatteringDistance = rp.Find(x => x.scatteringDistance),
transmissionTint = rp.Find(x => x.transmissionTint),
//forest-begin: Tweakable transmission
transmissionDirectScale = rp.Find(x => x.transmissionDirectScale),
transmissionIndirectScale = rp.Find(x => x.transmissionIndirectScale),
//forest-end:
texturingMode = rp.Find(x => x.texturingMode),
transmissionMode = rp.Find(x => x.transmissionMode),
thicknessRemap = rp.Find(x => x.thicknessRemap),
Expand Down Expand Up @@ -169,6 +177,10 @@ public override void OnInspectorGUI()
var thicknessRemap = profile.thicknessRemap.vector2Value;
EditorGUILayout.MinMaxSlider(s_Styles.profileThicknessRemap, ref thicknessRemap.x, ref thicknessRemap.y, 0f, 50f);
profile.thicknessRemap.vector2Value = thicknessRemap;
//forest-begin: Tweakable transmission
EditorGUILayout.Slider(profile.transmissionDirectScale, 0f, 8f, s_Styles.profileTransmissionDirectScale);
EditorGUILayout.Slider(profile.transmissionIndirectScale, 0f, 8f, s_Styles.profileTransmissionIndirectScale);
//forest-end:

EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.profilePreview0, s_Styles.centeredMiniBoldLabel);
Expand Down
Expand Up @@ -71,6 +71,10 @@ private class StylesLayer

public readonly GUIContent materialReferencesText = new GUIContent("Material References");

//forest-begin:
public readonly GUIContent enableTerrainModeText = new GUIContent("Enable Terrain Mode");
//forest-end:

public StylesLayer()
{
layerLabelColors[0].normal.textColor = layerColors[0];
Expand Down Expand Up @@ -147,6 +151,10 @@ public LayeredLitGUI()
MaterialProperty[] showLayer = new MaterialProperty[kMaxLayerCount];
const string kShowLayer = "_ShowLayer";

//forest-begin:
MaterialProperty enableTerrainMode = null;
const string kEnableTerrainMode = "_EnableTerrainMode";
//forest-end:
bool m_UseHeightBasedBlend;

protected override void FindMaterialProperties(MaterialProperty[] props)
Expand Down Expand Up @@ -183,6 +191,10 @@ protected override void FindMaterialProperties(MaterialProperty[] props)
inheritBaseColor[i - 1] = FindProperty(string.Format("{0}{1}", kInheritBaseColor, i), props);
}
}

//forest-begin:
enableTerrainMode = FindProperty(kEnableTerrainMode, props, false);
//forest-end:
}

int numLayer
Expand Down Expand Up @@ -364,6 +376,7 @@ bool DoLayerGUI(AssetImporter materialImporter, int layerIndex)
return result;
}


void DoLayeringInputGUI()
{
EditorGUI.indentLevel++;
Expand Down Expand Up @@ -751,6 +764,10 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
EditorGUI.indentLevel++;
m_MaterialEditor.EnableInstancingField();
m_MaterialEditor.ShaderProperty(enableSpecularOcclusion, Styles.enableSpecularOcclusionText);
//forest-begin:
if(enableTerrainMode != null)
m_MaterialEditor.ShaderProperty(enableTerrainMode, styles.enableTerrainModeText);
//forest-end:
EditorGUI.indentLevel--;

if (layerChanged || optionsChanged)
Expand Down

0 comments on commit a969c38

Please sign in to comment.