Search Unity

Procedural Mesh with Animated Height Map

Discussion in 'Scripting' started by len, May 21, 2007.

  1. len

    len

    Joined:
    May 15, 2007
    Posts:
    4
    I'm trying to tweak the procedural sample project (GenerateHeightMap) found on this site to accept an animated height map and can't figure it out.
    I get a single frame rendered fine and have added code to update the Texture2D frame attribute, but the GetPixel call still doesn't want to read anything but the first frame's imagery.

    I've debugged it to the level of seeing that the Texture's frame attribute is being updated (I can read and print the value) but no visible animation.
    Very strange.
    If I add a small changing term I get that animation, indicating that all the functions are getting called correctly.
    It's almost as if the texture frame change isn't getting into the pipeline correctly.
    Any one have any thoughts on this? I'm totally stuck.
    Thanks!
     

    Attached Files:

  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,768
    I think in 1.6.2 GetPixel doesnt take into account the frame.

    I'd suggest you just use a bunch of seperate textures as the input.
     
  3. len

    len

    Joined:
    May 15, 2007
    Posts:
    4
    That WOULD explain what I'm seeing.

    If I do switch to using separate texture files, how would you recommend I go about switching them in to the displacement script?
    I've tried constructing the Texture2D name via:

    GetComponent("DisplaceMesh").heightMap = "textureFile.000"+frameIndex;

    where the individual texture files are named: textureFile.0001, 0002, etc.

    But the string I'm building needs to get re-cast into a Texture2D object for this to work.
    How could I pull this off?

    Thanks!
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,768
    var textures : Texture2D[];

    Gives you an array which you can arbitrarily resizes in the inspector and assign textures to.

    Alternatively you can use Resources.Load via name as you suggest.
     
  5. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    is there a working iteration of this?

    I was going to apply a render texture to a height map and just displace that once per frame.

    [edit] or just a single image to displace a plane [/edit]

    Any advice?
     
    Last edited: Jun 30, 2014