Local project added
This commit is contained in:
60
Assets/Scripts/VoxelOctree/GPU/VoxelRaycastGPU.cs
Normal file
60
Assets/Scripts/VoxelOctree/GPU/VoxelRaycastGPU.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class VoxelRaycastGPU : MonoBehaviour
|
||||
{
|
||||
public VoxelRaycastGPU(ComputeShader computeShader)
|
||||
{
|
||||
raycastShader = computeShader;
|
||||
}
|
||||
|
||||
public ComputeShader raycastShader;
|
||||
|
||||
public struct Ray
|
||||
{
|
||||
public float pad;
|
||||
public Vector3 direction;
|
||||
}
|
||||
|
||||
public struct BatchData
|
||||
{
|
||||
public Vector3 origin;
|
||||
public float maxDistance;
|
||||
};
|
||||
|
||||
public struct Hit
|
||||
{
|
||||
public float penetrationFactor;
|
||||
public float reflexionFactor;
|
||||
public float lastDistance;
|
||||
private float _pad1;
|
||||
public Vector3 origin;
|
||||
private float _pad2;
|
||||
public Vector3 position;
|
||||
private float _pad3;
|
||||
public float distance;
|
||||
public uint hit;
|
||||
private float _pad4;
|
||||
private float _pad5;
|
||||
}
|
||||
|
||||
public void Init( ComputeShader computeShader )
|
||||
{
|
||||
raycastShader = computeShader;
|
||||
}
|
||||
|
||||
public void Raycast( in Ray[] rays, float maxDistance, ref ComputeBuffer rayBuffer, ref ComputeBuffer hitBuffer )
|
||||
{
|
||||
int kernel = raycastShader.FindKernel("CSMain");
|
||||
|
||||
rayBuffer.SetData(rays);
|
||||
raycastShader.SetBuffer(kernel, "rays", rayBuffer);
|
||||
raycastShader.SetBuffer(kernel, "hits", hitBuffer);
|
||||
raycastShader.SetFloat("maxDistance", maxDistance);
|
||||
|
||||
int threadGroups = Mathf.CeilToInt(rays.Length / 64f);
|
||||
raycastShader.Dispatch(kernel, threadGroups, 1, 1);
|
||||
|
||||
Hit[] hits = new Hit[rays.Length];
|
||||
hitBuffer.GetData(hits);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user