protected void UpdateMaterial(Material mat)
    {
        VtsTexture tex = draws.celestial.atmosphere.densityTexture as VtsTexture;

        if (atmosphere && tex != null)
        {
            var cel = draws.celestial;
            var atm = cel.atmosphere;
            mat.SetVector(shaderPropertyAtmSizes, new Vector4(
                              (float)(atm.boundaryThickness / cel.majorRadius),
                              (float)(cel.majorRadius / cel.minorRadius),
                              (float)(1.0 / cel.majorRadius),
                              0));
            mat.SetVector(shaderPropertyAtmCoefficients, new Vector4(
                              (float)atm.horizontalExponent,
                              (float)atm.colorGradientExponent,
                              0,
                              0));
            mat.SetVector(shaderPropertyAtmCameraPosition, VtsUtil.V2U3(draws.camera.eye) / (float)cel.majorRadius);
            mat.SetMatrix(shaderPropertyAtmViewInv, VtsUtil.V2U44(Math.Inverse44(draws.camera.view)));
            mat.SetVector(shaderPropertyAtmColorHorizon, VtsUtil.V2U4(atm.colorHorizon));
            mat.SetVector(shaderPropertyAtmColorZenith, VtsUtil.V2U4(atm.colorZenith));
            mat.SetTexture("vtsTexAtmDensity", tex.Get());
            mat.EnableKeyword("VTS_ATMOSPHERE");
        }
        else
        {
            mat.DisableKeyword("VTS_ATMOSPHERE");
        }
    }
Beispiel #2
0
    void Update()
    {
        Map map = GetComponent <VtsMap>().map;

        if (map.GetMapConfigAvailable())
        {
            double[] p = new double[3] {
                longitude, latitude, altitude
            };
            p = map.Convert(p, Srs.Navigation, Srs.Physical);
            { // swap YZ
                double tmp = p[1];
                p[1] = p[2];
                p[2] = tmp;
            }
            Vector3 v = Vector3.Scale(VtsUtil.V2U3(p), transform.localScale);
            float   m = v.magnitude;
            transform.position = new Vector3(0, -m, 0);
            transform.rotation = Quaternion.FromToRotation(-v, transform.position);
            if (singleUse)
            {
                Destroy(this);
            }
        }
    }
