Ejemplo n.º 1
0
    public override IEnumerator ComputeStarData()
    {
        SendProgress(0);

        // Create 1 large texture, then render smaller tiles into it.
        Texture2D tex = new Texture2D((int)imageSize, (int)imageSize, TextureFormat.RGBA32, false);

        // Random points on sphere surface to position stars.
        int tileSize = (int)imageSize;
        List <StarPoint> starPoints = GenerateRandomStarsPoints(density, tileSize, tileSize);

        SendProgress(0);

        // Fill in the image.
        for (int yIndex = 0; yIndex < tileSize; yIndex++)
        {
            float yPercent  = (float)yIndex / (float)(tileSize - 1);
            float yPosition = SphereUtility.PercentToHeight(yPercent);

            for (int xIndex = 0; xIndex < tileSize; xIndex++)
            {
                float anglePercent = (float)xIndex / (float)(tileSize - 1);
                float angle        = SphereUtility.PercentToRadAngle(anglePercent);

                Vector3 currentSpot = SphereUtility.SphericalToPoint(yPosition, angle);

                // Closest star to current spot.
                StarPoint star = NearestStarPoint(currentSpot, starPoints);

                UnityEngine.Color c = new UnityEngine.Color(
                    PointAxisToPercent(star.position.x),
                    PointAxisToPercent(star.position.y),
                    PointAxisToPercent(star.position.z),
                    star.noise); // Noise value used to randomize each star.

                tex.SetPixel(xIndex, yIndex, c);
            }

            // Update the GUI progress bar.
            float totalProgress = (float)((yIndex + 1) * tileSize) / (float)(tileSize * tileSize);
            SendProgress(totalProgress);

            yield return(null);
        }

        tex.Apply(false);

        SendCompletion(tex, true);

        yield break;
    }
Ejemplo n.º 2
0
    void UpdateMoonData(List <MaterialProperty> allProps)
    {
        MaterialProperty heightProp = GetPropertyWithName(allProps, "_MoonHeight");

        if (heightProp == null)
        {
            Debug.LogError("Missing moon height property");
            return;
        }

        MaterialProperty angleProp = GetPropertyWithName(allProps, "_MoonAngle");

        if (angleProp == null)
        {
            Debug.LogError("Missing moon angle property");
            return;
        }

        // Convert our percent properties to spherical point.
        float   moonYPosition = SphereUtility.PercentToHeight(heightProp.floatValue);
        float   moonAngle     = SphereUtility.PercentToRadAngle(angleProp.floatValue);
        Vector3 moonPoint     = SphereUtility.SphericalToPoint(moonYPosition, moonAngle);

        float xRotation = 0;
        float yRotation = 0;

        SphereUtility.CalculateStarRotation(moonPoint, out xRotation, out yRotation);

        MaterialProperty moonPositionProp = GetPropertyWithName(allProps, "_MoonComputedPositionData");

        if (moonPositionProp == null)
        {
            Debug.LogError("Can't update precomputed moon position without property");
            return;
        }

        moonPositionProp.vectorValue = new Vector4(moonPoint.x, moonPoint.y, moonPoint.z, 0);

        MaterialProperty moonRotationProp = GetPropertyWithName(allProps, "_MoonComputedRotationData");

        if (moonRotationProp == null)
        {
            Debug.LogError("Can't update precomputed moon rotation without property");
            return;
        }

        moonRotationProp.vectorValue = new Vector4(xRotation, yRotation, 0, 0);
    }
Ejemplo n.º 3
0
    public void UpdateMoonData()
    {
        // Convert our percent properties to spherical point.
        float   moonYPosition = SphereUtility.PercentToHeight(verticalPosition);
        float   moonAngle     = SphereUtility.PercentToRadAngle(horizontalPosition);
        Vector3 moonPoint     = SphereUtility.SphericalToPoint(moonYPosition, moonAngle);

        float xRotation = 0;
        float yRotation = 0;

        SphereUtility.CalculateStarRotation(moonPoint, out xRotation, out yRotation);


        Vector4 moonPositionData = new Vector4(moonPoint.x, moonPoint.y, moonPoint.z, 0);
        Vector4 moonRotationData = new Vector4(xRotation, yRotation, 0, 0);

        moonMaterial.SetVector("_MoonComputedPositionData", moonPositionData);
        moonMaterial.SetVector("_MoonComputedRotationData", moonRotationData);
    }