Created
January 16, 2018 04:02
-
-
Save Santarh/cd3f2a1112c099b3f692f7c98d479f06 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using UnityEngine; | |
using UnityEngine.Rendering; | |
public class AAA : MonoBehaviour | |
{ | |
[SerializeField] private Mesh _mesh; | |
[SerializeField] private Material _material; | |
private Matrix4x4[] _matrices; | |
private void OnEnable() | |
{ | |
var cam = Camera.main; | |
_matrices = new Matrix4x4[900]; | |
UpdatePosition(); | |
var cb = new CommandBuffer(); | |
cb.DrawMeshInstanced(_mesh, 0, _material, 0, _matrices); | |
cam.AddCommandBuffer(CameraEvent.AfterForwardOpaque, cb); | |
} | |
private void UpdatePosition() | |
{ | |
for (var x = 0; x < 30; ++x) | |
{ | |
for (var y = 0; y < 30; ++y) | |
{ | |
var i = x * 30 + y; | |
_matrices[i] = Matrix4x4.Translate(new Vector3(x * 1.5f, y * 1.5f, 0f)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment