if (i < rings.Length && rings[i] != this)
Well, for one “rings != this” is invalid because your rings are “MeshGeneratedInfluenceBorder” type and you’re checking against “RingMapper” type.
The code above works for me because my rings list is of the same type than the class I’ve put this code in. Both are type of “Ring” so I can actually compare them. For you, you could compare gameobjects instead, since you have your MeshGeneratedInfluenceBorder and RingMapper components on the same GOs. Or your list could be of type RingMapper.
The reason behind that line is that the current ring should not be added to its own rings map because the shader would have no way to know that this ring is the current ring, and thus wouldn’t be able to treat it differently. It would simply consider it as another ring laid right on top of the current, with the same radius, and wouldn’t render properly.
Vector3 ringPosition = rings[i].transform.position;
I’m not sure how you setup your mesh generation for your rings but if the transform.position is not at the center of the ring, you should update the line above to reflect the actual center of the ring. If it is, you can disregard what I said.
Also, the radius in your code “RingMapper” class isn’t used at all. You’re assigning its value but never reading it. You’re reading the radius straight from the MeshGeneratedInfluenceBorder, since that’s the type of your list.
I think there might also be a problem on the shader side. With the problems above, it shouldn’t work properly but I think you should be able to see at least some kind of behaviour. Can you post your graph and the custom node as well?
And just in case, are you certain that the materials of your rings are actually using the shader?
edit : Here’s the script I used when testing. Add it to a few gameobject in a blank scene. Make sure you add your material to the meshrenderer that it’ll create and you should be able to test to see if your shader is actually the problem.
Just in case, that code isn’t good code. It’s working code I used for testing. Don’t use calls like FindObjectsOfType every frame.
Rings
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class Ring : MonoBehaviour
{
[SerializeField]
private float radius = 2f;
[SerializeField]
private float height = 0.4f;
[SerializeField]
private int resolution = 32;
private MeshRenderer meshRenderer;
private Texture2D ringsMap;
private Mesh mesh;
private void Awake()
{
ringsMap = new Texture2D(4, 4, TextureFormat.RGBAFloat, false);
meshRenderer = GetComponent<MeshRenderer>();
meshRenderer.material.SetTexture("_RingsMap", ringsMap);
}
private void Start()
{
mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
RedrawMesh();
}
private void RedrawMesh()
{
List<Vector3> verts = new List<Vector3>();
List<int> triangles = new List<int>();
for (int i = 0; i < resolution; i++)
{
float angle = i * Mathf.PI * 2f / resolution;
Vector3 pos = new Vector3(Mathf.Cos(angle) * radius, 0f, Mathf.Sin(angle) * radius);
verts.Add(pos);
verts.Add(pos + Vector3.up * height);
}
for (int i = 0; i < resolution; i++)
{
int index = i * 2;
triangles.Add(index);
triangles.Add(index + 3);
triangles.Add(index + 2);
triangles.Add(index + 1);
triangles.Add(index + 3);
triangles.Add(index);
}
for (int i = triangles.Count - 6; i < triangles.Count; i++)
{
triangles[i] %= verts.Count;
}
mesh.SetVertices(verts);
mesh.SetTriangles(triangles, 0);
}
private void LateUpdate()
{
RedrawMesh();
MapRings();
}
private void MapRings()
{
List<Color> pixels = new List<Color>();
Ring[] rings = FindObjectsOfType<Ring>();
for (int i = 0; i < ringsMap.width * ringsMap.height; i++)
{
if (i < rings.Length && rings[i] != this)
{
Vector3 ringPosition = rings[i].transform.position;
pixels.Add(new Color(ringPosition.x, ringPosition.z, rings[i].radius));
}
else
{
pixels.Add(Color.clear);
}
}
ringsMap.SetPixels(pixels.ToArray());
ringsMap.Apply();
}
}