本文整理汇总了C#中UnityEngine.Material.SetBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# Material.SetBuffer方法的具体用法?C# Material.SetBuffer怎么用?C# Material.SetBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Material
的用法示例。
在下文中一共展示了Material.SetBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: OnRender
private void OnRender(Material mat)
{
//
if( !m_bInit )
return;
if( m_DepthPoints == null || m_BodyIndexPoints == null)
{
return;
}
// TODO: fix perf on this call.
m_DepthBuffer.SetData(m_DepthPoints);
//m_DepthBuffer.SetData(dss);
mat.SetBuffer( "depthCoordinates", m_DepthBuffer );
// ComputeBuffers do not accept bytes, so we need to convert to float.
float[] buffer = new float[m_BodyIndexPoints.Length];
for (int i = 0; i < m_BodyIndexPoints.Length; i++)
{
buffer[i] = (float)m_BodyIndexPoints[i];
}
m_BodyIndexBuffer.SetData(buffer);
mat.SetBuffer ( "bodyIndexBuffer", m_BodyIndexBuffer );
for(int i = 0;i<6;i++)
{
mat.SetColor("bodyIndexColor" + i,BodyColor[i]);
}
buffer = null;
UserManager m_UserManager = UserManager.Instance;
if (!m_UserManager.Inited || !m_UserManager.HasLockUser)
{
mat.SetInt("lockBodyIndex",255);
return;
}
Windows.Kinect.Body lockBody = m_UserManager.LockBody;
if (lockBody != null)
{
mat.SetInt("lockBodyIndex",m_UserManager.LockBodyIndex);
Debug.Log("lockBodyIndex : " + m_UserManager.LockBodyIndex);
}
else
{
mat.SetInt("lockBodyIndex",255);
}
}
示例3: CloneMaterial
public override Material CloneMaterial(Material src, int nth)
{
Material m = new Material(src);
m.SetInt("g_batch_begin", nth * m_instances_par_batch);
m.SetBuffer("particles", m_world.GetParticleBuffer());
m.SetBuffer("params", m_buf_trail_params);
m.SetBuffer("vertices", m_buf_trail_vertices);
// fix rendering order for transparent objects
if (m.renderQueue >= 3000)
{
m.renderQueue = m.renderQueue + (nth + 1);
}
return m;
}
示例4: CloneMaterial
public override Material CloneMaterial(Material src, int nth)
{
Material m = new Material(src);
m.SetInt("g_batch_begin", nth * m_instances_par_batch);
m.SetBuffer("particles", m_world.GetParticleBuffer());
if (m_hdr)
{
m.SetInt("_SrcBlend", (int)BlendMode.One);
m.SetInt("_DstBlend", (int)BlendMode.One);
}
else
{
m.SetInt("_SrcBlend", (int)BlendMode.DstColor);
m.SetInt("_DstBlend", (int)BlendMode.Zero);
}
if(m_enable_shadow)
{
m.EnableKeyword("ENABLE_SHADOW");
switch (m_sample)
{
case Sample.Fast:
m.EnableKeyword("QUALITY_FAST");
break;
case Sample.Medium:
m.EnableKeyword("QUALITY_MEDIUM");
break;
case Sample.High:
m.EnableKeyword("QUALITY_HIGH");
break;
}
}
return m;
}
示例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);
}
示例6: SetShaderParams
/// <summary>
/// Sets the shader parameters of this renderer to the specified material.
/// </summary>
/// <param name="material"></param>
public void SetShaderParams(Material material)
{
// Set all properties
material.SetBuffer("HairVertexTangents", this._master.g_HairVertexTangents);
material.SetBuffer("HairVertexPositions", this._master.g_HairVertexPositions);
material.SetBuffer("TriangleIndicesBuffer", this.g_TriangleIndicesBuffer);
material.SetBuffer("LineIndicesBuffer", this.g_LineIndicesBuffer);
material.SetBuffer("GlobalRotations", this._master.g_GlobalRotations);
material.SetBuffer("HairThicknessCoeffs", this._master.g_HairThicknessCoeffs);
material.SetBuffer("TexCoords", this._master.g_TexCoords);
material.SetFloat("_ThinTip", this.hairMaterial.GetFloat("_ThinTip"));
material.SetFloat("_HairWidth", this.hairMaterial.GetFloat("_HairWidth"));
material.SetFloat("_HairWidthMultiplier", this.hairMaterial.GetFloat("_HairWidthMultiplier"));
SetSimulationTransformCorrection(material);
}
示例7: DrawProteinSphereBatches
public static void DrawProteinSphereBatches(Material renderProteinsMaterial, Camera camera, RenderBuffer colorBuffer, RenderBuffer depthBuffer, int pass)
{
// Protein params
renderProteinsMaterial.SetInt("_EnableLod", Convert.ToInt32(PersistantSettings.Instance.EnableLod));
renderProteinsMaterial.SetFloat("_Scale", PersistantSettings.Instance.Scale);
renderProteinsMaterial.SetFloat("_FirstLevelBeingRange", PersistantSettings.Instance.FirstLevelOffset);
renderProteinsMaterial.SetVector("_CameraForward", camera.transform.forward);
renderProteinsMaterial.SetBuffer("_LodLevelsInfos", GPUBuffers.Instance.LodInfo);
renderProteinsMaterial.SetBuffer("_ProteinInstanceInfo", GPUBuffers.Instance.ProteinInstanceInfo);
renderProteinsMaterial.SetBuffer("_ProteinInstancePositions", GPUBuffers.Instance.ProteinInstancePositions);
renderProteinsMaterial.SetBuffer("_ProteinInstanceRotations", GPUBuffers.Instance.ProteinInstanceRotations);
renderProteinsMaterial.SetBuffer("_ProteinColors", GPUBuffers.Instance.ProteinColors);
renderProteinsMaterial.SetBuffer("_ProteinAtomPositions", GPUBuffers.Instance.ProteinAtoms);
renderProteinsMaterial.SetBuffer("_ProteinClusterPositions", GPUBuffers.Instance.ProteinAtomClusters);
renderProteinsMaterial.SetBuffer("_ProteinSphereBatchInfos", GPUBuffers.Instance.SphereBatches);
Graphics.SetRenderTarget(colorBuffer, depthBuffer);
renderProteinsMaterial.SetPass(pass);
Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Instance.ArgBuffer);
}
示例8: Init
public void Init()
{
_grassShader = Resources.Load<Shader>("Shaders/GrassGeneratorShader");
_grassMaterial = Resources.Load<Material>("GrassGeneratorMat");
_noiseTex = Resources.Load<Texture>("Noise");
if(_noiseTex == null)
{
Debug.LogError("Not found noise");
}
_grassComputeShader = Resources.Load<ComputeShader>("ComputeShaders/GrassComputeShader");
_initGrassKernelId = _grassComputeShader.FindKernel(kInitGrassKernel);
_updateGrassKernelId = _grassComputeShader.FindKernel(kUpdateGrassKernel);
_numGrassItems = _numGroupGrassX*_numGroupGrassY*kThreadsX*kThreadsY;
_grassBuffer = new ComputeBuffer(_numGrassItems, System.Runtime.InteropServices.Marshal.SizeOf(typeof(GrassData)));
_obstaclesBuffer = new ComputeBuffer(kMaxObstacles, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ObstacleData)));
_grassComputeShader.SetFloat("_Width", _numGroupGrassX*kThreadsX);
_grassComputeShader.SetFloat("_Height", _numGroupGrassY*kThreadsY);
_grassComputeShader.SetTexture(_initGrassKernelId, "_NoiseTex", _noiseTex);
_grassMaterial.SetTexture("_NoiseTex", _noiseTex);
_grassMaterial.SetFloat("_Width", _numGroupGrassX*kThreadsX);
_grassMaterial.SetFloat("_Height", _numGroupGrassY*kThreadsY);
_grassComputeShader.SetBuffer(_initGrassKernelId, "_GrassBuffer", _grassBuffer);
_grassComputeShader.SetBuffer(_updateGrassKernelId, "_GrassBuffer", _grassBuffer);
_grassComputeShader.SetBuffer(_updateGrassKernelId, "_ObstaclesBuffer", _obstaclesBuffer);
_grassComputeShader.SetInt("_NumObstacles", 0);
_grassMaterial.SetBuffer("_GrassBuffer", _grassBuffer);
_grassComputeShader.Dispatch(_initGrassKernelId, _numGroupGrassX, _numGroupGrassY, 1);
#if GRASS_CPU
_grassDataTestCPU = new GrassData[_numGrassItems];
_grassBuffer.GetData(_grassDataTestCPU);
#endif
_isInit = true;
}
示例9: ComputeOcclusionMaskGEqual
//ComputeShaderManager.Get.ObjectSpaceCutAwaysCS.SetBuffer(0, "_CutInfos", GPUBuffers.Get.CutInfo);
public static void ComputeOcclusionMaskGEqual(Material OcclusionQueriesMaterial, RenderTexture tempBuffer, bool maskProtein, bool maskLipid)
{
// First clear mask buffer
Graphics.SetRenderTarget(tempBuffer);
GL.Clear(true, true, Color.blue, 0);
//***** Compute Protein Mask *****//
if (maskProtein)
{
// Always clear append buffer before usage
GPUBuffers.Get.SphereBatches.ClearAppendBuffer();
//Fill the buffer with occludees
ComputeShaderManager.Get.SphereBatchCS.SetUniform("_NumInstances", SceneManager.Get.NumProteinInstances);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_ProteinInstanceCullFlags", GPUBuffers.Get.ProteinInstanceCullFlags);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_IngredientMaskParams", GPUBuffers.Get.IngredientMaskParams);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
ComputeShaderManager.Get.SphereBatchCS.Dispatch(1, Mathf.CeilToInt(SceneManager.Get.NumProteinInstances / 64.0f), 1, 1);
// Count occludees instances
ComputeBuffer.CopyCount(GPUBuffers.Get.SphereBatches, GPUBuffers.Get.ArgBuffer, 0);
// Prepare draw call
OcclusionQueriesMaterial.SetFloat("_Scale", GlobalProperties.Get.Scale);
OcclusionQueriesMaterial.SetBuffer("_ProteinRadii", GPUBuffers.Get.ProteinRadii);
OcclusionQueriesMaterial.SetBuffer("_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
OcclusionQueriesMaterial.SetBuffer("_ProteinInstancePositions", GPUBuffers.Get.ProteinInstancePositions);
OcclusionQueriesMaterial.SetBuffer("_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
OcclusionQueriesMaterial.SetPass(4);
// Draw occludees - bounding sphere only - write to depth and stencil buffer
Graphics.SetRenderTarget(tempBuffer);
Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Get.ArgBuffer);
}
//***** Compute Lipid Mask *****//
if (maskLipid)
{
// Always clear append buffer before usage
GPUBuffers.Get.SphereBatches.ClearAppendBuffer();
//Fill the buffer with occludees
ComputeShaderManager.Get.SphereBatchCS.SetUniform("_NumInstances", SceneManager.Get.NumLipidInstances);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_LipidInstanceInfo", GPUBuffers.Get.LipidInstancesInfo);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_LipidInstanceCullFlags", GPUBuffers.Get.LipidInstanceCullFlags);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_IngredientMaskParams", GPUBuffers.Get.IngredientMaskParams);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
ComputeShaderManager.Get.SphereBatchCS.Dispatch(3, Mathf.CeilToInt(SceneManager.Get.NumLipidInstances / 64.0f), 1, 1);
// Count occludees instances
ComputeBuffer.CopyCount(GPUBuffers.Get.SphereBatches, GPUBuffers.Get.ArgBuffer, 0);
//DebugSphereBatchCount();
// Prepare draw call
OcclusionQueriesMaterial.SetFloat("_Scale", GlobalProperties.Get.Scale);
OcclusionQueriesMaterial.SetBuffer("_LipidInstanceInfo", GPUBuffers.Get.LipidInstancesInfo);
OcclusionQueriesMaterial.SetBuffer("_LipidInstancePositions", GPUBuffers.Get.LipidInstancePositions);
OcclusionQueriesMaterial.SetBuffer("_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
OcclusionQueriesMaterial.SetPass(5);
// Draw occludees - bounding sphere only - write to depth and stencil buffer
Graphics.SetRenderTarget(tempBuffer);
Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Get.ArgBuffer);
}
}
示例10: ComputeColorComposition
public static void ComputeColorComposition(Camera camera, Material colorCompositeMaterial, RenderTexture dst, RenderTexture instanceIdBuffer, RenderTexture atomIdBuffer, RenderTexture depthBuffer)
{
var temp1 = new DisplayInfo[CPUBuffers.Get.IngredientsDisplayInfo.Count];
var temp2 = new DisplayInfo[CPUBuffers.Get.IngredientGroupsDisplayInfo.Count];
GPUBuffers.Get.IngredientsColorInfo.GetData(temp1);
GPUBuffers.Get.IngredientGroupsColorInfo.GetData(temp2);
CPUBuffers.Get.IngredientsDisplayInfo = temp1.ToList();
CPUBuffers.Get.IngredientGroupsDisplayInfo = temp2.ToList();
//Debug.Log(temp2[5].ToString());
/**************/
//colorCompositeMaterial.SetFloat("_depth", ColorManager.Get.depthSlider);
colorCompositeMaterial.SetFloat("_UseHCL", Convert.ToInt32(ColorManager.Get.UseHCL));
colorCompositeMaterial.SetFloat("_ShowAtoms", Convert.ToInt32(ColorManager.Get.ShowAtoms));
colorCompositeMaterial.SetFloat("_ShowChains", Convert.ToInt32(ColorManager.Get.ShowChains));
colorCompositeMaterial.SetFloat("_ShowResidues", Convert.ToInt32(ColorManager.Get.ShowResidues));
colorCompositeMaterial.SetFloat("_ShowSecondaryStructures", Convert.ToInt32(ColorManager.Get.ShowSecondaryStructures));
colorCompositeMaterial.SetFloat("_AtomDistance", ColorManager.Get.AtomDistance);
colorCompositeMaterial.SetFloat("_ChainDistance", ColorManager.Get.ChainDistance);
colorCompositeMaterial.SetFloat("_ResidueDistance", ColorManager.Get.ResidueDistance);
colorCompositeMaterial.SetFloat("_SecondaryStructureDistance", ColorManager.Get.SecondaryStructureDistance);
// LOD infos
var rangeValues = Matrix4x4.zero;
int distAcc = 0;
for (int i = 0; i < ColorManager.Get.LevelRanges.Length; i++)
{
distAcc += (int)(ColorManager.Get.LevelRanges[i] * ColorManager.Get.DistanceMax);
rangeValues[i] = distAcc;
}
rangeValues[ColorManager.Get.LevelRanges.Length] = ColorManager.Get.DistanceMax;
var selectionSphere = (Vector4)SelectionManager.Instance.SelectionGameObject.transform.position;
selectionSphere.w = SelectionManager.Instance.SelectionGameObject.GetComponent<SphereCollider>().radius;
colorCompositeMaterial.SetVector("_FocusSphere", selectionSphere);
colorCompositeMaterial.SetMatrix("_ProjectionMatrix", camera.projectionMatrix);
colorCompositeMaterial.SetMatrix("_InverseViewMatrix", camera.cameraToWorldMatrix);
colorCompositeMaterial.SetInt("_UseDistanceLevels", Convert.ToInt32(ColorManager.Get.UseDistanceLevels));
colorCompositeMaterial.SetInt("_NumLevelMax", ColorManager.Get.NumLevelMax);
colorCompositeMaterial.SetInt("_DistanceMax", ColorManager.Get.DistanceMax);
colorCompositeMaterial.SetMatrix("_LevelRanges", rangeValues);
//*****//
colorCompositeMaterial.SetFloat("_LevelLerpFactor", ColorManager.Get.LevelLerpFactor);
colorCompositeMaterial.SetInt("_NumPixels", instanceIdBuffer.width * instanceIdBuffer.height);
//*****//
colorCompositeMaterial.SetTexture("_DepthBuffer", depthBuffer);
colorCompositeMaterial.SetTexture("_AtomIdBuffer", atomIdBuffer);
colorCompositeMaterial.SetTexture("_InstanceIdBuffer", instanceIdBuffer);
// Properties
colorCompositeMaterial.SetBuffer("_ProteinAtomInfos", GPUBuffers.Get.ProteinAtomInfo);
colorCompositeMaterial.SetBuffer("_ProteinAtomInfos2", GPUBuffers.Get.ProteinAtomInfo2);
colorCompositeMaterial.SetBuffer("_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
colorCompositeMaterial.SetBuffer("_LipidAtomInfos", GPUBuffers.Get.LipidAtomPositions);
colorCompositeMaterial.SetBuffer("_LipidInstancesInfo", GPUBuffers.Get.LipidInstancesInfo);
colorCompositeMaterial.SetBuffer("_IngredientsInfo", GPUBuffers.Get.IngredientsInfo);
colorCompositeMaterial.SetBuffer("_IngredientGroupsColorInfo", GPUBuffers.Get.IngredientGroupsColorInfo);
colorCompositeMaterial.SetBuffer("_ProteinIngredientsColorInfo", GPUBuffers.Get.IngredientsColorInfo);
// Predifined colors
colorCompositeMaterial.SetBuffer("_AtomColors", GPUBuffers.Get.AtomColors);
colorCompositeMaterial.SetBuffer("_AminoAcidColors", GPUBuffers.Get.AminoAcidColors);
colorCompositeMaterial.SetBuffer("_IngredientsColors", GPUBuffers.Get.IngredientsColors);
colorCompositeMaterial.SetBuffer("_IngredientsChainColors", GPUBuffers.Get.IngredientsChainColors);
colorCompositeMaterial.SetBuffer("_IngredientGroupsColor", GPUBuffers.Get.IngredientGroupsColor);
// Values for color generation on the fly
colorCompositeMaterial.SetBuffer("_IngredientGroupsLerpFactors", GPUBuffers.Get.IngredientGroupsLerpFactors);
colorCompositeMaterial.SetBuffer("_IngredientGroupsColorValues", GPUBuffers.Get.IngredientGroupsColorValues);
colorCompositeMaterial.SetBuffer("_IngredientGroupsColorRanges", GPUBuffers.Get.IngredientGroupsColorRanges);
colorCompositeMaterial.SetBuffer("_ProteinIngredientsRandomValues", GPUBuffers.Get.ProteinIngredientsRandomValues);
Graphics.Blit(null, dst, colorCompositeMaterial, 0);
}
示例11: AddPaintLayer
void AddPaintLayer(RenderTargetIdentifier[] mrt, int sceneRenderID, int colorReadID, int depthReadID, ComputeBuffer strokeBuffer, Material strokeMaterial) {
// MAIN BRUSHSTROKE CONTENTS PASS!!!:
strokeMaterial.SetPass(0);
strokeMaterial.SetBuffer("strokeDataBuffer", strokeBuffer);
strokeMaterial.SetBuffer("quadPointsBuffer", quadPointsBuffer);
cmdBuffer.SetGlobalTexture("_CanvasColorReadTex", colorReadID);
cmdBuffer.SetGlobalTexture("_CanvasDepthReadTex", depthReadID);
cmdBuffer.SetRenderTarget(mrt, BuiltinRenderTextureType.CameraTarget); // Set render Targets
cmdBuffer.SetGlobalTexture("_BrushColorReadTex", sceneRenderID); // Copy the Contents of FrameBuffer into brushstroke material so it knows what color it should be
cmdBuffer.DrawProcedural(Matrix4x4.identity, strokeMaterial, 0, MeshTopology.Triangles, 6, strokeBuffer.count); // Apply brushstrokes
}
示例12: ComputeOcclusionQueries
public static void ComputeOcclusionQueries(RenderTexture _floodFillTexturePong, Material OcclusionQueriesMaterial, RenderTexture tempBuffer, CutObject cutObject, int cutObjectIndex, int internalState, bool cullProtein, bool cullLipid)
{
if (cullProtein)
{
// Always clear append buffer before usage
GPUBuffers.Get.SphereBatches.ClearAppendBuffer();
//Fill the buffer with occluders
ComputeShaderManager.Get.SphereBatchCS.SetUniform("_NumInstances", SceneManager.Get.NumProteinInstances);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_ProteinInstanceCullFlags", GPUBuffers.Get.ProteinInstanceCullFlags);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_IngredientMaskParams", GPUBuffers.Get.IngredientMaskParams);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
ComputeShaderManager.Get.SphereBatchCS.Dispatch(1, Mathf.CeilToInt(SceneManager.Get.NumProteinInstances / 64.0f), 1, 1);
// Count occluder instances
ComputeBuffer.CopyCount(GPUBuffers.Get.SphereBatches, GPUBuffers.Get.ArgBuffer, 0);
//DebugSphereBatchCount();
// Clear protein occlusion buffer
ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(0, "_FlagBuffer", GPUBuffers.Get.ProteinInstanceOcclusionFlags);
ComputeShaderManager.Get.ComputeVisibilityCS.Dispatch(0, Mathf.CeilToInt(SceneManager.Get.NumProteinInstances / 64.0f), 1, 1);
// Bind the read/write occlusion buffer to the shader
// After this draw call the occlusion buffer will be filled with ones if an instance occluded and occludee, zero otherwise
Graphics.SetRandomWriteTarget(1, GPUBuffers.Get.ProteinInstanceOcclusionFlags);
MyUtility.DummyBlit(); // Dunny why yet, but without this I cannot write to the buffer from the shader, go figure
// Set the render target
Graphics.SetRenderTarget(tempBuffer);
OcclusionQueriesMaterial.SetInt("_CutObjectIndex", cutObjectIndex);
OcclusionQueriesMaterial.SetInt("_NumIngredients", SceneManager.Get.NumAllIngredients);
OcclusionQueriesMaterial.SetBuffer("_CutInfo", GPUBuffers.Get.CutInfo);
OcclusionQueriesMaterial.SetTexture("_DistanceField", _floodFillTexturePong);
OcclusionQueriesMaterial.SetFloat("_Scale", GlobalProperties.Get.Scale);
OcclusionQueriesMaterial.SetBuffer("_ProteinRadii", GPUBuffers.Get.ProteinRadii);
OcclusionQueriesMaterial.SetBuffer("_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
OcclusionQueriesMaterial.SetBuffer("_ProteinInstancePositions", GPUBuffers.Get.ProteinInstancePositions);
OcclusionQueriesMaterial.SetBuffer("_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
OcclusionQueriesMaterial.SetPass(1);
// Issue draw call for occluders - bounding quads only - depth/stencil test enabled - no write to color/depth/stencil
Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Get.ArgBuffer);
Graphics.ClearRandomWriteTargets();
ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_CutObjectIndex", cutObjectIndex);
ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_NumIngredients", SceneManager.Get.NumAllIngredients);
ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_CutInfo", GPUBuffers.Get.CutInfo);
//// Discard occluding instances according to value2
ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_CutObjectId", cutObject.Id);
ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_ConsumeRestoreState", internalState);
ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_Histograms", GPUBuffers.Get.Histograms);
ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_HistogramsLookup", GPUBuffers.Get.HistogramsLookup);
ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_ProteinInstanceCullFlags", GPUBuffers.Get.ProteinInstanceCullFlags);
ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_ProteinInstanceOcclusionFlags", GPUBuffers.Get.ProteinInstanceOcclusionFlags);
ComputeShaderManager.Get.ComputeVisibilityCS.Dispatch(3, Mathf.CeilToInt(SceneManager.Get.NumProteinInstances / 64.0f), 1, 1);
}
if (cullLipid)
{
// Always clear append buffer before usage
GPUBuffers.Get.SphereBatches.ClearAppendBuffer();
//Fill the buffer with occluders
ComputeShaderManager.Get.SphereBatchCS.SetUniform("_NumInstances", SceneManager.Get.NumLipidInstances);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_LipidInstanceInfo", GPUBuffers.Get.LipidInstancesInfo);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_LipidInstanceCullFlags", GPUBuffers.Get.LipidInstanceCullFlags);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_IngredientMaskParams", GPUBuffers.Get.IngredientMaskParams);
ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
ComputeShaderManager.Get.SphereBatchCS.Dispatch(3, Mathf.CeilToInt(SceneManager.Get.NumLipidInstances / 64.0f), 1, 1);
// Count occluder instances
ComputeBuffer.CopyCount(GPUBuffers.Get.SphereBatches, GPUBuffers.Get.ArgBuffer, 0);
// Clear lipid occlusion buffer
ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(0, "_FlagBuffer", GPUBuffers.Get.LipidInstanceOcclusionFlags);
ComputeShaderManager.Get.ComputeVisibilityCS.Dispatch(0, Mathf.CeilToInt(SceneManager.Get.NumLipidInstances / 64.0f), 1, 1);
// Bind the read/write occlusion buffer to the shader
// After this draw call the occlusion buffer will be filled with ones if an instance occluded and occludee, zero otherwise
Graphics.SetRandomWriteTarget(1, GPUBuffers.Get.LipidInstanceOcclusionFlags);
MyUtility.DummyBlit(); // Dunny why yet, but without this I cannot write to the buffer from the shader, go figure
// Set the render target
Graphics.SetRenderTarget(tempBuffer);
OcclusionQueriesMaterial.SetInt("_CutObjectIndex", cutObjectIndex);
OcclusionQueriesMaterial.SetInt("_NumIngredients", SceneManager.Get.NumAllIngredients);
OcclusionQueriesMaterial.SetBuffer("_CutInfo", GPUBuffers.Get.CutInfo);
OcclusionQueriesMaterial.SetTexture("_DistanceField", _floodFillTexturePong);
OcclusionQueriesMaterial.SetFloat("_Scale", GlobalProperties.Get.Scale);
OcclusionQueriesMaterial.SetBuffer("_LipidInstanceInfo", GPUBuffers.Get.LipidInstancesInfo);
//.........这里部分代码省略.........
示例13: InitializeMaterialBuffers
// Need to set material buffers that only need to be set once at the beginning (all except segmentX-Forms)
public void InitializeMaterialBuffers(ref Material brushstrokeCritterMaterialRef) {
brushstrokeCritterMaterialRef.SetBuffer("strokeDataBuffer", initPositionsBuffer);
//procMaterial.SetColor("_Color", color);
//procMaterial.SetTexture("_Sprite", sprite);
//procMaterial.SetVector("_Size", size);
//procMaterial.SetVector("_SizeRandom", sizeRandom);
//procMaterial.SetFloat("_BodyColorAmount", bodyColorAmount);
//procMaterial.SetFloat("_OrientForwardTangent", orientForwardTangent);
//procMaterial.SetFloat("_OrientRandom", orientRandom);
//procMaterial.SetInt("_Type", type);
//procMaterial.SetInt("_NumRibbonSegments", numRibbonSegments);
//procMaterial.SetInt("_StaticCylinderSpherical", billboardType);
brushstrokeCritterMaterialRef.SetBuffer("buf_skinningData", skinningBuffer); // Link same buffer to display Shader!
brushstrokeCritterMaterialRef.SetBuffer("buf_bindPoses", bindPoseBuffer); // set buffer within display Shader to same ComputeBuffer (then just pray it works)
brushstrokeCritterMaterialRef.SetBuffer("buf_xforms", segmentBuffer);
}
示例14: DrawProteinsAtoms
public static void DrawProteinsAtoms(Material renderProteinsMaterial, Camera camera, RenderBuffer instanceId, RenderBuffer atomId, RenderBuffer depthBuffer, int pass)
{
// Protein params
renderProteinsMaterial.SetInt("_EnableLod", Convert.ToInt32(GlobalProperties.Get.EnableLod));
renderProteinsMaterial.SetFloat("_Scale", GlobalProperties.Get.Scale);
renderProteinsMaterial.SetFloat("_FirstLevelBeingRange", GlobalProperties.Get.FirstLevelOffset);
renderProteinsMaterial.SetVector("_CameraForward", camera.transform.forward);
renderProteinsMaterial.SetBuffer("_LodLevelsInfos", GPUBuffers.Get.LodInfo);
renderProteinsMaterial.SetBuffer("_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
renderProteinsMaterial.SetBuffer("_ProteinInstancePositions", GPUBuffers.Get.ProteinInstancePositions);
renderProteinsMaterial.SetBuffer("_ProteinInstanceRotations", GPUBuffers.Get.ProteinInstanceRotations);
renderProteinsMaterial.SetBuffer("_ProteinColors", GPUBuffers.Get.IngredientsColors);
renderProteinsMaterial.SetBuffer("_ProteinAtomInfo", GPUBuffers.Get.ProteinAtomInfo);
renderProteinsMaterial.SetBuffer("_ProteinAtomPositions", GPUBuffers.Get.ProteinAtoms);
renderProteinsMaterial.SetBuffer("_ProteinClusterPositions", GPUBuffers.Get.ProteinAtomClusters);
renderProteinsMaterial.SetBuffer("_ProteinSphereBatchInfos", GPUBuffers.Get.SphereBatches);
/****/
renderProteinsMaterial.SetInt("_NumCutObjects", SceneManager.Get.NumCutObjects);
renderProteinsMaterial.SetInt("_NumIngredientTypes", SceneManager.Get.NumAllIngredients);
renderProteinsMaterial.SetBuffer("_CutInfos", GPUBuffers.Get.CutInfo);
renderProteinsMaterial.SetBuffer("_CutScales", GPUBuffers.Get.CutScales);
renderProteinsMaterial.SetBuffer("_CutPositions", GPUBuffers.Get.CutPositions);
renderProteinsMaterial.SetBuffer("_CutRotations", GPUBuffers.Get.CutRotations);
/****/
Graphics.SetRenderTarget(new[] { instanceId, atomId }, depthBuffer);
renderProteinsMaterial.SetPass(1);
Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Get.ArgBuffer);
}
示例15: DrawLipidShadows
public static void DrawLipidShadows(Material RenderLipidsMaterial, RenderTexture colorBuffer, RenderTexture depthBuffer)
{
RenderLipidsMaterial.SetFloat("_Scale", GlobalProperties.Get.Scale);
RenderLipidsMaterial.SetBuffer("_LipidSphereBatches", GPUBuffers.Get.SphereBatches);
RenderLipidsMaterial.SetBuffer("_LipidAtomPositions", GPUBuffers.Get.LipidAtomPositions);
//RenderLipidsMaterial.SetBuffer("_LipidInstanceInfos", GPUBuffer.Get.LipidInstanceInfos);
RenderLipidsMaterial.SetBuffer("_LipidInstancePositions", GPUBuffers.Get.LipidInstancePositions);
RenderLipidsMaterial.SetPass(1);
Graphics.SetRenderTarget(colorBuffer.colorBuffer, depthBuffer.depthBuffer);
Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Get.ArgBuffer);
}