Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Changing a picture inside a "picture frame"

Discussion in 'General Graphics' started by avance70, Aug 5, 2016.

  1. avance70

    avance70

    Joined:
    Aug 13, 2015
    Posts:
    6
    I have a nice frame... just imagine any kind of a frame: e.g. http://www.pptbackgroundstemplates.com/backgrounds/Gold-Embossed-Frame-Backgrounds.jpg

    Inside of it I have a simple quad with a texture that shows a picture.

    What is the best way to change the texture of this quad to show a different picture? (keeping in mind that i have many of these, each with a different picture -- if i just change the texture in the material, all pictures will be the same)

    i.e. do i need multiple materials or is there a "better" solution?
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    One of many options is to put the pictures all on one texture sheet and offset the UV coordinates of each quad - so each quad shows a different picture. If you want to change a picture - change the offset of the UV's to the desired texture.

    I intentionally didn't explain how to accomplish this - because I've never done it, although I know it can be done.
     
  3. kB11

    kB11

    Joined:
    Jan 24, 2016
    Posts:
    89
    I haven't done this either, but I think it should be rather easy to implement. Most of the premade shaders that come with Unity have an offset parameter (which you should be able to access in code), so one could either use those directly or use them as a reference on how to do it.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    If the pictures aren't going to change the best option is to make an atlas (one texture with all of the pictures in it) and make a custom quad mesh for each picture pre-UVed to only show one image.

    Changing the offset parameter means multiple materials just like just changing the texture would.
     
    avance70 likes this.
  5. avance70

    avance70

    Joined:
    Aug 13, 2015
    Posts:
    6
    That's a cool suggestion, it did not cross my mind!

    Just a quick additional question: let's say I have 1000 pictures... would it be better to have 1000 materials or 1000 custom quads?
     
  6. kB11

    kB11

    Joined:
    Jan 24, 2016
    Posts:
    89
    I believe having 1000 quads which use only one material is better because Unity can batch them together and draw them all at once.
     
    theANMATOR2b likes this.
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    This. And technically you don't need 1000 custom quads, you probably want to calculate the quads directly, or maybe just use one quad and modify the UVs using AdditionalVertexStreams. However using 1000 custom meshes doesn't require learning how to program.
     
    theANMATOR2b likes this.