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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Object selection via projection...help pls

Discussion in 'Editor & General Support' started by Bunzaga, Apr 19, 2009.

  1. Bunzaga

    Bunzaga

    Joined:
    Jan 9, 2009
    Posts:
    202
    I wanted to make an object selection system where I project a texture down onto the terrain so I get a cool effect which I am sure a lot of people have seen in other games.

    Here is a great example of what I mean:


    I thought I would use the 'projector' thing, but I just don't have enough experience with Unity, or projected textures to know what I am doing wrong, or what check mark I am missing, in short, why it's not working.

    I started out by creating an empty game object (so I could rotate the darn thing), then linked the projector to the game object by dragging and dropping it onto the game object.

    I rotated it 90 degrees on the X axis, so it was pointing down, I set it to ortho, because I wanted it to be perfectly round, and I wanted to be able to control the size based on radius.

    I then created a new material, and added a simple 128x128 image I made in photoshop (I saved it as a png, it has some transparancy).

    I then added some objects like cubes, planes, etc to test the effects.

    It didn't work as I had thought...

    If anyone could point me in the right direction, I'd appreciate it. Am I barking up the wrong tree for this? Should I be using a different method?

    The idea behind this, is I am working on a 'Tower Defence' type game and I want to show the range of the tower with one of these projected textures. If all else fails, I could use a hollowed out cylinder, or a sphere, but I really wanted to go with this.

    BUnzaga
     

    Attached Files:

  2. Bunzaga

    Bunzaga

    Joined:
    Jan 9, 2009
    Posts:
    202
    Is this the wrong forum for this question? I thought it didn't really fit the 'scripting' forum because there isn't really any script involved.

    Has anyone tried this before with Unity? Any info would be appreciated.
     
  3. Hanford

    Hanford

    Joined:
    Aug 28, 2008
    Posts:
    166
    I can't tell what's going on in your screenshot. What is it doing? Is it not showing up at all, or just showing up incorrectly?

    What color is the ground plane?

    Are you not seeing your PNG at all or is it there but way bigger than it should be? (I can't tell if the green on your ground plane is the projector or if that's what the ground plane looks like).

    What shader are you using?
     
  4. Hanford

    Hanford

    Joined:
    Aug 28, 2008
    Posts:
    166
    BTW, based on your first screenshot, I'd say you want something like the additive projector shader, which is on the unity wiki here:

    http://www.unifycommunity.com/wiki/index.php?title=ProjectorAdditive

    This one works slightly differently than the multiply one. It didn't appear to support alpha, you need make the BKG black. it's additive so black does not add at all, white adds the most, meaning it's only going to make the surface it's projecting onto lighter; never darker.
     
  5. Bunzaga

    Bunzaga

    Joined:
    Jan 9, 2009
    Posts:
    202
    Hey thanks for responding! Sorry, you are correct, it isn't clear what is going wrong.

    When I added the projected texture, suddenly the entire ground plane turned that color, as if I added the texture to the ground plane itself. Initially all it had was the basic white texture, all new objects come with. Then I thought the projected texture would overlap the cube, but it didn't even effect the cube at all. Then I thought the size of the texture would be contained inside the square of the projector.

    I'll take a look at the link you provided and that is good to know about the 'additive' projector shader. I think I was just using a regular diffuse material.

    Thanks again, I appreciate the help and I'm checking out the link now.
     
  6. Bunzaga

    Bunzaga

    Joined:
    Jan 9, 2009
    Posts:
    202
    Ok so I got it 'mostly' working thanks to that shader.

    I get these weird artifacts though, on the edges where there is color on the border. Any ideas?

    I tried giving it a couple pixels of black for a border, but even then there is a faint beam.
     

    Attached Files:

  7. Hanford

    Hanford

    Joined:
    Aug 28, 2008
    Posts:
    166
    No problem! I was having all these problems yesterday and have been slowly figuring them out myself.

    The issue you're seeing there is the "Clamp" effect. You've got color out to the edge of your PNG and so it repeats that single pixel edge forever. The solution is to make sure your PNG has a 1 pixel of nothing border. (nothing = black for the additive projector, transparent for the multiply projector). Make sure when you do this you keep your image as a power of 2 size.

    You say you've done that already, but double check your image to make sure there's nothing faint in there. I had the problem and giving it the border fixed it.

    You can also have the projector project onto the ground only by setting a layer for the ground an assigning the projector to only affect that layer.
     
  8. Bunzaga

    Bunzaga

    Joined:
    Jan 9, 2009
    Posts:
    202
    Chances are that the border pixels were being distorted because initially I was just using paintbrush and when it saves as .jpg it blends colors around. After that I used Photoshop and as you said, the borders were pink, so it repeated that color.

    When I resized the image, and then set the canvas to a bit larger, with a few pixels of black, it worked perfectly.

    Thanks for all the help, I would never have figured out the additive shader thing.
     
  9. Hanford

    Hanford

    Joined:
    Aug 28, 2008
    Posts:
    166
    yeah, the additive shader thing is a bit tricky. I've played with particles and noticed they had add and multiply (which are also layer types in Photoshop) so I knew what was going on and what to search for when I discovered normal materials weren't projecting correctly.

    The weird part is why Additive and, hell, just a "project with transparency mask" shaders are not included in the standard assets package. I think I'll put in a request.
     
  10. Maker16

    Maker16

    Joined:
    Mar 4, 2009
    Posts:
    779
    Just want to jump in on this and ask a question about something that was mentionted earlier. You said the additive shader will never make anything darker. So, can I not use this to project shadows?
     
  11. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    To project shadows use the blob shadow prefab that is included in the Standard Assets package.
     
  12. simone007

    simone007

    Joined:
    Oct 30, 2008
    Posts:
    221
    This thread is very interesting for me.

    I have a question: what's the meanining of the second texture in the additive shader?
     
  13. EdwinFoe

    EdwinFoe

    Joined:
    Apr 14, 2015
    Posts:
    3
  14. EdwinFoe

    EdwinFoe

    Joined:
    Apr 14, 2015
    Posts:
    3
    i use unity 5.0.