SetBuffer() публичный Метод

Set a named ComputeBuffer value.

public SetBuffer ( int nameID, ComputeBuffer value ) : void
nameID int Property name ID, use Shader.PropertyToID to get it.
value ComputeBuffer ComputeBuffer value to set.
Результат void
Пример #1
0
        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
0
	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
0
     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
0
    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);
    }
Пример #5
0
    static int SetBuffer(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes <int, UnityEngine.ComputeBuffer>(L, 2))
            {
                UnityEngine.Material obj = (UnityEngine.Material)ToLua.CheckObject <UnityEngine.Material>(L, 1);
                int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)ToLua.ToObject(L, 3);
                obj.SetBuffer(arg0, arg1);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes <string, UnityEngine.ComputeBuffer>(L, 2))
            {
                UnityEngine.Material obj = (UnityEngine.Material)ToLua.CheckObject <UnityEngine.Material>(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)ToLua.ToObject(L, 3);
                obj.SetBuffer(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Material.SetBuffer"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
 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;
 }
 static int SetBuffer(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.Material obj = (UnityEngine.Material)ToLua.CheckObject(L, 1, typeof(UnityEngine.Material));
         string arg0 = ToLua.CheckString(L, 2);
         UnityEngine.ComputeBuffer arg1 = (UnityEngine.ComputeBuffer)ToLua.CheckObject(L, 3, typeof(UnityEngine.ComputeBuffer));
         obj.SetBuffer(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #8
0
 static public int SetBuffer(IntPtr l)
 {
     try {
         UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
         System.String        a1;
         checkType(l, 2, out a1);
         UnityEngine.ComputeBuffer a2;
         checkType(l, 3, out a2);
         self.SetBuffer(a1, a2);
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Пример #9
0
 static public int SetBuffer(IntPtr l)
 {
     try {
         UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
         System.String        a1;
         checkType(l, 2, out a1);
         UnityEngine.ComputeBuffer a2;
         checkType(l, 3, out a2);
         self.SetBuffer(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #10
0
        /// <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);
        }
Пример #11
0
    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);
    }
Пример #12
0
    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;
    }
Пример #13
0
    //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);
        }
    }
Пример #14
0
    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);
    }
Пример #15
0
    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);
            OcclusionQueriesMaterial.SetBuffer("_LipidInstancePositions", GPUBuffers.Get.LipidInstancePositions);
            OcclusionQueriesMaterial.SetBuffer("_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
            OcclusionQueriesMaterial.SetPass(3);

            // 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(4, "_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(4, "_Histograms", GPUBuffers.Get.Histograms);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(4, "_HistogramsLookup", GPUBuffers.Get.HistogramsLookup);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(4, "_LipidInstanceInfo", GPUBuffers.Get.LipidInstancesInfo);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(4, "_LipidInstanceCullFlags", GPUBuffers.Get.LipidInstanceCullFlags);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(4, "_LipidInstanceOcclusionFlags", GPUBuffers.Get.LipidInstanceOcclusionFlags);
            ComputeShaderManager.Get.ComputeVisibilityCS.Dispatch(4, Mathf.CeilToInt(SceneManager.Get.NumLipidInstances / 64.0f), 1, 1);
        }
    }
Пример #16
0
    public override Material CloneMaterial(Material src, int nth)
    {
        Material m = new Material(src);
        if (m_data_transfer_mode == DataTransferMode.Buffer)
        {
            m.EnableKeyword("ENABLE_INSTANCE_BUFFER");
        }
        if (m_enable_rotation)
        {
            m.EnableKeyword("ENABLE_INSTANCE_ROTATION");
        }
        if (m_enable_scale)
        {
            m.EnableKeyword("ENABLE_INSTANCE_SCALE");
        }
        if (m_enable_emission)
        {
            m.EnableKeyword("ENABLE_INSTANCE_EMISSION");
        }
        if (m_enable_color)
        {
            m.EnableKeyword("ENABLE_INSTANCE_COLOR");
        }
        if (m_enable_uv_offset)
        {
            m.EnableKeyword("ENABLE_INSTANCE_UVOFFSET");
        }

        m.SetInt("g_batch_begin", nth * m_instances_par_batch);
        m.SetVector("g_texel_size", m_instance_texel_size);

        if (m_instance_buffer != null)
        {
            m.SetBuffer("g_instance_buffer_t", m_instance_buffer.translation);
            m.SetBuffer("g_instance_buffer_r", m_instance_buffer.rotation);
            m.SetBuffer("g_instance_buffer_s", m_instance_buffer.scale);
            m.SetBuffer("g_instance_buffer_color", m_instance_buffer.color);
            m.SetBuffer("g_instance_buffer_emission", m_instance_buffer.emission);
            m.SetBuffer("g_instance_buffer_uv", m_instance_buffer.uv_offset);
        }
        if (m_instance_texture != null)
        {
            m.SetTexture("g_instance_texture_t", m_instance_texture.translation);
            m.SetTexture("g_instance_texture_r", m_instance_texture.rotation);
            m.SetTexture("g_instance_texture_s", m_instance_texture.scale);
            m.SetTexture("g_instance_texture_color", m_instance_texture.color);
            m.SetTexture("g_instance_texture_emission", m_instance_texture.emission);
            m.SetTexture("g_instance_texture_uv", m_instance_texture.uv_offset);
        }

        // fix rendering order for transparent objects
        if (m.renderQueue >= 3000)
        {
            m.renderQueue = m.renderQueue + (nth + 1);
        }
        return m;
    }
