Beispiel #1
0
    public void ApplyTerrainLODSettings(int val = -1)
    {
        Terrain        activeTerrain = Terrain.activeTerrain;
        RTP_LODmanager rtp_LODmanager;

        if (activeTerrain == null)
        {
            rtp_LODmanager = null;
        }
        else
        {
            ReliefTerrain component = activeTerrain.gameObject.GetComponent <ReliefTerrain>();
            rtp_LODmanager = ((component != null) ? component.globalSettingsHolder.Get_RTP_LODmanagerScript() : null);
        }
        RTP_LODmanager rtp_LODmanager2 = rtp_LODmanager;

        if (rtp_LODmanager2)
        {
            switch (val)
            {
            case 0:
                rtp_LODmanager2.RTP_LODlevel = TerrainShaderLod.SIMPLE;
                break;

            case 1:
                rtp_LODmanager2.RTP_LODlevel = TerrainShaderLod.PM;
                break;

            case 2:
                rtp_LODmanager2.RTP_LODlevel = TerrainShaderLod.POM;
                break;
            }
            rtp_LODmanager2.RefreshLODlevel();
        }
    }
 private void GetLODManager()
 {
     GameObject gameObject = GameObject.Find("_RTP_LODmanager");
     if (gameObject == null)
     {
         return;
     }
     this.LODmanager = (RTP_LODmanager)gameObject.GetComponent(typeof(RTP_LODmanager));
 }
Beispiel #3
0
    public void ApplyTerrainSettings(int val = -1)
    {
        Terrain activeTerrain = Terrain.activeTerrain;
        int     num           = (val == -1) ? QualitySettings.GetQualityLevel() : val;

        if (activeTerrain)
        {
            activeTerrain.heightmapPixelError = CJTools.Math.GetProportionalClamp(70f, 20f, (float)num, 0f, 4f);
            if (num == 0)
            {
                activeTerrain.basemapDistance = 0f;
            }
            else
            {
                activeTerrain.basemapDistance = CJTools.Math.GetProportionalClamp(10f, 25f, (float)num, 1f, 4f);
            }
            activeTerrain.castShadows = false;
            ReliefTerrain component = activeTerrain.gameObject.GetComponent <ReliefTerrain>();
            ReliefTerrainGlobalSettingsHolder reliefTerrainGlobalSettingsHolder = (component != null) ? component.globalSettingsHolder : null;
            if (reliefTerrainGlobalSettingsHolder != null)
            {
                reliefTerrainGlobalSettingsHolder.DIST_STEPS          = CJTools.Math.GetProportionalClamp(4f, 25f, (float)num, 0f, 4f);
                reliefTerrainGlobalSettingsHolder.WAVELENGTH          = CJTools.Math.GetProportionalClamp(16f, 2.5f, (float)num, 0f, 4f);
                reliefTerrainGlobalSettingsHolder.SHADOW_STEPS        = CJTools.Math.GetProportionalClamp(0f, 25f, (float)num, 0f, 4f);
                reliefTerrainGlobalSettingsHolder.WAVELENGTH_SHADOWS  = CJTools.Math.GetProportionalClamp(16f, 0.5f, (float)num, 0f, 4f);
                reliefTerrainGlobalSettingsHolder.distance_start      = CJTools.Math.GetProportionalClamp(5f, 15f, (float)num, 0f, 4f);
                reliefTerrainGlobalSettingsHolder.distance_transition = CJTools.Math.GetProportionalClamp(5f, 10f, (float)num, 0f, 4f);
                if (reliefTerrainGlobalSettingsHolder.distance_start_bumpglobal < reliefTerrainGlobalSettingsHolder.distance_start)
                {
                    reliefTerrainGlobalSettingsHolder.distance_start_bumpglobal = reliefTerrainGlobalSettingsHolder.distance_start;
                }
                RTP_LODmanager rtp_LODmanagerScript = reliefTerrainGlobalSettingsHolder.Get_RTP_LODmanagerScript();
                if (rtp_LODmanagerScript)
                {
                    TerrainShaderLod rtp_LODlevel = rtp_LODmanagerScript.RTP_LODlevel;
                    if (num == 0)
                    {
                        rtp_LODmanagerScript.RTP_LODlevel = TerrainShaderLod.SIMPLE;
                    }
                    else if (num == 1)
                    {
                        rtp_LODmanagerScript.RTP_LODlevel = TerrainShaderLod.PM;
                    }
                    else
                    {
                        rtp_LODmanagerScript.RTP_LODlevel = TerrainShaderLod.POM;
                    }
                    if (rtp_LODlevel != rtp_LODmanagerScript.RTP_LODlevel)
                    {
                        rtp_LODmanagerScript.RefreshLODlevel();
                    }
                }
                reliefTerrainGlobalSettingsHolder.RefreshAll();
            }
        }
    }
Beispiel #4
0
    private void GetLODManager()
    {
        GameObject gameObject = GameObject.Find("_RTP_LODmanager");

        if (gameObject == null)
        {
            return;
        }
        this.LODmanager = (RTP_LODmanager)gameObject.GetComponent(typeof(RTP_LODmanager));
    }
Beispiel #5
0
    void GetLODManager()
    {
        GameObject go = GameObject.Find("_RTP_LODmanager");

        if (go == null)
        {
            return;
        }
        LODmanager = (RTP_LODmanager)go.GetComponent(typeof(RTP_LODmanager));
    }
 void Update()
 {
     if (UpdateOnEveryFrame)
     {
                     #if UNITY_EDITOR
         RTP_LODmanager LODmanager = GetComponent(typeof(RTP_LODmanager)) as RTP_LODmanager;
         if (LODmanager && prev_LinearColorSpace != LinearColorSpace)
         {
             prev_LinearColorSpace            = LinearColorSpace;
             LODmanager.RTP_COLORSPACE_LINEAR = LinearColorSpace;
         }
                     #endif
         RTPFogUpdate.Refresh(LinearColorSpace);
     }
 }
	private void SyncFarOnlyNumLayersProcessed(string shader_path, RTP_LODmanager _target) {
		_target.numLayersProcessedByFarShader=0;

		if (System.IO.File.Exists(shader_path)) {
			string _code = System.IO.File.ReadAllText(shader_path);
			if (_code.IndexOf("///* AddFar")>0) {
				if (_target.RTP_4LAYERS_MODE) {
					_target.numLayersProcessedByFarShader=8;
				} else {
					_target.numLayersProcessedByFarShader=12;
				}
			} else if (_code.IndexOf("/* AddFar")>0) {
				if (_target.RTP_4LAYERS_MODE) {
					_target.numLayersProcessedByFarShader=4;
				} else {
					_target.numLayersProcessedByFarShader=8;
				}
			}
		}
		//Debug.Log ("R" + _target.numLayersProcessedByFarShader);
		return;
	}
