예제 #1
0
    public void Update()
    {
        ReactorField.UpdateShaderConstants(PlaneMaterial);

        int numPlanesToDraw = kNumPlaneCells;

        for (int i = 0; i < m_aaInstancedPlaneCellMatrix.Length; ++i)
        {
            var aMat = m_aaInstancedPlaneCellMatrix[i];
            Graphics.DrawMeshInstanced(m_planeMesh, 0, PlaneMaterial, aMat, Mathf.Min(numPlanesToDraw, kNumInstancedPlaneCellPerDrawCall));
            numPlanesToDraw -= kNumInstancedPlaneCellPerDrawCall;
        }

        for (int i = 0; i < kNumMovingEffectors; ++i)
        {
            var effector = m_aMovingEffector[i];

            float phase = m_aMovingEffectorPhase[i];
            phase += MathUtil.TwoPi * kMovingEffectorPhaseSpeed * Time.deltaTime;
            float prevPhase = phase;
            phase = Mathf.Repeat(phase + MathUtil.HalfPi, MathUtil.Pi) - MathUtil.HalfPi;
            m_aMovingEffectorPhase[i] = phase;

            if (phase < prevPhase - 0.01f)
            {
                ResetEffector(effector);
            }

            Vector3 position = effector.transform.position;
            position.y = Mathf.Tan(Mathf.Clamp(phase, -MathUtil.HalfPi + 0.2f, MathUtil.HalfPi - 0.2f)) + 3.5f;
            effector.transform.position = position;
        }
    }
예제 #2
0
    public void Update()
    {
  #if UNITY_2017_1_OR_NEWER && !UNITY_2018_3_OR_NEWER
        if (!s_warnedMaterialPropertyBlocks)
        {
            Debug.LogWarning
            (
                "There's a known issue with Unity between 2017.1 and 2018.2 where material property blocks are not correctly applied to instanced meshes.\n"
                + "You may not see the effects applied properly to instanced meshes in this example. "
                + "This issue has been fixed since Unity 2018.3."
            );

            s_warnedMaterialPropertyBlocks = true;
        }
  #endif

        int iSphere = 0;
        for (int c = 0; c < NumCircles; ++c)
        {
            float radius = MaxCircleRadius / (c + 1);
            for (int s = 0; s < NumSpheresPerCircle; ++s)
            {
                float phase = m_basePhase + (s / (float)NumSpheresPerCircle) * 2.0f * Mathf.PI;
                phase *= (c % 2 == 0) ? 1.0f : -1.0f;

                var sphere = m_aSphere[iSphere];

                sphere.transform.position =
                    new Vector3
                    (
                        radius * Mathf.Cos(phase),
                        0.2f,
                        radius * Mathf.Sin(phase)
                    );

                ++iSphere;
            }
        }

        m_basePhase -= (CircleSpeed / MaxCircleRadius) * Time.deltaTime;

        if (m_aaInstancedBushMatrix != null)
        {
            var bushMesh     = Bush.GetComponent <MeshFilter>().sharedMesh;
            var bushMaterial = Bush.GetComponent <MeshRenderer>().sharedMaterial;

            if (m_bushMaterialProps == null)
            {
                m_bushMaterialProps = new MaterialPropertyBlock();
            }

            if (ReactorField.UpdateShaderConstants(m_bushMaterialProps))
            {
                foreach (var aInstancedBushMatrix in m_aaInstancedBushMatrix)
                {
                    Graphics.DrawMeshInstanced(bushMesh, 0, bushMaterial, aInstancedBushMatrix, aInstancedBushMatrix.Length, m_bushMaterialProps);
                }
            }
        }
    }
