Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
373a7a9
Fix missing null checks in BRG test projects
vincent-breysse Nov 16, 2021
0f979b9
Setup URP/HDRP test scenes + Add relevant shaders
vincent-breysse Nov 18, 2021
1edd2bc
Add missing #pragma editor_sync_compilation + Tags{ "RenderPipeline" …
vincent-breysse Nov 22, 2021
18c3a4c
Put HDRP loading shader under Hidden/
vincent-breysse Nov 22, 2021
fcb987c
Setup HDRP error material test scene
vincent-breysse Nov 22, 2021
61468f4
Fix "Shaders/Utils/MaterialError.shader" Reload errors
vincent-breysse Nov 22, 2021
785d15d
Setup error material test scene
vincent-breysse Nov 22, 2021
850eed3
Update error material test scene to cover missing DOTS_INSTANCING_ON …
vincent-breysse Dec 1, 2021
a0483d0
Prepare merge with master
vincent-breysse Dec 1, 2021
77ce6ab
Merge branch 'master' into graphics/brg-error-loading-shader
vincent-breysse Dec 1, 2021
0e9b061
Re-add error material test scenes
vincent-breysse Dec 1, 2021
0a2eb95
Remove unecessary diff
vincent-breysse Dec 10, 2021
99aa775
Cleanup
vincent-breysse Dec 10, 2021
f02e0e8
Merge branch 'master' into graphics/brg-error-loading-shader
vincent-breysse Jan 10, 2022
2fd030b
Update chaneglogs
vincent-breysse Jan 10, 2022
754c9ec
Mute intentional shader errors for error material testing to avoid co…
vincent-breysse Jan 10, 2022
3e8fcb3
Add comment
vincent-breysse Jan 12, 2022
68781bb
Add a checkbox to toggle error/loading material usage in test scenes
vincent-breysse Jan 12, 2022
afef3c6
Fix error/loading material not set correctly in player
vincent-breysse Jan 13, 2022
bb8b92a
Merge branch 'master' into graphics/brg-error-loading-shader
vincent-breysse Feb 1, 2022
1a1d40c
Fix changelog mergeing + Add [Reload("Shaders/Utils/FallbackLoading.s…
vincent-breysse Feb 1, 2022
2a99dff
Add [Reload("Shaders/Utils/FallbackLoading.shader")] in URP ForwardRe…
vincent-breysse Feb 1, 2022
c59155c
Fix changelog typo
vincent-breysse Feb 1, 2022
eda4556
GFXHYR-308
vincent-breysse Feb 3, 2022
e70ee51
Merge branch 'master' into graphics/brg-error-loading-shader
vincent-breysse Feb 9, 2022
b6fda3e
Disable all picking related code by default
vincent-breysse Jan 13, 2022
2116f4d
Merge branch 'master' into graphics/brg-error-loading-shader
vincent-breysse Feb 9, 2022
43d7b7a
Update com.unity.render-pipelines.universal/CHANGELOG.md
vincent-breysse Feb 9, 2022
f1e2cf7
URP side reviews
vincent-breysse Feb 9, 2022
0e757a0
Merge branch 'graphics/brg-error-loading-shader' of github.com:Unity-…
vincent-breysse Feb 9, 2022
3af38c3
Fix potential formatting issue
vincent-breysse Feb 10, 2022
aab1f23
Hide error/loading shader API call under a define for now. Uncomment …
vincent-breysse Feb 14, 2022
32e79b0
Merge branch 'master' into graphics/brg-error-loading-shader
vincent-breysse Feb 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#if UNITY_EDITOR
//#define ENABLE_PICKING
#endif
//#define ENABLE_ERROR_LOADING_MATERIALS

using System;
using System.Collections.Generic;
using Unity.Burst;
Expand Down Expand Up @@ -32,16 +37,21 @@ public struct DrawKey : IEquatable<DrawKey>
public uint submeshIndex;
public BatchMaterialID material;
public ShadowCastingMode shadows;

#if ENABLE_PICKING
public int pickableObjectInstanceID;
#endif

public bool Equals(DrawKey other)
{
return
#if ENABLE_PICKING
pickableObjectInstanceID == other.pickableObjectInstanceID &&
#endif
meshID == other.meshID &&
submeshIndex == other.submeshIndex &&
material == other.material &&
shadows == other.shadows &&
pickableObjectInstanceID == other.pickableObjectInstanceID;
shadows == other.shadows;
}
}

Expand Down Expand Up @@ -103,6 +113,8 @@ static float4 GetSHC(SphericalHarmonicsL2 sh)

public unsafe class RenderBRG : MonoBehaviour
{
public bool SetFallbackMaterialsOnStart = true;

private BatchRendererGroup m_BatchRendererGroup;
private GraphicsBuffer m_GPUPersistentInstanceData;

Expand Down Expand Up @@ -270,12 +282,12 @@ public void Execute()
flags = BatchDrawCommandFlags.None,
sortingPosition = 0
};

#if ENABLE_PICKING
if (draws.drawCommandPickingInstanceIDs != null)
{
draws.drawCommandPickingInstanceIDs[outBatch] = drawBatches[remappedIndex].key.pickableObjectInstanceID;
}

#endif
outBatch++;
}

