Exemplo n.º 1
0
        private void FlipTriangle(TriangleVertex vertex, RenderPassMode passMode)
        {
            // 三角形转到屏幕坐标系
            RenderTarget target = this.Target;

            if (target != null)
            {
                if (IsShowVertexLog)
                {
                    DebugVertexLog(vertex);
                }

                // 这里是VertexShader的部分
                // 世界坐标系到屏幕坐标系
                if (passMode.vertexShader == null)
                {
                    // 默认的一个处理
                    //vertex.triangle.Trans(this.WorldToScreenPointEvt2, false);
                    vertex.triangle.MulMatrix(this.Shader_MVP_Matrix);
                }
                else
                {
                    InitPassMode(passMode);
                    passMode.vertexShader.Main(ref vertex);
                }

                // 做个三角形的判断
                if (vertex.IsAllZGreateOne)
                {
                    return;
                }

                // 这里做背面剔除
                if (SoftMath.Is_MVP_Culled(passMode.Cull, vertex.triangle))
                {
                    return;
                }

                vertex.triangle.MulMatrix(this.LinkerScreenMatrix);
#if _Use_FlipTrangle2
                target.FlipScreenTriangle2(this, vertex, passMode);
#else
                target.FlipScreenTriangle(this, vertex, passMode);
#endif
            }
        }
Exemplo n.º 2
0
        private void FlipTraiangles(RenderPassMode passMode)
        {
            TriangleVertex tri;

            for (int i = 0; i < m_TrianglesMgr.Count; ++i)
            {
                if (m_TrianglesMgr.GetTrangle(i, out tri))
                {
                    // tri已经是世界坐标系的
                    FlipTriangle(tri, passMode);
                }
                else
                {
                    break;
                }
            }
            m_TrianglesMgr.Clear();
        }
        // 提交到渲染队列中
        public override bool Render(SoftCamera camera, RenderPassMode passMode)
        {
            if (camera == null || passMode == null || m_Mesh == null)
            {
                return(false);
            }
            UpdateGlobalToLocalMatrix();
            CullMode old = passMode.Cull;

            passMode.Cull = this.cullMode;
            int oldMainTex = passMode.mainTex;

            passMode.mainTex = m_MainTex;
            bool ret = camera.RenderMesh(m_Mesh, m_MeshAxisToGlobalMatrix, passMode);

            passMode.Cull    = old;
            passMode.mainTex = oldMainTex;
            return(ret);
        }
Exemplo n.º 4
0
        public bool RenderMesh(SoftMesh mesh, Matrix4x4 objToWorld, RenderPassMode passMode)
        {
            if (mesh == null || passMode == null)
            {
                return(false);
            }
            var  subMeshes = mesh.SubMeshes;
            bool ret       = false;

            if (subMeshes != null)
            {
                for (int i = 0; i < subMeshes.Count; ++i)
                {
                    var subMesh = subMeshes[i];
                    if (RenderSubMesh(mesh, subMesh, objToWorld, passMode))
                    {
                        ret = true;
                    }
                }
            }
            return(ret);
        }
Exemplo n.º 5
0
        private bool RenderSubMesh(SoftMesh mesh, SoftSubMesh subMesh, Matrix4x4 objToWorld, RenderPassMode passMode)
        {
            if (subMesh == null || passMode == null)
            {
                return(false);
            }
            var  indexes = subMesh.Indexes;
            var  vertexs = mesh.Vertexs;
            var  colors  = mesh.Colors;
            var  uv1s    = mesh.UV1s;
            bool ret     = false;

            bool    isColorEmpty = colors == null || colors.Count <= 0;
            bool    isUV1Empty   = uv1s == null || uv1s.Count <= 0;
            Color   c1           = Color.white;
            Color   c2           = Color.white;
            Color   c3           = Color.white;
            Vector4 uv1_1        = Vector4.zero;
            Vector4 uv1_2        = Vector4.zero;
            Vector4 uv1_3        = Vector4.zero;

            if (vertexs != null && (isColorEmpty || vertexs.Count == colors.Count) &&
                indexes != null && indexes.Count > 0)
            {
                int triangleCnt = ((int)indexes.Count / 3);
                for (int i = 0; i < triangleCnt; ++i)
                {
                    int     idx   = i * 3;
                    int     index = indexes[idx];
                    Vector3 p1    = vertexs[index];
                    if (!isColorEmpty)
                    {
                        c1 = colors[index];
                    }
                    if (!isUV1Empty)
                    {
                        uv1_1 = uv1s[index];
                    }
                    index = indexes[idx + 1];
                    Vector3 p2 = vertexs[index];
                    if (!isColorEmpty)
                    {
                        c2 = colors[index];
                    }
                    if (!isUV1Empty)
                    {
                        uv1_2 = uv1s[index];
                    }
                    index = indexes[idx + 2];
                    Vector3 p3 = vertexs[index];
                    if (!isColorEmpty)
                    {
                        c3 = colors[index];
                    }
                    if (!isUV1Empty)
                    {
                        uv1_3 = uv1s[index];
                    }
                    Triangle tri = new Triangle(p1, p2, p3);

                    // 三角形转到世界坐标系
                    tri.MulMatrix(objToWorld);
                    // 过CullMode 【注意】根据渲染管线VertexShader中可以任意改变三角形,所以要放到VS后面才行,也就是到MVP坐标系里判断
                    // 不在这里做摄影机剔除,移到VS后面
                    //   if (SoftMath.IsCulled(this, passMode.Cull, tri)) {
                    //       continue;
                    //   }
                    //----

                    TriangleVertex triV = new TriangleVertex(tri, c1, c2, c3, passMode.mainTex);
                    if (!isUV1Empty)
                    {
                        triV.uv1_1 = uv1_1;
                        triV.uv1_2 = uv1_2;
                        triV.uv1_3 = uv1_3;
                    }

                    // 进入VertexShader了, 做顶点变换等
                    m_TrianglesMgr.AddTriangle(triV);
                    ret = true;
                }
            }
            return(ret);
        }
Exemplo n.º 6
0
 internal virtual void DoCameraPostRender(RenderPassMode passMode)
 {
     // 提交渲染结果
     FlipTraiangles(passMode);
 }
Exemplo n.º 7
0
 private void InitPassMode(RenderPassMode passMode)
 {
     passMode.MVPMatrix = this.Shader_MVP_Matrix;
 }
Exemplo n.º 8
0
 public virtual bool Render(SoftCamera camera, RenderPassMode passMode)
 {
     return(false);
 }