Ejemplo n.º 1
0
    // Draw and process routines
    private void DrawProcessedLOD(ref TreeSystemLODData[] data, ref int maxLod3D, ref TreeSystemLODInstance lodInst, ref TreeSystemStoredInstance inst, ref bool shadowsOnly)
    {
        int lod = lodInst.m_LODLevel;

        // Draw the stuff with the material specific for each LOD
        Draw3DLOD(ref data[lod], ref lodInst, ref inst, ref shadowsOnly);
    }
Ejemplo n.º 2
0
    public void Draw3DLOD(TreeSystemLODData data, ref TreeSystemLODInstance inst)
    {
        // data.m_Block.SetVector(system.m_ShaderIDFadeLOD, new Vector4(inst.m_LODTransition, inst.m_LODFullFade, 0, 0));

        for (int mat = 0; mat < data.m_Materials.Length; mat++)
        {
            Graphics.DrawMesh(data.m_Mesh, transform.localToWorldMatrix, data.m_Materials[mat], mat, null, mat, data.m_Block, true, true);
        }
    }
Ejemplo n.º 3
0
    public void Draw3DLOD(ref TreeSystemLODData data, ref TreeSystemLODInstance lodInst, ref TreeSystemStoredInstance inst)
    {
        data.m_Block.SetVector(m_ShaderIDFadeLOD, new Vector4(lodInst.m_LODTransition, lodInst.m_LODFullFade, 0, 0));

        for (int mat = 0; mat < data.m_Materials.Length; mat++)
        {
            Graphics.DrawMesh(data.m_Mesh, inst.m_PositionMtx, data.m_Materials[mat], 0, null, mat, data.m_Block, true, true);
            m_DataIssuesDrawCalls++;
        }
    }
Ejemplo n.º 4
0
    public void DrawProcessedLOD(TreeSystemLODData[] data, ref TreeSystemLODInstance inst)
    {
        int lod = inst.m_LODLevel;

        // Draw the stuff with the material specific for each LOD
        Draw3DLOD(data[lod], ref inst);

        if (lod == protoData.m_MaxLod3DIndex && inst.m_LODFullFade < 1)
        {
            // Since we only need for the last 3D lod the calculations...
            DrawBillboardLOD(data[lod + 1], ref inst);
        }
    }
Ejemplo n.º 5
0
    // Draw and process routines
    private void DrawProcessedLOD(ref TreeSystemLODData[] data, ref int maxLod3D, ref TreeSystemLODInstance lodInst, ref TreeSystemStoredInstance inst, ref bool shadowsOnly)
    {
        int lod = lodInst.m_LODLevel;

        // Draw the stuff with the material specific for each LOD
        Draw3DLOD(ref data[lod], ref lodInst, ref inst, ref shadowsOnly);

        if (lod == maxLod3D && lodInst.m_LODFullFade < 1)
        {
            // Since we only need for the last 3D lod the calculations...
            DrawBillboardLOD(ref data[lod + 1], ref lodInst, ref inst);
        }
    }
Ejemplo n.º 6
0
    public void Draw3DLOD(ref TreeSystemLODData data, ref TreeSystemLODInstance lodInst, ref TreeSystemStoredInstance inst)
    {
        m_TempLOD[0] = lodInst.m_LODTransition;
        data.m_Block.SetFloatArray(m_ShaderIDFadeLODDetail, m_TempLOD);
        m_TempLOD[0] = lodInst.m_LODFullFade;
        data.m_Block.SetFloatArray(m_ShaderIDFadeLODFull, m_TempLOD);

        for (int mat = 0; mat < data.m_Materials.Length; mat++)
        {
            Graphics.DrawMesh(data.m_Mesh, inst.m_PositionMtx, data.m_Materials[mat], m_UsedLayerId, m_UsedCamera, mat, data.m_Block, true, true);

            m_DataIssuesDrawCalls++;
        }
    }
Ejemplo n.º 7
0
    public void Draw3DLOD(ref TreeSystemLODData data, ref TreeSystemLODInstance lodInst, ref TreeSystemStoredInstance inst, ref bool shadowsOnly)
    {
        m_TempLOD[0] = lodInst.m_LODTransition;
        data.m_Block.SetFloatArray(m_ShaderIDFadeLODDetail, m_TempLOD);
        m_TempLOD[0] = lodInst.m_LODFullFade;
        data.m_Block.SetFloatArray(m_ShaderIDFadeLODFull, m_TempLOD);

        for (int mat = 0; mat < data.m_Materials.Length; mat++)
        {
            Graphics.DrawMesh(data.m_Mesh, inst.m_PositionMtx, data.m_Materials[mat], m_UsedLayerId, m_Settings.m_UsedCamera, mat, data.m_Block,
                              shadowsOnly == false ? UnityEngine.Rendering.ShadowCastingMode.On : UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly,
                              true);

            m_DataIssuesDrawCalls++;
        }
    }
