コード例 #1
0
    public CLodSphere(bool outer, CPlanet planet)
    {
        CGlobal global = CGlobal.GetInstance();

        m_Planet = planet;

        if (outer)
        {
            // outer atmosphere
            m_Material = (Material)Material.Instantiate(global.OuterAtmosphereMaterial);
        }
        else
        {
            // inner atmosphere
            m_Material = (Material)Material.Instantiate(global.InnerAtmosphereMaterial);
        }

        m_Material.SetFloat("_planetRadius", m_Planet.m_Radius);
        m_Material.SetFloat("_atmosRadius", m_Planet.AtmosRadius);
        m_Material.SetColor("_color1", m_Planet.m_AtmosColor1);
        m_Material.SetColor("_color2", m_Planet.m_AtmosColor2);
        m_Material.SetFloat("_sunIntensity", m_Planet.m_sunIntensity);
        m_Material.SetFloat("_horizonHeight", m_Planet.m_HorizonHeight);
        m_Material.SetFloat("_horizonIntensity", m_Planet.m_HorizonIntensity);
        m_Material.SetFloat("_horizonPower", m_Planet.m_HorizonPower);
        m_Material.SetFloat("_minAlpha", m_Planet.m_MinAtmosAlpha);

        m_Spheres = new GameObject[3];

        // lod is 0:lowest, 1:mid, 2:highest detail
        for (int i = 0; i < 3; i++)
        {
            // save original parent transformations
            Vector3    parentPos = m_Planet.gameObject.transform.position;
            Quaternion parentQua = m_Planet.gameObject.transform.rotation;

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

            m_Spheres[i] = new GameObject("atmos lod " + i);
            m_Spheres[i].AddComponent <MeshFilter>();
            m_Spheres[i].AddComponent <MeshRenderer>();

            // ### outer atmosphere tesselation should be using AtmosSlices and AtmosStacks configs from CPatchConfig...
            m_Spheres[i].GetComponent <MeshFilter>().sharedMesh = global.MakeSphere((outer ? m_Planet.AtmosRadius : m_Planet.AtmosRadius * 1.25f), 15 * ((i + 1) * 4), 11 * ((i + 1) * 4));
            m_Spheres[i].transform.parent = m_Planet.gameObject.transform;

            m_Spheres[i].renderer.sharedMaterial = m_Material;

            // restore parent transformations
            m_Planet.gameObject.transform.position = parentPos;
            m_Planet.gameObject.transform.rotation = parentQua;

            // inactivate this gameobject
            m_Spheres[i].hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable;
        }
    }
コード例 #2
0
    // uses GPU to accumulate layers of noise
    public static void Execute(CNoiseLayer layer, RenderTexture noiseRT, CBoundingVolume volume, bool flip, float planetRadius)
    {
        CGlobal global = CGlobal.GetInstance();

        int   matidx    = 0;
        float amp       = 1.0f;
        float frequency = layer.m_Frequency;

        switch (layer.m_LayerType)
        {
        case NoiseLayerType.Cell:
        {
            Debug.Log("[ETHEREA1] NoiseLayerType.Cell is not implemented yet! Please select Ridged or Turbulence instead.");
            break;
        }

        case NoiseLayerType.Ridged:
        {
            matidx = 0;
            break;
        }

        case NoiseLayerType.Turbulence:
        {
            matidx = 1;
            break;
        }
        }

        for (int i = 0; i < layer.m_Octaves; i++)
        {
            RenderTexture.active = noiseRT;

            global.GenNoiseMaterial[matidx].SetFloat("_planetRadius", planetRadius);
            global.GenNoiseMaterial[matidx].SetVector("_noiseOffset", layer.m_NoiseOffset);
            global.GenNoiseMaterial[matidx].SetFloat("_offset", layer.m_Offset);
            global.GenNoiseMaterial[matidx].SetFloat("_hpower", layer.m_HPower);
            global.GenNoiseMaterial[matidx].SetTexture("_permTexture", global.PermTex);
            global.GenNoiseMaterial[matidx].SetTexture("_simplexTexture", global.SimplexTex);
            global.GenNoiseMaterial[matidx].SetFloat("_contribution", layer.m_Contribution);

            global.GenNoiseMaterial[matidx].SetTexture("_previousPass", noiseRT);
            global.GenNoiseMaterial[matidx].SetFloat("_amp", amp);
            global.GenNoiseMaterial[matidx].SetFloat("_frequency", frequency);

            // ### render with extended volume coordinates but with normal uv volume coordinates
            //global.RenderQuadVolumeExCoord(noiseRT.width, noiseRT.height, global.GenNoiseMaterial[matidx], volume, flip);
            global.RenderQuadVolume(noiseRT.width, noiseRT.height, global.GenNoiseMaterial[matidx], volume, flip);

            frequency *= layer.m_Lacunarity;
            amp       *= layer.m_Persistence;

            RenderTexture.active = null;
        }
    }