Пример #17
0
    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);
    }
 // 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);
 }
    public void UpdateBuffersAndMaterial(ref Material brushstrokeCritterMaterialRef) {
        if (initPositionsBuffer != null && isOn) {
            UpdateXforms();

            brushstrokeCritterMaterialRef.SetPass(0);
            brushstrokeCritterMaterialRef.SetBuffer("buf_xforms", segmentBuffer);
            //brushstrokeCritterMaterialRef.SetColor("_Color", color);
            //brushstrokeCritterMaterialRef.SetTexture("_Sprite", sprite);
            //brushstrokeCritterMaterialRef.SetVector("_Size", size);
            //brushstrokeCritterMaterialRef.SetInt("_StaticCylinderSpherical", billboardType);
            //brushstrokeCritterMaterialRef.SetVector("_SizeRandom", sizeRandom);
            //brushstrokeCritterMaterialRef.SetFloat("_BodyColorAmount", bodyColorAmount);
            //brushstrokeCritterMaterialRef.SetFloat("_OrientForwardTangent", orientForwardTangent);
            //brushstrokeCritterMaterialRef.SetFloat("_OrientRandom", orientRandom);
            //brushstrokeCritterMaterialRef.SetFloat("_Diffuse", diffuse);
            //brushstrokeCritterMaterialRef.SetFloat("_DiffuseWrap", diffuseWrap);
            //brushstrokeCritterMaterialRef.SetFloat("_RimGlow", rimGlow);
            //brushstrokeCritterMaterialRef.SetFloat("_RimPow", rimPow);

            //Graphics.DrawProcedural(MeshTopology.Points, outputBuffer.count);            
            //Debug.Log("DrawProcedural! " + material.GetVector("_Size").ToString());
        }
    }
Пример #20
0
    public override Material CloneMaterial(Material src, int nth)
    {
        Material m = new Material(src);
        m.SetInt("g_batch_begin", nth * m_instances_par_batch);
        m.SetInt("g_flag_rotation", m_enable_rotation ? 1 : 0);
        m.SetInt("g_flag_scale", m_enable_scale ? 1 : 0);
        m.SetInt("g_flag_color", m_enable_color ? 1 : 0);
        m.SetInt("g_flag_emission", m_enable_emission ? 1 : 0);
        m.SetInt("g_flag_uvoffset", m_enable_uv_offset ? 1 : 0);
        m.SetInt("g_flag_use_buffer", m_data_transfer_mode==DataTransferMode.Buffer ? 1 : 0);
        m.SetVector("g_texel_size", m_instance_texel_size);

        if (m_instance_buffer != null)
        {
            m.SetBuffer("g_instance_buffer_t", m_instance_buffer.translation);
            m.SetBuffer("g_instance_buffer_r", m_instance_buffer.rotation);
            m.SetBuffer("g_instance_buffer_s", m_instance_buffer.scale);
            m.SetBuffer("g_instance_buffer_color", m_instance_buffer.color);
            m.SetBuffer("g_instance_buffer_emission", m_instance_buffer.emission);
            m.SetBuffer("g_instance_buffer_uv", m_instance_buffer.uv_offset);
        }
        if (m_instance_texture != null)
        {
            m.SetTexture("g_instance_texture_t", m_instance_texture.translation);
            m.SetTexture("g_instance_texture_r", m_instance_texture.rotation);
            m.SetTexture("g_instance_texture_s", m_instance_texture.scale);
            m.SetTexture("g_instance_texture_color", m_instance_texture.color);
            m.SetTexture("g_instance_texture_emission", m_instance_texture.emission);
            m.SetTexture("g_instance_texture_uv", m_instance_texture.uv_offset);
        }

        // fix rendering order for transparent objects
        if (m.renderQueue >= 3000)
        {
            m.renderQueue = m.renderQueue + (nth + 1);
        }
        return m;
    }
 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
 }
Пример #22
0
 public void SetData(Material m)
 {
     m.SetInt(ShaderConsts.PROP_POINT_COUNT, _count);
     m.SetBuffer(ShaderConsts.BUF_POINT, _points);
 }
Пример #23
0
    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);
    }