Exemplo n.º 1
0
    public void SetWaterTextures()
    {
        Texture2D WaterRamp = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.TexPathWaterRamp, false, true, true);

        WaterRamp.wrapMode = TextureWrapMode.Clamp;
        Shader.SetGlobalTexture("_WaterRam", WaterRamp);

        try
        {
            Cubemap WaterReflection = GetGamedataFile.GetGamedataCubemap(GetGamedataFile.TexturesScd, map.Water.TexPathCubemap);
            WaterMaterial.SetTexture("SkySampler", WaterReflection);
        }
        catch
        {
            WaterMaterial.SetTexture("SkySampler", DefaultWaterSky);
        }

        const int WaterAnisoLevel = 4;

        Texture2D WaterNormal = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.WaveTextures[0].TexPath, false, true, true);

        WaterNormal.anisoLevel = WaterAnisoLevel;
        WaterMaterial.SetTexture("NormalSampler0", WaterNormal);
        WaterNormal            = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.WaveTextures[1].TexPath, false, true, true);
        WaterNormal.anisoLevel = WaterAnisoLevel;
        WaterMaterial.SetTexture("NormalSampler1", WaterNormal);
        WaterNormal            = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.WaveTextures[2].TexPath, false, true, true);
        WaterNormal.anisoLevel = WaterAnisoLevel;
        WaterMaterial.SetTexture("NormalSampler2", WaterNormal);
        WaterNormal            = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.WaveTextures[3].TexPath, false, true, true);
        WaterNormal.anisoLevel = WaterAnisoLevel;
        WaterMaterial.SetTexture("NormalSampler3", WaterNormal);

        Shader.SetGlobalVector("normal1Movement", map.Water.WaveTextures[0].NormalMovement);
        Shader.SetGlobalVector("normal2Movement", map.Water.WaveTextures[1].NormalMovement);
        Shader.SetGlobalVector("normal3Movement", map.Water.WaveTextures[2].NormalMovement);
        Shader.SetGlobalVector("normal4Movement", map.Water.WaveTextures[3].NormalMovement);
        Shader.SetGlobalVector("normalRepeatRate", new Vector4(map.Water.WaveTextures[0].NormalRepeat, map.Water.WaveTextures[1].NormalRepeat, map.Water.WaveTextures[2].NormalRepeat, map.Water.WaveTextures[3].NormalRepeat));
    }
Exemplo n.º 2
0
    public IEnumerator LoadScmapFile()
    {
        map = new Map();

        //string MapPath = EnvPaths.GetMapsPath();
        string path = MapLuaParser.MapRelativePath(MapLuaParser.Current.ScenarioLuaFile.Data.map);

        if (map.Load(path))
        {
            UpdateLighting();
        }
        else
        {
            Debug.LogWarning("File not found!\n" + path);
            yield break;
        }


        if (map.VersionMinor >= 60)
        {
            map.AdditionalSkyboxData.Data.UpdateSize();
        }
        else
        {
            LoadDefaultSkybox();
        }


        EnvPaths.CurrentGamedataPath = EnvPaths.GamedataPath;

        //Shader
        MapLuaParser.Current.EditMenu.TexturesMenu.TTerrainXP.isOn = map.TerrainShader == "TTerrainXP";
        ToogleShader();

        // Set Variables
        int   xRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[0];
        int   zRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[1];
        float HalfxRes = xRes / 10f;
        float HalfzRes = zRes / 10f;


        TerrainMaterial.SetTexture("_TerrainNormal", map.UncompressedNormalmapTex);
        Shader.SetGlobalTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        Shader.SetGlobalFloat("_WaterScaleX", xRes);
        Shader.SetGlobalFloat("_WaterScaleZ", xRes);

        //*****************************************
        // ***** Set Terrain proportives
        //*****************************************

        LoadHeights();


        // Load Stratum Textures Paths
        LoadStratumScdTextures();
        MapLuaParser.Current.InfoPopup.Show(true, "Loading map...\n( Assing scmap data )");


        WaterLevel.transform.localScale = new Vector3(HalfxRes, 1, HalfzRes);
        TerrainMaterial.SetFloat("_GridScale", HalfxRes);
        TerrainMaterial.SetTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        WaterMaterial.SetFloat("_GridScale", HalfxRes);


        for (int i = 0; i < map.EnvCubemapsFile.Length; i++)
        {
            if (map.EnvCubemapsName[i] == "<default>")
            {
                try
                {
                    CurrentEnvironmentCubemap = GetGamedataFile.GetGamedataCubemap(GetGamedataFile.TexturesScd, map.EnvCubemapsFile[i]);
                    Shader.SetGlobalTexture("environmentSampler", CurrentEnvironmentCubemap);
                }
                catch
                {
                    WaterMaterial.SetTexture("environmentSampler", DefaultWaterSky);
                }
            }
        }

        SetWaterTextures();

        SetWater();

        Teren.gameObject.layer = 8;

        SetTextures();

        if (Slope)
        {
            ToogleSlope(Slope);
        }

        yield return(null);
    }
