Exemple #1
0
        public virtual void SetUniforms(Material target)
        {
            if (target == null)
            {
                return;
            }

            ParentBody.SetUniforms(target);

            Deformation.SetUniforms(this, target);
        }
Exemple #2
0
        protected override void UpdateNode()
        {
            var localToCamera    = (Matrix4x4d)GodManager.Instance.WorldToCamera * LocalToWorld;
            var localToScreen    = (Matrix4x4d)GodManager.Instance.CameraToScreen * localToCamera;
            var invLocalToCamera = localToCamera.Inverse();

            DeformedCameraPosition = invLocalToCamera * Vector3d.zero; // TODO : Really? zero?
            DeformedFrustumPlanes  = Frustum.GetFrustumPlanes(localToScreen);
            LocalCameraPosition    = Deformation.DeformedToLocal(DeformedCameraPosition);

            var m = Deformation.LocalToDeformedDifferential(LocalCameraPosition, true);

            var left  = DeformedFrustumPlanes[0].XYZ().Normalized();
            var right = DeformedFrustumPlanes[1].XYZ().Normalized();

            var fov = (float)MathUtility.Safe_Acos(-left.Dot(right));

            SplitDistance  = SplitFactor * Screen.width / 1024.0f * Mathf.Tan(40.0f * Mathf.Deg2Rad) / Mathf.Tan(fov / 2.0f);
            DistanceFactor = (float)Math.Max((new Vector3d(m.m[0, 0], m.m[1, 0], m.m[2, 0])).Magnitude(), (new Vector3d(m.m[0, 1], m.m[1, 1], m.m[2, 1])).Magnitude());

            if (SplitDistance < 1.1f || !MathUtility.IsFinite(SplitDistance))
            {
                SplitDistance = 1.1f;
            }

            // initializes data structures for horizon occlusion culling
            if (UseHorizonCulling && LocalCameraPosition.z <= TerrainQuadRoot.ZMax)
            {
                var deformedDirection = invLocalToCamera * Vector3d.forward;
                var localDirection    = (Deformation.DeformedToLocal(deformedDirection) - LocalCameraPosition).XY().Normalized();

                LocalCameraDirection = new Matrix2x2d(localDirection.y, -localDirection.x, -localDirection.x, -localDirection.y);

                for (int i = 0; i < HORIZON_SIZE; ++i)
                {
                    Horizon[i] = float.NegativeInfinity;
                }
            }

            TerrainQuadRoot.UpdateLOD();

            //Manager.GetSkyNode().SetUniforms(TerrainMaterial);
            //Manager.GetSunNode().SetUniforms(TerrainMaterial);
            Body.SetUniforms(TerrainMaterial);
            Deformation.SetUniforms(this, TerrainMaterial);

            //if (Manager.GetOceanNode() != null)
            //    Manager.GetOceanNode().SetUniforms(TerrainMaterial);
            //else
            TerrainMaterial.SetFloat("_Ocean_DrawBRDF", 0.0f);

            //if (Manager.GetPlantsNode() != null)
            //    Manager.GetPlantsNode().SetUniforms(TerrainMaterial);
        }
Exemple #3
0
        public void SetPerQuadUniforms(TerrainQuad quad, MaterialPropertyBlock target)
        {
            // TODO : BOTTLENECK!
            Deformation.SetUniforms(this, quad, target);

            // TODO : Planet texturing...

            /*
             * var rootQuadSize = TerrainQuadRoot.Length;
             * var offset = new Vector4d(((double)quad.Tx / (1 << quad.Level) - 0.5) * rootQuadSize,
             *                        ((double)quad.Ty / (1 << quad.Level) - 0.5) * rootQuadSize,
             *                        rootQuadSize / (1 << quad.Level),
             *                        ParentBody.Size);
             *
             * target.SetVector("_Offset", offset.ToVector4());
             *
             * if (ParentBody.TCCPS != null) ParentBody.TCCPS.SetUniforms(target);
             */

            /*
             * if (ParentBody.TCCPS != null) ParentBody.TCCPS.SetUniforms(target);
             */
        }