Beispiel #8
0
    public void RefreshTextures(Material mat = null, bool check_weak_references = false)
    {
        this.GetGlobalSettingsHolder();
        this.InitTerrainTileSizes();
        if (this.globalSettingsHolder != null && this.BumpGlobalCombined != null)
        {
            this.globalSettingsHolder.BumpGlobalCombinedSize = this.BumpGlobalCombined.width;
        }
        this.UpdateBasemapDistance(true);
        Terrain terrain = (Terrain)base.GetComponent(typeof(Terrain));

        if (terrain && !this.globalSettingsHolder.useTerrainMaterial && this.globalSettingsHolder.numTiles > 1 && !mat)
        {
            SplatPrototype[] splatPrototypes = terrain.terrainData.splatPrototypes;
            if (splatPrototypes.Length < 4)
            {
                Debug.Log("RTP must use at least 4 layers !");
                return;
            }
            if (this.ColorGlobal)
            {
                splatPrototypes[0].texture = this.ColorGlobal;
            }
            if (this.NormalGlobal)
            {
                splatPrototypes[1].texture = this.NormalGlobal;
            }
            if (this.TreesGlobal)
            {
                splatPrototypes[2].texture = this.TreesGlobal;
            }
            if (this.AmbientEmissiveMap)
            {
                splatPrototypes[2].texture = this.AmbientEmissiveMap;
            }
            if (this.BumpGlobalCombined)
            {
                splatPrototypes[3].texture = this.BumpGlobalCombined;
            }
            int num = 0;
            if (splatPrototypes.Length >= 5 && splatPrototypes.Length <= 8 && this.globalSettingsHolder._4LAYERS_SHADER_USED)
            {
                num = 4;
            }
            else if (splatPrototypes.Length > 8)
            {
                num = 8;
            }
            if (num > 0)
            {
                if (this.ColorGlobal)
                {
                    splatPrototypes[num].texture = this.ColorGlobal;
                }
                bool           flag = false;
                RTP_LODmanager rtp_LODmanagerScript = this.globalSettingsHolder.Get_RTP_LODmanagerScript();
                if (rtp_LODmanagerScript && rtp_LODmanagerScript.RTP_CROSSPASS_HEIGHTBLEND)
                {
                    flag = true;
                }
                if (this.NormalGlobal)
                {
                    splatPrototypes[1 + num].texture = this.NormalGlobal;
                }
                if (this.globalSettingsHolder._RTP_LODmanagerScript.RTP_4LAYERS_MODE && flag)
                {
                    if (this.controlA)
                    {
                        splatPrototypes[2 + num].texture = this.controlA;
                    }
                }
                else
                {
                    if (this.TreesGlobal)
                    {
                        splatPrototypes[2 + num].texture = this.TreesGlobal;
                    }
                    if (this.AmbientEmissiveMap)
                    {
                        splatPrototypes[2 + num].texture = this.AmbientEmissiveMap;
                    }
                }
                if (this.BumpGlobalCombined)
                {
                    splatPrototypes[3 + num].texture = this.BumpGlobalCombined;
                }
            }
            terrain.terrainData.splatPrototypes = splatPrototypes;
        }
        else
        {
            this.globalSettingsHolder.use_mat = mat;
            if (!terrain && !mat)
            {
                if (base.GetComponent <Renderer>().sharedMaterial == null || base.GetComponent <Renderer>().sharedMaterial.name != "RTPMaterial")
                {
                    base.GetComponent <Renderer>().sharedMaterial      = new Material(Shader.Find("Relief Pack/Terrain2Geometry"));
                    base.GetComponent <Renderer>().sharedMaterial.name = "RTPMaterial";
                }
                this.globalSettingsHolder.use_mat = base.GetComponent <Renderer>().sharedMaterial;
            }
            if (terrain && this.globalSettingsHolder.useTerrainMaterial && terrain.materialTemplate != null)
            {
                this.globalSettingsHolder.use_mat = terrain.materialTemplate;
                terrain.materialTemplate.SetVector("RTP_CustomTiling", new Vector4(1f / this.customTiling.x, 1f / this.customTiling.y, 0f, 0f));
            }
            this.globalSettingsHolder.use_mat = null;
        }
        this.RefreshControlMaps(mat);
        if (mat)
        {
            mat.SetVector("RTP_CustomTiling", new Vector4(1f / this.customTiling.x, 1f / this.customTiling.y, 0f, 0f));
        }
        else if (terrain && !this.globalSettingsHolder.useTerrainMaterial)
        {
            if (this.globalSettingsHolder.numTiles == 1)
            {
                Shader.SetGlobalVector("RTP_CustomTiling", new Vector4(1f / this.customTiling.x, 1f / this.customTiling.y, 0f, 0f));
            }
            else
            {
                SplatPrototype[] splatPrototypes2 = terrain.terrainData.splatPrototypes;
                splatPrototypes2[0].tileSize        = Vector2.one;
                splatPrototypes2[0].tileOffset      = new Vector2(1f / this.customTiling.x, 1f / this.customTiling.y);
                terrain.terrainData.splatPrototypes = splatPrototypes2;
            }
        }
    }
    public void Refresh(Material mat=null, ReliefTerrain rt_caller=null)
    {
        if (splats==null) return;
        #if UNITY_EDITOR
        if (_RTP_LODmanager==null) {
            if ((_RTP_LODmanager=GameObject.Find("_RTP_LODmanager"))==null) {
                _RTP_LODmanager=new GameObject("_RTP_LODmanager");
                _RTP_LODmanager.AddComponent(typeof(RTP_LODmanager));
                _RTP_LODmanager.AddComponent(typeof(RTPFogUpdate));
                _RTP_LODmanagerScript=(RTP_LODmanager)_RTP_LODmanager.GetComponent(typeof(RTP_LODmanager));
                EditorUtility.DisplayDialog("RTP Notification", "_RTP_LODmanager object added to the scene.\nIts script handles LOD properties of RTP shaders.","OK");
                Selection.activeObject=_RTP_LODmanager;
            }
        }
        if (_RTP_LODmanagerScript==null) {
            _RTP_LODmanagerScript=(RTP_LODmanager)_RTP_LODmanager.GetComponent(typeof(RTP_LODmanager));
        }
        _4LAYERS_SHADER_USED=_RTP_LODmanagerScript.RTP_4LAYERS_MODE;

        colorSpaceLinear = ( PlayerSettings.colorSpace==ColorSpace.Linear );
        #endif
        // switch for SetShaderParam - when use_mat defined we're injecting param into material
        #if !UNITY_3_5
        if (mat==null && rt_caller!=null) {
            if (rt_caller.globalSettingsHolder==this) {
                Terrain ter=rt_caller.GetComponent(typeof(Terrain)) as Terrain;
                if (ter) {
                    rt_caller.globalSettingsHolder.Refresh(ter.materialTemplate);
                } else {
                    if (rt_caller.GetComponent<Renderer>()!=null && rt_caller.GetComponent<Renderer>().sharedMaterial!=null) {
                        rt_caller.globalSettingsHolder.Refresh(rt_caller.GetComponent<Renderer>().sharedMaterial);
                    }
                }
            }
        }
        #endif
        use_mat=mat;

        for(int i=0; i<numLayers; i++) {
            if (i<4) {
                ApplyGlossBakedTexture("_SplatA"+i, i);
            } else if (i<8) {
                if (_4LAYERS_SHADER_USED) {
                    ApplyGlossBakedTexture("_SplatC"+(i-4), i);
                    // potrzebne przy sniegu (firstpass moze korzystac z koloru i bumpmap 4-7)
                    ApplyGlossBakedTexture("_SplatB"+(i-4), i);
                } else {
                    ApplyGlossBakedTexture("_SplatB"+(i-4), i);
                }
            } else if (i<12) {
                ApplyGlossBakedTexture("_SplatC"+(i-8), i);
            }
        }

        // > RTP3.1
        // update-set to default
        if (CheckAndUpdate(ref RTP_gloss2mask, 0.5f, numLayers)) {
            for(int k=0; k<numLayers; k++) {
                Spec[k]=1; // zresetuj od razu mnożnik glossa (RTP3.1 - zmienna ma inne znaczenie)
            }
        }
        CheckAndUpdate(ref RTP_gloss_mult, 1f, numLayers);
        CheckAndUpdate(ref RTP_gloss_shaping, 0.5f, numLayers);
        CheckAndUpdate(ref RTP_Fresnel, 0, numLayers);
        CheckAndUpdate(ref RTP_FresnelAtten, 0, numLayers);
        CheckAndUpdate(ref RTP_DiffFresnel, 0, numLayers);
        CheckAndUpdate(ref RTP_IBL_bump_smoothness, 0.7f, numLayers);
        CheckAndUpdate(ref RTP_IBL_DiffuseStrength, 0.5f, numLayers);
        CheckAndUpdate(ref RTP_IBL_SpecStrength, 0.5f, numLayers);
        CheckAndUpdate(ref _DeferredSpecDampAddPass, 1f, numLayers);

        CheckAndUpdate(ref TERRAIN_WaterSpecularity, 0.5f, numLayers);
        CheckAndUpdate(ref TERRAIN_WaterGloss, 0.1f, numLayers);
        CheckAndUpdate(ref TERRAIN_WaterGlossDamper, 0f, numLayers);
        CheckAndUpdate(ref TERRAIN_WetSpecularity, 0.2f, numLayers);
        CheckAndUpdate(ref TERRAIN_WetGloss, 0.05f, numLayers);
        CheckAndUpdate(ref TERRAIN_WetFlow, 0.05f, numLayers);

        CheckAndUpdate(ref MixBrightness, 2.0f, numLayers);
        CheckAndUpdate(ref MixReplace, 0.0f, numLayers);
        CheckAndUpdate(ref LayerBrightness, 1.0f, numLayers);
        CheckAndUpdate(ref LayerBrightness2Spec, 0.0f, numLayers);
        CheckAndUpdate(ref LayerAlbedo2SpecColor, 0.0f, numLayers);
        CheckAndUpdate(ref LayerSaturation, 1.0f, numLayers);
        CheckAndUpdate(ref LayerEmission, 0f, numLayers);
        CheckAndUpdate(ref FarSpecCorrection, 0f, numLayers);
        CheckAndUpdate(ref LayerEmissionColor, Color.black, numLayers);
        CheckAndUpdate(ref LayerEmissionRefractStrength, 0, numLayers);
        CheckAndUpdate(ref LayerEmissionRefractHBedge, 0, numLayers);

        CheckAndUpdate(ref TERRAIN_WaterIBL_SpecWetStrength, 0.1f, numLayers);
        CheckAndUpdate(ref TERRAIN_WaterIBL_SpecWaterStrength, 0.5f, numLayers);
        CheckAndUpdate(ref TERRAIN_WaterEmission, 0f, numLayers);

        /////////////////////////////////////////////////////////////////////
        //
        // layer independent
        //
        /////////////////////////////////////////////////////////////////////

        // custom fog (unity's fog doesn't work with this shader - too many texture interpolators)
        if (RenderSettings.fog) {
            Shader.SetGlobalFloat("_Fdensity", RenderSettings.fogDensity);
            if (colorSpaceLinear) {
                Shader.SetGlobalColor("_FColor", RenderSettings.fogColor.linear);
            } else {
                Shader.SetGlobalColor("_FColor", RenderSettings.fogColor);
            }
            Shader.SetGlobalFloat("_Fstart", RenderSettings.fogStartDistance);
            Shader.SetGlobalFloat("_Fend", RenderSettings.fogEndDistance);
        } else {
            Shader.SetGlobalFloat("_Fdensity", 0);
            Shader.SetGlobalFloat("_Fstart", 1000000);
            Shader.SetGlobalFloat("_Fend", 2000000);
        }

        SetShaderParam("terrainTileSize", terrainTileSize);

        SetShaderParam("RTP_AOamp", RTP_AOamp);
        SetShaderParam("RTP_AOsharpness", RTP_AOsharpness);

        SetShaderParam("EmissionRefractFiltering", EmissionRefractFiltering);
        SetShaderParam("EmissionRefractAnimSpeed", EmissionRefractAnimSpeed);

        // global
        SetShaderParam("_VerticalTexture", VerticalTexture);

        SetShaderParam("_GlobalColorMapBlendValues", GlobalColorMapBlendValues);
        SetShaderParam("_GlobalColorMapSaturation", GlobalColorMapSaturation);
        SetShaderParam("_GlobalColorMapSaturationFar", GlobalColorMapSaturationFar);
        //SetShaderParam("_GlobalColorMapSaturationByPerlin", GlobalColorMapSaturationByPerlin);
        SetShaderParam("_GlobalColorMapDistortByPerlin", GlobalColorMapDistortByPerlin);

        SetShaderParam("_GlobalColorMapBrightness", GlobalColorMapBrightness);
        SetShaderParam("_GlobalColorMapBrightnessFar", GlobalColorMapBrightnessFar);
        SetShaderParam("_GlobalColorMapNearMIP", _GlobalColorMapNearMIP);

        SetShaderParam("_RTP_MIP_BIAS", RTP_MIP_BIAS);

        SetShaderParam("_BumpMapGlobalScale", BumpMapGlobalScale);
        SetShaderParam("_FarNormalDamp", _FarNormalDamp);

        SetShaderParam("_SpecColor", _SpecColor);
        SetShaderParam("RTP_DeferredAddPassSpec", RTP_DeferredAddPassSpec);

        SetShaderParam("_blend_multiplier", blendMultiplier);
        SetShaderParam("_TERRAIN_ReliefTransform", ReliefTransform);

        SetShaderParam("_TERRAIN_ReliefTransformTriplanarZ", ReliefTransform.x);
        SetShaderParam("_TERRAIN_DIST_STEPS", DIST_STEPS);
        SetShaderParam("_TERRAIN_WAVELENGTH", WAVELENGTH);

        SetShaderParam("_TERRAIN_ExtrudeHeight", ExtrudeHeight);
        SetShaderParam("_TERRAIN_LightmapShading", LightmapShading);

        SetShaderParam("_TERRAIN_SHADOW_STEPS", SHADOW_STEPS);
        SetShaderParam("_TERRAIN_WAVELENGTH_SHADOWS", WAVELENGTH_SHADOWS);
        SetShaderParam("_TERRAIN_SHADOW_SMOOTH_STEPS", SHADOW_SMOOTH_STEPS);

        SetShaderParam("_TERRAIN_SelfShadowStrength", SelfShadowStrength);
        SetShaderParam("_TERRAIN_ShadowSmoothing", ShadowSmoothing);

        SetShaderParam("_TERRAIN_distance_start", distance_start);
        SetShaderParam("_TERRAIN_distance_transition", distance_transition);

        SetShaderParam("_TERRAIN_distance_start_bumpglobal", distance_start_bumpglobal);
        SetShaderParam("_TERRAIN_distance_transition_bumpglobal", distance_transition_bumpglobal);
        SetShaderParam("rtp_perlin_start_val", rtp_perlin_start_val);

        Shader.SetGlobalVector("_TERRAIN_trees_shadow_values", new Vector4(trees_shadow_distance_start, trees_shadow_distance_transition, trees_shadow_value, global_normalMap_multiplier));
        Shader.SetGlobalVector("_TERRAIN_trees_pixel_values", new Vector4(trees_pixel_distance_start, trees_pixel_distance_transition, trees_pixel_blend_val, global_normalMap_farUsage));

        SetShaderParam("_Phong", _Phong);
        SetShaderParam("_TessSubdivisions", _TessSubdivisions);
        SetShaderParam("_TessSubdivisionsFar", _TessSubdivisionsFar);
        SetShaderParam("_TessYOffset", _TessYOffset);

        Shader.SetGlobalFloat("_AmbientEmissiveMultiplier", _AmbientEmissiveMultiplier);
        Shader.SetGlobalFloat("_AmbientEmissiveRelief", _AmbientEmissiveRelief);

        SetShaderParam("_SuperDetailTiling", _SuperDetailTiling);

        Shader.SetGlobalFloat("rtp_snow_strength", _snow_strength);
        Shader.SetGlobalFloat("rtp_global_color_brightness_to_snow", _global_color_brightness_to_snow);
        Shader.SetGlobalFloat("rtp_snow_slope_factor", _snow_slope_factor);
        Shader.SetGlobalFloat("rtp_snow_edge_definition", _snow_edge_definition);
        Shader.SetGlobalFloat("rtp_snow_height_treshold", _snow_height_treshold);
        Shader.SetGlobalFloat("rtp_snow_height_transition", _snow_height_transition);
        Shader.SetGlobalColor("rtp_snow_color", _snow_color);
        Shader.SetGlobalFloat("rtp_snow_specular", _snow_specular);
        Shader.SetGlobalFloat("rtp_snow_gloss", _snow_gloss);
        Shader.SetGlobalFloat("rtp_snow_reflectivness", _snow_reflectivness);
        Shader.SetGlobalFloat("rtp_snow_deep_factor", _snow_deep_factor);
        Shader.SetGlobalFloat("rtp_snow_fresnel", _snow_fresnel);
        Shader.SetGlobalFloat("rtp_snow_diff_fresnel", _snow_diff_fresnel);

        Shader.SetGlobalFloat("rtp_snow_IBL_DiffuseStrength", _snow_IBL_DiffuseStrength);
        Shader.SetGlobalFloat("rtp_snow_IBL_SpecStrength", _snow_IBL_SpecStrength);

        // caustics
        SetShaderParam("TERRAIN_CausticsAnimSpeed", TERRAIN_CausticsAnimSpeed);
        SetShaderParam("TERRAIN_CausticsColor", TERRAIN_CausticsColor);
        if (TERRAIN_CausticsWaterLevelRefObject) TERRAIN_CausticsWaterLevel=TERRAIN_CausticsWaterLevelRefObject.transform.position.y;
        Shader.SetGlobalFloat("TERRAIN_CausticsWaterLevel", TERRAIN_CausticsWaterLevel);
        Shader.SetGlobalFloat("TERRAIN_CausticsWaterLevelByAngle", TERRAIN_CausticsWaterLevelByAngle);
        Shader.SetGlobalFloat("TERRAIN_CausticsWaterDeepFadeLength", TERRAIN_CausticsWaterDeepFadeLength);
        Shader.SetGlobalFloat("TERRAIN_CausticsWaterShallowFadeLength", TERRAIN_CausticsWaterShallowFadeLength);
        SetShaderParam("TERRAIN_CausticsTilingScale", TERRAIN_CausticsTilingScale);
        SetShaderParam("TERRAIN_CausticsTex", TERRAIN_CausticsTex);

        if (numLayers>0) {
            int tex_width=512;
            for(int i=0; i<numLayers; i++) {
                if (splats[i]) {
                    tex_width=splats[i].width;
                    break;
                }
            }
            SetShaderParam("rtp_mipoffset_color", -Mathf.Log(1024.0f/tex_width)/Mathf.Log(2) );
            if (Bump01!=null) {
                tex_width=Bump01.width;
            }
            SetShaderParam("rtp_mipoffset_bump", -Mathf.Log(1024.0f/tex_width)/Mathf.Log(2));
            if (HeightMap) {
                tex_width=HeightMap.width;
            } else if (HeightMap2) {
                tex_width=HeightMap2.width;
            } else if (HeightMap3) {
                tex_width=HeightMap3.width;
            }
            SetShaderParam("rtp_mipoffset_height", -Mathf.Log(1024.0f/tex_width)/Mathf.Log(2));

            tex_width=BumpGlobalCombinedSize;
            SetShaderParam("rtp_mipoffset_globalnorm", -Mathf.Log(1024.0f/(tex_width*BumpMapGlobalScale))/Mathf.Log(2)+rtp_mipoffset_globalnorm);
            SetShaderParam("rtp_mipoffset_superdetail", -Mathf.Log(1024.0f/(tex_width*_SuperDetailTiling))/Mathf.Log(2));
            SetShaderParam("rtp_mipoffset_flow", -Mathf.Log(1024.0f/(tex_width*TERRAIN_FlowScale))/Mathf.Log(2) + TERRAIN_FlowMipOffset);
            if (TERRAIN_RippleMap) {
                tex_width=TERRAIN_RippleMap.width;
            }
            SetShaderParam("rtp_mipoffset_ripple", -Mathf.Log(1024.0f/(tex_width*TERRAIN_RippleScale))/Mathf.Log(2));
            if (TERRAIN_CausticsTex) {
                tex_width=TERRAIN_CausticsTex.width;
            }
            SetShaderParam("rtp_mipoffset_caustics", -Mathf.Log(1024.0f/(tex_width*TERRAIN_CausticsTilingScale))/Mathf.Log(2));
        }

        SetShaderParam("TERRAIN_ReflectionMap", TERRAIN_ReflectionMap);
        SetShaderParam("TERRAIN_ReflColorA", TERRAIN_ReflColorA);
        SetShaderParam("TERRAIN_ReflColorB", TERRAIN_ReflColorB);
        SetShaderParam("TERRAIN_ReflColorC", TERRAIN_ReflColorC);
        SetShaderParam("TERRAIN_ReflColorCenter", TERRAIN_ReflColorCenter);
        SetShaderParam("TERRAIN_ReflGlossAttenuation", TERRAIN_ReflGlossAttenuation);
        SetShaderParam("TERRAIN_ReflectionRotSpeed", TERRAIN_ReflectionRotSpeed);

        SetShaderParam("TERRAIN_GlobalWetness", TERRAIN_GlobalWetness);
        Shader.SetGlobalFloat("TERRAIN_GlobalWetness", TERRAIN_GlobalWetness);
        SetShaderParam("TERRAIN_RippleMap", TERRAIN_RippleMap);
        SetShaderParam("TERRAIN_RippleScale", TERRAIN_RippleScale);
        SetShaderParam("TERRAIN_FlowScale",  TERRAIN_FlowScale);
        SetShaderParam("TERRAIN_FlowMipOffset", TERRAIN_FlowMipOffset);
        SetShaderParam("TERRAIN_FlowSpeed", TERRAIN_FlowSpeed);
        SetShaderParam("TERRAIN_FlowCycleScale", TERRAIN_FlowCycleScale);
        Shader.SetGlobalFloat("TERRAIN_RainIntensity", TERRAIN_RainIntensity);
        SetShaderParam("TERRAIN_DropletsSpeed", TERRAIN_DropletsSpeed);
        SetShaderParam("TERRAIN_WetDropletsStrength", TERRAIN_WetDropletsStrength);
        SetShaderParam("TERRAIN_WetDarkening", TERRAIN_WetDarkening);
        SetShaderParam("TERRAIN_mipoffset_flowSpeed", TERRAIN_mipoffset_flowSpeed);
        SetShaderParam("TERRAIN_WetHeight_Treshold", TERRAIN_WetHeight_Treshold);
        SetShaderParam("TERRAIN_WetHeight_Transition", TERRAIN_WetHeight_Transition);

        Shader.SetGlobalVector("rtp_customAmbientCorrection", new Vector4(rtp_customAmbientCorrection.r-0.2f, rtp_customAmbientCorrection.g-0.2f, rtp_customAmbientCorrection.b-0.2f, 0)*0.1f);
        SetShaderParam("_CubemapDiff", _CubemapDiff);
        SetShaderParam("_CubemapSpec", _CubemapSpec);

        Shader.SetGlobalFloat("TERRAIN_IBL_DiffAO_Damp", TERRAIN_IBL_DiffAO_Damp);
        Shader.SetGlobalFloat("TERRAIN_IBLRefl_SpecAO_Damp", TERRAIN_IBLRefl_SpecAO_Damp);

        Shader.SetGlobalVector("RTP_LightDefVector", RTP_LightDefVector);
        Shader.SetGlobalFloat("RTP_BackLightStrength", RTP_LightDefVector.x);
        Shader.SetGlobalFloat("RTP_ReflexLightDiffuseSoftness", RTP_LightDefVector.y);
        Shader.SetGlobalFloat("RTP_ReflexLightSpecSoftness", RTP_LightDefVector.z);
        Shader.SetGlobalFloat("RTP_ReflexLightSpecularity", RTP_LightDefVector.w);
        Shader.SetGlobalColor("RTP_ReflexLightDiffuseColor1", RTP_ReflexLightDiffuseColor);
        Shader.SetGlobalColor("RTP_ReflexLightDiffuseColor2", RTP_ReflexLightDiffuseColor2);
        Shader.SetGlobalColor("RTP_ReflexLightSpecColor", RTP_ReflexLightSpecColor);

        SetShaderParam("_VerticalTextureGlobalBumpInfluence", VerticalTextureGlobalBumpInfluence);
        SetShaderParam("_VerticalTextureTiling", VerticalTextureTiling);

        /////////////////////////////////////////////////////////////////////
        //
        // layer dependent numeric
        //
        /////////////////////////////////////////////////////////////////////
        float[] tmp_RTP_gloss_mult=new float[RTP_gloss_mult.Length];
        for(int k=0; k<tmp_RTP_gloss_mult.Length; k++) {
            if (gloss_baked[k]!=null && gloss_baked[k].baked) {
                tmp_RTP_gloss_mult[k]=1;
            } else {
                tmp_RTP_gloss_mult[k]=RTP_gloss_mult[k];
            }
        }
        float[] tmp_RTP_gloss_shaping=new float[RTP_gloss_shaping.Length];
        for(int k=0; k<tmp_RTP_gloss_shaping.Length; k++) {
            if (gloss_baked[k]!=null && gloss_baked[k].baked) {
                tmp_RTP_gloss_shaping[k]=0.5f;
            } else {
                tmp_RTP_gloss_shaping[k]=RTP_gloss_shaping[k];
            }
        }
        SetShaderParam("_Spec0123", getVector(Spec, 0,3));
        SetShaderParam("_FarSpecCorrection0123", getVector(FarSpecCorrection, 0,3));
        SetShaderParam("_MIPmult0123", getVector(MIPmult, 0,3));
        SetShaderParam("_MixScale0123", getVector(MixScale, 0,3));
        SetShaderParam("_MixBlend0123", getVector(MixBlend, 0,3));
        SetShaderParam("_MixSaturation0123", getVector(MixSaturation, 0, 3));

        // RTP3.1
        SetShaderParam("RTP_gloss2mask0123", getVector(RTP_gloss2mask, 0,3));
        SetShaderParam("RTP_gloss_mult0123", getVector(tmp_RTP_gloss_mult, 0,3));
        SetShaderParam("RTP_gloss_shaping0123", getVector(tmp_RTP_gloss_shaping, 0,3));
        SetShaderParam("RTP_Fresnel0123", getVector(RTP_Fresnel, 0,3));
        SetShaderParam("RTP_FresnelAtten0123", getVector(RTP_FresnelAtten, 0,3));
        SetShaderParam("RTP_DiffFresnel0123", getVector(RTP_DiffFresnel, 0,3));
        SetShaderParam("RTP_IBL_bump_smoothness0123", getVector(RTP_IBL_bump_smoothness, 0,3));
        SetShaderParam("RTP_IBL_DiffuseStrength0123", getVector(RTP_IBL_DiffuseStrength, 0,3));
        SetShaderParam("RTP_IBL_SpecStrength0123", getVector(RTP_IBL_SpecStrength, 0,3));
        // (only in deferred addpass)
        //SetShaderParam("_DeferredSpecDampAddPass0123", getVector(_DeferredSpecDampAddPass, 0,3));

        SetShaderParam("_MixBrightness0123", getVector(MixBrightness, 0, 3));
        SetShaderParam("_MixReplace0123", getVector(MixReplace, 0, 3));
        SetShaderParam("_LayerBrightness0123", MasterLayerBrightness*getVector(LayerBrightness, 0, 3));
        SetShaderParam("_LayerSaturation0123", MasterLayerSaturation*getVector(LayerSaturation, 0, 3));
        SetShaderParam("_LayerEmission0123", getVector(LayerEmission, 0, 3));
        SetShaderParam("_LayerEmissionColorR0123", getColorVector(LayerEmissionColor, 0, 3, 0));
        SetShaderParam("_LayerEmissionColorG0123", getColorVector(LayerEmissionColor, 0, 3, 1));
        SetShaderParam("_LayerEmissionColorB0123", getColorVector(LayerEmissionColor, 0, 3, 2));
        SetShaderParam("_LayerEmissionColorA0123", getColorVector(LayerEmissionColor, 0, 3, 3));
        SetShaderParam("_LayerBrightness2Spec0123", getVector(LayerBrightness2Spec, 0, 3));
        SetShaderParam("_LayerAlbedo2SpecColor0123", getVector(LayerAlbedo2SpecColor, 0, 3));
        SetShaderParam("_LayerEmissionRefractStrength0123", getVector(LayerEmissionRefractStrength, 0, 3));
        SetShaderParam("_LayerEmissionRefractHBedge0123", getVector(LayerEmissionRefractHBedge, 0, 3));

        SetShaderParam("_GlobalColorPerLayer0123", getVector(GlobalColorPerLayer, 0, 3));

        SetShaderParam("_GlobalColorBottom0123", getVector(GlobalColorBottom, 0, 3));
        SetShaderParam("_GlobalColorTop0123", getVector(GlobalColorTop, 0, 3));
        SetShaderParam("_GlobalColorColormapLoSat0123", getVector(GlobalColorColormapLoSat, 0, 3));
        SetShaderParam("_GlobalColorColormapHiSat0123", getVector(GlobalColorColormapHiSat, 0, 3));
        SetShaderParam("_GlobalColorLayerLoSat0123", getVector(GlobalColorLayerLoSat, 0, 3));
        SetShaderParam("_GlobalColorLayerHiSat0123", getVector(GlobalColorLayerHiSat, 0, 3));
        SetShaderParam("_GlobalColorLoBlend0123", getVector(GlobalColorLoBlend, 0, 3));
        SetShaderParam("_GlobalColorHiBlend0123", getVector(GlobalColorHiBlend, 0, 3));

        SetShaderParam("PER_LAYER_HEIGHT_MODIFIER0123",  getVector(PER_LAYER_HEIGHT_MODIFIER, 0,3));

        SetShaderParam("rtp_snow_strength_per_layer0123",  getVector(_snow_strength_per_layer, 0,3));

        SetShaderParam("_SuperDetailStrengthMultA0123", getVector(_SuperDetailStrengthMultA, 0,3));
        SetShaderParam("_SuperDetailStrengthMultB0123", getVector(_SuperDetailStrengthMultB, 0,3));
        SetShaderParam("_SuperDetailStrengthNormal0123", getVector(_SuperDetailStrengthNormal, 0,3));
        SetShaderParam("_BumpMapGlobalStrength0123", getVector(_BumpMapGlobalStrength, 0,3));

        SetShaderParam("_SuperDetailStrengthMultASelfMaskNear0123", getVector(_SuperDetailStrengthMultASelfMaskNear, 0,3));
        SetShaderParam("_SuperDetailStrengthMultASelfMaskFar0123", getVector(_SuperDetailStrengthMultASelfMaskFar, 0,3));
        SetShaderParam("_SuperDetailStrengthMultBSelfMaskNear0123", getVector(_SuperDetailStrengthMultBSelfMaskNear, 0,3));
        SetShaderParam("_SuperDetailStrengthMultBSelfMaskFar0123", getVector(_SuperDetailStrengthMultBSelfMaskFar, 0,3));

        SetShaderParam("TERRAIN_LayerWetStrength0123", getVector(TERRAIN_LayerWetStrength, 0,3));
        SetShaderParam("TERRAIN_WaterLevel0123", getVector(TERRAIN_WaterLevel, 0,3));
        SetShaderParam("TERRAIN_WaterLevelSlopeDamp0123", getVector(TERRAIN_WaterLevelSlopeDamp, 0,3));
        SetShaderParam("TERRAIN_WaterEdge0123", getVector(TERRAIN_WaterEdge, 0,3));
        SetShaderParam("TERRAIN_WaterSpecularity0123", getVector(TERRAIN_WaterSpecularity, 0,3));
        SetShaderParam("TERRAIN_WaterGloss0123", getVector(TERRAIN_WaterGloss, 0,3));
        SetShaderParam("TERRAIN_WaterGlossDamper0123", getVector(TERRAIN_WaterGlossDamper, 0,3));
        SetShaderParam("TERRAIN_WaterOpacity0123", getVector(TERRAIN_WaterOpacity, 0,3));
        SetShaderParam("TERRAIN_Refraction0123", getVector(TERRAIN_Refraction, 0,3));
        SetShaderParam("TERRAIN_WetRefraction0123", getVector(TERRAIN_WetRefraction, 0,3));
        SetShaderParam("TERRAIN_Flow0123", getVector(TERRAIN_Flow, 0,3));
        SetShaderParam("TERRAIN_WetFlow0123", getVector(TERRAIN_WetFlow, 0,3));
        SetShaderParam("TERRAIN_WetSpecularity0123", getVector(TERRAIN_WetSpecularity, 0,3));
        SetShaderParam("TERRAIN_WetGloss0123", getVector(TERRAIN_WetGloss, 0,3));
        SetShaderParam("TERRAIN_WaterColorR0123", getColorVector(TERRAIN_WaterColor, 0,3, 0));
        SetShaderParam("TERRAIN_WaterColorG0123", getColorVector(TERRAIN_WaterColor, 0,3, 1));
        SetShaderParam("TERRAIN_WaterColorB0123", getColorVector(TERRAIN_WaterColor, 0,3, 2));
        SetShaderParam("TERRAIN_WaterColorA0123", getColorVector(TERRAIN_WaterColor, 0,3, 3));
        SetShaderParam("TERRAIN_WaterIBL_SpecWetStrength0123", getVector(	TERRAIN_WaterIBL_SpecWetStrength, 0,3));
        SetShaderParam("TERRAIN_WaterIBL_SpecWaterStrength0123", getVector(	TERRAIN_WaterIBL_SpecWaterStrength, 0,3));
        SetShaderParam("TERRAIN_WaterEmission0123", getVector(	TERRAIN_WaterEmission, 0,3));

        SetShaderParam("RTP_AO_0123", getVector(AO_strength, 0,3));
        SetShaderParam("_VerticalTexture0123", getVector(VerticalTextureStrength, 0,3));

        if ((numLayers>4) && _4LAYERS_SHADER_USED) {
            //
            // przekieruj parametry warstw 4-7 na AddPass
            //
            SetShaderParam("_Spec89AB", getVector(Spec, 4,7));
            SetShaderParam("_FarSpecCorrection89AB", getVector(FarSpecCorrection, 4,7));
            SetShaderParam("_MIPmult89AB", getVector(MIPmult, 4,7));
            SetShaderParam("_MixScale89AB", getVector(MixScale, 4,7));
            SetShaderParam("_MixBlend89AB", getVector(MixBlend, 4,7));
            SetShaderParam("_MixSaturation89AB", getVector(MixSaturation, 4, 7));

            // RTP3.1
            SetShaderParam("RTP_gloss2mask89AB", getVector(RTP_gloss2mask, 4, 7));
            SetShaderParam("RTP_gloss_mult89AB", getVector(tmp_RTP_gloss_mult, 4, 7));
            SetShaderParam("RTP_gloss_shaping89AB", getVector(tmp_RTP_gloss_shaping, 4, 7));
            SetShaderParam("RTP_Fresnel89AB", getVector(RTP_Fresnel, 4, 7));
            SetShaderParam("RTP_FresnelAtten89AB", getVector(RTP_FresnelAtten, 4, 7));
            SetShaderParam("RTP_DiffFresnel89AB", getVector(RTP_DiffFresnel, 4, 7));
            SetShaderParam("RTP_IBL_bump_smoothness89AB", getVector(RTP_IBL_bump_smoothness, 4, 7));
            SetShaderParam("RTP_IBL_DiffuseStrength89AB", getVector(RTP_IBL_DiffuseStrength, 4, 7));
            SetShaderParam("RTP_IBL_SpecStrength89AB", getVector(RTP_IBL_SpecStrength, 4, 7));
            SetShaderParam("_DeferredSpecDampAddPass89AB", getVector(_DeferredSpecDampAddPass, 4,7));

            SetShaderParam("_MixBrightness89AB", getVector(MixBrightness, 4, 7));
            SetShaderParam("_MixReplace89AB", getVector(MixReplace, 4, 7));
            SetShaderParam("_LayerBrightness89AB", MasterLayerBrightness*getVector(LayerBrightness, 4, 7));
            SetShaderParam("_LayerSaturation89AB", MasterLayerSaturation*getVector(LayerSaturation, 4, 7));
            SetShaderParam("_LayerEmission89AB", getVector(LayerEmission, 4, 7));
            SetShaderParam("_LayerEmissionColorR89AB", getColorVector(LayerEmissionColor, 4, 7, 0));
            SetShaderParam("_LayerEmissionColorG89AB", getColorVector(LayerEmissionColor, 4, 7, 1));
            SetShaderParam("_LayerEmissionColorB89AB", getColorVector(LayerEmissionColor, 4, 7, 2));
            SetShaderParam("_LayerEmissionColorA89AB", getColorVector(LayerEmissionColor, 4, 7, 3));
            SetShaderParam("_LayerBrightness2Spec89AB", getVector(LayerBrightness2Spec, 4, 7));
            SetShaderParam("_LayerAlbedo2SpecColor89AB", getVector(LayerAlbedo2SpecColor, 4, 7));
            SetShaderParam("_LayerEmissionRefractStrength89AB", getVector(LayerEmissionRefractStrength, 4, 7));
            SetShaderParam("_LayerEmissionRefractHBedge89AB", getVector(LayerEmissionRefractHBedge, 4, 7));

            SetShaderParam("_GlobalColorPerLayer89AB", getVector(GlobalColorPerLayer, 4, 7));

            SetShaderParam("_GlobalColorBottom89AB", getVector(GlobalColorBottom, 4, 7));
            SetShaderParam("_GlobalColorTop89AB", getVector(GlobalColorTop, 4, 7));
            SetShaderParam("_GlobalColorColormapLoSat89AB", getVector(GlobalColorColormapLoSat, 4, 7));
            SetShaderParam("_GlobalColorColormapHiSat89AB", getVector(GlobalColorColormapHiSat, 4, 7));
            SetShaderParam("_GlobalColorLayerLoSat89AB", getVector(GlobalColorLayerLoSat, 4, 7));
            SetShaderParam("_GlobalColorLayerHiSat89AB", getVector(GlobalColorLayerHiSat, 4, 7));
            SetShaderParam("_GlobalColorLoBlend89AB", getVector(GlobalColorLoBlend, 4, 7));
            SetShaderParam("_GlobalColorHiBlend89AB", getVector(GlobalColorHiBlend, 4, 7));

            SetShaderParam("PER_LAYER_HEIGHT_MODIFIER89AB", getVector(PER_LAYER_HEIGHT_MODIFIER, 4,7));

            SetShaderParam("rtp_snow_strength_per_layer89AB",  getVector(_snow_strength_per_layer, 4,7));

            SetShaderParam("_SuperDetailStrengthMultA89AB", getVector(_SuperDetailStrengthMultA, 4,7));
            SetShaderParam("_SuperDetailStrengthMultB89AB", getVector(_SuperDetailStrengthMultB, 4,7));
            SetShaderParam("_SuperDetailStrengthNormal89AB", getVector(_SuperDetailStrengthNormal, 4,7));
            SetShaderParam("_BumpMapGlobalStrength89AB", getVector(_BumpMapGlobalStrength, 4,7));

            SetShaderParam("_SuperDetailStrengthMultASelfMaskNear89AB", getVector(_SuperDetailStrengthMultASelfMaskNear, 4,7));
            SetShaderParam("_SuperDetailStrengthMultASelfMaskFar89AB", getVector(_SuperDetailStrengthMultASelfMaskFar, 4,7));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskNear89AB", getVector(_SuperDetailStrengthMultBSelfMaskNear, 4,7));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskFar89AB", getVector(_SuperDetailStrengthMultBSelfMaskFar, 4,7));

            SetShaderParam("TERRAIN_LayerWetStrength89AB", getVector(TERRAIN_LayerWetStrength, 4,7));
            SetShaderParam("TERRAIN_WaterLevel89AB", getVector(TERRAIN_WaterLevel, 4,7));
            SetShaderParam("TERRAIN_WaterLevelSlopeDamp89AB", getVector(TERRAIN_WaterLevelSlopeDamp, 4,7));
            SetShaderParam("TERRAIN_WaterEdge89AB", getVector(TERRAIN_WaterEdge, 4,7));
            SetShaderParam("TERRAIN_WaterSpecularity89AB", getVector(TERRAIN_WaterSpecularity, 4,7));
            SetShaderParam("TERRAIN_WaterGloss89AB", getVector(TERRAIN_WaterGloss, 4,7));
            SetShaderParam("TERRAIN_WaterGlossDamper89AB", getVector(TERRAIN_WaterGlossDamper, 4,7));
            SetShaderParam("TERRAIN_WaterOpacity89AB", getVector(TERRAIN_WaterOpacity, 4,7));
            SetShaderParam("TERRAIN_Refraction89AB", getVector(TERRAIN_Refraction, 4,7));
            SetShaderParam("TERRAIN_WetRefraction89AB", getVector(TERRAIN_WetRefraction, 4,7));
            SetShaderParam("TERRAIN_Flow89AB", getVector(TERRAIN_Flow, 4,7));
            SetShaderParam("TERRAIN_WetFlow89AB", getVector(TERRAIN_WetFlow, 4,7));
            SetShaderParam("TERRAIN_WetSpecularity89AB", getVector(TERRAIN_WetSpecularity, 4,7));
            SetShaderParam("TERRAIN_WetGloss89AB", getVector(TERRAIN_WetGloss, 4,7));
            SetShaderParam("TERRAIN_WaterColorR89AB", getColorVector(TERRAIN_WaterColor, 4,7, 0));
            SetShaderParam("TERRAIN_WaterColorG89AB", getColorVector(TERRAIN_WaterColor, 4,7, 1));
            SetShaderParam("TERRAIN_WaterColorB89AB", getColorVector(TERRAIN_WaterColor, 4,7, 2));
            SetShaderParam("TERRAIN_WaterColorA89AB", getColorVector(TERRAIN_WaterColor, 4,7, 3));
            SetShaderParam("TERRAIN_WaterIBL_SpecWetStrength89AB", getVector(TERRAIN_WaterIBL_SpecWetStrength, 4,7));
            SetShaderParam("TERRAIN_WaterIBL_SpecWaterStrength89AB", getVector(TERRAIN_WaterIBL_SpecWaterStrength, 4,7));
            SetShaderParam("TERRAIN_WaterEmission89AB", getVector(	TERRAIN_WaterEmission, 4,7));

            SetShaderParam("RTP_AO_89AB", getVector(AO_strength, 4,7));
            SetShaderParam("_VerticalTexture89AB", getVector(VerticalTextureStrength, 4,7));
        } else {
            SetShaderParam("_Spec4567", getVector(Spec, 4,7));
            SetShaderParam("_FarSpecCorrection4567", getVector(FarSpecCorrection, 4,7));
            SetShaderParam("_MIPmult4567", getVector(MIPmult, 4,7));
            SetShaderParam("_MixScale4567", getVector(MixScale, 4,7));
            SetShaderParam("_MixBlend4567", getVector(MixBlend, 4,7));
            SetShaderParam("_MixSaturation4567", getVector(MixSaturation, 4, 7));

            // RTP3.1
            SetShaderParam("RTP_gloss2mask4567", getVector(RTP_gloss2mask, 4, 7));
            SetShaderParam("RTP_gloss_mult4567", getVector(tmp_RTP_gloss_mult, 4, 7));
            SetShaderParam("RTP_gloss_shaping4567", getVector(tmp_RTP_gloss_shaping, 4, 7));
            SetShaderParam("RTP_Fresnel4567", getVector(RTP_Fresnel, 4, 7));
            SetShaderParam("RTP_FresnelAtten4567", getVector(RTP_FresnelAtten, 4, 7));
            SetShaderParam("RTP_DiffFresnel4567", getVector(RTP_DiffFresnel, 4, 7));
            SetShaderParam("RTP_IBL_bump_smoothness4567", getVector(RTP_IBL_bump_smoothness, 4, 7));
            SetShaderParam("RTP_IBL_DiffuseStrength4567", getVector(RTP_IBL_DiffuseStrength, 4, 7));
            SetShaderParam("RTP_IBL_SpecStrength4567", getVector(RTP_IBL_SpecStrength, 4, 7));
            // only in deferred add pass
            //SetShaderParam("_DeferredSpecDampAddPass4567", getVector(_DeferredSpecDampAddPass, 4,7));

            SetShaderParam("_MixBrightness4567", getVector(MixBrightness, 4, 7));
            SetShaderParam("_MixReplace4567", getVector(MixReplace, 4, 7));
            SetShaderParam("_LayerBrightness4567", MasterLayerBrightness*getVector(LayerBrightness, 4, 7));
            SetShaderParam("_LayerSaturation4567", MasterLayerSaturation*getVector(LayerSaturation, 4, 7));
            SetShaderParam("_LayerEmission4567", getVector(LayerEmission, 4, 7));
            SetShaderParam("_LayerEmissionColorR4567", getColorVector(LayerEmissionColor, 4, 7, 0));
            SetShaderParam("_LayerEmissionColorG4567", getColorVector(LayerEmissionColor, 4, 7, 1));
            SetShaderParam("_LayerEmissionColorB4567", getColorVector(LayerEmissionColor, 4, 7, 2));
            SetShaderParam("_LayerEmissionColorA4567", getColorVector(LayerEmissionColor, 4, 7, 3));
            SetShaderParam("_LayerBrightness2Spec4567", getVector(LayerBrightness2Spec, 4, 7));
            SetShaderParam("_LayerAlbedo2SpecColor4567", getVector(LayerAlbedo2SpecColor, 4, 7));
            SetShaderParam("_LayerEmissionRefractStrength4567", getVector(LayerEmissionRefractStrength, 4, 7));
            SetShaderParam("_LayerEmissionRefractHBedge4567", getVector(LayerEmissionRefractHBedge, 4, 7));

            SetShaderParam("_GlobalColorPerLayer4567", getVector(GlobalColorPerLayer, 4, 7));

            SetShaderParam("_GlobalColorBottom4567", getVector(GlobalColorBottom, 4, 7));
            SetShaderParam("_GlobalColorTop4567", getVector(GlobalColorTop, 4, 7));
            SetShaderParam("_GlobalColorColormapLoSat4567", getVector(GlobalColorColormapLoSat, 4, 7));
            SetShaderParam("_GlobalColorColormapHiSat4567", getVector(GlobalColorColormapHiSat, 4, 7));
            SetShaderParam("_GlobalColorLayerLoSat4567", getVector(GlobalColorLayerLoSat, 4, 7));
            SetShaderParam("_GlobalColorLayerHiSat4567", getVector(GlobalColorLayerHiSat, 4, 7));
            SetShaderParam("_GlobalColorLoBlend4567", getVector(GlobalColorLoBlend, 4, 7));
            SetShaderParam("_GlobalColorHiBlend4567", getVector(GlobalColorHiBlend, 4, 7));

            SetShaderParam("PER_LAYER_HEIGHT_MODIFIER4567", getVector(PER_LAYER_HEIGHT_MODIFIER, 4,7));

            SetShaderParam("rtp_snow_strength_per_layer4567",  getVector(_snow_strength_per_layer, 4,7));

            SetShaderParam("_SuperDetailStrengthMultA4567", getVector(_SuperDetailStrengthMultA, 4,7));
            SetShaderParam("_SuperDetailStrengthMultB4567", getVector(_SuperDetailStrengthMultB, 4,7));
            SetShaderParam("_SuperDetailStrengthNormal4567", getVector(_SuperDetailStrengthNormal, 4,7));
            SetShaderParam("_BumpMapGlobalStrength4567", getVector(_BumpMapGlobalStrength, 4,7));

            SetShaderParam("_SuperDetailStrengthMultASelfMaskNear4567", getVector(_SuperDetailStrengthMultASelfMaskNear, 4,7));
            SetShaderParam("_SuperDetailStrengthMultASelfMaskFar4567", getVector(_SuperDetailStrengthMultASelfMaskFar, 4,7));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskNear4567", getVector(_SuperDetailStrengthMultBSelfMaskNear, 4,7));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskFar4567", getVector(_SuperDetailStrengthMultBSelfMaskFar, 4,7));

            SetShaderParam("TERRAIN_LayerWetStrength4567", getVector(TERRAIN_LayerWetStrength, 4,7));
            SetShaderParam("TERRAIN_WaterLevel4567", getVector(TERRAIN_WaterLevel, 4,7));
            SetShaderParam("TERRAIN_WaterLevelSlopeDamp4567", getVector(TERRAIN_WaterLevelSlopeDamp, 4,7));
            SetShaderParam("TERRAIN_WaterEdge4567", getVector(TERRAIN_WaterEdge, 4,7));
            SetShaderParam("TERRAIN_WaterSpecularity4567", getVector(TERRAIN_WaterSpecularity, 4,7));
            SetShaderParam("TERRAIN_WaterGloss4567", getVector(TERRAIN_WaterGloss, 4,7));
            SetShaderParam("TERRAIN_WaterGlossDamper4567", getVector(TERRAIN_WaterGlossDamper, 4,7));
            SetShaderParam("TERRAIN_WaterOpacity4567", getVector(TERRAIN_WaterOpacity, 4,7));
            SetShaderParam("TERRAIN_Refraction4567", getVector(TERRAIN_Refraction, 4,7));
            SetShaderParam("TERRAIN_WetRefraction4567", getVector(TERRAIN_WetRefraction, 4,7));
            SetShaderParam("TERRAIN_Flow4567", getVector(TERRAIN_Flow, 4,7));
            SetShaderParam("TERRAIN_WetFlow4567", getVector(TERRAIN_WetFlow, 4,7));
            SetShaderParam("TERRAIN_WetSpecularity4567", getVector(TERRAIN_WetSpecularity, 4,7));
            SetShaderParam("TERRAIN_WetGloss4567", getVector(TERRAIN_WetGloss, 4,7));
            SetShaderParam("TERRAIN_WaterColorR4567", getColorVector(TERRAIN_WaterColor, 4,7, 0));
            SetShaderParam("TERRAIN_WaterColorG4567", getColorVector(TERRAIN_WaterColor, 4,7, 1));
            SetShaderParam("TERRAIN_WaterColorB4567", getColorVector(TERRAIN_WaterColor, 4,7, 2));
            SetShaderParam("TERRAIN_WaterColorA4567", getColorVector(TERRAIN_WaterColor, 4,7, 3));
            SetShaderParam("TERRAIN_WaterIBL_SpecWetStrength4567", getVector(	TERRAIN_WaterIBL_SpecWetStrength, 4,7));
            SetShaderParam("TERRAIN_WaterIBL_SpecWaterStrength4567", getVector(	TERRAIN_WaterIBL_SpecWaterStrength, 4,7));
            SetShaderParam("TERRAIN_WaterEmission4567", getVector(	TERRAIN_WaterEmission, 4,7));

            SetShaderParam("RTP_AO_4567", getVector(AO_strength, 4,7));
            SetShaderParam("_VerticalTexture4567", getVector(VerticalTextureStrength, 4,7));

            //
            // AddPass
            //
            SetShaderParam("_Spec89AB", getVector(Spec, 8,11));
            SetShaderParam("_FarSpecCorrection89AB", getVector(FarSpecCorrection, 8,11));
            SetShaderParam("_MIPmult89AB", getVector(MIPmult, 8,11));
            SetShaderParam("_MixScale89AB", getVector(MixScale, 8,11));
            SetShaderParam("_MixBlend89AB", getVector(MixBlend, 8,11));
            SetShaderParam("_MixSaturation89AB", getVector(MixSaturation, 8, 11));

            // RTP3.1
            SetShaderParam("RTP_gloss2mask89AB", getVector(RTP_gloss2mask, 8,11));
            SetShaderParam("RTP_gloss_mult89AB", getVector(tmp_RTP_gloss_mult, 8,11));
            SetShaderParam("RTP_gloss_shaping89AB", getVector(tmp_RTP_gloss_shaping, 8,11));
            SetShaderParam("RTP_Fresnel89AB", getVector(RTP_Fresnel, 8,11));
            SetShaderParam("RTP_FresnelAtten89AB", getVector(RTP_FresnelAtten, 8,11));
            SetShaderParam("RTP_DiffFresnel89AB", getVector(RTP_DiffFresnel, 8,11));
            SetShaderParam("RTP_IBL_bump_smoothness89AB", getVector(RTP_IBL_bump_smoothness, 8,11));
            SetShaderParam("RTP_IBL_DiffuseStrength89AB", getVector(RTP_IBL_DiffuseStrength, 8,11));
            SetShaderParam("RTP_IBL_SpecStrength89AB", getVector(RTP_IBL_SpecStrength, 8,11));
            SetShaderParam("_DeferredSpecDampAddPass89AB", getVector(_DeferredSpecDampAddPass, 8,11));

            SetShaderParam("_MixBrightness89AB", getVector(MixBrightness, 8, 11));
            SetShaderParam("_MixReplace89AB", getVector(MixReplace, 8, 11));
            SetShaderParam("_LayerBrightness89AB", MasterLayerBrightness*getVector(LayerBrightness, 8, 11));
            SetShaderParam("_LayerSaturation89AB", MasterLayerSaturation*getVector(LayerSaturation, 8, 11));
            SetShaderParam("_LayerEmission89AB", getVector(LayerEmission, 8, 11));
            SetShaderParam("_LayerEmissionColorR89AB", getColorVector(LayerEmissionColor, 8, 11, 0));
            SetShaderParam("_LayerEmissionColorG89AB", getColorVector(LayerEmissionColor, 8, 11, 1));
            SetShaderParam("_LayerEmissionColorB89AB", getColorVector(LayerEmissionColor, 8, 11, 2));
            SetShaderParam("_LayerEmissionColorA89AB", getColorVector(LayerEmissionColor, 8, 11, 3));
            SetShaderParam("_LayerBrightness2Spec89AB", getVector(LayerBrightness2Spec, 8, 11));
            SetShaderParam("_LayerAlbedo2SpecColor89AB", getVector(LayerAlbedo2SpecColor, 8, 11));
            SetShaderParam("_LayerEmissionRefractStrength89AB", getVector(LayerEmissionRefractStrength, 8, 11));
            SetShaderParam("_LayerEmissionRefractHBedge89AB", getVector(LayerEmissionRefractHBedge, 8, 11));

            SetShaderParam("_GlobalColorPerLayer89AB", getVector(GlobalColorPerLayer, 8, 11));

            SetShaderParam("_GlobalColorBottom89AB", getVector(GlobalColorBottom, 8, 11));
            SetShaderParam("_GlobalColorTop89AB", getVector(GlobalColorTop, 8, 11));
            SetShaderParam("_GlobalColorColormapLoSat89AB", getVector(GlobalColorColormapLoSat, 8, 11));
            SetShaderParam("_GlobalColorColormapHiSat89AB", getVector(GlobalColorColormapHiSat, 8, 11));
            SetShaderParam("_GlobalColorLayerLoSat89AB", getVector(GlobalColorLayerLoSat, 8, 11));
            SetShaderParam("_GlobalColorLayerHiSat89AB", getVector(GlobalColorLayerHiSat, 8, 11));
            SetShaderParam("_GlobalColorLoBlend89AB", getVector(GlobalColorLoBlend, 8, 11));
            SetShaderParam("_GlobalColorHiBlend89AB", getVector(GlobalColorHiBlend, 8, 11));

            SetShaderParam("PER_LAYER_HEIGHT_MODIFIER89AB", getVector(PER_LAYER_HEIGHT_MODIFIER, 8,11));

            SetShaderParam("rtp_snow_strength_per_layer89AB",  getVector(_snow_strength_per_layer, 8,11));

            SetShaderParam("_SuperDetailStrengthMultA89AB", getVector(_SuperDetailStrengthMultA, 8,11));
            SetShaderParam("_SuperDetailStrengthMultB89AB", getVector(_SuperDetailStrengthMultB, 8,11));
            SetShaderParam("_SuperDetailStrengthNormal89AB", getVector(_SuperDetailStrengthNormal, 8,11));
            SetShaderParam("_BumpMapGlobalStrength89AB", getVector(_BumpMapGlobalStrength, 8,11));

            SetShaderParam("_SuperDetailStrengthMultASelfMaskNear89AB", getVector(_SuperDetailStrengthMultASelfMaskNear, 8,11));
            SetShaderParam("_SuperDetailStrengthMultASelfMaskFar89AB", getVector(_SuperDetailStrengthMultASelfMaskFar, 8,11));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskNear89AB", getVector(_SuperDetailStrengthMultBSelfMaskNear, 8,11));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskFar89AB", getVector(_SuperDetailStrengthMultBSelfMaskFar, 8,11));

            SetShaderParam("TERRAIN_LayerWetStrength89AB", getVector(TERRAIN_LayerWetStrength,  8,11));
            SetShaderParam("TERRAIN_WaterLevel89AB", getVector(TERRAIN_WaterLevel,  8,11));
            SetShaderParam("TERRAIN_WaterLevelSlopeDamp89AB", getVector(TERRAIN_WaterLevelSlopeDamp,  8,11));
            SetShaderParam("TERRAIN_WaterEdge89AB", getVector(TERRAIN_WaterEdge,  8,11));
            SetShaderParam("TERRAIN_WaterSpecularity89AB", getVector(TERRAIN_WaterSpecularity,  8,11));
            SetShaderParam("TERRAIN_WaterGloss89AB", getVector(TERRAIN_WaterGloss, 8,11));
            SetShaderParam("TERRAIN_WaterGlossDamper89AB", getVector(TERRAIN_WaterGlossDamper, 8,11));
            SetShaderParam("TERRAIN_WaterOpacity89AB", getVector(TERRAIN_WaterOpacity,  8,11));
            SetShaderParam("TERRAIN_Refraction89AB", getVector(TERRAIN_Refraction,  8,11));
            SetShaderParam("TERRAIN_WetRefraction89AB", getVector(TERRAIN_WetRefraction,  8,11));
            SetShaderParam("TERRAIN_Flow89AB", getVector(TERRAIN_Flow,  8,11));
            SetShaderParam("TERRAIN_WetFlow89AB", getVector(TERRAIN_WetFlow,  8,11));
            SetShaderParam("TERRAIN_WetSpecularity89AB", getVector(TERRAIN_WetSpecularity,  8,11));
            SetShaderParam("TERRAIN_WetGloss89AB", getVector(TERRAIN_WetGloss,  8,11));
            SetShaderParam("TERRAIN_WaterColorR89AB", getColorVector(TERRAIN_WaterColor, 8,11, 0));
            SetShaderParam("TERRAIN_WaterColorG89AB", getColorVector(TERRAIN_WaterColor, 8,11, 1));
            SetShaderParam("TERRAIN_WaterColorB89AB", getColorVector(TERRAIN_WaterColor, 8,11, 2));
            SetShaderParam("TERRAIN_WaterColorA89AB", getColorVector(TERRAIN_WaterColor, 8,11, 3));
            SetShaderParam("TERRAIN_WaterIBL_SpecWetStrength89AB", getVector(TERRAIN_WaterIBL_SpecWetStrength, 8,11));
            SetShaderParam("TERRAIN_WaterIBL_SpecWaterStrength89AB", getVector(TERRAIN_WaterIBL_SpecWaterStrength, 8,11));
            SetShaderParam("TERRAIN_WaterEmission89AB", getVector(	TERRAIN_WaterEmission, 8,11));

            SetShaderParam("RTP_AO_89AB", getVector(AO_strength, 8,11));
            SetShaderParam("_VerticalTexture89AB", getVector(VerticalTextureStrength, 8,11));
        }

        /////////////////////////////////////////////////////////////////////
        //
        // layer dependent textures
        //
        /////////////////////////////////////////////////////////////////////
        // update (RTP3.1)
        if (splat_atlases.Length==2) {
            Texture2D _atA=splat_atlases[0];
            Texture2D _atB=splat_atlases[1];
            splat_atlases=new Texture2D[3];
            splat_atlases[0]=_atA;
            splat_atlases[1]=_atB;
        }
        ApplyGlossBakedAtlas("_SplatAtlasA", 0);
        SetShaderParam("_BumpMap01", Bump01);
        SetShaderParam("_BumpMap23", Bump23);
        SetShaderParam("_TERRAIN_HeightMap", HeightMap);
        SetShaderParam("_SSColorCombinedA", SSColorCombinedA);

        if (numLayers>4) {
            ApplyGlossBakedAtlas("_SplatAtlasB", 1);
            ApplyGlossBakedAtlas("_SplatAtlasC", 1);
            SetShaderParam("_TERRAIN_HeightMap2", HeightMap2);
            SetShaderParam("_SSColorCombinedB", SSColorCombinedB);
        }
        if (numLayers>8) {
            ApplyGlossBakedAtlas("_SplatAtlasC", 2);
        }
        if ((numLayers>4) && _4LAYERS_SHADER_USED) {
            //
            // przekieruj parametry warstw 4-7 na AddPass
            //
            SetShaderParam("_BumpMap89", Bump45);
            SetShaderParam("_BumpMapAB", Bump67);
            SetShaderParam("_TERRAIN_HeightMap3", HeightMap2);
            // potrzebne przy sniegu (firstpass moze korzystac z koloru i bumpmap 4-7)
            SetShaderParam("_BumpMap45", Bump45);
            SetShaderParam("_BumpMap67", Bump67);
        } else {
            SetShaderParam("_BumpMap45", Bump45);
            SetShaderParam("_BumpMap67", Bump67);

            //
            // AddPass
            //
            SetShaderParam("_BumpMap89", Bump89);
            SetShaderParam("_BumpMapAB", BumpAB);
            SetShaderParam("_TERRAIN_HeightMap3", HeightMap3);
        }

        use_mat=null;
    }
 void GetLODManager()
 {
     GameObject go=GameObject.Find("_RTP_LODmanager");
     if (go==null) return;
     LODmanager=(RTP_LODmanager)go.GetComponent(typeof(RTP_LODmanager));
 }
    public void Refresh(Material mat=null)
    {
        if (splats==null) return;
        #if UNITY_EDITOR
        if (_RTP_LODmanager==null) {
            if ((_RTP_LODmanager=GameObject.Find("_RTP_LODmanager"))==null) {
                _RTP_LODmanager=new GameObject("_RTP_LODmanager");
                _RTP_LODmanager.AddComponent(typeof(RTP_LODmanager));
                _RTP_LODmanagerScript=(RTP_LODmanager)_RTP_LODmanager.GetComponent(typeof(RTP_LODmanager));
                EditorUtility.DisplayDialog("RTP Notification", "_RTP_LODmanager object added to the scene.\nIts script handles LOD properties of RTP shaders.","OK");
                Selection.activeObject=_RTP_LODmanager;
            }
        }
        if (_RTP_LODmanagerScript==null) {
            _RTP_LODmanagerScript=(RTP_LODmanager)_RTP_LODmanager.GetComponent(typeof(RTP_LODmanager));
        }
        _4LAYERS_SHADER_USED=_RTP_LODmanagerScript.RTP_4LAYERS_MODE;

        colorSpaceLinear = ( PlayerSettings.colorSpace==ColorSpace.Linear );
        #endif
        // switch for SetShaderParam - when use_mat defined we're injecting param into material
        use_mat=mat;

        for(int i=0; i<numLayers; i++) {
            if (i<4) {
                SetShaderParam("_SplatA"+i, splats[i]);
            } else if (i<8) {
                if (_4LAYERS_SHADER_USED) {
                    SetShaderParam("_SplatC"+(i-4), splats[i]);
                    // potrzebne przy sniegu (firstpass moze korzystac z koloru i bumpmap 4-7)
                    SetShaderParam("_SplatB"+(i-4), splats[i]);
                } else {
                    SetShaderParam("_SplatB"+(i-4), splats[i]);
                }
            } else if (i<12) {
                SetShaderParam("_SplatC"+(i-8), splats[i]);
            }
        }

        /////////////////////////////////////////////////////////////////////
        //
        // layer independent
        //
        /////////////////////////////////////////////////////////////////////

        // custom fog (exp2, unity's fog doesn't work with this shader - too many texture interpolators)
        if (RenderSettings.fog) {
            Shader.SetGlobalFloat("_Fdensity", Mathf.Log(1-RenderSettings.fogDensity)/Mathf.Log(2));
            if (colorSpaceLinear) {
                Shader.SetGlobalColor("_FColor", RenderSettings.fogColor.linear);
            } else {
                Shader.SetGlobalColor("_FColor", RenderSettings.fogColor);
            }
        } else {
            Shader.SetGlobalFloat("_Fdensity", 0);
        }

        Shader.SetGlobalFloat("RTP_AOamp", RTP_AOamp);
        Shader.SetGlobalFloat("RTP_AOsharpness", RTP_AOsharpness);

        // global
        SetShaderParam("_VerticalTexture", VerticalTexture);

        SetShaderParam("_GlobalColorMapBlendValues", GlobalColorMapBlendValues);
        SetShaderParam("_GlobalColorMapSaturation", GlobalColorMapSaturation);
        SetShaderParam("_GlobalColorMapBrightness", GlobalColorMapBrightness);
        SetShaderParam("_GlobalColorMapNearMIP", _GlobalColorMapNearMIP);

        SetShaderParam("_RTP_MIP_BIAS", RTP_MIP_BIAS);

        SetShaderParam("_BumpMapGlobalScale", BumpMapGlobalScale);
        SetShaderParam("_FarNormalDamp", _FarNormalDamp);

        SetShaderParam("_SpecColor", _SpecColor);

        SetShaderParam("_blend_multiplier", blendMultiplier);

        SetShaderParam("_TERRAIN_ReliefTransform", ReliefTransform);
        SetShaderParam("_TERRAIN_ReliefTransformTriplanarZ", terrainTileSizeX/ReliefTransform.x);
        SetShaderParam("_TERRAIN_DIST_STEPS", DIST_STEPS);
        SetShaderParam("_TERRAIN_WAVELENGTH", WAVELENGTH);

        SetShaderParam("_TERRAIN_ExtrudeHeight", ExtrudeHeight);
        SetShaderParam("_TERRAIN_LightmapShading", LightmapShading);

        SetShaderParam("_TERRAIN_SHADOW_STEPS", SHADOW_STEPS);
        SetShaderParam("_TERRAIN_WAVELENGTH_SHADOWS", WAVELENGTH_SHADOWS);
        SetShaderParam("_TERRAIN_SHADOW_SMOOTH_STEPS", SHADOW_SMOOTH_STEPS);

        SetShaderParam("_TERRAIN_SelfShadowStrength", SelfShadowStrength);
        SetShaderParam("_TERRAIN_ShadowSmoothing", ShadowSmoothing);
        SetShaderParam("_TERRAIN_ShadowColorization", ShadowColor);

        SetShaderParam("_TERRAIN_distance_start", distance_start);
        SetShaderParam("_TERRAIN_distance_transition", distance_transition);

        SetShaderParam("_TERRAIN_distance_start_bumpglobal", distance_start_bumpglobal);
        SetShaderParam("_TERRAIN_distance_transition_bumpglobal", distance_transition_bumpglobal);
        SetShaderParam("rtp_perlin_start_val", rtp_perlin_start_val);

        SetShaderParam("_TERRAIN_trees_shadow_values", new Vector4(trees_shadow_distance_start, trees_shadow_distance_transition, trees_shadow_value, global_normalMap_multiplier));
        SetShaderParam("_TERRAIN_trees_pixel_values", new Vector4(trees_pixel_distance_start, trees_pixel_distance_transition, trees_pixel_blend_val, 0));

        SetShaderParam("_SuperDetailTiling", _SuperDetailTiling);

        SetShaderParam("rtp_snow_strength", _snow_strength);
        SetShaderParam("rtp_global_color_brightness_to_snow", _global_color_brightness_to_snow);
        SetShaderParam("rtp_snow_slope_factor", _snow_slope_factor);
        SetShaderParam("rtp_snow_edge_definition", _snow_edge_definition);
        SetShaderParam("rtp_snow_height_treshold", _snow_height_treshold);
        SetShaderParam("rtp_snow_height_transition", _snow_height_transition);
        SetShaderParam("rtp_snow_color", _snow_color);
        SetShaderParam("rtp_snow_specular", _snow_specular);
        SetShaderParam("rtp_snow_gloss", _snow_gloss);
        SetShaderParam("rtp_snow_reflectivness", _snow_reflectivness);
        SetShaderParam("rtp_snow_deep_factor", _snow_deep_factor);

        // caustics
        SetShaderParam("TERRAIN_CausticsAnimSpeed", TERRAIN_CausticsAnimSpeed);
        SetShaderParam("TERRAIN_CausticsColor", TERRAIN_CausticsColor);
        if (TERRAIN_CausticsWaterLevelRefObject) TERRAIN_CausticsWaterLevel=TERRAIN_CausticsWaterLevelRefObject.transform.position.y;
        SetShaderParam("TERRAIN_CausticsWaterLevel", TERRAIN_CausticsWaterLevel);
        SetShaderParam("TERRAIN_CausticsWaterLevelByAngle", TERRAIN_CausticsWaterLevelByAngle);
        SetShaderParam("TERRAIN_CausticsWaterDeepFadeLength", TERRAIN_CausticsWaterDeepFadeLength);
        SetShaderParam("TERRAIN_CausticsWaterShallowFadeLength", TERRAIN_CausticsWaterShallowFadeLength);
        SetShaderParam("TERRAIN_CausticsTilingScale", TERRAIN_CausticsTilingScale);
        SetShaderParam("TERRAIN_CausticsTex", TERRAIN_CausticsTex);

        if (numLayers>0) {
            int tex_width=512;
            for(int i=0; i<numLayers; i++) {
                if (splats[i]) {
                    tex_width=splats[i].width;
                    break;
                }
            }
            SetShaderParam("rtp_mipoffset_color", -Mathf.Log(1024.0f/tex_width)/Mathf.Log(2) );
            if (Bump01!=null) {
                tex_width=Bump01.width;
            }
            SetShaderParam("rtp_mipoffset_bump", -Mathf.Log(1024.0f/tex_width)/Mathf.Log(2));
            if (HeightMap) {
                tex_width=HeightMap.width;
            } else if (HeightMap2) {
                tex_width=HeightMap2.width;
            } else if (HeightMap3) {
                tex_width=HeightMap3.width;
            }
            SetShaderParam("rtp_mipoffset_height", -Mathf.Log(1024.0f/tex_width)/Mathf.Log(2));

            tex_width=BumpGlobalCombinedSize;
            SetShaderParam("rtp_mipoffset_globalnorm", -Mathf.Log(1024.0f/(tex_width*BumpMapGlobalScale))/Mathf.Log(2)+rtp_mipoffset_globalnorm);
            SetShaderParam("rtp_mipoffset_superdetail", -Mathf.Log(1024.0f/(tex_width*_SuperDetailTiling))/Mathf.Log(2));
            SetShaderParam("rtp_mipoffset_flow", -Mathf.Log(1024.0f/(tex_width*TERRAIN_FlowScale))/Mathf.Log(2) + TERRAIN_FlowMipOffset);
            if (TERRAIN_RippleMap) {
                tex_width=TERRAIN_RippleMap.width;
            }
            SetShaderParam("rtp_mipoffset_ripple", -Mathf.Log(1024.0f/(tex_width*TERRAIN_RippleScale))/Mathf.Log(2));
            if (TERRAIN_CausticsTex) {
                tex_width=TERRAIN_CausticsTex.width;
            }
            SetShaderParam("rtp_mipoffset_caustics", -Mathf.Log(1024.0f/(tex_width*TERRAIN_CausticsTilingScale))/Mathf.Log(2));
        }

        SetShaderParam("TERRAIN_ReflectionMap", TERRAIN_ReflectionMap);
        SetShaderParam("TERRAIN_ReflColorA", TERRAIN_ReflColorA);
        SetShaderParam("TERRAIN_ReflColorB", TERRAIN_ReflColorB);
        SetShaderParam("TERRAIN_ReflDistortion", TERRAIN_ReflDistortion);
        SetShaderParam("TERRAIN_ReflectionRotSpeed", TERRAIN_ReflectionRotSpeed);
        SetShaderParam("TERRAIN_FresnelPow", TERRAIN_FresnelPow);
        SetShaderParam("TERRAIN_FresnelOffset", TERRAIN_FresnelOffset);

        SetShaderParam("TERRAIN_GlobalWetness", TERRAIN_GlobalWetness);
        SetShaderParam("TERRAIN_WaterSpecularity", TERRAIN_WaterSpecularity);
        SetShaderParam("TERRAIN_RippleMap", TERRAIN_RippleMap);
        SetShaderParam("TERRAIN_RippleScale", TERRAIN_RippleScale);
        SetShaderParam("TERRAIN_FlowScale",  TERRAIN_FlowScale);
        SetShaderParam("TERRAIN_FlowMipOffset", TERRAIN_FlowMipOffset);
        SetShaderParam("TERRAIN_FlowSpeed", TERRAIN_FlowSpeed);
        SetShaderParam("TERRAIN_RainIntensity", TERRAIN_RainIntensity);
        SetShaderParam("TERRAIN_DropletsSpeed", TERRAIN_DropletsSpeed);
        SetShaderParam("TERRAIN_WetDropletsStrength", TERRAIN_WetDropletsStrength);
        SetShaderParam("TERRAIN_WetDarkening", TERRAIN_WetDarkening);
        SetShaderParam("TERRAIN_mipoffset_flowSpeed", TERRAIN_mipoffset_flowSpeed);

        Shader.SetGlobalVector("rtp_customAmbientCorrection", new Vector4(rtp_customAmbientCorrection.r-0.2f, rtp_customAmbientCorrection.g-0.2f, rtp_customAmbientCorrection.b-0.2f, 0)*0.1f);

        Shader.SetGlobalVector("RTP_LightDefVector", RTP_LightDefVector);
        Shader.SetGlobalColor("RTP_ReflexLightDiffuseColor", RTP_ReflexLightDiffuseColor);
        Shader.SetGlobalColor("RTP_ReflexLightSpecColor", RTP_ReflexLightSpecColor);

        SetShaderParam("_VerticalTextureGlobalBumpInfluence", VerticalTextureGlobalBumpInfluence);
        SetShaderParam("_VerticalTextureTiling", VerticalTextureTiling);

        /////////////////////////////////////////////////////////////////////
        //
        // layer dependent numeric
        //
        /////////////////////////////////////////////////////////////////////
        SetShaderParam("_Spec0123", getVector(Spec, 0,3));
        SetShaderParam("_FarGlossCorrection0123", getVector(FarGlossCorrection, 0,3));
        SetShaderParam("_MIPmult0123", getVector(MIPmult, 0,3));
        SetShaderParam("_MixScale0123", getVector(MixScale, 0,3));
        SetShaderParam("_MixBlend0123", getVector(MixBlend, 0,3));
        SetShaderParam("_MixSaturation0123", getVector(MixSaturation, 0, 3));
        SetShaderParam("_GlobalColorPerLayer0123", getVector(GlobalColorPerLayer, 0, 3));

        SetShaderParam("PER_LAYER_HEIGHT_MODIFIER0123",  getVector(PER_LAYER_HEIGHT_MODIFIER, 0,3));

        SetShaderParam("rtp_snow_strength_per_layer0123",  getVector(_snow_strength_per_layer, 0,3));

        SetShaderParam("_SuperDetailStrengthMultA0123", getVector(_SuperDetailStrengthMultA, 0,3));
        SetShaderParam("_SuperDetailStrengthMultB0123", getVector(_SuperDetailStrengthMultB, 0,3));
        SetShaderParam("_SuperDetailStrengthNormal0123", getVector(_SuperDetailStrengthNormal, 0,3));
        SetShaderParam("_BumpMapGlobalStrength0123", getVector(_BumpMapGlobalStrength, 0,3));

        SetShaderParam("_SuperDetailStrengthMultASelfMaskNear0123", getVector(_SuperDetailStrengthMultASelfMaskNear, 0,3));
        SetShaderParam("_SuperDetailStrengthMultASelfMaskFar0123", getVector(_SuperDetailStrengthMultASelfMaskFar, 0,3));
        SetShaderParam("_SuperDetailStrengthMultBSelfMaskNear0123", getVector(_SuperDetailStrengthMultBSelfMaskNear, 0,3));
        SetShaderParam("_SuperDetailStrengthMultBSelfMaskFar0123", getVector(_SuperDetailStrengthMultBSelfMaskFar, 0,3));

        SetShaderParam("TERRAIN_LayerWetStrength0123", getVector(TERRAIN_LayerWetStrength, 0,3));
        SetShaderParam("TERRAIN_WaterLevel0123", getVector(TERRAIN_WaterLevel, 0,3));
        SetShaderParam("TERRAIN_WaterLevelSlopeDamp0123", getVector(TERRAIN_WaterLevelSlopeDamp, 0,3));
        SetShaderParam("TERRAIN_WaterEdge0123", getVector(TERRAIN_WaterEdge, 0,3));
        SetShaderParam("TERRAIN_WaterGloss0123", getVector(TERRAIN_WaterGloss, 0,3));
        SetShaderParam("TERRAIN_WaterOpacity0123", getVector(TERRAIN_WaterOpacity, 0,3));
        SetShaderParam("TERRAIN_Refraction0123", getVector(TERRAIN_Refraction, 0,3));
        SetShaderParam("TERRAIN_WetRefraction0123", getVector(TERRAIN_WetRefraction, 0,3));
        SetShaderParam("TERRAIN_Flow0123", getVector(TERRAIN_Flow, 0,3));
        SetShaderParam("TERRAIN_WetSpecularity0123", getVector(TERRAIN_WetSpecularity, 0,3));
        SetShaderParam("TERRAIN_WetReflection0123", getVector(TERRAIN_WetReflection, 0,3));
        SetShaderParam("TERRAIN_WaterColorR0123", getColorVector(TERRAIN_WaterColor, 0,3, 0));
        SetShaderParam("TERRAIN_WaterColorG0123", getColorVector(TERRAIN_WaterColor, 0,3, 1));
        SetShaderParam("TERRAIN_WaterColorB0123", getColorVector(TERRAIN_WaterColor, 0,3, 2));
        SetShaderParam("TERRAIN_WaterColorA0123", getColorVector(TERRAIN_WaterColor, 0,3, 3));
        SetShaderParam("TERRAIN_LayerReflection0123", getVector(	TERRAIN_LayerReflection, 0,3));

        SetShaderParam("RTP_AO_0123", getVector(AO_strength, 0,3));
        SetShaderParam("_VerticalTexture0123", getVector(VerticalTextureStrength, 0,3));

        if ((numLayers>4) && _4LAYERS_SHADER_USED) {
            //
            // przekieruj parametry warstw 4-7 na AddPass
            //
            SetShaderParam("_Spec89AB", getVector(Spec, 4,7));
            SetShaderParam("_FarGlossCorrection89AB", getVector(FarGlossCorrection, 4,7));
            SetShaderParam("_MIPmult89AB", getVector(MIPmult, 4,7));
            SetShaderParam("_MixScale89AB", getVector(MixScale, 4,7));
            SetShaderParam("_MixBlend89AB", getVector(MixBlend, 4,7));
            SetShaderParam("_MixSaturation89AB", getVector(MixSaturation, 4, 7));
            SetShaderParam("_GlobalColorPerLayer89AB", getVector(GlobalColorPerLayer, 4, 7));

            SetShaderParam("PER_LAYER_HEIGHT_MODIFIER89AB", getVector(PER_LAYER_HEIGHT_MODIFIER, 4,7));

            SetShaderParam("rtp_snow_strength_per_layer89AB",  getVector(_snow_strength_per_layer, 4,7));

            SetShaderParam("_SuperDetailStrengthMultA89AB", getVector(_SuperDetailStrengthMultA, 4,7));
            SetShaderParam("_SuperDetailStrengthMultB89AB", getVector(_SuperDetailStrengthMultB, 4,7));
            SetShaderParam("_SuperDetailStrengthNormal89AB", getVector(_SuperDetailStrengthNormal, 4,7));
            SetShaderParam("_BumpMapGlobalStrength89AB", getVector(_BumpMapGlobalStrength, 4,7));

            SetShaderParam("_SuperDetailStrengthMultASelfMaskNear89AB", getVector(_SuperDetailStrengthMultASelfMaskNear, 4,7));
            SetShaderParam("_SuperDetailStrengthMultASelfMaskFar89AB", getVector(_SuperDetailStrengthMultASelfMaskFar, 4,7));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskNear89AB", getVector(_SuperDetailStrengthMultBSelfMaskNear, 4,7));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskFar89AB", getVector(_SuperDetailStrengthMultBSelfMaskFar, 4,7));

            SetShaderParam("TERRAIN_LayerWetStrength89AB", getVector(TERRAIN_LayerWetStrength, 4,7));
            SetShaderParam("TERRAIN_WaterLevel89AB", getVector(TERRAIN_WaterLevel, 4,7));
            SetShaderParam("TERRAIN_WaterLevelSlopeDamp89AB", getVector(TERRAIN_WaterLevelSlopeDamp, 4,7));
            SetShaderParam("TERRAIN_WaterEdge89AB", getVector(TERRAIN_WaterEdge, 4,7));
            SetShaderParam("TERRAIN_WaterGloss89AB", getVector(TERRAIN_WaterGloss, 4,7));
            SetShaderParam("TERRAIN_WaterOpacity89AB", getVector(TERRAIN_WaterOpacity, 4,7));
            SetShaderParam("TERRAIN_Refraction89AB", getVector(TERRAIN_Refraction, 4,7));
            SetShaderParam("TERRAIN_WetRefraction89AB", getVector(TERRAIN_WetRefraction, 4,7));
            SetShaderParam("TERRAIN_Flow89AB", getVector(TERRAIN_Flow, 4,7));
            SetShaderParam("TERRAIN_WetSpecularity89AB", getVector(TERRAIN_WetSpecularity, 4,7));
            SetShaderParam("TERRAIN_WetReflection89AB", getVector(TERRAIN_WetReflection, 4,7));
            SetShaderParam("TERRAIN_WaterColorR89AB", getColorVector(TERRAIN_WaterColor, 4,7, 0));
            SetShaderParam("TERRAIN_WaterColorG89AB", getColorVector(TERRAIN_WaterColor, 4,7, 1));
            SetShaderParam("TERRAIN_WaterColorB89AB", getColorVector(TERRAIN_WaterColor, 4,7, 2));
            SetShaderParam("TERRAIN_WaterColorA89AB", getColorVector(TERRAIN_WaterColor, 4,7, 3));
            SetShaderParam("TERRAIN_LayerReflection89AB", getVector(TERRAIN_LayerReflection, 4,7));

            SetShaderParam("RTP_AO_89AB", getVector(AO_strength, 4,7));
            SetShaderParam("_VerticalTexture89AB", getVector(VerticalTextureStrength, 4,7));
        } else {
            SetShaderParam("_Spec4567", getVector(Spec, 4,7));
            SetShaderParam("_FarGlossCorrection4567", getVector(FarGlossCorrection, 4,7));
            SetShaderParam("_MIPmult4567", getVector(MIPmult, 4,7));
            SetShaderParam("_MixScale4567", getVector(MixScale, 4,7));
            SetShaderParam("_MixBlend4567", getVector(MixBlend, 4,7));
            SetShaderParam("_MixSaturation4567", getVector(MixSaturation, 4, 7));
            SetShaderParam("_GlobalColorPerLayer4567", getVector(GlobalColorPerLayer, 4, 7));

            SetShaderParam("PER_LAYER_HEIGHT_MODIFIER4567", getVector(PER_LAYER_HEIGHT_MODIFIER, 4,7));

            SetShaderParam("rtp_snow_strength_per_layer4567",  getVector(_snow_strength_per_layer, 4,7));

            SetShaderParam("_SuperDetailStrengthMultA4567", getVector(_SuperDetailStrengthMultA, 4,7));
            SetShaderParam("_SuperDetailStrengthMultB4567", getVector(_SuperDetailStrengthMultB, 4,7));
            SetShaderParam("_SuperDetailStrengthNormal4567", getVector(_SuperDetailStrengthNormal, 4,7));
            SetShaderParam("_BumpMapGlobalStrength4567", getVector(_BumpMapGlobalStrength, 4,7));

            SetShaderParam("_SuperDetailStrengthMultASelfMaskNear4567", getVector(_SuperDetailStrengthMultASelfMaskNear, 4,7));
            SetShaderParam("_SuperDetailStrengthMultASelfMaskFar4567", getVector(_SuperDetailStrengthMultASelfMaskFar, 4,7));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskNear4567", getVector(_SuperDetailStrengthMultBSelfMaskNear, 4,7));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskFar4567", getVector(_SuperDetailStrengthMultBSelfMaskFar, 4,7));

            SetShaderParam("TERRAIN_LayerWetStrength4567", getVector(TERRAIN_LayerWetStrength, 4,7));
            SetShaderParam("TERRAIN_WaterLevel4567", getVector(TERRAIN_WaterLevel, 4,7));
            SetShaderParam("TERRAIN_WaterLevelSlopeDamp4567", getVector(TERRAIN_WaterLevelSlopeDamp, 4,7));
            SetShaderParam("TERRAIN_WaterEdge4567", getVector(TERRAIN_WaterEdge, 4,7));
            SetShaderParam("TERRAIN_WaterGloss4567", getVector(TERRAIN_WaterGloss, 4,7));
            SetShaderParam("TERRAIN_WaterOpacity4567", getVector(TERRAIN_WaterOpacity, 4,7));
            SetShaderParam("TERRAIN_Refraction4567", getVector(TERRAIN_Refraction, 4,7));
            SetShaderParam("TERRAIN_WetRefraction4567", getVector(TERRAIN_WetRefraction, 4,7));
            SetShaderParam("TERRAIN_Flow4567", getVector(TERRAIN_Flow, 4,7));
            SetShaderParam("TERRAIN_WetSpecularity4567", getVector(TERRAIN_WetSpecularity, 4,7));
            SetShaderParam("TERRAIN_WetReflection4567", getVector(TERRAIN_WetReflection, 4,7));
            SetShaderParam("TERRAIN_WaterColorR4567", getColorVector(TERRAIN_WaterColor, 4,7, 0));
            SetShaderParam("TERRAIN_WaterColorG4567", getColorVector(TERRAIN_WaterColor, 4,7, 1));
            SetShaderParam("TERRAIN_WaterColorB4567", getColorVector(TERRAIN_WaterColor, 4,7, 2));
            SetShaderParam("TERRAIN_WaterColorA4567", getColorVector(TERRAIN_WaterColor, 4,7, 3));
            SetShaderParam("TERRAIN_LayerReflection4567", getVector(TERRAIN_LayerReflection, 4,7));

            SetShaderParam("RTP_AO_4567", getVector(AO_strength, 4,7));
            SetShaderParam("_VerticalTexture4567", getVector(VerticalTextureStrength, 4,7));

            //
            // AddPass
            //
            SetShaderParam("_Spec89AB", getVector(Spec, 8,11));
            SetShaderParam("_FarGlossCorrection89AB", getVector(FarGlossCorrection, 8,11));
            SetShaderParam("_MIPmult89AB", getVector(MIPmult, 8,11));
            SetShaderParam("_MixScale89AB", getVector(MixScale, 8,11));
            SetShaderParam("_MixBlend89AB", getVector(MixBlend, 8,11));
            SetShaderParam("_MixSaturation89AB", getVector(MixSaturation, 8, 11));
            SetShaderParam("_GlobalColorPerLayer89AB", getVector(GlobalColorPerLayer, 8, 11));

            SetShaderParam("PER_LAYER_HEIGHT_MODIFIER89AB", getVector(PER_LAYER_HEIGHT_MODIFIER, 8,11));

            SetShaderParam("rtp_snow_strength_per_layer89AB",  getVector(_snow_strength_per_layer, 8,11));

            SetShaderParam("_SuperDetailStrengthMultA89AB", getVector(_SuperDetailStrengthMultA, 8,11));
            SetShaderParam("_SuperDetailStrengthMultB89AB", getVector(_SuperDetailStrengthMultB, 8,11));
            SetShaderParam("_SuperDetailStrengthNormal89AB", getVector(_SuperDetailStrengthNormal, 8,11));
            SetShaderParam("_BumpMapGlobalStrength89AB", getVector(_BumpMapGlobalStrength, 8,11));

            SetShaderParam("_SuperDetailStrengthMultASelfMaskNear89AB", getVector(_SuperDetailStrengthMultASelfMaskNear, 8,11));
            SetShaderParam("_SuperDetailStrengthMultASelfMaskFar89AB", getVector(_SuperDetailStrengthMultASelfMaskFar, 8,11));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskNear89AB", getVector(_SuperDetailStrengthMultBSelfMaskNear, 8,11));
            SetShaderParam("_SuperDetailStrengthMultBSelfMaskFar89AB", getVector(_SuperDetailStrengthMultBSelfMaskFar, 8,11));

            SetShaderParam("TERRAIN_LayerWetStrength89AB", getVector(TERRAIN_LayerWetStrength,  8,11));
            SetShaderParam("TERRAIN_WaterLevel89AB", getVector(TERRAIN_WaterLevel,  8,11));
            SetShaderParam("TERRAIN_WaterLevelSlopeDamp89AB", getVector(TERRAIN_WaterLevelSlopeDamp,  8,11));
            SetShaderParam("TERRAIN_WaterEdge89AB", getVector(TERRAIN_WaterEdge,  8,11));
            SetShaderParam("TERRAIN_WaterGloss89AB", getVector(TERRAIN_WaterGloss,  8,11));
            SetShaderParam("TERRAIN_WaterOpacity89AB", getVector(TERRAIN_WaterOpacity,  8,11));
            SetShaderParam("TERRAIN_Refraction89AB", getVector(TERRAIN_Refraction,  8,11));
            SetShaderParam("TERRAIN_WetRefraction89AB", getVector(TERRAIN_WetRefraction,  8,11));
            SetShaderParam("TERRAIN_Flow89AB", getVector(TERRAIN_Flow,  8,11));
            SetShaderParam("TERRAIN_WetSpecularity89AB", getVector(TERRAIN_WetSpecularity,  8,11));
            SetShaderParam("TERRAIN_WetReflection89AB", getVector(TERRAIN_WetReflection,  8,11));
            SetShaderParam("TERRAIN_WaterColorR89AB", getColorVector(TERRAIN_WaterColor, 8,11, 0));
            SetShaderParam("TERRAIN_WaterColorG89AB", getColorVector(TERRAIN_WaterColor, 8,11, 1));
            SetShaderParam("TERRAIN_WaterColorB89AB", getColorVector(TERRAIN_WaterColor, 8,11, 2));
            SetShaderParam("TERRAIN_WaterColorA89AB", getColorVector(TERRAIN_WaterColor, 8,11, 3));
            SetShaderParam("TERRAIN_LayerReflection89AB", getVector(TERRAIN_LayerReflection,  8,11));

            SetShaderParam("RTP_AO_89AB", getVector(AO_strength, 8,11));
            SetShaderParam("_VerticalTexture89AB", getVector(VerticalTextureStrength, 8,11));
        }

        /////////////////////////////////////////////////////////////////////
        //
        // layer dependent textures
        //
        /////////////////////////////////////////////////////////////////////
        SetShaderParam("_SplatAtlasA", splat_atlases[0]);
        SetShaderParam("_BumpMap01", Bump01);
        SetShaderParam("_BumpMap23", Bump23);
        SetShaderParam("_TERRAIN_HeightMap", HeightMap);
        SetShaderParam("_SSColorCombinedA", SSColorCombined);

        if (numLayers>4) {
            SetShaderParam("_SplatAtlasB", splat_atlases[1]);
            SetShaderParam("_TERRAIN_HeightMap2", HeightMap2);
        }
        if ((numLayers>4) && _4LAYERS_SHADER_USED) {
            //
            // przekieruj parametry warstw 4-7 na AddPass
            //
            SetShaderParam("_BumpMap89", Bump45);
            SetShaderParam("_BumpMapAB", Bump67);
            SetShaderParam("_TERRAIN_HeightMap3", HeightMap2);
            // potrzebne przy sniegu (firstpass moze korzystac z koloru i bumpmap 4-7)
            SetShaderParam("_BumpMap45", Bump45);
            SetShaderParam("_BumpMap67", Bump67);
        } else {
            SetShaderParam("_BumpMap45", Bump45);
            SetShaderParam("_BumpMap67", Bump67);

            //
            // AddPass
            //
            SetShaderParam("_BumpMap89", Bump89);
            SetShaderParam("_BumpMapAB", BumpAB);
            SetShaderParam("_TERRAIN_HeightMap3", HeightMap3);
        }

        use_mat=null;
    }