0
\$\begingroup\$

As you can see from this video, the shader graph was used to curve the path. In landscape mode, it works as expected but in portrait mode nearby objects (the buildings and other objects) disappear from view.

They are not getting destroyed, they still exist in the scene, but disappearing from view abruptly. How do I stop this from happening?

I have tried this with different implementations of shader graphs, but the same problem exists with all. Shader graphs tried:

Shader Graph 1

Shader Graph 2

Also note that I am completely inexperienced with Shader Graphs and I was following Udemy and Youtube tutorials.

Using provided solution like this:

private void SpawnBuildings(GameObject itBlock)
{
    foreach (var i in buildingSpawnPoints)
    {
        Vector3 buildingSpawnLocation = itBlock.transform.position + (i.position - startingPoint.position);
        int rotationOffsetBy90 = Random.Range(0, 3);
        Quaternion buildingSpawnRotation = Quaternion.Euler(0, rotationOffsetBy90 * 90, 0);
        Vector3 buildingSpawnSize = Vector3.one * Random.Range(buildingSpawnScaleRange.x, buildingSpawnScaleRange.y);
        int buildingPick = Random.Range(0, buildings.Length);
   
        GameObject newBuilding = Instantiate(buildings[buildingPick], buildingSpawnLocation, buildingSpawnRotation, itBlock.transform);
        newBuilding.transform.localScale = buildingSpawnSize;

        // Fustrum culling
        Mesh mesh = newBuilding.GetComponent<MeshFilter>().mesh;
        mesh.bounds = new Bounds(newBuilding.transform.localPosition, buildingSpawnSize);
        // Vector3.one instead of buildingSpawnSize causes it to render similarly
    }
}

causes the same culling. Using the above causes it to be rendered as shown here. It's not culling the buildings on the sides near the edge of the screen but it's culling those at a distance.

\$\endgroup\$
6
  • \$\begingroup\$ Sounds like frustum culling. The culling system doesn't know about how you've curved this object, so it gets culled based on its original, un-bent bounds when they're off screen (which happens more often when your frustum is narrow, like in portrait mode). You can override the bounds on an object to make them encapsulate the full extents of the curve as shown here. \$\endgroup\$ Commented Oct 17, 2023 at 10:51
  • \$\begingroup\$ @DMGregory Thanks for your response, yes it is frustum culling, thanks for pointing me in the right direction. I could not get that solution to work, but I managed to do using this: vertexfragment.com/ramblings/unity-prevent-object-culling and also this: discussions.unity.com/t/disable-frustum-culling/11018/10 The first solution causes unintended problems but the second one works.. although I needed to call OnPreCull() from Start() to make it work. Is this an acceptable solution (the second one), or is it problematic and would cause unintended consequences? Thanks. \$\endgroup\$ Commented Oct 18, 2023 at 8:47
  • \$\begingroup\$ Be sure to write up the solution that worked for you as an answer in the "Your Answer" box below. Users can then vote and comment on the answer to give you the feedback you're looking for. (But generally in games, if it works and profiles OK, it's good enough). It looks like that solution will disable frustum culling for other objects too, not just this one, which isn't a big deal if you don't have a lot of other objects in your scene. If you want help with the solution I linked, edit your question to show how you tried using it and what went wrong. \$\endgroup\$ Commented Oct 18, 2023 at 8:58
  • \$\begingroup\$ @DMGregory I edited the question with my attempt of the solution you gave. Thanks. Please tell me where I'm going wrong. \$\endgroup\$ Commented Oct 18, 2023 at 19:03
  • \$\begingroup\$ The bounds are specified in the mesh's local space, so passing a transform position in world space makes no sense here. Does your bending never move any vertices outside a range of one unit from the mesh's original pivot point? \$\endgroup\$ Commented Oct 18, 2023 at 19:20

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.