Пример #1
0
 public void InitMaterials()
 {
     if (StarfieldMaterial == null)
     {
         StarfieldMaterial = MaterialHelper.CreateTemp(StarfieldShader, "Starfield");
     }
 }
Пример #2
0
        protected override void InitNode()
        {
            Body = GetComponentInParent <CelestialBody>();
            Body.TerrainNodes.Add(this);

            TerrainMaterial = MaterialHelper.CreateTemp(Body.ColorShader, "TerrainNode");

            //Manager.GetSkyNode().InitUniforms(TerrainMaterial);

            var faces = new Vector3d[] { new Vector3d(0, 0, 0), new Vector3d(90, 0, 0), new Vector3d(90, 90, 0), new Vector3d(90, 180, 0), new Vector3d(90, 270, 0), new Vector3d(0, 180, 180) };

            FaceToLocal = Matrix4x4d.Identity();

            // If this terrain is deformed into a sphere the face matrix is the rotation of the
            // terrain needed to make up the spherical planet. In this case there should be 6 terrains, each with a unique face number
            if (Face - 1 >= 0 && Face - 1 < 6)
            {
                FaceToLocal = Matrix4x4d.Rotate(faces[Face - 1]);
            }

            //LocalToWorld = Matrix4x4d.ToMatrix4x4d(transform.localToWorldMatrix) * FaceToLocal;
            LocalToWorld = FaceToLocal;

            Deformation = new DeformationSpherical(Body.Radius);

            TerrainQuadRoot = new TerrainQuad(this, null, 0, 0, -Body.Radius, -Body.Radius, 2.0 * Body.Radius, ZMin, ZMax);
        }
Пример #3
0
 public void InitMaterials()
 {
     if (SkyMaterial == null)
     {
         SkyMaterial = MaterialHelper.CreateTemp(SkyShader, "Sky");
     }
 }
Пример #4
0
        public void Start()
        {
            if (Sun == null)
            {
                if (GetComponent <AtmosphereSun>() != null)
                {
                    Sun = GetComponent <AtmosphereSun>();
                }
            }

            SunGlareMaterial = MaterialHelper.CreateTemp(SunGlareShader, "Sunglare", (int)RenderQueue);

            mesh        = MeshFactory.MakePlane(8, 8, MeshFactory.PLANE.XY, false, false, false);
            mesh.bounds = new Bounds(Vector4.zero, new Vector3(9e37f, 9e37f, 9e37f));

            for (int i = 0; i < Ghost1SettingsList.Count; i++)
            {
                Ghost1Settings.SetRow(i, Ghost1SettingsList[i]);
            }

            for (int i = 0; i < Ghost2SettingsList.Count; i++)
            {
                Ghost2Settings.SetRow(i, Ghost2SettingsList[i]);
            }

            for (int i = 0; i < Ghost3SettingsList.Count; i++)
            {
                Ghost3Settings.SetRow(i, Ghost3SettingsList[i]);
            }

            InitUniforms(SunGlareMaterial);
        }
Пример #5
0
        protected override void InitNode()
        {
            if (Settings == null)
            {
                return;
            }

            SunGlareMaterial = MaterialHelper.CreateTemp(SunGlareShader, "Sunglare", (int)RenderQueue);

            SunGlareMesh        = MeshFactory.MakePlane(8, MeshFactory.PLANE.XY, false, false, false);
            SunGlareMesh.bounds = new Bounds(Vector4.zero, new Vector3(9e37f, 9e37f, 9e37f));

            for (var i = 0; i < Settings.Ghost1SettingsList.Count; i++)
            {
                Ghost1Settings.SetRow(i, Settings.Ghost1SettingsList[i]);
            }

            for (var i = 0; i < Settings.Ghost2SettingsList.Count; i++)
            {
                Ghost2Settings.SetRow(i, Settings.Ghost2SettingsList[i]);
            }

            for (var i = 0; i < Settings.Ghost3SettingsList.Count; i++)
            {
                Ghost3Settings.SetRow(i, Settings.Ghost3SettingsList[i]);
            }

            InitUniforms(SunGlareMaterial);
        }
Пример #6
0
        protected virtual void CreateLineMaterial()
        {
            if (lineShader == null)
            {
                throw new System.NullReferenceException("Line Shader is null!");
            }

            if (!lineMaterial)
            {
                lineMaterial = MaterialHelper.CreateTemp(lineShader, "Line");
            }
        }
Пример #7
0
        private void Start()
        {
            if (FBProcessShader == null)
            {
                FBProcessShader = Shader.Find("Hidden/FrameBufferProcess");
            }

            FBProcessMaterial = MaterialHelper.CreateTemp(FBProcessShader, "FrameBufferProcess");

            CMDBufferCreate();
            FBORecreate();

            LastScreenSize = ScreenSize;
        }