Ejemplo n.º 8
0
    public void DrawBillboardLOD(ref TreeSystemLODData data, ref TreeSystemLODInstance lodInst, ref TreeSystemStoredInstance inst)
    {
        data.m_Block.SetVector(m_ShaderIDFadeLOD, new Vector4(lodInst.m_LODTransition, 1.0f - lodInst.m_LODFullFade, 0, 0));

        // Set extra scale and stuff
        Vector4 extra = inst.m_WorldScale;

        extra.w = inst.m_WorldRotation;
        data.m_Block.SetVector(m_ShaderIDBillboardScaleRotation, extra);

        for (int mat = 0; mat < data.m_Materials.Length; mat++)
        {
            Graphics.DrawMesh(data.m_Mesh, inst.m_PositionMtx, data.m_Materials[mat], 0, null, mat, data.m_Block, true, true);
            m_DataIssuesDrawCalls++;
        }
    }
Ejemplo n.º 9
0
    /**
     * Must be called only if the camera distance is smaller than the maximum tree view distance.
     */
    private void ProcessLOD(ref TreeSystemLODData[] data, ref int max3DLOD, ref TreeSystemLODInstance inst, ref float cameraDistance)
    {
        if (cameraDistance <= m_Settings.m_MaxTreeDistance + m_Settings.m_LODTranzitionThreshold)
        {
            for (int i = 0; i < data.Length - 1; i++)
            {
                if (data[i].IsInRange(cameraDistance))
                {
                    // Calculate lod tranzition value
                    if (cameraDistance > data[i].m_EndDistance - m_Settings.m_LODTranzitionThreshold)
                    {
                        inst.m_LODTransition = 1.0f - (data[i].m_EndDistance - cameraDistance) / m_Settings.m_LODTranzitionThreshold;
                    }
                    else
                    {
                        inst.m_LODTransition = 0.0f;
                    }

                    inst.m_LODLevel = i;
                    break;
                }
            }


            if (inst.m_LODLevel == max3DLOD && inst.m_LODFullFade < 1)
            {
                // If we are the last 3D lod then we animate nicely
                inst.m_LODFullFade += Time.deltaTime * m_Settings.m_LODFadeSpeed;
            }
            else if (inst.m_LODFullFade < 1)
            {
                // If we are not the lost LOD level simply set the value to 1
                inst.m_LODFullFade = 1f;
            }
        }


        else
        {
            inst.m_LODLevel = max3DLOD;
            if (inst.m_LODFullFade > 0)
            {
                inst.m_LODFullFade -= Time.deltaTime * m_Settings.m_LODFadeSpeed;
            }
        }
    }
Ejemplo n.º 10
0
    public void DrawBillboardLOD(ref TreeSystemLODData data, ref TreeSystemLODInstance lodInst, ref TreeSystemStoredInstance inst)
    {
        data.m_Block.SetVector(m_ShaderIDFadeBillboard, new Vector4(lodInst.m_LODTransition, 1.0f - lodInst.m_LODFullFade, 0, 0));

        // Set extra scale and stuff
        Vector4 extra = inst.m_WorldScale;

        extra.w = inst.m_WorldRotation;

        // Set positions used in shader
        data.m_Block.SetVector(m_ShaderIDBillboardScaleRotation, extra);

        m_BillboardTempPos.m03 = inst.m_WorldPosition.x;
        m_BillboardTempPos.m13 = inst.m_WorldPosition.y;
        m_BillboardTempPos.m23 = inst.m_WorldPosition.z;

        for (int mat = 0; mat < data.m_Materials.Length; mat++)
        {
            Graphics.DrawMesh(data.m_Mesh, m_BillboardTempPos, data.m_Materials[mat], m_UsedLayerId, m_Settings.m_UsedCamera, mat, data.m_Block, true, true);
            m_DataIssuesDrawCalls++;
        }
    }
Ejemplo n.º 11
0
    /**
     * Must be called only if the camera distance is smaller than the maximum tree view distance.
     */
    public void ProcessLOD(TreeSystemLODData[] data, ref TreeSystemLODInstance inst, ref float cameraDistance)
    {
        if (cameraDistance < procDistance)
        {
            for (int i = 0; i < data.Length - 1; i++)
            {
                if (data[i].IsInRange(cameraDistance))
                {
                    // Calculate lod tranzition value
                    if (cameraDistance > data[i].m_EndDistance - THRESHOLD)
                    {
                        inst.m_LODTransition = 1.0f - (data[i].m_EndDistance - cameraDistance) / THRESHOLD;
                    }
                    else
                    {
                        inst.m_LODTransition = 0.0f;
                    }

                    inst.m_LODLevel = i;
                    break;
                }
            }

            if (inst.m_LODFullFade < 1)
            {
                inst.m_LODFullFade += Time.deltaTime * m_FadeSpeed;
            }
        }
        else
        {
            inst.m_LODLevel = 2;
            if (inst.m_LODFullFade >= 0)
            {
                inst.m_LODFullFade -= Time.deltaTime * m_FadeSpeed;
            }
        }
    }