Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Beast Lightmaps to Vertex Colors in Unity (with texture blend support)

Discussion in 'Works In Progress - Archive' started by hausmaus, Mar 12, 2012.

  1. hausmaus

    hausmaus

    Joined:
    Dec 9, 2011
    Posts:
    105
    This started out as a little script that I got interested in and decided to flesh out and do a video for.



    The basic idea here is to store Beast-generated lightmaps as vertex colors. That by itself is very simple: iterate over the object’s vertices and for each one, get the interpolated value of the lightmap at that vertex’s uv2 coordinate, and store that RGBA value as the vertex color at that location. To make these new vertex colors useful, a shader must treat the vertex colors the way it would otherwise have treated the lightmap values.

    The problem here is that you’re giving up all of your vertex color channels to store this lightmap information. You could get around this issue a few ways, but the solution presented here is to copy the original vertex colors, and after you are done with the lightmap conversion, store the first two vertex color channels (RG of RGBA) into UV2. Since UV2 is unnecessary now that the lightmap has been stored as vertex colors, that’s technically a Vector2 array which is available to shaders that isn’t being used for anything.

    As you can see in the video, there are a few ways of organizing this general form of solution. At its core, it’s really just a question of storing useful information somewhere a shader can read it, and writing a compatible shader. That covers too much ground, so a working, fairly intuitive, holistic example provided in the project archive which absolutely does work and should (hopefully!) be useful for mobile or web developers.

    Project archive:
    http://www.vertexcolors.com/shared/unity_beast_to_vertex_colors_deep.zip

    Full post:
    http://vertexcolors.com/?p=60

    Cheers,
    -abm
     
  2. cupsster

    cupsster

    Joined:
    Apr 14, 2009
    Posts:
    363
    Thank You for sharing developement! Maybe I will explore this feature in a while. :)
     
  3. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    Interesting project! Thanks for sharing with us hausmaus :)
     
  4. iisjreg

    iisjreg

    Joined:
    Mar 25, 2011
    Posts:
    101
    Another reason to take a look at shader programming. Good work sir, this looks SUPREMELY useful!
    Thank you.
     
  5. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    Clever approach ;)
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Like it.
     
  7. giyomu

    giyomu

    Joined:
    Oct 6, 2008
    Posts:
    1,094
    nice share :)
     
  8. layola

    layola

    Joined:
    Aug 6, 2013
    Posts:
    94
    Anyone have a copy of the scripts? The website is down.
     
    owenoury and dozhwal like this.