Пример #8
0
        private void Start()
        {
            var startTime = Time.realtimeSinceStartup;

            ApplicationDataPath = Application.dataPath;

            ViewMaterial = MaterialHelper.CreateTemp(ViewShader, "TreeView");

            CalculateMesh();
            //CalculateAO();
            CalculateViews();

            Debug.Log(string.Format("PreProcessTree.Start: Computation time: {0} s", (Time.realtimeSinceStartup - startTime)));
        }
Пример #9
0
        public override void InitNode()
        {
            ParentBody = GetComponentInParent <Body>();

            TerrainMaterial = MaterialHelper.CreateTemp(ParentBody.ColorShader, "TerrainNode");

            FaceToLocal = Matrix4x4d.identity;

            // NOTE : Body shape dependent...
            var celestialBody = ParentBody as CelestialBody;
            var faces         = new Vector3d[] { new Vector3d(0, 0, 0), new Vector3d(90, 0, 0), new Vector3d(90, 90, 0), new Vector3d(90, 180, 0), new Vector3d(90, 270, 0), new Vector3d(0, 180, 180) };

            // If this terrain is deformed into a sphere the face matrix is the rotation of the
            // terrain needed to make up the spherical planet. In this case there should be 6 terrains, each with a unique face number
            if (Face - 1 >= 0 && Face - 1 < 6)
            {
                FaceToLocal = Matrix4x4d.Rotate(faces[Face - 1]);
            }
            if (celestialBody == null)
            {
                throw new Exception("Wow! Celestial body isn't Celestial?!");
            }

            LocalToWorld = Matrix4x4d.ToMatrix4x4d(celestialBody.transform.localToWorldMatrix) * FaceToLocal;
            Deformation  = new DeformationSpherical(celestialBody.Size);

            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]);

            InitUniforms(TerrainMaterial);

            CreateTerrainQuadRoot(ParentBody.Size);

            CollectSamplers();
            CollectSamplersSuitable();

            SamplersOrder = new TileSamplerOrder(Samplers);

            var producers    = GetComponentsInChildren <TileProducer>();
            var lastProducer = producers[producers.Length - 1];

            if (lastProducer.IsLastInSequence == false)
            {
                lastProducer.IsLastInSequence = true;

                Debug.Log(string.Format("TerrainNode: {0} probably last in generation sequence, but maybe accidentally not marked as. Fixed!", lastProducer.name));
            }
        }
Пример #10
0
    public void SetupMainQuad(QuadPosition quadPosition)
    {
        GameObject go = new GameObject(string.Format("Quad_{0}", quadPosition));

        go.transform.parent        = QuadsRoot.transform;
        go.transform.position      = Vector3.zero;
        go.transform.rotation      = Quaternion.identity;
        go.transform.localPosition = Vector3.zero;
        go.transform.localRotation = Quaternion.identity;

        Mesh mesh = GetMesh(quadPosition);

        mesh.bounds = new Bounds(Vector3.zero, new Vector3(PlanetRadius * 2, PlanetRadius * 2, PlanetRadius * 2));

        Material material = MaterialHelper.CreateTemp(ColorShader, "Quad");

        Quad quadComponent = go.AddComponent <Quad>();

        quadComponent.Planetoid    = this;
        quadComponent.QuadMesh     = mesh;
        quadComponent.QuadMaterial = material;

        if (Atmosphere != null)
        {
            Atmosphere.InitUniforms(null, quadComponent.QuadMaterial, false);
        }

        QuadGenerationConstants gc = QuadGenerationConstants.Init(TerrainMaxHeight);

        gc.planetRadius = PlanetRadius;

        gc.cubeFaceEastDirection  = quadComponent.GetCubeFaceEastDirection(quadPosition);
        gc.cubeFaceNorthDirection = quadComponent.GetCubeFaceNorthDirection(quadPosition);
        gc.patchCubeCenter        = quadComponent.GetPatchCubeCenter(quadPosition);

        quadComponent.Position            = quadPosition;
        quadComponent.ID                  = QuadID.One;
        quadComponent.generationConstants = gc;
        quadComponent.SetupCorners(quadPosition);
        quadComponent.ShouldDraw       = true;
        quadComponent.ReadyForDispatch = true;

        Quads.Add(quadComponent);
        MainQuads.Add(quadComponent);
    }
