Пример #1
0
    public void ApplyToMaterial(Material material)
    {
        material.SetFloat("minHeight", MinHeight - HeightOffsetScaled);
        material.SetFloat("maxHeight", MaxHeight - HeightOffsetScaled);

        material.SetInt("layers", layers.Count);

        if (layers.Count > 0)
        {
            material.SetFloatArray("startHeights", layers.Select(x => x.startHeight).ToArray());
            material.SetFloatArray("blendHeights", layers.Select(x => x.blendHeight).ToArray());
            material.SetFloatArray("textureScales", layers.Select(x => x.textureScale).ToArray());
            material.SetColorArray("tintColors", layers.Select(x => x.tintColor).ToArray());
            material.SetFloatArray("tintColorBlends", layers.Select(x => x.tintBlend).ToArray());

            Texture2DArray albedoTextures = TextureGenerator.GenerateTextureArray(textureResolution,
                                                                                  layers.Select(x => x.albedo).ToArray());
            if (albedoTextures.depth > 0)
            {
                material.SetTexture("albedoTextures", albedoTextures);
            }

            Texture2DArray normalTextures = TextureGenerator.GenerateTextureArray(textureResolution,
                                                                                  layers.Select(x => x.normal).ToArray());
            if (normalTextures.depth > 0)
            {
                material.SetTexture("normalTextures", albedoTextures);
            }
        }
    }