Author Topic: Weird issue of highlight not showing  (Read 32 times)

wheee

  • Newbie
  • *
  • Posts: 5
    • View Profile
Weird issue of highlight not showing
« on: April 15, 2021, 05:28:21 AM »
Very odd issue - here are two scenarios:

1. multiple gameObjects, each with a Highlight effect component loading from a profile - enabled by default.  When viewing in editor or in play mode, the highlight effect does not show.  But if I go to the profile and modify any parameter, the outlines suddenly show up.
2. a gameObject with the Highlight effect component, and it's enabled programatically via script.  But the outline doesn't show up.  However, when I find the gameObject in the Hierarchy and select it (the one specifically with the Highlight Effect component) then the outline appears.

It sounds like some sort of odd refresh issue.  Have you run into this?

Oddly enough, I have another scenario where I programatically enable the highlight effect and it works... it's part of animation tho. 


wheee

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Weird issue of highlight not showing
« Reply #1 on: April 15, 2021, 06:39:26 AM »
Ok, so I dug through the highlight effect source code and figured out the issue.  In my scenarios, when the scene is loaded and the game objects are being rendered, the HighlightEffect components are enabled already BEFORE the mesh(e) are added to the game object as children (or set explicitly on the mesh filter).  Because of this, it seems like the SetupMaterial isn't called, which in turn doesn't set the command buffers and therefore no outline is rendered.  

By clicking on the gameobject in the hierarchy, the Highlight effect editor#enabled method is called which calls Refresh and that's why the outline is rendered afterwards.

If I call Refresh after the meshes are set then the outlines are rendered properly.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6869
    • View Profile
Re: Weird issue of highlight not showing
« Reply #2 on: April 15, 2021, 09:24:31 AM »
Hello,

Yes, you're right indeed and that's not uncommon when using any procedural or scripted based geometry.
The Refresh() method is there to ensure Highlight Plus uses the latest meshes.

It might not be very clear but this is covered in the page 6 of the documentation ("Using scripting to add effects").

Regards

wheee

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Weird issue of highlight not showing
« Reply #3 on: April 15, 2021, 03:18:07 PM »
Note to self to re-RTFM again =)

If I can, I have a question about your GPU instancing implementation.

I'm finding myself transitioning away from using game objects and instead using meshes and rendering them via GPU instancing which is why I ran into the above problem in the first place.  Now, I'm wondering if it's possible to have one highlight effect for multiple instances of the same mesh. 

One scenario is that I have say hundreds of asteroids that are composed of 3-4 different asteroid meshes that have varying TRS (transformation, rotation, scale).  I would like to be able to highlight all/some/none of the meshes with only using 3-4 highlight effects and updating their Material Property blocks as needed.

I haven't inspected your GPU instancing code in much detail yet but what are your thoughts on that?  Is that possible or will I need to extend the code to support this?

EDIT: alternatively - Please correct me if I'm wrong - I'm assuming that the HightlightEffect generates a special mesh that is rendered by the renderer pass.  If I get my hands on that mesh when it's rendered, I wonder if I can handle the GPU instancing for it and the renderer pass will still handle it correctly.

Thanks!





« Last Edit: April 15, 2021, 03:23:22 PM by wheee »

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6869
    • View Profile
Re: Weird issue of highlight not showing
« Reply #4 on: April 16, 2021, 10:07:20 AM »
Highlight Plus uses the API DrawMeshInstanced() to render multiple times the meshes when drawing the glow or outline effects in a single draw call (only in mesh-based mode, in screen-space mode it uses a bloom-like method). This method is designed to render the same mesh multiple times. Because this asset is designed to highlight multiple different objects, it assumes that each object can have its own different mesh. It also supports standard 3d meshes or skinned mesh renderers which work differently.

The asset has an "Include" option in the inspector that you can use to use a single Highlight Effect script (ie. attached to the root of a group of asteroids) so the entire group is highlighted and acts as a single object. But each object effect (outline, glow, etc) is rendered separatedly in that group.

The asset also has the option to combine meshes automatically. This is useful for static elements (ie. do not rotate individually) which you want to highlight as a single group. In this case adding a Highlight Effect to the root of that group and checking the "Include" to cover the entire group and also using the "Combine Meshes" option, will reduce the draw calls dramatically.

You could add a Highlight Effect to the root of all asteroids and use the "Combine Meshes" option. Highlight Plus will generate a single mesh and render all the effects over all asteroids in one or two calls (depending on the number of effecfts). However as you can see, this only works if the individual asteroids don't move or rotate independently.

The alternative would be grouping the asteroids by mesh type and having a single Highlight Effect at the root. Then redesign the interior logic so it can apply the same effects to the string of meshes in that group using the same API referred above. This would require a major rewrite of the asset as the main code responsible for rendering the effects (in DoOnRenderObject()) is not designed for that. For example, you will need to implement culling as well, since the GPU instancing method assumes you perform culling by yourself and only include the visible asteroids in the array of instances to be passed to the method.

Note that this can only work for non-skinned meshes.








wheee

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Weird issue of highlight not showing
« Reply #5 on: April 17, 2021, 06:04:23 PM »
The alternative would be grouping the asteroids by mesh type and having a single Highlight Effect at the root. Then redesign the interior logic so it can apply the same effects to the string of meshes in that group using the same API referred above. This would require a major rewrite of the asset as the main code responsible for rendering the effects (in DoOnRenderObject()) is not designed for that. For example, you will need to implement culling as well, since the GPU instancing method assumes you perform culling by yourself and only include the visible asteroids in the array of instances to be passed to the method.

Note that this can only work for non-skinned meshes.

Thanks for the response.

It sounds like the alternative method is what I need to do.  I have my own GPU instancing framework (adapted from the GPUInstancer asset) and it handles the culling and what not already provided I can get access to the highlight effect meshses.  But yes, sounds like something that will take me at least a few days to figure out and come up with a way that won't require me to change too much of the internals of your asset to protect me from future updates.  The GPU Instancer doesn't have a render pass whereas Highlight Effect does so I would need to understand the implications there. 


Quick question: is there any sort of LOD built-in or should I handle it manually?   I noticed the outline thickness is as thick zoomed out as when zoomed in.  Not hard to solve jus wondering if there's something I can leverage.



By the way, have a suggestion... more of a nice-to-have (and probably not worth the effort it at this point but food for thought):

Currently when I use Highlight effect, I primarily use it for the outline effect itself so the rest (outer glow, inner glow, etc) are kind of noise to me.  It would be nice if you could collapse unused effects  in the inspector (ie. when their respective value is 0).

A more robust (definitely more expensive way) is to have a separate dedicated component for each effect and simply add them in as needed to the "core" highlight effect component.  This would have some implications on how you handle profiles but it would have nice net effect of breaking up the code itself into smaller pieces.  Highlight effect is a rather huge file.

Thanks again!