<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Map with spotlight = clipping issues?]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2156&amp;type=atom" />
	<updated>2023-08-23T22:22:24Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=2156</id>
		<entry>
			<title type="html"><![CDATA[Re: Map with spotlight = clipping issues?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9159#p9159" />
			<content type="html"><![CDATA[<p>That worked!!! Thank you so much for the help <img src="https://forum.infinity-code.com/img/smilies/big_smile.png" width="15" height="15" alt="big_smile" /></p>]]></content>
			<author>
				<name><![CDATA[slomb]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2672</uri>
			</author>
			<updated>2023-08-23T22:22:24Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9159#p9159</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Map with spotlight = clipping issues?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9158#p9158" />
			<content type="html"><![CDATA[<p>Try this:<br /></p><div class="codebox"><pre><code>using System.Collections.Generic;
using UnityEngine;

namespace InfinityCode.OnlineMapsSupport
{
    public class TilesetSmoothNormals : MonoBehaviour
    {
        public OnlineMapsTileSetControl control;

        private void Start()
        {
            if (control == null) control = OnlineMapsTileSetControl.instance;
            control.OnMeshUpdated += OnMeshUpdated;
        }

        private void OnMeshUpdated()
        {
            Mesh mesh = control.meshFilter.sharedMesh;
            mesh.RecalculateNormals();

            Vector3[] vertices = mesh.vertices;
            Vector3[] normals = mesh.normals;

            Dictionary&lt;int, Item&gt; items = new Dictionary&lt;int, Item&gt;();

            for (int i = 0; i &lt; vertices.Length; i++)
            {
                Vector3 vertex = vertices[i];
                int hash = vertex.GetHashCode();
                Item item = null;
                if (!items.TryGetValue(hash, out item))
                {
                    item = new Item();
                    items[hash] = item;
                }

                item.Add(i, normals[i]);
            }

            foreach (KeyValuePair&lt;int, Item&gt; pair in items)
            {
                Item item = pair.Value;
                item.FixNormals(normals);
            }

            mesh.normals = normals;
            control.meshFilter.sharedMesh = mesh;
        }

        internal class Item
        {
            public List&lt;int&gt; indices;
            private Vector3 sumOfNormals;

            public Item()
            {
                indices = new List&lt;int&gt;();
            }

            public void Add(int index, Vector3 normal)
            {
                indices.Add(index);
                sumOfNormals += normal;
            }

            public void FixNormals(Vector3[] normals)
            {
                Vector3 normal = (sumOfNormals / indices.Count).normalized;
                for (int i = 0; i &lt; indices.Count; i++)
                {
                    int index = indices[i];
                    normals[index] = normal;
                }
            }
        }
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-08-23T19:32:36Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9158#p9158</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Map with spotlight = clipping issues?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9157#p9157" />
			<content type="html"><![CDATA[<p>Thank you for the help! Step 3 actually fixed the problem for me, but I seem to have another problem from it. My light that&#039;s projected seems to be faceted, but i need the normals to be smooth. Currently my light looks like varying shades of squares depending on the shadows. Do you know how i can fix this?</p>]]></content>
			<author>
				<name><![CDATA[slomb]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2672</uri>
			</author>
			<updated>2023-08-23T16:51:50Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9157#p9157</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Map with spotlight = clipping issues?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9155#p9155" />
			<content type="html"><![CDATA[<p>Hello.</p><p>To fix the problem:<br />1. Enable shadows in the Light component.<br />2. Go to Edit / Project Settings / Quality and increase Shadow Distance to the size of the map in the scene * 2.<br />You can also increase Shadow Resolution.<br />3. (Optional) In the OnlineMapsTileSetControl script, after the line &quot;tilesetMesh.RecalculateBounds();&quot; (line ~1200) add the line &quot;tilesetMesh.RecalculateNormals();&quot;. But to be honest I didn&#039;t notice any difference.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-08-23T13:38:48Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9155#p9155</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Map with spotlight = clipping issues?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9152#p9152" />
			<content type="html"><![CDATA[<p>I have a map object, and a spotlight object. When I shine the spotlight on the map with elevation enabled (I have mapbox enabled), the spotlight will often ignore the elevation in certain parts and show up on the other side of a mountain, even though the mountain should stop the light completely. <br />I&#039;ve included an example of this with arrows pointing at some of the light that shouldnt be shining through. The light is coming from the top left of the scene. The parts where the spotlight disappears is where the mountain goes up, but when the mountain comes back down, the light reappears, even though it should be cut off.<br />Not sure what I can do to fix this problem.. If anyone knows what I can do to make sure the light stops wherever it touches elevation that would be great!</p>]]></content>
			<author>
				<name><![CDATA[slomb]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2672</uri>
			</author>
			<updated>2023-08-22T22:28:52Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9152#p9152</id>
		</entry>
</feed>