Expand Down Expand Up @@ -330,6 +342,10 @@ public JobHandle OnPerformCulling(BatchRendererGroup rendererGroup, BatchCulling
return new JobHandle();
}

#if ENABLE_PICKING
bool isPickingCulling = cullingContext.viewType == BatchCullingViewType.Picking;
#endif

var splitCounts = new NativeArray<int>(cullingContext.cullingSplits.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
for (int i = 0; i < splitCounts.Length; ++i)
{
Expand All @@ -344,8 +360,10 @@ public JobHandle OnPerformCulling(BatchRendererGroup rendererGroup, BatchCulling
drawCommands.drawCommands = Malloc<BatchDrawCommand>(m_drawBatches.Length *
splitCounts.Length * 10); // TODO: Multiplying the DrawCommand count by splitCount*10 is NOT an conservative upper bound. But in practice is enough. Sorting would give us a real conservative bound...

drawCommands.drawCommandPickingInstanceIDs = Malloc<int>(m_drawBatches.Length);
drawCommands.visibleInstances = Malloc<int>(m_instanceIndices.Length);
#if ENABLE_PICKING
drawCommands.drawCommandPickingInstanceIDs = isPickingCulling ? Malloc<int>(m_drawBatches.Length) : null;
#endif

// Zero init: Culling job sets the values!
drawCommands.drawRangeCount = 0;
Expand Down Expand Up @@ -385,10 +403,9 @@ public JobHandle OnPerformCulling(BatchRendererGroup rendererGroup, BatchCulling
return jobHandleOutput;
}

#if UNITY_EDITOR
public static Material LoadPickingMaterial()
static Material LoadMaterialWithHideAndDontSave(string name)
{
Shader shader = Shader.Find("Hidden/HDRP/BRGPicking");
Shader shader = Shader.Find(name);

if (shader == null) return null;

Expand All @@ -400,18 +417,29 @@ public static Material LoadPickingMaterial()
return material;
}

Material m_pickingMaterial;
#endif

Material m_PickingMaterial;
Material m_ErrorMaterial;
Material m_LoadingMaterial;

// Start is called before the first frame update
void Start()
{
m_BatchRendererGroup = new BatchRendererGroup(this.OnPerformCulling, IntPtr.Zero);

#if UNITY_EDITOR
m_pickingMaterial = LoadPickingMaterial();
m_BatchRendererGroup.SetPickingMaterial(m_pickingMaterial);
#if ENABLE_PICKING
m_PickingMaterial = LoadMaterialWithHideAndDontSave("Hidden/HDRP/BRGPicking");
m_BatchRendererGroup.SetPickingMaterial(m_PickingMaterial);
#endif

#if ENABLE_ERROR_LOADING_MATERIALS
if (SetFallbackMaterialsOnStart)
{
m_ErrorMaterial = LoadMaterialWithHideAndDontSave("Hidden/HDRP/MaterialError");
m_BatchRendererGroup.SetErrorMaterial(m_ErrorMaterial);

m_LoadingMaterial = LoadMaterialWithHideAndDontSave("Hidden/HDRP/MaterialLoading");
m_BatchRendererGroup.SetLoadingMaterial(m_LoadingMaterial);
}
#endif

// Create a batch...
Expand Down Expand Up @@ -502,13 +530,17 @@ void Start()
renderer.GetSharedMaterials(sharedMaterials);

var shadows = renderer.shadowCastingMode;
int instanceID = renderer.gameObject.GetInstanceID();

for (int matIndex = 0; matIndex < sharedMaterials.Count; matIndex++)
{
var material = m_BatchRendererGroup.RegisterMaterial(sharedMaterials[matIndex]);

var key = new DrawKey { material = material, meshID = mesh, submeshIndex = (uint)matIndex, shadows = shadows, pickableObjectInstanceID = instanceID };
var key = new DrawKey { material = material, meshID = mesh, submeshIndex = (uint)matIndex, shadows = shadows };

#if ENABLE_PICKING
key.pickableObjectInstanceID = renderer.gameObject.GetInstanceID();
#endif

var drawBatch = new DrawBatch
{
key = key,
Expand Down Expand Up @@ -681,9 +713,11 @@ private void OnDestroy()
m_instanceIndices.Dispose();
m_drawIndices.Dispose();

#if UNITY_EDITOR
DestroyImmediate(m_pickingMaterial);
#if ENABLE_PICKING
DestroyImmediate(m_PickingMaterial);
#endif
DestroyImmediate(m_ErrorMaterial);
DestroyImmediate(m_LoadingMaterial);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading