Skip to content

Commit

Permalink
Merge pull request #109 from Algoryx/feature/emitter-instanced-rendering
Browse files Browse the repository at this point in the history
Added instanced rendering mode to RigidBodyEmitter
  • Loading branch information
nmalg committed May 2, 2023
2 parents f38853e + 038d0a9 commit 7f1c377
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 37 deletions.
14 changes: 12 additions & 2 deletions AGXUnity/Rendering/DeformableTerrainParticleRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ protected override bool Initialize()

protected override void OnEnable()
{
Camera.onPreCull -= Render;
Camera.onPreCull += Render;
Simulation.Instance.StepCallbacks.PostStepForward += PostUpdate;

if ( State == States.INITIALIZED )
Expand All @@ -113,6 +115,7 @@ protected override void OnEnable()

protected override void OnDisable()
{
Camera.onPreCull -= Render;
// We may not "change GameObject hierarchy" when the actual
// game object is being destroyed, e.g., when hitting stop.
if ( gameObject.activeSelf )
Expand Down Expand Up @@ -207,7 +210,10 @@ private void Update()
Synchronize();
m_needsSynchronize = false;
}
}

private void Render(Camera cam)
{
var isValidDrawInstanceMode = RenderMode == GranuleRenderMode.DrawMeshInstanced &&
m_numGranulars > 0 &&
m_meshInstance != null &&
Expand All @@ -223,7 +229,9 @@ private void Update()
m_numGranulars,
m_meshInstanceProperties,
m_shadowCastingMode,
m_receiveShadows );
m_receiveShadows,
0,
cam);
}
// DrawMeshInstanced only supports up to 1023 meshes for each call,
// we need to subdivide if we have more particles than that.
Expand All @@ -237,7 +245,9 @@ private void Update()
count,
m_meshInstanceProperties,
m_shadowCastingMode,
m_receiveShadows );
m_receiveShadows,
0,
cam );
}
}
}
Expand Down
Loading

0 comments on commit 7f1c377

Please sign in to comment.