Пример #1
0
    private float DesiredLodLevel()
    {
        float   edgeLength = LodFace.GetEdgeLength(LodNode.CHUNK_RESOLUTION);
        Vector3 scales     = this.gameObject.transform.TransformVector(this.gameObject.transform.InverseTransformDirection(Vector3.one));
        float   maxScale   = Mathf.Max(scales.x, scales.y, scales.z);
        // float scaledEdgeLength = maxScale * edgeLength * this.lodProperties.heightGenerator.GetMaximumValue();
        float scaledEdgeLength = maxScale * edgeLength;
        float cameraDistance   = Mathf.Sqrt(this.meshRenderer.bounds.SqrDistance(Camera.main.transform.position));

        if (cameraDistance == 0f)
        {
            return(int.MaxValue);
        }
        Vector3 boundsPoint          = Camera.main.WorldToScreenPoint(Camera.main.transform.position + Camera.main.transform.forward * cameraDistance);
        Vector3 offsetPoint          = Camera.main.WorldToScreenPoint(Camera.main.transform.position + Camera.main.transform.forward * cameraDistance + Camera.main.transform.up * edgeLength);
        float   unitVectorLength     = offsetPoint.y - boundsPoint.y;
        float   edgeLengthAtDistance = unitVectorLength * scaledEdgeLength;
        float   tessellationFactor   = edgeLengthAtDistance / LodNode.DESIRED_EDGE_LENGTH;
        float   lodLevel             = Mathf.Log(tessellationFactor, 6f);

        return(lodLevel);
    }
Пример #2
0
    void Start()
    {
        LodHeightGenerator.Properties properties = new LodHeightGenerator.Properties();
        properties.strength    = 0.28f;
        properties.frequency   = 1f;
        properties.lacunarity  = 2.3f;
        properties.persistence = 0.40f;
        properties.octaves     = 8;

        Perlin perlin = new Perlin(0);

        this.heightGenerator = new LodHeightGenerator(perlin, properties);
        this.material.SetTexture("_Gradients2D", PerlinTextureGenerator.CreateGradientsTexture(perlin));
        this.material.SetTexture("_Permutation2D", PerlinTextureGenerator.CreatePermutationTexture(perlin));
        this.material.SetFloat("_Strength", properties.strength);
        this.material.SetFloat("_Frequency", properties.frequency);
        this.material.SetFloat("_Lacunarity", properties.lacunarity);
        this.material.SetFloat("_Persistence", properties.persistence);
        this.material.SetInt("_Octaves", properties.octaves);

        this.rootGameObjects = new GameObject[6];
        this.roots           = new LodNode[6];
        for (int i = 0; i < 6; i++)
        {
            this.rootGameObjects[i] = new GameObject("Face (" + i + ")");
            this.rootGameObjects[i].transform.SetParent(this.transform, false);

            Vector3       up            = LodManager.directions[i];
            LodProperties lodProperties = new LodProperties();
            lodProperties.gameObject      = this.rootGameObjects[i];
            lodProperties.material        = this.material;
            lodProperties.up              = up;
            lodProperties.heightGenerator = this.heightGenerator;

            this.roots[i] = new LodNode(null, lodProperties, 0, up, LodFace.GetForward(up), LodFace.GetRight(up));
        }
    }
Пример #3
0
 public static Vector3 GetRight(Vector3 up)
 {
     return(Vector3.Cross(up, LodFace.GetForward(up)));
 }