本文整理汇总了C#中UnityEngine.ComputeBuffer类的典型用法代码示例。如果您正苦于以下问题:C# ComputeBuffer类的具体用法?C# ComputeBuffer怎么用?C# ComputeBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ComputeBuffer类属于UnityEngine命名空间,在下文中一共展示了ComputeBuffer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: WallService
public WallService(int capacity)
{
this.capacity = capacity;
_colliders = new List<Transform>(capacity);
_walls = new Wall[capacity];
Walls = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(Wall)));
Walls.SetData(_walls);
}
开发者ID:sugi-cho,项目名称:ParticlePhysics,代码行数:8,代码来源:WallService.cs
示例2: Start
// Use this for initialization
void Start()
{
Debug.Log("Population size: " + populationSize);
int width = (int)Mathf.Round(Mathf.Sqrt(populationSize));
int height = (int)Mathf.Round(Mathf.Sqrt(populationSize));
testing = new ComputeBuffer(10, Marshal.SizeOf(typeof(Individual)));
Debug.Log("Seed " + DateTime.Now.Millisecond);
// Fill with random genome, and run first fitness test.
int kernel = shader.FindKernel("InitializePopulation");
DebugAux.Assert(kernel >= 0, "Couldn't find kernel: " + "InitializePopulation " + kernel);
shader.SetBuffer(kernel, "Population", testing);
shader.SetFloat("seed", DateTime.Now.Millisecond);
shader.Dispatch(kernel, 32, 32, 1);
Individual[] tes = new Individual[10];
testing.GetData(tes);
for (int i = 0; i < tes.Length; i++)
Debug.Log(tes[i].genome + " " + tes[i].fitness);
// Selection..
/*kernel = shader.FindKernel("AllOnesFitness");
DebugAux.Assert(kernel >= 0, "Couldn't find kernel: " + "AllOnesFitness " + kernel);
shader.SetBuffer(kernel, "Population", testing);
shader.Dispatch(kernel, 32, 32, 1);*/
testing.Dispose();
}
开发者ID:KalleSjostrom,项目名称:Genome,代码行数:31,代码来源:GeneticAlgorithmCS.cs
示例3: SplatGenVerticesPass
public SplatGenVerticesPass()
{
base.LoadComputeShader("Assets/Shaders/splat_gen_vertices.compute");
indexCounterBuffer = new ComputeBuffer(1, sizeof(int));
nonemptyLeft = new ComputeBuffer(1, sizeof(int));
}
开发者ID:Mymicky,项目名称:MarchingCubesUnity,代码行数:7,代码来源:SplatGenVerticesPass.cs
示例4: ConstantService
public ConstantService(int capacity, ConstantData d)
{
_data = d;
_dragCoeffData = new float[capacity];
_dragCoeffs = new ComputeBuffer (capacity, Marshal.SizeOf (typeof(float)));
CheckDragCoeffs();
}
开发者ID:nobnak,项目名称:ParticlePhysics,代码行数:7,代码来源:ConstantService.cs
示例5: Init
public void Init()
{
_numParticlesX = _particleGroupsX * kNumThreadsX;
_numParticlesY = _particleGroupsY * kNumThreadsY;
_numParticles = _numParticlesX * _numParticlesY;
_currentCopiedVertices = 0;
_particleMaterial = Resources.Load<Material>("GPUParticleMat");
_computeShader = Resources.Load<ComputeShader>("ComputeShaders/GPUParticleUpdater");
_kernelMoveParticles = _computeShader.FindKernel(kKernelMoveParticles);
_particlesData = new Particle[_numParticles];
InitBuffer(_particlesData);
for (int i = 0; i < _particlesData.Length; ++i)
{
float id = ((float)i) / 10000.1f;
CreateParticle(id);
}
// Set ComputeShader Parameters
_particlesBuffer = new ComputeBuffer(_particlesData.Length, System.Runtime.InteropServices.Marshal.SizeOf(typeof(GPUParticleSystem.Particle)));
_particlesBuffer.SetData(_particlesData);
_computeShader.SetBuffer(_kernelMoveParticles, "_ParticlesBuffer", _particlesBuffer);
_computeShader.SetFloat("_Width", _numParticlesX);
_computeShader.SetFloat("_Height", _numParticlesY);
// Set Shader Parameters
_particleMaterial.SetBuffer("_ParticlesBuffer", _particlesBuffer);
}
开发者ID:mqmtech,项目名称:ShadersDemo,代码行数:34,代码来源:GPUParticleSystem.cs
示例6: InitBuffers
public void InitBuffers()
{
// Ingredient data
if (ProteinColors == null) ProteinColors = new ComputeBuffer(NumIngredientsMax, 16);
if (ProteinToggleFlags == null) ProteinToggleFlags = new ComputeBuffer(NumIngredientsMax, 4);
// Instance data
if (ProteinInstanceInfos == null) ProteinInstanceInfos = new ComputeBuffer(NumProteinInstancesMax, 16);
if (ProteinInstanceCullFlags == null) ProteinInstanceCullFlags = new ComputeBuffer(NumProteinInstancesMax, 4);
if (ProteinInstancePositions == null) ProteinInstancePositions = new ComputeBuffer(NumProteinInstancesMax, 16);
if (ProteinInstanceRotations == null) ProteinInstanceRotations = new ComputeBuffer(NumProteinInstancesMax, 16);
// Atom data
if (ProteinAtomPositions == null) ProteinAtomPositions = new ComputeBuffer(NumProteinAtomMax, 16);
if (ProteinAtomCount == null) ProteinAtomCount = new ComputeBuffer(NumIngredientsMax, 4);
if (ProteinAtomStart == null) ProteinAtomStart = new ComputeBuffer(NumIngredientsMax, 4);
// Cluster data
if (ProteinClusterPositions == null) ProteinClusterPositions = new ComputeBuffer(NumProteinAtomMax, 16);
if (ProteinClusterCount == null) ProteinClusterCount = new ComputeBuffer(NumIngredientsMax * 4, 4);
if (ProteinClusterStart == null) ProteinClusterStart = new ComputeBuffer(NumIngredientsMax * 4, 4);
// Lod data
if (LodInfos == null) LodInfos = new ComputeBuffer(8, 16);
// Sphere batch
if (SphereBatchBuffer == null) SphereBatchBuffer = new ComputeBuffer(NumSphereBatchesMax, 16, ComputeBufferType.Append);
}
开发者ID:illvisation,项目名称:cellVIEW_lite,代码行数:28,代码来源:ComputeBufferManager.cs
示例7: Awake
void Awake()
{
var mf = prefab.GetComponent<MeshFilter>();
var mesh = mf.sharedMesh;
_indexBuf = new ComputeBuffer(mesh.triangles.Length, Marshal.SizeOf(mesh.triangles[0]));
_indexBuf.SetData(mesh.triangles);
_vertexBuf = new ComputeBuffer(mesh.vertices.Length, Marshal.SizeOf(mesh.vertices[0]));
_vertexBuf.SetData(mesh.vertices);
_uvBuf = new ComputeBuffer(mesh.uv.Length, Marshal.SizeOf(mesh.uv[0]));
_uvBuf.SetData(mesh.uv);
var gofab = new GameObject("Position");
gofab.hideFlags = HideFlags.HideAndDontSave;
_trs = GenerateRandom(gofab, count);
_worlds = new float[16 * _trs.Length];
_worldBuf = new ComputeBuffer(_trs.Length, 16 * Marshal.SizeOf(_worlds[0]));
UpdateWorlds();
_mat = new Material(prefab.renderer.sharedMaterial);
_mat.SetBuffer(CS_INDEX_BUFFER, _indexBuf);
_mat.SetBuffer(CS_VERTEX_BUFFER, _vertexBuf);
_mat.SetBuffer(CS_UV_BUFFER, _uvBuf);
_mat.SetBuffer(CS_WORLD_BUFFER, _worldBuf);
}
开发者ID:nobnak,项目名称:InstancingExampleUnity,代码行数:27,代码来源:Instancing.cs
示例8: Start
void Start()
{
ComputeBuffer buffer = new ComputeBuffer (4 * 4 * 2 * 2, sizeof(int));
int kernel = shader.FindKernel ("CSMain2");
shader.SetBuffer (kernel, "buffer2", buffer);
shader.Dispatch (kernel, 2, 2, 1);
int[] data = new int[4 * 4 * 2 * 2];
buffer.GetData (data);
for(int i = 0; i < 8; i++)
{
string line = "";
for(int j = 0; j < 8; j++)
{
line += " " + data[j+i*8];
}
Debug.Log (line);
}
buffer.Release ();
}
开发者ID:Appms,项目名称:GPGPU-Tests,代码行数:26,代码来源:KernelExample.cs
示例9: constructor
static public int constructor(IntPtr l) {
try {
int argc = LuaDLL.lua_gettop(l);
UnityEngine.ComputeBuffer o;
if(argc==3){
System.Int32 a1;
checkType(l,2,out a1);
System.Int32 a2;
checkType(l,3,out a2);
o=new UnityEngine.ComputeBuffer(a1,a2);
pushValue(l,true);
pushValue(l,o);
return 2;
}
else if(argc==4){
System.Int32 a1;
checkType(l,2,out a1);
System.Int32 a2;
checkType(l,3,out a2);
UnityEngine.ComputeBufferType a3;
checkEnum(l,4,out a3);
o=new UnityEngine.ComputeBuffer(a1,a2,a3);
pushValue(l,true);
pushValue(l,o);
return 2;
}
return error(l,"New object failed.");
}
catch(Exception e) {
return error(l,e);
}
}
开发者ID:602147629,项目名称:2DPlatformer-SLua,代码行数:32,代码来源:Lua_UnityEngine_ComputeBuffer.cs
示例10: Awake
protected override void Awake()
{
base.Awake();
int tileSize = GetTileSize();
int capacity = GetCapacity();
for(int i = 0; i < capacity; i++)
{
ComputeBuffer buffer;
switch((int)m_dataType)
{
case (int)DATA_TYPE.FLOAT:
buffer = new ComputeBuffer(tileSize, sizeof(float) * m_channels, m_bufferType);
break;
case (int)DATA_TYPE.INT:
buffer = new ComputeBuffer(tileSize, sizeof(int) * m_channels, m_bufferType);
break;
case (int)DATA_TYPE.BYTE:
buffer = new ComputeBuffer(tileSize, sizeof(byte) * m_channels, m_bufferType);
break;
default:
buffer = new ComputeBuffer(tileSize, sizeof(float) * m_channels, m_bufferType);
break;
};
CBSlot slot = new CBSlot(this, buffer);
AddSlot(i, slot);
}
}
开发者ID:Climberfx,项目名称:Scatterer,代码行数:35,代码来源:CBTileStorage.cs
示例11: DoInit
void DoInit()
{
if(_particlesBuffer != null)
{
_particlesBuffer.Release();
_particlesBuffer = null;
}
_particlesBuffer = new ComputeBuffer(_totalNumParticles, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ImageParticleEngine.ParticleData)) );
_particlesPhysicsBuffer = new ComputeBuffer(_totalNumParticles, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ImageParticleEngine.ParticlePhysicsData)) );
_shaderCompute.SetBuffer(_initImageKernelId, "_ParticlesBuffer", _particlesBuffer);
_shaderCompute.SetBuffer(_initImageKernelId, "_ParticlesPhysicsBuffer", _particlesPhysicsBuffer);
_shaderCompute.SetBuffer(_updateParticlesKernel, "_ParticlesBuffer", _particlesBuffer);
_shaderCompute.SetBuffer(_updateParticlesKernel, "_ParticlesPhysicsBuffer", _particlesPhysicsBuffer);
_shaderCompute.SetVector("_ImageSize", new Vector4(_image.width, _image.height, 0f, 0f));
_shaderCompute.SetTexture(_initImageKernelId, "_Image", _image);
_shaderCompute.SetVector("_Position", transform.position);
_shaderCompute.SetVector("_ParticleHalfSize", new Vector4(1f, 1f, 1f, 1f)*0.016f);
_shaderCompute.SetInt("_ImageLayers", _imageLayers);
_material.SetBuffer("_ParticlesBuffer", _particlesBuffer);
_material.SetVector("_ImageSize", new Vector4(_image.width, _image.height, 0f, 0f));
_material.SetVector("_ParticleHalfSize", new Vector4(1f, 1f, 0f, 1f)*0.016f);
_shaderCompute.Dispatch(_initImageKernelId, _numThreadGroupsX, _numThreadGroupsY, _numThreadGroupsZ);
}
开发者ID:mqmtech,项目名称:ShadersDemo,代码行数:29,代码来源:ImageParticleEngine.cs
示例12: InitializeSimulation
void InitializeSimulation()
{
if (SystemInfo.supportsComputeShaders)
{
m_cb_params = new ComputeBuffer(1, CSParams.size);
m_cb_particles = new ComputeBuffer(m_particle_count, peParticle.size);
m_cb_positions = new ComputeBuffer(m_particle_count, 12);
m_cb_velocities = new ComputeBuffer(m_particle_count, 12);
m_buf_positions = new Vector3[m_particle_count];
m_buf_velocities = new Vector3[m_particle_count];
m_csparams = new CSParams[1];
}
{
UnityEngine.Random.seed = 0;
var tmp = new peParticle[m_particle_count];
for (int i = 0; i < tmp.Length; ++i)
{
tmp[i].position = new Vector3(
UnityEngine.Random.Range(-5.0f, 5.0f),
UnityEngine.Random.Range(-5.0f, 5.0f) + 5.0f,
UnityEngine.Random.Range(-5.0f, 5.0f));
}
m_cb_particles.SetData(tmp);
}
}
开发者ID:garytyler,项目名称:AlembicImporter,代码行数:25,代码来源:ParticleEngine.cs
示例13: BitonicSort
public void BitonicSort(ComputeBuffer kip, ComputeBuffer kip_tmp, uint num)
{
uint BITONIC_BLOCK_SIZE = 512;
uint TRANSPOSE_BLOCK_SIZE = 16;
uint NUM_ELEMENTS = num;
uint MATRIX_WIDTH = BITONIC_BLOCK_SIZE;
uint MATRIX_HEIGHT = NUM_ELEMENTS / BITONIC_BLOCK_SIZE;
for (uint level = 2; level <= BITONIC_BLOCK_SIZE; level <<= 1)
{
m_consts[0].level = level;
m_consts[0].levelMask = level;
m_consts[0].width = MATRIX_HEIGHT; // not a mistake!
m_consts[0].height = MATRIX_WIDTH; //
m_buf_consts[0].SetData(m_consts);
m_cs_bitonic_sort.SetBuffer(0, "consts", m_buf_consts[0]);
m_cs_bitonic_sort.SetBuffer(0, "kip_rw", kip);
m_cs_bitonic_sort.Dispatch(0, (int)(NUM_ELEMENTS / BITONIC_BLOCK_SIZE), 1, 1);
}
// Then sort the rows and columns for the levels > than the block size
// Transpose. Sort the Columns. Transpose. Sort the Rows.
for (uint level = (BITONIC_BLOCK_SIZE << 1); level <= NUM_ELEMENTS; level <<= 1)
{
m_consts[0].level = (level / BITONIC_BLOCK_SIZE);
m_consts[0].levelMask = (level & ~NUM_ELEMENTS) / BITONIC_BLOCK_SIZE;
m_consts[0].width = MATRIX_WIDTH;
m_consts[0].height = MATRIX_HEIGHT;
m_buf_consts[0].SetData(m_consts);
// Transpose the data from buffer 1 into buffer 2
m_cs_bitonic_sort.SetBuffer(1, "consts", m_buf_consts[0]);
m_cs_bitonic_sort.SetBuffer(1, "kip", kip);
m_cs_bitonic_sort.SetBuffer(1, "kip_rw", kip_tmp);
m_cs_bitonic_sort.Dispatch(1, (int)(MATRIX_WIDTH / TRANSPOSE_BLOCK_SIZE), (int)(MATRIX_HEIGHT / TRANSPOSE_BLOCK_SIZE), 1);
// Sort the transposed column data
m_cs_bitonic_sort.SetBuffer(0, "consts", m_buf_consts[0]);
m_cs_bitonic_sort.SetBuffer(0, "kip_rw", kip_tmp);
m_cs_bitonic_sort.Dispatch(0, (int)(NUM_ELEMENTS / BITONIC_BLOCK_SIZE), 1, 1);
m_consts[0].level = BITONIC_BLOCK_SIZE;
m_consts[0].levelMask = level;
m_consts[0].width = MATRIX_HEIGHT;
m_consts[0].height = MATRIX_WIDTH;
m_buf_consts[0].SetData(m_consts);
// Transpose the data from buffer 2 back into buffer 1
m_cs_bitonic_sort.SetBuffer(1, "consts", m_buf_consts[0]);
m_cs_bitonic_sort.SetBuffer(1, "kip", kip_tmp);
m_cs_bitonic_sort.SetBuffer(1, "kip_rw", kip);
m_cs_bitonic_sort.Dispatch(1, (int)(MATRIX_HEIGHT / TRANSPOSE_BLOCK_SIZE), (int)(MATRIX_WIDTH / TRANSPOSE_BLOCK_SIZE), 1);
// Sort the row data
m_cs_bitonic_sort.SetBuffer(0, "consts", m_buf_consts[0]);
m_cs_bitonic_sort.SetBuffer(0, "kip_rw", kip);
m_cs_bitonic_sort.Dispatch(0, (int)(NUM_ELEMENTS / BITONIC_BLOCK_SIZE), 1, 1);
}
}
开发者ID:WondermSwift,项目名称:BlueImpulse,代码行数:60,代码来源:GPUSort.cs
示例14: Start
void Start ()
{
ReleaseBuffers ();
if (CoordinateMapperManager == null)
{
return;
}
_CoordinateMapperManager = CoordinateMapperManager.GetComponent<CoordinateMapperManager>();
Texture2D renderTexture = _CoordinateMapperManager.GetColorTexture();
if (renderTexture != null)
{
gameObject.GetComponent<Renderer>().material.SetTexture("_MainTex", renderTexture);
}
depthPoints = _CoordinateMapperManager.GetDepthCoordinates ();
if (depthPoints != null)
{
depthBuffer = new ComputeBuffer(depthPoints.Length, sizeof(float) * 2);
gameObject.GetComponent<Renderer>().material.SetBuffer("depthCoordinates", depthBuffer);
}
bodyIndexPoints = _CoordinateMapperManager.GetBodyIndexBuffer ();
if (bodyIndexPoints != null)
{
bodyIndexBuffer = new ComputeBuffer(bodyIndexPoints.Length, sizeof(float));
gameObject.GetComponent<Renderer>().material.SetBuffer ("bodyIndexBuffer", bodyIndexBuffer);
}
}
开发者ID:iEmily,项目名称:nutra-ninja,代码行数:31,代码来源:CoordinateMapperView.cs
示例15: InitiateBuffers
//
private void InitiateBuffers()
{
//
Debug.Log("InitiateBuffers");
//
Texture2D renderTexture = m_MultiSourceManger.GetColorTexture();
if( renderTexture != null )
{
gameObject.renderer.material.SetTexture("_MainTex", renderTexture);
}
m_DepthPoints = m_MultiSourceManger.GetDepthCoordinates();
if( m_DepthPoints != null )
{
m_DepthBuffer = new ComputeBuffer( m_DepthPoints.Length, sizeof(float) * 2 );
gameObject.renderer.material.SetBuffer( "depthCoordinates", m_DepthBuffer );
}
m_BodyIndexPoints = m_MultiSourceManger.GetBodyIndexData();
if( m_BodyIndexPoints != null)
{
m_BodyIndexBuffer = new ComputeBuffer( m_BodyIndexPoints.Length, sizeof(float) );
gameObject.renderer.material.SetBuffer ( "bodyIndexBuffer", m_BodyIndexBuffer );
}
}
开发者ID:ShipuW,项目名称:unity-study,代码行数:27,代码来源:UserVisualPanel.cs
示例16: InitializeBuffers
void InitializeBuffers() {
computeBuffer = new ComputeBuffer(numPoints, 12);
computeShaderA.SetBuffer(kernelID, "outputBuffer", computeBuffer);
timeBuffer = new ComputeBuffer(1, 4);
timeArray = new float[1];
material.SetBuffer("buf_Points", computeBuffer);
}
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:7,代码来源:TestComputeSharedBufferA.cs
示例17: InitializeBuffers
void InitializeBuffers()
{
// Set start point compute buffer
startPointBuffer = new ComputeBuffer(VertCount, 4); // create space in the buffer for 3 float per point (float = 4 bytes)
// Set const compute buffer size
constantBuffer = new ComputeBuffer(1, 4);
modBuffer = new ComputeBuffer(VertCount, 8);
// Set output buffer size.
outputBuffer = new ComputeBuffer(VertCount, 12);
// These values will be the starting y coords for each point.
float[] values = new float[VertCount];
Vector2[] mods = new Vector2[VertCount];
for (int i = 0; i < VertCount; i++)
{
values[i] = Random.value * 2 * Mathf.PI;
mods[i] = new Vector2(.1f + Random.value, .1f + Random.value);
}
modBuffer.SetData(mods);
// Load starting valuse into the compute buffer
startPointBuffer.SetData(values);
// Only need to set the offsets once in the CS
computeShader.SetBuffer(CSKernel, "startPointBuffer", startPointBuffer);
}
开发者ID:emomper23,项目名称:PsychVR,代码行数:31,代码来源:WeatherShaderOutput.cs
示例18: Start
void Start()
{
//清空緩衝器。
ReleaseBuffers ();
//如果讀取不到資料來源程式,跳出。
if (CoordinateMapperManager == null)
{
return;
}
_CoordinateMapperManager = CoordinateMapperManager.GetComponent<CoordinateMapperManager>();
//讀取彩色貼圖。
Texture2D renderTexture = _CoordinateMapperManager.GetColorTexture();
if (renderTexture != null)
{
gameObject.renderer.material.SetTexture("_MainTex", renderTexture);
}
//讀取深度資料座標。
depthPoints = _CoordinateMapperManager.GetDepthCoordinates ();
if (depthPoints != null)
{
depthBuffer = new ComputeBuffer(depthPoints.Length, sizeof(float) * 2);
gameObject.renderer.material.SetBuffer("depthCoordinates", depthBuffer);
}
//讀取人體辨識資料。
bodyIndexPoints = _CoordinateMapperManager.GetBodyIndexBuffer ();
if (bodyIndexPoints != null)
{
bodyIndexBuffer = new ComputeBuffer(bodyIndexPoints.Length, sizeof(float));
gameObject.renderer.material.SetBuffer ("bodyIndexBuffer", bodyIndexBuffer);
}
}
开发者ID:josephMG,项目名称:KinectOneForZigFu,代码行数:32,代码来源:CoordinateMapperView.cs
示例19: Initialize
public void Initialize(ComputeShader sh_bitonic_sort)
{
m_cs_bitonic_sort = sh_bitonic_sort;
m_buf_consts[0] = new ComputeBuffer(1, 16);
m_buf_consts[1] = new ComputeBuffer(1, 16);
m_buf_dummies[0] = new ComputeBuffer(1, 16);
m_buf_dummies[1] = new ComputeBuffer(1, 16);
}
开发者ID:WondermSwift,项目名称:BlueImpulse,代码行数:8,代码来源:GPUSort.cs
示例20: InitializeBuffers
void InitializeBuffers() {
outputBuffer = new ComputeBuffer(VertCount, (sizeof(float) * 3) + (sizeof(int) * 6));
computeShader.SetBuffer(CSKernel, "outputBuffer", outputBuffer);
if (Debugrender)
PointMaterial.SetBuffer("buf_Points", outputBuffer);
}
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:8,代码来源:TestComputeShaderOutput.cs
注:本文中的UnityEngine.ComputeBuffer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论