Search Unity

shadder Dissapears with occlusion

Discussion in 'Shaders' started by IndieFist, Jul 22, 2019.

  1. IndieFist

    IndieFist

    Joined:
    Jul 18, 2013
    Posts:
    520
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    An object can be marked as Occluder Static and/or Occludee Static. The important part is the "static" there, that just means the object can't move. Any object not marked as Occludee Static will still be occluded, just without the optimizations that can be used if the object never moves.

    There is no way to make an object not be an occludee.

    If you want something to never be occluded you instead need to use command buffers to render an object which skips the built in occlusion culling. It also skips Unity's lighting systems...

    Alternatively you can use the hack of a script to modify the mesh / renderer bounds to something insanely large. This also disables frustum culling by fooling Unity into thinking it's always in view.
     
    IndieFist likes this.
  3. IndieFist

    IndieFist

    Joined:
    Jul 18, 2013
    Posts:
    520
    Thank you for support.
    I have found a thread with that:
    • mesh = this.GetComponentInChildren().mesh;
    • mesh.bounds = new Bounds(Vector3.zero, Vector3.one * 10000f);

    Maybe this could be a solution, add this to the shader or a simple class inside the objects outline i will have always visible?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    That's c# code. You cannot modify the bounds from a shader.
     
    IndieFist likes this.
  5. IndieFist

    IndieFist

    Joined:
    Jul 18, 2013
    Posts:
    520
    Yes, i have created a file and use it, and workis like a charm.
    I would use that system because i want to reveal some items sometimes to help players to find items.
    Then if i want to get the item in same state before this i have to use:
    public void Normal()
    {
    miMesh.material = outlined;
    miCapa.bounds = new Bounds(Vector3.zero, Vector3.one);
    }
    ?
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    No, because those aren’t guaranteed to be the mesh’s bounds. That’s saying “this mesh is the size of a 1 unit box”, which may or may not be true. It’s better to store the original bounds in the script on Start() or Awake() as a private value and reset it to that afterward.
     
    IndieFist likes this.
  7. IndieFist

    IndieFist

    Joined:
    Jul 18, 2013
    Posts:
    520
    Code (CSharp):
    1. private Bounds oldBounds;
    2.  
    3. void Awake(){
    4. oldBounds = GetComponent<Mesh>().bounds;
    5. }
    6. void RestoreBounds{
    7. mesh.bounds = oldBounds;
    8. }
    9.  
    somethings like this really?
    Ok i will test my fps right now, because i have tested other outline shader options for android and you loss alot of fps. I have to start with studying shaders and get my own :p
    Thank you for support again.
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    That's closer, yes.

    Note that GetComponent<Mesh>() won't work as a Mesh isn't a component. It's an asset. Components are scripts that are attached to game objects, like the MeshRenderer or MeshFilter, the later of which has a reference to the mesh asset as a public property. So really you'd want:
    Code (csharp):
    1. oldBounds = GetComponent<MeshFilter>().mesh.bounds;
    Also note that accessing .mesh will actually create a unique copy of the mesh asset and modify that. This is good in that you're not going to be modifying the original mesh, but may lead to noticeable increase in memory usage if you're not mindful and doing this to a large number of objects. Even if they're all using the same original mesh, each use of that script will be generating a new copy. If this is an mesh that you'll be using a large number of, you may want to be a little more fancy and cache off the original .sharedMesh and new .mesh as a shared static value, then swap the .sharedMesh back and forth.
     
    IndieFist likes this.
  9. IndieFist

    IndieFist

    Joined:
    Jul 18, 2013
    Posts:
    520
    Thank you very much for this leasson, i really apreciate it.
    I only was using with 1-2 objects at same time, but we are a mobile market and we have to do it like you say, thank you.