Beispiel #3
0
    public static bool MakeLocal(VtsMap umap, double[] navPt)
    {
        Util.CheckArray(navPt, 3);
        Map map = umap.GetVtsMap();

        if (!map.GetMapconfigAvailable())
        {
            return(false);
        }
        double[] p = map.Convert(navPt, Srs.Navigation, Srs.Physical);
        { // swap YZ
            double tmp = p[1];
            p[1] = p[2];
            p[2] = tmp;
        }
        Vector3 v = Vector3.Scale(VtsUtil.V2U3(p), umap.transform.localScale);

        if (map.GetProjected())
        {
            umap.transform.position = -v;
        }
        else
        {
            float m = v.magnitude;
            umap.transform.position = new Vector3(0, -m, 0);              // altitude
            umap.transform.rotation =
                Quaternion.Euler(0, (float)navPt[0] + 90.0f, 0)           // align to north
                * Quaternion.FromToRotation(-v, umap.transform.position); // latlon
        }
        return(true);
    }
 private void RegenerateCommandBuffer(CommandBuffer buffer, List <DrawTask> tasks)
 {
     buffer.Clear();
     if (atmosphere && draws.celestial.atmosphere.densityTexture as VtsTexture != null)
     {
         buffer.EnableShaderKeyword("VTS_ATMOSPHERE");
     }
     else
     {
         buffer.DisableShaderKeyword("VTS_ATMOSPHERE");
     }
     buffer.SetViewMatrix(Matrix4x4.identity);
     buffer.SetProjectionMatrix(cam.projectionMatrix);
     foreach (DrawTask t in tasks)
     {
         if (t.mesh == null)
         {
             continue;
         }
         MaterialPropertyBlock mat    = new MaterialPropertyBlock();
         VtsTexture            atmTex = draws.celestial.atmosphere.densityTexture as VtsTexture;
         if (atmosphere && atmTex != null)
         {
             var cel = draws.celestial;
             var atm = cel.atmosphere;
             mat.SetVector(shaderPropertyAtmSizes, new Vector4(
                               (float)(atm.boundaryThickness / cel.majorRadius),
                               (float)(cel.majorRadius / cel.minorRadius),
                               (float)(1.0 / cel.majorRadius),
                               0));
             mat.SetVector(shaderPropertyAtmCoefficients, new Vector4(
                               (float)atm.horizontalExponent,
                               (float)atm.colorGradientExponent,
                               0,
                               0));
             mat.SetVector(shaderPropertyAtmCameraPosition, VtsUtil.V2U3(draws.camera.eye) / (float)cel.majorRadius);
             mat.SetMatrix(shaderPropertyAtmViewInv, VtsUtil.V2U44(Math.Inverse44(draws.camera.view)));
             mat.SetVector(shaderPropertyAtmColorHorizon, VtsUtil.V2U4(atm.colorHorizon));
             mat.SetVector(shaderPropertyAtmColorZenith, VtsUtil.V2U4(atm.colorZenith));
             mat.SetTexture("vtsTexAtmDensity", atmTex.Get());
         }
         bool monochromatic = false;
         if (t.texColor != null)
         {
             var tt = t.texColor as VtsTexture;
             mat.SetTexture(shaderPropertyMainTex, tt.Get());
             monochromatic = tt.monochromatic;
         }
         if (t.texMask != null)
         {
             mat.SetTexture(shaderPropertyMaskTex, (t.texMask as VtsTexture).Get());
         }
         mat.SetMatrix(shaderPropertyUvMat, VtsUtil.V2U33(t.data.uvm));
         mat.SetVector(shaderPropertyUvClip, VtsUtil.V2U4(t.data.uvClip));
         mat.SetVector(shaderPropertyColor, VtsUtil.V2U4(t.data.color));
         // flags: mask, monochromatic, flat shading, uv source
         mat.SetVector(shaderPropertyFlags, new Vector4(t.texMask == null ? 0 : 1, monochromatic ? 1 : 0, 0, t.data.externalUv ? 1 : 0));
         buffer.DrawMesh((t.mesh as VtsMesh).Get(), VtsUtil.V2U44(t.data.mv), renderMaterial, 0, -1, mat);
     }
 }
Beispiel #5
0
 void Update()
 {
     coordsUnity.text = "";
     coordsVts.text   = "";
     if (!map.GetVtsMap().GetMapconfigAvailable())
     {
         return;
     }
     double[] p = VtsUtil.U2V3(transform.position);
     p = map.UnityToVtsNavigation(p);
     coordsUnity.text = "Unity World: " + transform.position.ToString("F5");
     coordsVts.text   = "Vts Navigation: " + VtsUtil.V2U3(p).ToString("F5");
 }
Beispiel #6
0
    void Update()
    {
        var um = mapObject.GetComponent <VtsMap>();

        if (um.Map.GetMapconfigAvailable())
        {
            double[] p = new double[3] {
                x, y, z
            };
            p = um.VtsNavigationToUnity(p);
            transform.position += VtsUtil.V2U3(p);
            Destroy(this); // destroy this component
        }
    }
Beispiel #7
0
    void Update()
    {
        coordsUnity.text = "";
        coordsVts.text   = "";
        if (!map.GetVtsMap().GetMapconfigAvailable())
        {
            return;
        }
        Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (!Physics.Raycast(ray, out hit))
        {
            return;
        }
        double[] p = VtsUtil.U2V3(hit.point);
        p = map.UnityToVtsNavigation(p);
        coordsUnity.text = "Unity World: " + hit.point.ToString("F5");
        coordsVts.text   = "Vts Navigation: " + VtsUtil.V2U3(p).ToString("F5");
    }