Пример #11
0
    public Quad SetupSubQuad(QuadPosition quadPosition)
    {
        GameObject go = new GameObject(string.Format("Quad_{0}", quadPosition));

        Mesh mesh = GetMesh(quadPosition);

        mesh.bounds = new Bounds(Vector3.zero, new Vector3(PlanetRadius * 2, PlanetRadius * 2, PlanetRadius * 2));

        Material material = MaterialHelper.CreateTemp(ColorShader, "Quad");

        Quad quadComponent = go.AddComponent <Quad>();

        quadComponent.Planetoid    = this;
        quadComponent.QuadMesh     = mesh;
        quadComponent.QuadMaterial = material;
        quadComponent.SetupCorners(quadPosition);

        if (Atmosphere != null)
        {
            Atmosphere.InitUniforms(null, quadComponent.QuadMaterial, false);
        }

        QuadGenerationConstants gc = QuadGenerationConstants.Init(TerrainMaxHeight);

        gc.planetRadius = PlanetRadius;

        quadComponent.Position            = quadPosition;
        quadComponent.generationConstants = gc;
        quadComponent.ShouldDraw          = false;

        if (qdtccc == null)
        {
            qdtccc = new QuadDistanceToClosestCornerComparer();
        }

        Quads.Add(quadComponent);
        Quads.Sort(qdtccc);

        return(quadComponent);
    }
Пример #12
0
        protected override void InitNode()
        {
            InitOceanNode();

            OceanMaterial = MaterialHelper.CreateTemp(OceanShader, "Ocean");

            ParentBody.Atmosphere.InitUniforms(OceanMaterial);

            OldLocalToOcean = Matrix4x4d.identity;
            Offset          = Vector4.zero;

            // Create the projected grid. The resolution is the size in pixels of each square in the grid.
            // If the squares are small the size of the mesh will exceed the max verts for a mesh in Unity. In this case split the mesh up into smaller meshes.
            Resolution = Mathf.Max(1, Resolution);

            // The number of squares in the grid on the x and y axis
            var NX       = Screen.width / Resolution;
            var NY       = Screen.height / Resolution;
            var numGrids = 1;

            const int MAX_VERTS = 65000;

            // The number of meshes need to make a grid of this resolution
            if (NX * NY > MAX_VERTS)
            {
                numGrids += (NX * NY) / MAX_VERTS;
            }

            ScreenMeshGrids = new Mesh[numGrids];

            // Make the meshes. The end product will be a grid of verts that cover the screen on the x and y axis with the z depth at 0.
            // This grid is then projected as the ocean by the shader
            for (byte i = 0; i < numGrids; i++)
            {
                NY = Screen.height / numGrids / Resolution;

                ScreenMeshGrids[i]        = MeshFactory.MakeOceanPlane(NX, NY, (float)i / (float)numGrids, 1.0f / (float)numGrids);
                ScreenMeshGrids[i].bounds = new Bounds(Vector3.zero, new Vector3(1e8f, 1e8f, 1e8f));
            }
        }
Пример #13
0
        public override void InitNode()
        {
            base.InitNode();

            if (InitJacobiansMaterial == null)
            {
                Debug.Log("OceanWhiteCaps: Init jacobians material is null! Trying to find it out...");
                InitJacobiansMaterial = MaterialHelper.CreateTemp(Shader.Find("SpaceEngine/Ocean/InitJacobians"), "InitJacobians");
            }

            if (WhiteCapsPrecomputeMaterial == null)
            {
                Debug.Log("OceanWhiteCaps: White caps precompute material is null! Trying to find it out...");
                WhiteCapsPrecomputeMaterial = MaterialHelper.CreateTemp(Shader.Find("SpaceEngine/Ocean/WhiteCapsPrecompute"), "WhiteCapsPrecompute");
            }

            InitJacobiansMaterial.SetTexture("_Spectrum01", Spectrum01);
            InitJacobiansMaterial.SetTexture("_Spectrum23", Spectrum23);
            InitJacobiansMaterial.SetTexture("_WTable", WTable);
            InitJacobiansMaterial.SetVector("_Offset", Offset);
            InitJacobiansMaterial.SetVector("_InverseGridSizes", InverseGridSizes);
        }
