-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+CPU per cell frustum culling, can render 10M grass on adreno612 now
- Loading branch information
1 parent
01e3adb
commit 8ef84a1
Showing
6 changed files
with
248 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...GrassInstancedIndirectDemo/InstancedIndirectGrass/Core/InstancedIndirectGrassPosDefine.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class InstancedIndirectGrassPosDefine : MonoBehaviour | ||
{ | ||
[Range(1, 40000000)] | ||
public int instanceCount = 1000000; | ||
public float drawDistance = 125; | ||
|
||
int cacheCount = -1; | ||
|
||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
UpdatePosIfNeeded(); | ||
} | ||
|
||
private void UpdatePosIfNeeded() | ||
{ | ||
if (instanceCount == cacheCount) | ||
return; | ||
|
||
Debug.Log("UpdatePos (Slow)"); | ||
|
||
//same seed to keep grass visual the same | ||
UnityEngine.Random.InitState(123); | ||
|
||
//auto keep density the same | ||
float scale = Mathf.Sqrt((instanceCount / 4)) / 2f; | ||
transform.localScale = new Vector3(scale, transform.localScale.y, scale); | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
//can define any posWS in this section, random is just an example | ||
////////////////////////////////////////////////////////////////////////// | ||
List<Vector3> positions = new List<Vector3>(instanceCount); | ||
for (int i = 0; i < instanceCount; i++) | ||
{ | ||
Vector3 pos = Vector3.zero; | ||
|
||
pos.x = UnityEngine.Random.Range(-1f, 1f) * transform.lossyScale.x; | ||
pos.z = UnityEngine.Random.Range(-1f, 1f) * transform.lossyScale.z; | ||
|
||
//transform to posWS in C# | ||
pos += transform.position; | ||
|
||
positions.Add(new Vector3(pos.x, pos.y, pos.z)); | ||
} | ||
|
||
//send all posWS to renderer | ||
InstancedIndirectGrassRenderer.instance.allGrassPos = positions; | ||
cacheCount = positions.Count; | ||
} | ||
private void Update() | ||
{ | ||
UpdatePosIfNeeded(); | ||
} | ||
private void OnGUI() | ||
{ | ||
GUI.Label(new Rect(300, 50, 200, 30), "Instance Count: " + instanceCount/1000000 + "Million"); | ||
instanceCount = Mathf.Max(1, (int)(GUI.HorizontalSlider(new Rect(300, 100, 200, 30), instanceCount / 1000000f, 1, 10)) * 1000000); | ||
|
||
GUI.Label(new Rect(300, 150, 200, 30), "Draw Distance: " + drawDistance); | ||
drawDistance = Mathf.Max(1, (int)(GUI.HorizontalSlider(new Rect(300, 200, 200, 30), drawDistance / 25f, 1, 8)) * 25); | ||
InstancedIndirectGrassRenderer.instance.drawDistance = drawDistance; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...InstancedIndirectDemo/InstancedIndirectGrass/Core/InstancedIndirectGrassPosDefine.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.