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

            ParentBody.SetUniforms(target);

            Deformation.SetUniforms(this, target);
        }
예제 #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);
        }
예제 #3
0
    private void Start()
    {
        player   = GameObject.FindGameObjectWithTag("Player");
        text     = GameObject.FindGameObjectWithTag("InteractionText").GetComponent <TMP_Text>();
        exitText = GameObject.FindGameObjectWithTag("ExitText").GetComponent <TMP_Text>();

        deform = GameObject.FindGameObjectWithTag("Deform").GetComponent <Deformation>();
        door   = GameObject.FindGameObjectWithTag("Door").GetComponent <Door>();

        textColor = text.color;
        text.SetText("");
    }
예제 #4
0
    public void startDeform(Vector3 to, float timeTo, float timeReturn = 0.5f, float offsetDir = 0, string tag = "default", bool unique = false)
    {
        Deformation newDeform = new Deformation(to, timeTo, timeReturn, offsetDir);

        newDeform.tag = tag;
        if (unique && tag != "default" && tag != null && tag != "")
        {
            if (deforms.Find(d => d.tag.Equals(tag)) != null)
            {
                return;
            }
        }
        deforms.Add(newDeform);
    }
예제 #5
0
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                // this below is the important part
                Deformation deform = hit.collider.GetComponent <Deformation>();
                if (deform)
                {
                    Vector3 point = hit.point;
                    point += hit.normal * offset;
                    deform.AddDeformForce(point, force);
                }
            }
        }
    }
            // Load the saved Deformations
            public override void OnLoad(ConfigNode node)
            {
                // Loop through all child-nodes
                foreach (ConfigNode bodyNode in node.nodes)
                {
                    // Get the CelestialBody
                    CelestialBody body = PSystemManager.Instance.localBodies.Find(b => b.transform.name == bodyNode.name);

                    // Get the Deformation controller and clear it
                    PQSMod_TerrainDeformation pqsDeformation = body.pqsController.GetComponentInChildren<PQSMod_TerrainDeformation>();
                    pqsDeformation.deformations.Clear();

                    // Build the Deformations
                    foreach (ConfigNode deformationNode in bodyNode.nodes)
                    {
                        Vector3 position = ConfigNode.ParseVector3D(deformationNode.GetValue("position"));
                        double depth = double.Parse(deformationNode.GetValue("depth"));
                        double width = double.Parse(deformationNode.GetValue("width"));
                        Deformation deformation = new Deformation(position, body, depth, width);
                        pqsDeformation.deformations.Add(deformation);
                    }
                }
            }
예제 #7
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);
             */
        }
예제 #8
0
 void Start()
 {
     deform = GetComponentInChildren <Deformation>();
 }
예제 #9
0
 public void SetPerQuadUniforms(TerrainQuad quad, MaterialPropertyBlock matPropertyBlock)
 {
     // TODO : BOTTLENECK!
     Deformation.SetUniforms(this, quad, matPropertyBlock);
 }
예제 #10
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);
        }
예제 #11
0
        public override void UpdateNode()
        {
            TerrainMaterial.renderQueue = (int)ParentBody.RenderQueue + ParentBody.RenderQueueOffset;

            // NOTE : Body shape dependent...
            LocalToWorld = Matrix4x4d.ToMatrix4x4d(ParentBody.transform.localToWorldMatrix) * 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]);

            LocalToCamera = GodManager.Instance.View.WorldToCameraMatrix * LocalToWorld;
            LocalToScreen = GodManager.Instance.View.CameraToScreenMatrix * LocalToCamera;

            var invLocalToCamera = LocalToCamera.Inverse();

            DeformedCameraPosition = invLocalToCamera * Vector3d.zero;
            DeformedFrustumPlanes  = Frustum3d.GetFrustumPlanes(LocalToScreen); // NOTE : Extract frustum planes from LocalToScreen matrix...

            LocalCameraPosition = Deformation.DeformedToLocal(DeformedCameraPosition);

            DeformedLocalToTangent = Deformation.DeformedToTangentFrame(GodManager.Instance.View.WorldCameraPosition) * LocalToWorld * Deformation.LocalToDeformedDifferential(LocalCameraPosition);

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

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

            var fov = (float)Functions.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 || SplitDistance > 128.0f || !Functions.IsFinite(SplitDistance))
            {
                SplitDistance = 1.1f;
            }

            var splitDistanceBlending = SplitDistance + 1.0f;

            DistanceBlending = new Vector2(splitDistanceBlending, 2.0f * SplitDistance - splitDistanceBlending);

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

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

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

            if (ParentBody.UpdateLOD)
            {
                TerrainQuadRoot.UpdateLOD();
            }

            SetUniforms(TerrainMaterial);
        }
예제 #12
0
 public Frustum.VISIBILITY GetVisibility(Box3d localBox)
 {
     return(Deformation.GetVisibility(this, localBox));
 }
            // If a vessel dies, rebuild the sphere
            public void onVesselDestroy(Vessel vessel)
            {
                // If there's no vessel, abort
                if (vessel == null)
                    return;

                if (vessel.state == Vessel.State.DEAD) // More checking needed?
                {
                    // Get the CelestialBody
                    CelestialBody body = vessel.mainBody;

                    // Create the Deformation
                    Deformation deformation = new Deformation()
                    {
                        position = Utility.LLAtoECEF(vessel.latitude, vessel.longitude, vessel.altitude, vessel.mainBody.Radius),
                        body = vessel.mainBody,
                        depth = 10d,
                        width = 400d
                    };
                    body.GetComponentInChildren<PQSMod_TerrainDeformation>().deformations.Add(deformation);

                    // Rebuild the Sphere
                    PQ[] quads = Utility.FindNearbyQuads(body.pqsController, vessel.vesselTransform, 9);
                    StartCoroutine(Utility.RebuildSphere(quads, body.pqsController));
                }
            }