Пример #14
0
        public override void InitNode()
        {
            base.InitNode();

            if (InitSpectrumMaterial == null)
            {
                Debug.Log("OceanFFT: Init spectrum material is null! Trying to find it out...");
                InitSpectrumMaterial = MaterialHelper.CreateTemp(Shader.Find("SpaceEngine/Ocean/InitSpectrum"), "InitSpectrum");
            }

            if (InitDisplacementMaterial == null)
            {
                Debug.Log("OceanFFT: Init displacement material is null! Trying to find it out..");
                InitDisplacementMaterial = MaterialHelper.CreateTemp(Shader.Find("SpaceEngine/Ocean/InitDisplacement"), "InitDisplacement");
            }

            MapSize = (float)FourierGridSize;
            Offset  = new Vector4(1.0f + 0.5f / MapSize, 1.0f + 0.5f / MapSize, 0, 0);

            float factor = 2.0f * Mathf.PI * MapSize;

            InverseGridSizes = new Vector4(factor / GridSizes.x, factor / GridSizes.y, factor / GridSizes.z, factor / GridSizes.w);

            Fourier = new FourierGPU(FourierGridSize, FourierShader);

            //Create the data needed to make the waves each frame
            CreateRenderTextures();
            GenerateWavesSpectrum();
            CreateWTable();

            InitSpectrumMaterial.SetTexture("_Spectrum01", Spectrum01);
            InitSpectrumMaterial.SetTexture("_Spectrum23", Spectrum23);
            InitSpectrumMaterial.SetTexture("_WTable", WTable);
            InitSpectrumMaterial.SetVector("_Offset", Offset);
            InitSpectrumMaterial.SetVector("_InverseGridSizes", InverseGridSizes);

            InitDisplacementMaterial.SetVector("_InverseGridSizes", InverseGridSizes);
        }
Пример #15
0
 private void InitMaterial()
 {
     QuadMaterial = MaterialHelper.CreateTemp(Planetoid.ColorShader, "Quad", (int)Planetoid.RenderQueue);
 }
Пример #16
0
 private void InitMaterial()
 {
     RingMaterial = MaterialHelper.CreateTemp(RingShader, "Ring", (int)RenderQueue);
 }
Пример #17
0
    private void GenerateTerrain()
    {
        GameObject = new GameObject
        {
            name  = "Patch_LOD_ " + SplitLevel + " : [" + Up + "]",
            layer = Sphere.gameObject.layer
        };

        Mesh = new Mesh();
        Data = new PatchData(PatchSettings.Vertices);

        var origin  = Volume.Vertices[0];
        var spacing = Size / (PatchSettings.VerticesPerSide - 1);

        for (ushort y = 0; y < PatchSettings.VerticesPerSide; y++)
        {
            var offset = origin;

            for (ushort x = 0; x < PatchSettings.VerticesPerSide; x++)
            {
                var vertex = offset;

                Data.Vertices.Add(vertex.NormalizeToRadius(Sphere.Radius));
                Data.Normals.Add(vertex.normalized);
                Data.Volume.Add(offset);

                Data.UV1.Add(VectorHelper.CartesianToPolarUV(vertex));
                Data.UV2.Add(new Vector2(0, 0));

                offset += Right * spacing;
            }

            origin -= Front * spacing;
        }

        //update projected center
        MiddleProjected = MiddleProjected.NormalizeToRadius(Sphere.Radius);

        //save original parent transformations
        var parentPosition = Sphere.gameObject.transform.position;
        var parentRotation = Sphere.gameObject.transform.rotation;

        //reset parent transformations before assigning data (so our vertices will be centered on the parent transform)
        Sphere.gameObject.transform.position = Vector3.zero;
        Sphere.gameObject.transform.rotation = Quaternion.identity;

        //put this node as a child of parent
        GameObject.transform.parent = Sphere.gameObject.transform;

        var indices = Sphere.PatchManager.Patches[Edges];

        //assign data to this node's mesh
        Mesh.SetVertices(Data.Vertices);
        Mesh.SetNormals(Data.Normals);
        Mesh.SetTriangles(indices, 0);
        Mesh.SetUVs(0, Data.UV1);
        Mesh.SetUVs(1, Data.UV2);

        Mesh.hideFlags = HideFlags.HideAndDontSave;

        Mesh.SolveTangents(ref indices, ref Data.Vertices, ref Data.Normals, ref Data.UV1);
        Mesh.RecalculateBounds();

        //restore parent transformations
        Sphere.gameObject.transform.position = parentPosition;
        Sphere.gameObject.transform.rotation = parentRotation;

        NeedsTerrain = false;

        //discard parent's resources
        if (Parent != null)
        {
            Parent.DestroyNode();
        }

        var patch      = GameObject.AddComponent <Patch>();
        var meshFilter = GameObject.AddComponent <MeshFilter>();

        GameObject.AddComponent <MeshRenderer>();
        GameObject.GetComponent <MeshRenderer>().sharedMaterial = MaterialHelper.CreateTemp(Sphere.Shader, "Patch");

        meshFilter.mesh = Mesh;
        patch.PatchTree = this;
    }