コード例 #3
0
    public static void ShapeNoise(RenderTexture noiseRT, Texture2D shapeTex, CBoundingVolume volume)
    {
        CGlobal global = CGlobal.GetInstance();

        RenderTexture.active = noiseRT;

        global.ShapeNoiseMaterial.SetTexture("_hmap", noiseRT);
        global.ShapeNoiseMaterial.SetTexture("_shape", shapeTex);

        global.RenderQuadVolume(noiseRT.width, noiseRT.height, global.ShapeNoiseMaterial, volume, false);

        RenderTexture.active = null;
    }
コード例 #4
0
 // uses CPU to accumulate layers of noise
 public static void ExecuteCPU(CNoiseLayer layer, Color[] heights, int w, int h, CBoundingVolume volume, bool flip, float planetRadius)
 {
     CGlobal global = CGlobal.GetInstance();
     // actually, do nothing.
 }
コード例 #5
0
 public static void ShapeNoise(RenderTexture noiseRT, Texture2D shapeTex, CBoundingVolume volume)
 {
     CGlobal global = CGlobal.GetInstance();
     // actually, do nothing
 }
コード例 #6
0
ファイル: CPlanet.cs プロジェクト: Heavenfather/Mission
    public void Rebuild()
    {
        CGlobal global = CGlobal.GetInstance();

        m_LutGen       = new CLutGenerator();
        m_LutLayers[0] = new CLutLayer(m_Diffuse1LutLayer.minh, m_Diffuse1LutLayer.maxh, m_Diffuse1LutLayer.slope, m_Diffuse1LutLayer.aperture);
        m_LutLayers[1] = new CLutLayer(m_Diffuse2LutLayer.minh, m_Diffuse2LutLayer.maxh, m_Diffuse2LutLayer.slope, m_Diffuse2LutLayer.aperture);
        m_LutLayers[2] = new CLutLayer(m_Diffuse3LutLayer.minh, m_Diffuse3LutLayer.maxh, m_Diffuse3LutLayer.slope, m_Diffuse3LutLayer.aperture);
        m_LutLayers[3] = new CLutLayer(m_Diffuse4LutLayer.minh, m_Diffuse4LutLayer.maxh, m_Diffuse4LutLayer.slope, m_Diffuse4LutLayer.aperture);
        m_LutGen.UpdateLutTex(m_LutLayers);

        m_PatchConfig  = new CPatchConfig(m_PatchQuality, m_NormalQuality, m_FilteredHeights);
        m_PatchManager = new CPatchManager(m_PatchConfig, this);
        global.Setup();

        // ---

        // destroy the previous planet tree
        DestroyPlanet();

        //
        // rebuild patch tree
        //

        m_Quadtrees.Add(new CQuadtree(new Vector3(0, 1, 0), new Vector3(0, 0, -1), this, m_ShapeTop));                  // 0: top
        m_Quadtrees.Add(new CQuadtree(new Vector3(0, -1, 0), new Vector3(0, 0, 1), this, m_ShapeBottom));               // 1: bottom

        m_Quadtrees.Add(new CQuadtree(new Vector3(-1, 0, 0), new Vector3(0, 1, 0), this, m_ShapeLeft));                 // 2: left
        m_Quadtrees.Add(new CQuadtree(new Vector3(1, 0, 0), new Vector3(0, 1, 0), this, m_ShapeRight));                 // 3: right

        m_Quadtrees.Add(new CQuadtree(new Vector3(0, 0, 1), new Vector3(0, 1, 0), this, m_ShapeFront));                 // 4: front
        m_Quadtrees.Add(new CQuadtree(new Vector3(0, 0, -1), new Vector3(0, 1, 0), this, m_ShapeBack));                 // 5: back

        // link neighbors of TOP quadtree
        m_Quadtrees[0].SetNeighbor(en_NeighborDirection.NB_Top, m_Quadtrees[5], en_NeighborDirection.NB_Top);         // back
        m_Quadtrees[0].SetNeighbor(en_NeighborDirection.NB_Bottom, m_Quadtrees[4], en_NeighborDirection.NB_Top);      // front
        m_Quadtrees[0].SetNeighbor(en_NeighborDirection.NB_Left, m_Quadtrees[2], en_NeighborDirection.NB_Top);        // left
        m_Quadtrees[0].SetNeighbor(en_NeighborDirection.NB_Right, m_Quadtrees[3], en_NeighborDirection.NB_Top);       // right

        // link neighbors of BOTTOM quadtree
        m_Quadtrees[1].SetNeighbor(en_NeighborDirection.NB_Top, m_Quadtrees[4], en_NeighborDirection.NB_Bottom);         // front
        m_Quadtrees[1].SetNeighbor(en_NeighborDirection.NB_Bottom, m_Quadtrees[5], en_NeighborDirection.NB_Bottom);      // back
        m_Quadtrees[1].SetNeighbor(en_NeighborDirection.NB_Left, m_Quadtrees[2], en_NeighborDirection.NB_Bottom);        // left
        m_Quadtrees[1].SetNeighbor(en_NeighborDirection.NB_Right, m_Quadtrees[3], en_NeighborDirection.NB_Bottom);       // right

        // link neighbors of LEFT quadtree
        m_Quadtrees[2].SetNeighbor(en_NeighborDirection.NB_Top, m_Quadtrees[0], en_NeighborDirection.NB_Left);         // top
        m_Quadtrees[2].SetNeighbor(en_NeighborDirection.NB_Bottom, m_Quadtrees[1], en_NeighborDirection.NB_Left);      // bottom
        m_Quadtrees[2].SetNeighbor(en_NeighborDirection.NB_Left, m_Quadtrees[5], en_NeighborDirection.NB_Right);       // back
        m_Quadtrees[2].SetNeighbor(en_NeighborDirection.NB_Right, m_Quadtrees[4], en_NeighborDirection.NB_Left);       // front

        // link neighbors of RIGHT quadtree
        m_Quadtrees[3].SetNeighbor(en_NeighborDirection.NB_Top, m_Quadtrees[0], en_NeighborDirection.NB_Right);         // top
        m_Quadtrees[3].SetNeighbor(en_NeighborDirection.NB_Bottom, m_Quadtrees[1], en_NeighborDirection.NB_Right);      // bottom
        m_Quadtrees[3].SetNeighbor(en_NeighborDirection.NB_Left, m_Quadtrees[4], en_NeighborDirection.NB_Right);        // front
        m_Quadtrees[3].SetNeighbor(en_NeighborDirection.NB_Right, m_Quadtrees[5], en_NeighborDirection.NB_Left);        // back

        // link neighbors of FRONT quadtree
        m_Quadtrees[4].SetNeighbor(en_NeighborDirection.NB_Top, m_Quadtrees[0], en_NeighborDirection.NB_Bottom);         // top
        m_Quadtrees[4].SetNeighbor(en_NeighborDirection.NB_Bottom, m_Quadtrees[1], en_NeighborDirection.NB_Top);         // bottom
        m_Quadtrees[4].SetNeighbor(en_NeighborDirection.NB_Left, m_Quadtrees[2], en_NeighborDirection.NB_Right);         // left
        m_Quadtrees[4].SetNeighbor(en_NeighborDirection.NB_Right, m_Quadtrees[3], en_NeighborDirection.NB_Left);         // right

        // link neighbors of BACK quadtree
        m_Quadtrees[5].SetNeighbor(en_NeighborDirection.NB_Top, m_Quadtrees[0], en_NeighborDirection.NB_Top);         // top
        m_Quadtrees[5].SetNeighbor(en_NeighborDirection.NB_Bottom, m_Quadtrees[1], en_NeighborDirection.NB_Bottom);   // bottom
        m_Quadtrees[5].SetNeighbor(en_NeighborDirection.NB_Left, m_Quadtrees[3], en_NeighborDirection.NB_Right);      // right
        m_Quadtrees[5].SetNeighbor(en_NeighborDirection.NB_Right, m_Quadtrees[2], en_NeighborDirection.NB_Left);      // left

        // atmosphere
        m_AtmosRadius = m_Radius + m_HeightScale * m_AtmosScale;
        m_LodSpheres  = new CLodSphere[]
        {
            new CLodSphere(true, this),                         // outer sphere
            new CLodSphere(false, this)                         // inner sphere
        };

        if (m_Camera == null)
        {
            Debug.Log("[ETHEREA1] Planet " + this.name + " had no associated Camera. Main Camera is being selected as the Camera for this Planet.");
            m_Camera = Camera.main;
        }

        if (m_SunTransform == null)
        {
            Debug.Log("[ETHEREA1] Planet " + this.name + " has no Sun. Please select a Light as the Sun for this Planet.");
        }
    }