Exemplo n.º 3
0
    public IEnumerator LoadScmapFile()
    {
        //UnloadMap();

        map = new Map();

        //string MapPath = EnvPaths.GetMapsPath();
        string path = MapLuaParser.MapRelativePath(MapLuaParser.Current.ScenarioLuaFile.Data.map);

        //Debug.Log("Load SCMAP file: " + path);


        if (map.Load(path))
        {
            UpdateLighting();
            Skybox.LoadSkybox();
        }
        else
        {
            Debug.LogError("File not found!" + path);
            MapLuaParser.Current.StopCoroutine(MapLuaParser.LoadScmapFile);
        }


        if (map.VersionMinor >= 60)
        {
        }
        else
        {
            LoadDefaultSkybox();
        }


        EnvPaths.CurrentGamedataPath = EnvPaths.GamedataPath;

        //Shader
        MapLuaParser.Current.EditMenu.TexturesMenu.TTerrainXP.isOn = map.TerrainShader == "TTerrainXP";
        ToogleShader();

        // Set Variables
        int   xRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[0];
        int   zRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[1];
        float HalfxRes = xRes / 10f;
        float HalfzRes = zRes / 10f;


        TerrainMaterial.SetTexture("_TerrainNormal", map.UncompressedNormalmapTex);
        Shader.SetGlobalTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        Shader.SetGlobalFloat("_WaterScaleX", xRes);
        Shader.SetGlobalFloat("_WaterScaleZ", xRes);

        //*****************************************
        // ***** Set Terrain proportives
        //*****************************************

        LoadHeights();


        // Load Stratum Textures Paths
        LoadStratumScdTextures();
        MapLuaParser.Current.InfoPopup.Show(true, "Loading map...\n( Assing scmap data )");


        WaterLevel.transform.localScale = new Vector3(HalfxRes, 1, HalfzRes);
        TerrainMaterial.SetFloat("_GridScale", HalfxRes);
        TerrainMaterial.SetTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        WaterMaterial.SetFloat("_GridScale", HalfxRes);



        /*
         * // Cubemap
         * Texture2D Cubemap = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.TexPathCubemap);
         * Debug.Log(Cubemap.width);
         * Cubemap cb = new Cubemap(Cubemap.width, TextureFormat.RGB24, Cubemap.mipmapCount > 1);
         * cb.SetPixels(Cubemap.GetPixels(), CubemapFace.PositiveX);
         * WaterMaterial.SetTexture("_Reflection", cb);
         */

        for (int i = 0; i < map.EnvCubemapsFile.Length; i++)
        {
            if (map.EnvCubemapsName[i] == "<default>")
            {
                try
                {
                    CurrentEnvironmentCubemap = GetGamedataFile.GetGamedataCubemap(GetGamedataFile.TexturesScd, map.EnvCubemapsFile[i]);
                    Shader.SetGlobalTexture("environmentSampler", CurrentEnvironmentCubemap);
                }
                catch
                {
                    WaterMaterial.SetTexture("environmentSampler", DefaultWaterSky);
                }
            }
        }

        SetWaterTextures();

        SetWater();



        Teren.gameObject.layer = 8;

        SetTextures();

        if (Slope)
        {
            ToogleSlope(Slope);
        }

        yield return(null);
        //Debug.Log("Scmap load complited");

        //GetGamedataFile.UnitObject NewUnit = new GetGamedataFile.UnitObject();
    }