Beispiel #8
0
    private void PrepareShaderData()
    {
        var cel = draws.celestial;
        var atm = cel.atmosphere;

        shaderValueAtmSizes = new Vector4(
            (float)(atm.boundaryThickness / cel.majorRadius),
            (float)(cel.majorRadius / cel.minorRadius),
            (float)(1.0 / cel.majorRadius),
            0);
        shaderValueAtmCoefficients = new Vector4(
            (float)atm.horizontalExponent,
            (float)atm.colorGradientExponent,
            0,
            0);
        shaderValueAtmCameraPosition = VtsUtil.V2U3(draws.camera.eye) / (float)cel.majorRadius;
        shaderValueAtmViewInv        = VtsUtil.V2U44(Math.Inverse44(draws.camera.view));
        shaderValueAtmColorHorizon   = VtsUtil.V2U4(atm.colorHorizon);
        shaderValueAtmColorZenith    = VtsUtil.V2U4(atm.colorZenith);
    }
    void Start()
    {
        if (isServer)
        {
            color = Color.HSVToRGB(Random.value, Random.value * 0.5f + 0.5f, Random.value * 0.5f + 0.5f);
        }

        if (isLocalPlayer)
        {
            Debug.Log("Initializing world '" + config.name + "'");

            // initialize the map
            GameObject map = FindObjectOfType <VtsMap>().gameObject;
            map.GetComponent <VtsMap>().Map.SetMapconfigPath(config.mapconfigUrl);
            {
                VtsMapMakeLocal l = map.GetComponent <VtsMapMakeLocal>();
                l.x = config.position[0];
                l.y = config.position[1];
                l.z = config.position[2];
            }

            // initialize the car
            GetComponent <VtsRigidBodyActivate>().map      = map;
            GetComponent <VtsColliderProbe>().mapObject    = map;
            GetComponent <VtsColliderProbe>().collidersLod = config.collisionlod;

            // initialize other objects
            GameObject.Find("mainCamera").GetComponent <FollowingCamera>().target   = gameObject;
            GameObject.Find("mainCamera").GetComponent <FollowingCamera>().enabled  = true;
            GameObject.Find("minimapCamera").GetComponent <MinimapCamera>().target  = gameObject;
            GameObject.Find("minimapCamera").GetComponent <MinimapCamera>().enabled = true;
            GameObject.Find("sun").transform.rotation = Quaternion.Euler(VtsUtil.V2U3(config.sunDirection));

            // enable all components
            foreach (var c in gameObject.GetComponents <MonoBehaviour>())
            {
                c.enabled = true;
            }
        }
    }
Beispiel #10
0
    private void PrepareShaderData()
    {
        var cel = draws.celestial;
        var atm = cel.atmosphere;

        shaderValueAtmSizes = new Vector4(
            (float)(atm.boundaryThickness / cel.majorRadius),
            (float)(cel.majorRadius / cel.minorRadius),
            (float)(1.0 / cel.majorRadius),
            0);
        shaderValueAtmCoefficients = new Vector4(
            (float)atm.horizontalExponent,
            (float)atm.colorGradientExponent,
            0,
            0);
        shaderValueAtmCameraPosition = VtsUtil.V2U3(draws.camera.eye) / (float)cel.majorRadius;
        shaderValueAtmViewInv        = VtsUtil.V2U44(Math.Inverse44(draws.camera.view));
        shaderValueAtmColorHorizon   = VtsUtil.V2U4(atm.colorHorizon);
        shaderValueAtmColorZenith    = VtsUtil.V2U4(atm.colorZenith);
        shaderValueAtmEnabled        = Shader.IsKeywordEnabled("VTS_ATMOSPHERE") && draws.celestial.atmosphere.densityTexture != null;
        shaderValueFrameIndex++;
    }