Exemple #4
0
 public void SetPerQuadUniforms(TerrainQuad quad, MaterialPropertyBlock matPropertyBlock)
 {
     // TODO : BOTTLENECK!
     Deformation.SetUniforms(this, quad, matPropertyBlock);
 }
Exemple #5
0
        protected override void UpdateNode()
        {
            TerrainMaterial.renderQueue = (int)ParentBody.RenderQueue + ParentBody.RenderQueueOffset;

            if (ParentBody.GetBodyDeformationType() == BodyDeformationType.Spherical)
            {
                LocalToWorld = Matrix4x4d.ToMatrix4x4d(ParentBody.transform.localToWorldMatrix) * FaceToLocal;
            }
            else
            {
                LocalToWorld = FaceToLocal;
            }

            TangentFrameToWorld = new Matrix3x3d(LocalToWorld.m[0, 0], LocalToWorld.m[0, 1], LocalToWorld.m[0, 2],
                                                 LocalToWorld.m[1, 0], LocalToWorld.m[1, 1], LocalToWorld.m[1, 2],
                                                 LocalToWorld.m[2, 0], LocalToWorld.m[2, 1], LocalToWorld.m[2, 2]);

            var localToCamera    = GodManager.Instance.WorldToCamera * LocalToWorld;
            var invLocalToCamera = localToCamera.Inverse();

            DeformedCameraPosition = invLocalToCamera * Vector3d.zero;
            DeformedFrustumPlanes  = Frustum.GetFrustumPlanes(GodManager.Instance.CameraToScreen * localToCamera); // NOTE : Extract frustum planes from LocalToScreen matrix...
            LocalCameraPosition    = Deformation.DeformedToLocal(DeformedCameraPosition);

            var m = Deformation.LocalToDeformedDifferential(LocalCameraPosition, true);

            var left  = DeformedFrustumPlanes[0].XYZ().Normalized();
            var right = DeformedFrustumPlanes[1].XYZ().Normalized();

            var fov = (float)MathUtility.Safe_Acos(-left.Dot(right));

            SplitDistance  = SplitFactor * Screen.width / 1024.0f * Mathf.Tan(40.0f * Mathf.Deg2Rad) / Mathf.Tan(fov / 2.0f);
            DistanceFactor = (float)Math.Max((new Vector3d(m.m[0, 0], m.m[1, 0], m.m[2, 0])).Magnitude(), (new Vector3d(m.m[0, 1], m.m[1, 1], m.m[2, 1])).Magnitude());

            if (SplitDistance < 1.1f || !MathUtility.IsFinite(SplitDistance))
            {
                SplitDistance = 1.1f;
            }

            // initializes data structures for horizon occlusion culling
            if (UseHorizonCulling && LocalCameraPosition.z <= TerrainQuadRoot.ZMax)
            {
                var deformedDirection = invLocalToCamera * Vector3d.forward;
                var localDirection    = (Deformation.DeformedToLocal(deformedDirection) - LocalCameraPosition).xy.Normalized();

                LocalCameraDirection = new Matrix2x2d(localDirection.y, -localDirection.x, -localDirection.x, -localDirection.y);

                for (byte i = 0; i < HORIZON_SIZE; ++i)
                {
                    Horizon[i] = float.NegativeInfinity;
                }
            }

            TerrainQuadRoot.UpdateLOD();

            SetUniforms(TerrainMaterial);

            if (ParentBody.AtmosphereEnabled)
            {
                if (ParentBody.Atmosphere != null)
                {
                    ParentBody.Atmosphere.SetUniforms(TerrainMaterial);
                }
            }

            if (ParentBody.OceanEnabled)
            {
                if (ParentBody.Ocean != null)
                {
                    ParentBody.Ocean.SetUniforms(TerrainMaterial);
                }
                else
                {
                    TerrainMaterial.SetFloat("_Ocean_DrawBRDF", 0.0f);
                }
            }
            else
            {
                TerrainMaterial.SetFloat("_Ocean_DrawBRDF", 0.0f);
            }

            Deformation.SetUniforms(this, TerrainMaterial);

            //if (Manager.GetPlantsNode() != null)
            //    Manager.GetPlantsNode().SetUniforms(TerrainMaterial);
        }