Topic: Use TilesetOverlayUsingShader as layers

Hi Alex, I hope all is well.
I've done some testing with your "TilesetOverlayUsingShader" and it's great for my needs. It's just missing one feature that I can't implement and it would be perfect for me. I would like to have more GameObjects with OverlayShader in the scene and use them as real superimposable "LAYERS" like Photoshop layers so to speak. Now if I add a new GameObject with OverlayShader it "deletes" the previous one. I hope I explained myself correctly. Thanks Alex. Here is the script I tested:   

using System;
using UnityEngine;
using UnityEngine.UI;

public class TilesetOverlayUsingShader : MonoBehaviour
{
    public OnlineMapsTileSetControl control;
   
    // Overlay texture in mercator projection
    public Texture texture;

    /// <summary>
    /// Border coordinates of the overlay
    /// </summary>
    public double Nord_topLatitude;
    public double Ovest_leftLongitude;   
    public double Est_rightLongitude;
    public double Sud_bottomLatitude;

    // Reference to the UI Slider
    public Slider alphaSlider;

    // Overlay transparency
    [Range(0, 1)]
    public float alpha = 1;

    private float _alpha = 1;

    private void Start()
    {
        if (control == null) control = OnlineMapsTileSetControl.instance;
       
        // Subscribe to events
        OnlineMapsTileSetControl.instance.OnMeshUpdated += UpdateOverlay;
        UpdateOverlay();
    }

    private void Update()
    {
        if (_alpha != alpha)
        {
            _alpha = alpha;
            UpdateOverlay();
        }
    }

    private void UpdateOverlay()
    {
        Vector3 p1 = control.GetWorldPosition(Ovest_leftLongitude, Nord_topLatitude);
        Vector3 p2 = control.GetWorldPosition(Est_rightLongitude, Sud_bottomLatitude);
        Shader.SetGlobalTexture("_OverlayTex", texture);
        Shader.SetGlobalFloat("_OverlayAlpha", _alpha);
        Shader.SetGlobalVector("_OverlayTL", p1);
        Shader.SetGlobalVector("_OverlayBR", p2);
    }

    public void OnAlphaSliderValueChanged(float value)
    {
        alpha = value;
        UpdateOverlay();
    }

}

Re: Use TilesetOverlayUsingShader as layers

Hello.

To achieve this you need to uncomment the declaration lines in the Properties block of the shader, subscribe to OnlineMapsTileSetControl.OnDrawTile, and set the parameters using the material methods (material.SetTexture, etc).

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Use TilesetOverlayUsingShader as layers

Can I ask you for a little example help ? Thank you

Re: Use TilesetOverlayUsingShader as layers

A little help is attached ;D

Post's attachments

Attachment icon TilesetOverlayUsingShader2.cs 1.29 kb, 70 downloads since 2023-10-19 

Attachment icon TilesetWithOverlay2.shader 2.2 kb, 61 downloads since 2023-10-19 

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Use TilesetOverlayUsingShader as layers

Thanks Alex, thanks so much my friend but unfortunately it doesn't work or I can't make it work. I can use and activate (and not deactivate) only one element and not have more than one element with a custom Raster from Qgis. I have 5 distinct Raster Layers to activate and deactivate in RunTime with each its own alpha level at the same time and with the overlay order from the position of the GameObjects in the hierarchy. This is really nice and useful for my project but I understand that it may be "out of common" utility for OnLine Maps. If you think this job requires extra work let me know otherwise as always THANK YOU ALEX for your commitment. You are always my n°1 in Unity

Re: Use TilesetOverlayUsingShader as layers

This script and shader should be used on the map, not on other GameObjects.
Because of this I thought you wanted to have multiple maps, each with its own overlay.
After reading your last post I realized that this is not the case.

In order for me to make you the right script and shader, let's define the requirements of your project:
- How many maps (one or several)?
- Number of overlay layers up to 5 with the ability to disable, right?
- Multiple overlay layers can be active at the same time, right?
- Is there a chance that in the future you will want to have more than 7 overlay layers?
- Does it need to be elevation friendly?

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

7 (edited by LazzLab 2023-10-20 17:00:28)

Re: Use TilesetOverlayUsingShader as layers

You are amazing Alex .............

Requirements:

- How many maps (one or more)?
At the moment I only use one map but in the (distant) future there will have to be 2.

- Number of overlay levels up to 5 with the ability to disable them, right?
Yes, I confirm. 5 levels max. Each layer will have an on/off toggle and an alpha channel slider like the attached example image from Qgis with the layers.

- Multiple overlay layers can be active at the same time, right?
Yes, I confirm. All layers can be active at the same time and overlap.

- Is there a possibility that in the future you will want to have more than 7 levels of overlap?
Difficult but probable. At the moment 5 levels are sufficient and I would like to use a dynamic list for possible additions in runtime.

- Is it necessary to be conducive to elevation?
Yes, essential!

P.s. The script will be a prefab and instantiated in RunTime in a UI list outside the map (main script).

Thanks for the questions Alex.
I would also like to tell you that these implementations are not urgent. I'd like to have them at the beginning of the year.

The things I really need are:
- Have the initial script (therefore for a single layer) that can be activated/deactivated and its alpha slider. So with the only modification of being able to activate and deactivate it.
I'll use a ToggleGroup to handle the switch and not the overlay for now (so just one layer at a time for now)

Then there are other challenges that I'm sharing with you just to tell you what I "should" do and if you want to give me your feedback it's welcome.
- I'm looking for a method to read the GeoTif Raster that I export from Qgis and extract the text of the file name and above all the coordinates to give to your script automatically and in RunTime.
At the moment I start it "by hand" with input fields and I haven't succeeded in doing it automatically (I thought it would be simpler like reading an xml).
I would like to be able to export the shapes from Qgis and import them into MappeOnLine but this is really science fiction for me.....

Thanks Alex. Contact me privately if "I'm asking too much" wink

Post's attachments

Attachment icon Qgis Level example 00.jpg 282.02 kb, 32 downloads since 2023-10-20 

Re: Use TilesetOverlayUsingShader as layers

The script and shader are attached.

I've never worked with GeoTiff and Qgis, so unfortunately I can't give any advice here.

Post's attachments

Attachment icon TilesetOverlayUsingShader7.cs 1.88 kb, 74 downloads since 2023-10-22 

Attachment icon TilesetWithOverlay7.shader 5.57 kb, 72 downloads since 2023-10-22 

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Use TilesetOverlayUsingShader as layers

Thanks Alex it's fantastic and perfect. When you want to come on holiday you will always be my guest. Thanks thanks thanks smile