Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BloodMarked · Jan 21, 2018 at 12:33 PM · scripting problemmeshcullingdynamic mesh

culling issues on dynamically generated mesh

i am using a mesh to display gun trails in my game. i am updating only the vertex positions when a new trail is created, uvs and triangles are consistent.

the problem is that it disappears at certain camera angles / positions, i think the issue is occlusion / frustrum culling.


in 2017.2 i could solve this by disabling occlusion culling in the mesh renderer component.

unfortunately, as of 2017.3 the mesh is still culled.


what is the correct way to solve this?

can i disable culling for the object or can i update the culling box via script at runtime?

script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class gunTrail : MonoBehaviour {
     [RequireComponent(typeof(MeshFilter))]
     public int maxtrails = 6;
     public float trailWidth = .01f;
     int nextTrail = 0;
     bool Trailchanges = false;
     Vector3[] trailstart;
     Vector3[] traildirection;
 
     Vector3[] vertices;
     Vector2[] uvs;
     int[] triangles;
 
     Mesh mesh;
 
     void Start () {
         mesh = new Mesh ();
         GetComponent<MeshFilter> ().mesh = mesh;
 
         trailstart        = new Vector3[maxtrails];
         traildirection     = new Vector3[maxtrails];
 
         vertices = new Vector3[maxtrails*3]; 
         triangles = new int[maxtrails*3*2];
         uvs = new Vector2[vertices.Length];
 
         for (int i = 0; i < maxtrails; i++) {
             vertices [i * 3 + 0] = new Vector3 (0, -10, 0);
             vertices [i * 3 + 1] = new Vector3 (0, -10, 0);
             vertices [i * 3 + 2] = new Vector3 (0, -10, 0);
             triangles [i * 6 + 0] = i * 3;
             triangles [i * 6 + 1] = i * 3 + 1;
             triangles [i * 6 + 2] = i * 3 + 2;
             triangles [i * 6 + 3] = i * 3;
             triangles [i * 6 + 4] = i * 3 + 2;
             triangles [i * 6 + 5] = i * 3 + 1;
             uvs [i * 3 + 0] = new Vector2 (0f, 0f);  //wil be first start point
             uvs [i * 3 + 1] = new Vector2 (1f, .5f); //will be end point
             uvs [i * 3 + 2] = new Vector2 (0f, 1f);  //will be 2nd start point
         }
 
         mesh.vertices = vertices;
         mesh.uv = uvs;
         mesh.triangles = triangles;
 
     }
 
     void FixedUpdate () {
         if (Trailchanges) {
             mesh.vertices = vertices;
             //mesh.triangles = triangles;
             Trailchanges = false;
         }
     }
     public void makeTrail(Vector3 start, Vector3 direction){
         trailstart [nextTrail] = start;
         traildirection [nextTrail] = direction;
         if (false) {
             vertices [nextTrail * 3] = start;
             vertices [nextTrail * 3 + 1] = start + direction;
             vertices [nextTrail * 3 + 2] = start + new Vector3 (0f, trailWidth, 0f);
         } else {
             vertices [nextTrail * 3] = start + direction;
             vertices [nextTrail * 3 + 1] = start;
             vertices [nextTrail * 3 + 2] = start + direction + new Vector3 (0f, trailWidth, 0f);
         }
 
         Trailchanges = true;
         nextTrail++;
         nextTrail = nextTrail % maxtrails;
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by BloodMarked · Jan 21, 2018 at 12:41 PM

 mesh.RecalculateBounds();

now i feel dumb for even asking : |

but if anyone knows a way to disable culling on a mesh i would appreciate it

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jan 21, 2018 at 03:59 PM 0
Share

No, you can't disable frustum culling. However you could assign a custom bounds that is large enought so it's always in view. However in most cases any kind of mesh as some limits so it would be a good idea to set a bounds that actually fits the largest possible bounding volume your mesh might have.


Note that occlusion culling has nothing to do with frustum culling.

avatar image charutak · Oct 07, 2019 at 12:36 PM 0
Share

Thanks! This helps me a lot, now I feel dumb for getting stuck at this too :|

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

138 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

dynamic mesh keeps disappearing 2 Answers

Md5mesh uvs and vertices bugging 0 Answers

Finding the height of a mesh 1 Answer

How to get deform information from animating character's mesh 1 Answer

How to prevent frustum culling when using a vertex shader? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges