静态批处理

 

没有加批处理绘制次数很高  FPS 81

加批处理绘制次数降低  FPS 94

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StaticBatchProcessing : MonoBehaviour
{
public Texture2D texture;//纹理

public int wnum;
public int hnum;
int w = 128;
int h = 128;
// Start is called before the first frame update
void Start()
{

//顶点是有个数限制的最多65000个
//纹理尽力取2的次方
wnum =4;
hnum = 4;
//补缝用

int w2 = w + 2;
int h2 = h + 2;
for (int i = 0; i < wnum; i++)
{
for (int j = 0; j < hnum; j++)
{

for (int x = 0; x < w2; x++)
{
for (int z = 0; z < h2; z++)
{
//柏林噪声算法,传入两个坐标返回一个0-1的值(传入两个相同的值,返回结果一定相同)
float y = Mathf.PerlinNoise((i * w + x) * 0.02f, (j * h + z) * 0.02f);
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.parent = this.transform;
cube.transform.localPosition = new Vector3(w*i+x,y*5,h*j+z);
}
}
}

}
StaticBatchingUtility.Combine(gameObject);//此代码就是静态批处理代码

 


}

// Update is called once per frame
void Update()
{

}
}

 

posted @   天分丶张三  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示