資源簡介
實時遮擋剔除 無需垬焙,內附使用說明,有三個腳本,可實現遮擋剔除的效果,降低渲染壓力,提升運行速度

代碼片段和文件信息
using?UnityEngine;
using?System.Collections;
public?class?IOCcam?:?MonoBehaviour?{
public?layerMask?layerMsk;
public?string?iocTag;
public?int?samples;
public?float?viewDistance;
public?int?hideDelay;
public?bool?realtimeShadows;
public?float?lod1Distance;
public?float?lod2Distance;
public?float?lodMargin;
private?RaycastHit?hit;
private?Ray?r;
private?int?layerMask;
private?IOClod?l;
private?int?haltonIndex;
private?float[]?hx;
private?float[]?hy;
private?int?pixels;
private?Camera?cam;
void?Awake?()?{
cam?=?GetComponent();
hit?=?new?RaycastHit();
if(viewDistance?==?0)?viewDistance?=?100;
cam.farClipPlane?=?viewDistance;
haltonIndex?=?0;
if(this.GetComponent()?==?null)
{
gameobject.AddComponent().GetComponent().isTrigger?=?true;
}
}
void?Start?()?{
pixels?=?Mathf.FloorToInt(Screen.width?*?Screen.height?/?2f);
hx?=?new?float[pixels];
hy?=?new?float[pixels];
for(int?i=0;?i? {
hx[i]?=?HaltonSequence(i?2);
hy[i]?=?HaltonSequence(i?3);
}
foreach(Gameobject?go?in?Gameobject.FindobjectsOfType(typeof(Gameobject)))
{
if(go.tag?==?iocTag)
{
if(go.GetComponent()?==?null)
{
go.AddComponent().enabled=true;
????????????????????
}
}
}
}
void?Update?()?{
for(int?k=0;?k?<=?samples;?k++)
{
r?=?cam.ViewportPointToRay(new?Vector3(hx[haltonIndex]?hy[haltonIndex]?0f));
haltonIndex++;
if(haltonIndex?>=?pixels)?haltonIndex?=?0;
if(Physics.Raycast(r?out?hit?viewDistance?layerMsk.value))
{
if(l?=?hit.transform.GetComponent())
{
l.UnHide(hit);
}
else?if(l?=?hit.transform.parent.GetComponent())
{
l.UnHide(hit);
}
}
}
}
private?float?HaltonSequence(int?index?int?b)
{
float?res?=?0f;
float?f?=?1f?/?b;
int?i?=?index;
while(i?>?0)
{
res?=?res?+?f?*?(i?%?b);
i?=?Mathf.FloorToInt(i/b);
f?=?f?/?b;
}
return?res;
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2003??2017-05-25?14:04??實時遮擋剔除\IOCcam.cs
?????文件???????1982??2017-05-25?14:04??實時遮擋剔除\IocEditor.cs
?????文件???????8248??2017-05-25?14:04??實時遮擋剔除\IOClod.cs
?????文件????????302??2018-01-23?15:22??實時遮擋剔除\實時遮擋剔除說明.txt
?????目錄??????????0??2018-09-04?17:55??實時遮擋剔除
-----------?---------??----------?-----??----
????????????????12535????????????????????5
- 上一篇:AD5422芯片的C程序應用
- 下一篇:MPI并行遺傳算法
評論
共有 條評論