Splatmapping Terrain under object by position

Hello I have a question that seems simple but has stumped my because I am failing to wrap my mind around the math to calculate all the points between an x position and a y position.

So what I have created is a script to paint the terrain under an object. I am getting that area under the object by converting the positions of the objects corners to terrain coordinates.

My issue is I am unable to get the painted terrain area to fit closely to the objects corners. I just get a box around the object limited by the maximum x and max y coordinates.

How do I limit the area to just the corners? I know its a math issue. I just can’t figure it out.

Here is how I am currently checking coordinates.

if (x >= firstPoint.x && x <= thirdpoint.x && y <=fourthpoint.y)
                {
                    if (y >= secondpoint.y && y <= fourthpoint.y )
                    {
                        float a0 = maps[x, y, 0];
                        float a1 = maps[x, y, 1];

                        a0 += Random.value * noiseScale;
                        a1 += Random.value * noiseScale;

                        float total = a0 + a1;

                        maps[x, y, 0] = a0 / total;
                        maps[x, y, 1] = a1 / total;
                    }
                    else
                    {
                        float a0 = maps[x, y, 0];
                        float a1 = maps[x, y, 1];

                        float total = a0 + a1;

                        maps[x, y, 0] = a0;
                        maps[x, y, 1] = a1;
                    }

                }

The “points” are the spheres on the corners of the object.

The splatmap will always (obviously) be much tinier than the pixels making up your terrain.

This means that any given pixel of the splatmap might affect an arbitrarily large area.

You can improve it by making a larger splatmap, making a smaller terrain, or using many smaller terrains.

To see the highest-possible resolution of your splatmap, write a little script that produces a checkerboard at the splatmap pixel level, every alternating pixel mapped to texture 0 or texture 1.

1 Like