예제 #1
0
        /// <summary>
        /// 执行光纤追踪
        /// </summary>
        /// <param name="batch"></param>
        /// <param name="vertexGroup"></param>
        /// <param name="renderTarget"></param>
        /// <param name="preTex"></param>
        private void Raytracing(AOBakeBatch batch, AOBakeBatchVertexGroup vertexGroup, RenderTexture renderTarget, RenderTexture preTex)
        {
            m_BakeMaterial.SetTexture("_PreTex", preTex);//传入之前的结果,确保每次渲染都是基于之前的结果
            m_BakeMaterial.SetVectorArray("_Vertices", vertexGroup.vertices);
            m_BakeMaterial.SetFloat("_VertexCount", vertexGroup.vertexCount);
            if (m_CurrentBatch != batch)
            {
                m_CurrentBatch = batch;
                m_BakeMaterial.SetMatrix("_LocalToWorld", batch.localToWorld);
            }


            m_CommandBuffer.Clear();
            m_CommandBuffer.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));

            m_CommandBuffer.SetRenderTarget(renderTarget);

            m_CommandBuffer.DrawMesh(m_MeshFilter.sharedMesh, m_MeshFilter.transform.localToWorldMatrix, m_BakeMaterial, 0, 0);
        }
예제 #2
0
        private AOBakeBatch(Mesh mesh, GameObject gameObject)
        {
            m_Target       = gameObject;
            m_VertexGroups = new List <AOBakeBatchVertexGroup>();

            Vector3[] vertices     = mesh.vertices;
            int       subMeshCount = mesh.subMeshCount;

            AOBakeBatchVertexGroup group = new AOBakeBatchVertexGroup();

            for (int s = 0; s < subMeshCount; s++)
            {
                var triangles = mesh.GetTriangles(s);
                for (int i = 0; i < triangles.Length; i += 3)
                {
                    Vector4 p0 = vertices[triangles[i]];
                    Vector4 p1 = vertices[triangles[i + 1]];
                    Vector4 p2 = vertices[triangles[i + 2]];

                    p0.w = 1.0f;
                    p1.w = 1.0f;
                    p2.w = 1.0f;

                    group.AddTriangle(p0, p1, p2);
                    if (group.isFull)
                    {
                        m_VertexGroups.Add(group);
                        group = new AOBakeBatchVertexGroup();
                    }
                }
            }

            if (group.vertexCount > 0)
            {
                m_VertexGroups.Add(group);
            }
        }