Search Unity

Turn Screen-Capture Images into Low-LOD Geometry

Discussion in 'Assets and Asset Store' started by pvancamp, Feb 26, 2015.

  1. pvancamp

    pvancamp

    Joined:
    Feb 13, 2014
    Posts:
    6


    Hi all.

    I was creating a 3D game in Unity and found that I needed to reduce my polygon count to improve performance. A common solution to this common problem is to take renders of objects and place those images on to billboards or simplified geometry and use those as a low level-of-detail (LOD) representations. To my surprise I found very little support in the Unity Store for solving this problem. (There is an "Imposters" plug-in but that was not exactly what I needed.) Consequently I wrote my own and have chosen to publish it for others to use as well.

    My solution for render-based Low-LOD geometry is in the form of two assets. One is a free asset called "LOD Billboards" that takes a screen captured image while the game engine is running and converts it into a billboard prefab that sits at the camera's near-clipping-plane position. There is an on-screen dialog for setting clipping planes and a button for turning the screen-capture into a billboard prefab that can be dropped into the game. The resulting image has an alpha channel which makes the background transparent.

    Here is a -> link to the asset page. <-

    My second asset is called "LOD StandInGeo" and it is the same idea except that it puts the image onto a grid that has been conformed to the shape of the objects it is replacing by ray casting from the camera to collision objects in the scene. It also offers subdivision refinement for improved edge shape matching. A link to that one -> is here <-

    And here is a link to a webplayer demo and another link to the pdf documentation.

    If you should find the plug-ins to be useful then feedback would be appreciated.

    Thanks.

    PVC
     
    jdraper3 and mgear like this.
  2. Veggie

    Veggie

    Joined:
    Apr 3, 2013
    Posts:
    5
    Looks good but your asset description and screen shots are very obscure to its exact purpose. My advice is to use an individual object, instead of a scene, and show its transformation from high to low poly instead.
     
  3. Captain-Awesome

    Captain-Awesome

    Joined:
    Jul 29, 2014
    Posts:
    28
    This is a great idea, I found it accidentally while searching for campfires.

    You know where it would be most useful? For grass and trees. I had the nicest lawns and trees in my town, but the frame rate dropped from 90 fps down to 15 fps, so I had to get rid of most of it and billboard what was left by turning down the LOD quality settings. (this was on my PC with a 5 year old graphics card)

    If you could do a version that billboards trees and grass nicely, you might win a Nobel prize. (okay maybe that's a small exaggeration :)
     
  4. pvancamp

    pvancamp

    Joined:
    Feb 13, 2014
    Posts:
    6
    That award would have to go the makers of Unity's Terrain object. Look there for what you seek.
     
  5. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Awesome asset! Just one question, is there a way to get the capture of the geometry to have a clear background. For example, you say to isolate an object, or group of objects. A group of trees for example... Well I don't want the skybox to show up behind the trees, because the player will be able to see the skybox in the not moving in relation to the actual skybox.

    Also I'm getting this weird result where portions of the stand-in get clipped.




    Even when I copy your Example scene's PVC_Billboards (Script) settings exactly, I still get a bit of clipping on the top and right.
     
    Last edited: Mar 5, 2016
  6. pvancamp

    pvancamp

    Joined:
    Feb 13, 2014
    Posts:
    6
    Do not use a skybox when making standins. The tool works by taking two screen captures -- one where it sets the background to black and one where it sets the background to white. It then does a pixel by pixel comparison to determine where the image should be transparent due to the change in color and it sets the alpha channel accordingly.

    As for clipping, it all depends on the position of your camera and how you set the clipping distances.

    PVC
     
  7. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Well I'm talking about the white area on the stand in. It's not clipping. When I test out your Example scene in the asset package, I get absolutely no white area in the shots I take in the Example scene. However, when I make my own scene (with only the tree) and use the exact same Camera settings and PVC_Billboards settings as you did, I get that white area. The picture below shows it best. It's a scene view of my stand in...with the 3D model disabled. So all you're seeing is the stand-in object in the scene view. Any idea why I'm getting that white area?

     
  8. pvancamp

    pvancamp

    Joined:
    Feb 13, 2014
    Posts:
    6
    My first thought was that your Viewport Rect settings might not be right but I was not able to replicate your results. Clearly there is something different between your scene the given example scene. I suggest you start with the example scene and change things to meet your needs or else export the example camera as a prefab and bring it into your scene.

    Goog luck.

    PVC
     
  9. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Well I went into the example scene, deleted your geometry, and added my tree. Pressed play... Made the billboard. Worked PERFECTLY! So, in the same project, I opened a new scene, added my tree, added the PVC_Billboard script, pressed play, made the billboard, STILL got that white area! >< I have no idea what the issue is.

    However, trying to move forward... You mentioned:
    I'm not getting this. Even in your Example scene, it still has the solid blue background. Can you explain more how to get the background to be transparent, while still having the actual objects displayed in the billboard?
     
  10. pvancamp

    pvancamp

    Joined:
    Feb 13, 2014
    Posts:
    6
    The fact that the background is blue means that the script is not able to modify the background color which is true if you are using a skybox. The code for what it does is very straightforward. Since you work in Unity I assume that you have some familiarity with C# code. Below is the code that takes the two screen captures -- one with a white background and one with a black background and then sets the alpha channel based on pixel color changes.

    Code (CSharp):
    1.  
    2.     /// <summary>
    3.     /// Use ReadPixels to capture an image from the main camera.
    4.     /// </summary>
    5.     /// <returns>The captured image.</returns>
    6.     /// <param name="pRect">pRect is the rectange of the camera view which is to be captured.</param>
    7.     Texture2D _captureView(Rect pRect) {
    8.         Color oldBackgrd= _camera.backgroundColor;
    9.  
    10.         _camera.backgroundColor= Color.white;
    11.         _camera.Render();
    12.         Texture2D wOut = new Texture2D((int)pRect.width, (int)pRect.height, TextureFormat.ARGB32, false);
    13.         wOut.ReadPixels(pRect, 0, 0, false);
    14.  
    15.         _camera.backgroundColor= Color.black;
    16.         _camera.Render();
    17.         Texture2D bOut = new Texture2D((int)pRect.width, (int)pRect.height, TextureFormat.ARGB32, false);
    18.         bOut.ReadPixels(pRect, 0, 0, false);
    19.  
    20.         //Generate an alpha to make background transparent
    21.         for(int iy = 0; iy < pRect.height; iy++) {
    22.             for(int ix = 0; ix < pRect.width; ix++) {
    23.                 Color clrW= wOut.GetPixel(ix,iy);
    24.                 Color clrB = bOut.GetPixel(ix,iy);
    25.                 clrB.a= Color.white.r - (clrW.r-clrB.r);
    26.                 bOut.SetPixel(ix, iy, clrB);
    27.             }
    28.         }
    29.         Destroy( wOut );
    30.         bOut.Apply ();
    31.         _camera.backgroundColor= oldBackgrd;
    32.         return bOut;
    33.     }


    PVC
     
    Last edited: Mar 6, 2016
  11. lrb

    lrb

    Joined:
    Jun 21, 2014
    Posts:
    28
    Hi PVC.

    Congrats for the great job!
    Could you explain why the "LOD StandInGeo" aren't more on the Store?

    Thanks.
     
  12. pvancamp

    pvancamp

    Joined:
    Feb 13, 2014
    Posts:
    6
    Hi Irb. I stopped supporting these plugins over a year ago when I stopped using Unity and LOD StandInGeo was a more complicated product for which I had been charging $20. Since It did not make sense to continue selling a product that I can not support and, besides, it was not very popular anyway.

    I hope people find LOD Billboards useful but these days all my game making efforts are directed toward a non-Unity smart-phone party-game app called Icepix: https://youtu.be/1YZt3mF7LiQ