예제 #3
0
    public void Update()
    {
  #if UNITY_2017_1_OR_NEWER && !UNITY_2018_3_OR_NEWER
        if (!s_warnedMaterialPropertyBlocks)
        {
            Debug.LogWarning
            (
                "There's a known issue with Unity between 2017.1 and 2018.2 where material property blocks are not correctly applied to instanced meshes.\n"
                + "You may not see the effects applied properly to instanced meshes in this example. "
                + "This issue has been fixed since Unity 2018.3."
            );

            s_warnedMaterialPropertyBlocks = true;
        }
  #endif

        var mesh     = Diamond.GetComponent <MeshFilter>().sharedMesh;
        var material = Diamond.GetComponent <MeshRenderer>().sharedMaterial;

        if (m_diamondMaterialProps == null)
        {
            m_diamondMaterialProps = new MaterialPropertyBlock();
        }

        if (ReactorField.UpdateShaderConstants(m_diamondMaterialProps))
        {
            foreach (var aInstancedBushMatrix in m_aaInstancedDiamondMatrix)
            {
                Graphics.DrawMeshInstanced(mesh, 0, material, aInstancedBushMatrix, aInstancedBushMatrix.Length, m_diamondMaterialProps);
            }
        }
    }
    public void Update()
    {
        int iSphere = 0;

        for (int c = 0; c < NumCircles; ++c)
        {
            float radius = MaxCircleRadius / (c + 1);
            for (int s = 0; s < NumSpheresPerCircle; ++s)
            {
                float phase = m_basePhase + (s / (float)NumSpheresPerCircle) * 2.0f * Mathf.PI;
                phase *= (c % 2 == 0) ? 1.0f : -1.0f;

                var sphere = m_aSphere[iSphere];

                sphere.transform.position =
                    new Vector3
                    (
                        radius * Mathf.Cos(phase),
                        0.2f,
                        radius * Mathf.Sin(phase)
                    );

                ++iSphere;
            }
        }

        m_basePhase -= (CircleSpeed / MaxCircleRadius) * Time.deltaTime;

        if (m_aaInstancedBushMatrix != null)
        {
            var bushMesh     = Bush.GetComponent <MeshFilter>().sharedMesh;
            var bushMaterial = Bush.GetComponent <MeshRenderer>().sharedMaterial;

            if (m_bushMaterialProps == null)
            {
                m_bushMaterialProps = new MaterialPropertyBlock();
            }

            if (ReactorField.UpdateShaderConstants(m_bushMaterialProps))
            {
                foreach (var aInstancedBushMatrix in m_aaInstancedBushMatrix)
                {
                    Graphics.DrawMeshInstanced(bushMesh, 0, bushMaterial, aInstancedBushMatrix, aInstancedBushMatrix.Length, m_bushMaterialProps);
                }
            }
        }
    }
예제 #5
0
파일: LiquidMain.cs 프로젝트: NielsZB/Purge
    public void Update()
    {
  #if UNITY_2017_1_OR_NEWER && !UNITY_2018_3_OR_NEWER
        if (!s_warnedMaterialPropertyBlocks)
        {
            Debug.LogWarning
            (
                "There's a known issue with Unity between 2017.1 and 2018.2 where material property blocks are not correctly applied to instanced meshes.\n"
                + "You may not see the effects applied properly to instanced meshes in this example. "
                + "This issue has been fixed since Unity 2018.3."
            );

            s_warnedMaterialPropertyBlocks = true;
        }
  #endif

        ReactorField.UpdateShaderConstants(PlaneMaterial);

        int numPlanesToDraw = kNumPlaneCells;
        for (int i = 0; i < m_aaInstancedPlaneCellMatrix.Length; ++i)
        {
            var aMat = m_aaInstancedPlaneCellMatrix[i];
            Graphics.DrawMeshInstanced(m_planeMesh, 0, PlaneMaterial, aMat, Mathf.Min(numPlanesToDraw, kNumInstancedPlaneCellPerDrawCall));
            numPlanesToDraw -= kNumInstancedPlaneCellPerDrawCall;
        }

        for (int i = 0; i < kNumMovingEffectors; ++i)
        {
            var effector = m_aMovingEffector[i];

            float phase = m_aMovingEffectorPhase[i];
            phase += MathUtil.TwoPi * kMovingEffectorPhaseSpeed * Time.deltaTime;
            float prevPhase = phase;
            phase = Mathf.Repeat(phase + MathUtil.HalfPi, MathUtil.Pi) - MathUtil.HalfPi;
            m_aMovingEffectorPhase[i] = phase;

            if (phase < prevPhase - 0.01f)
            {
                ResetEffector(effector);
            }

            Vector3 position = effector.transform.position;
            position.y = Mathf.Tan(Mathf.Clamp(phase, -MathUtil.HalfPi + 0.2f, MathUtil.HalfPi - 0.2f)) + 3.5f;
            effector.transform.position = position;
        }
    }
예제 #6
0
    public void Update()
    {
        var mesh     = Diamond.GetComponent <MeshFilter>().sharedMesh;
        var material = Diamond.GetComponent <MeshRenderer>().sharedMaterial;

        if (m_diamondMaterialProps == null)
        {
            m_diamondMaterialProps = new MaterialPropertyBlock();
        }

        if (ReactorField.UpdateShaderConstants(m_diamondMaterialProps))
        {
            foreach (var aInstancedBushMatrix in m_aaInstancedDiamondMatrix)
            {
                Graphics.DrawMeshInstanced(mesh, 0, material, aInstancedBushMatrix, aInstancedBushMatrix.Length, m_diamondMaterialProps);
            }
        }
    }