Пример #18
0
        public override void InitNode()
        {
            OceanMaterial = MaterialHelper.CreateTemp(OceanShader, "Ocean");

            ParentBody.InitUniforms(OceanMaterial);
        }
Пример #19
0
 private void InitMaterial()
 {
     RingMaterial = MaterialHelper.CreateTemp(RingShader, "Ring");
 }
Пример #20
0
 public void InitMaterials()
 {
     CloudMaterial = MaterialHelper.CreateTemp(CloudShader, "Cloudsphere", (int)RenderQueue);
 }
Пример #21
0
    private void GenerateTerrain()
    {
        GameObject = new GameObject
        {
            name  = "Patch_LOD_ " + SplitLevel + " : [" + Up + "]",
            layer = Sphere.gameObject.layer
        };

        Mesh = new Mesh();
        Data = new PatchData(PatchSettings.Vertices);

        var origin = Volume.Vertices[0];

        var vertStep  = Size / (PatchSettings.VerticesPerSide - 1); //vertex spacing
        var startHMap = 1.0f;
        var endHMap   = 1.0f - startHMap;

        var uCoord = startHMap;
        var vCoord = startHMap;                                                   //uv coordinates for the heightmap

        var uvStep = (endHMap - startHMap) / (PatchSettings.VerticesPerSide - 1); //hmap uv step size inside the loop

        var uVolCoord = Volume.UVs[0].x;
        var vVolCoord = Volume.UVs[0].y;                                                              //flat uv coordinates for the cube face

        var volCoordStep = (Volume.UVs[1].x - Volume.UVs[0].x) / (PatchSettings.VerticesPerSide - 1); //step size of flat uv inside the loop
        var idx          = 0;

        for (ushort y = 0; y < PatchSettings.VerticesPerSide; y++)
        {
            var offset = origin;

            uCoord    = startHMap;
            uVolCoord = Volume.UVs[0].x;

            for (ushort x = 0; x < PatchSettings.VerticesPerSide; x++)
            {
                //heightmap texture coordinates
                Data.UV1[idx] = new Vector2(uCoord, vCoord);
                uCoord       += uvStep;

                //volume texture coordinates
                //x,y = flat volume uv coordinates
                //z = vertex slope
                Data.UV2[idx] = new Vector2(uVolCoord, vVolCoord);
                uVolCoord    += volCoordStep;

                //calculate vertex position
                var vtx = offset;

                //use normalized vertex position as vertex normal
                vtx.Normalize();
                Data.Normals[idx] = vtx;

                //scale to sphere
                vtx = vtx * Sphere.Radius;

                //store
                Data.Vertices[idx] = vtx;
                Data.Volume[idx]   = offset;

                idx++;
                offset += Right * vertStep;
            }

            origin    -= Front * vertStep;
            vCoord    += uvStep;
            vVolCoord += volCoordStep;
        }

        //update projected center
        MiddleProjected = MiddleProjected.NormalizeToRadius(Sphere.Radius);

        //save original parent transformations
        var parentPosition = Sphere.gameObject.transform.position;
        var parentRotation = Sphere.gameObject.transform.rotation;

        //reset parent transformations before assigning data (so our vertices will be centered on the parent transform)
        Sphere.gameObject.transform.position = Vector3.zero;
        Sphere.gameObject.transform.rotation = Quaternion.identity;

        //put this node as a child of parent
        GameObject.transform.parent = Sphere.gameObject.transform;

        //assign data to this node's mesh
        Mesh.SetVertices(Data.Vertices.ToList());
        Mesh.SetUVs(0, Data.UV1.ToList());
        Mesh.SetUVs(1, Data.UV2.ToList());
        Mesh.SetNormals(Data.Normals.ToList());
        Mesh.SetTriangles(Sphere.PatchManager.Patches[Edges], 0);
        Mesh.hideFlags = HideFlags.DontSave;

        MeshFactory.SolveTangents(Mesh);

        Mesh.RecalculateBounds();

        //restore parent transformations
        Sphere.gameObject.transform.position = parentPosition;
        Sphere.gameObject.transform.rotation = parentRotation;

        NeedsTerrain = false;

        //discard parent's resources
        if (Parent != null)
        {
            Parent.DestroyNode();
        }

        var patch      = GameObject.AddComponent <Patch>();
        var meshFilter = GameObject.AddComponent <MeshFilter>();

        GameObject.AddComponent <MeshRenderer>();
        GameObject.GetComponent <MeshRenderer>().sharedMaterial = MaterialHelper.CreateTemp(Sphere.Shader, "Patch");

        meshFilter.mesh = Mesh;
        patch.PatchTree = this;
    }