Is it possible to use lighting effects for the new 2D elements? I've been playing around with the new system and so far it doesn't seem like lighting effects the UI at all. Am I doing something wrong?
You'll need to add a material to your sprites for this which uses the Sprites Diffuse shader. As standard, sprites don't support lighting as we expect users to use them unlit and use lighting baked into the sprite design itself. Simply make a material, assign it to the sprite, and choose the Sprites Diffuse shader from the material as shown in the image below -
Is there a way to set up your 2D elements to cast shadows on 3D objects behind them? Also willgoldstone when's your next book going to be out which covers the new 2D system?
I just want to quickly jump in and say that it would be *really nice* if Sprite Renderer supported dynamic lights. I want to be able to use normal maps with my sprites. It's way too time consuming and memory intensive to use different sprites for different lighting conditions. I noticed that, with the right material, Sprite Renderer responds to the ambient light of the scene. Why does it not respond to dynamic lights?
Will, thanks for your reply and your knowledge. I'm trying to debug a small issue - some of my sprites seem to be quite binary in terms of whether they're lit or not - the two following images show what happens as I move a light source just a tiny bit to the left: Any idea of what setting I have to fix?
I would guess at you simply needing to move the light to the correct Z distance in front of your sprites so they're all hit by it. Remember that 2D in Unity is done with a series of 3D planes with Sprites overlaid.
Weirdly enough, that one block is the exact same Z value as the other level geometry blocks. It seems that this only happens with blocks that I've distorted the scaling of - the scale's no longer 1,1,1.
Resurrecting this thread for anyone still looking for solutions for the binary lighting thing, just figured it out myself. Two important things to check: 1) Is the light's render mode set to "Important"? This should fix the issues with scaled stuff. 2) Are you using scaling or rotation to flip your sprites? Sprite renderers work like textured planes, they only receive light on one side. If you rotate the characters to mirror their direction then the renderer is suddenly facing away from the light, but if you just scale the object by -1 you can flip the character without flipping the renderer's normal.
Im very new to Unity and I am having lighting issues as well. When I turn the built in lights off or on nothing happens. It is the same either way. Ive been trying for days to create lightning with no luck. Could you please explain to a COMPLETE newbie what you mean by, "If you rotate the characters to mirror their direction then the renderer is suddenly facing away from the light, but if you just scale the object by -1 you can flip the character without flipping the renderer's normal"?
You can light sprite only from face(front) side. If you rotate sprite to mirror, then faceside will be in backside and can not be lighted from front. If you scale, then face is still in front. to light try to do: -put sprite on scene -create new material, assign in inspector for the material sprite/diffuse (as in 2. post) -put your material in your sprite -create directional light for test if it work try other light (be sure it is between camera and sprite, so check z-direction) ps. and sorry for my bad english
Hi there, when i choose sprite diffuse i end up with this... Anyone have any idea why? im clueless...
I'm trying to make a 2D game that relies on light and darkness. I have tried the methods above (create Material with Sprites Diffuse and applied it to most of the sprites), but I'm sort of unsatisfied with the results. I would like to have anything unlit to be completely black and the lights to have harder edges and less intense in the center. Where are the settings to adjust this? Can I instead use a Directional or Spot Light rather than a Point Light, and how should I adjust the settings on those? Edit: Never mind. I found the Lighting panel under the Window menu. I then adjusted the "Ambient Intensity" slider to "0" to fill the rest of the scene with complete darkness. I then found that a Spot Light did work for what I wanted and just had to adjust the angle and intensity on that to where I was comfortable with. Though I would like to be able to adjust how hard the light's edge is instead of a softer transition to the darkness. Edit 2: Now I have a new concern. When multiple lights overlap, their brightness stacks rather than overlaps. I'd prefer this to be handled more discretely and simply whether the area of the environment is lit or not rather than how well lit. And more frustrating is that when a sprite seems to have more than 2 light sources affecting it, it seems to be almost completely lit up with a slight gradient to it. Is there something I can do to accomplish this such as making it so only the brightest light in the area is visible?
Hello all, I am working on 2.5D game, i have 3D character and 2D textures for objects that the character can walk behind and in front of them (like layers in 2D games) i put directional light from the left side of the room in order to cast the character's shadow on the right side of the floor, but the light is not hitting my 2D textures and therefore they all looks unlit. Any idea how to solve this 2.5D game issue?
Yes I am using spot lights. I already tried point lights, but the effect of spot lights pointed at the game's plane, creates the effect I wanted or at least almost. This is the scene without lighting, and everything is visible. The light sources are supposed to be the two lanterns and a fairy that follows the mouse. This is the scene with lighting except that one of the lanterns is off for a reason. As you can see, the lighting around the lantern and the fairy works as I intended, an almost distinct circle centered on the source. A point light would have instead have been a light that grew gradually less intense farther from the source. But a complaint about this is that where the lights overlap, the lights are added together and brighter where the effect I want is for it to be more discrete with a consistent or maximum light level within lit areas of the screen. Otherwise, this method works as I intended except for a major problem I'm having with the lighting system demonstrated below. When I turn on the right light, the whole lighting system is messed up. Though the left lantern is on, you can't see the light around it because it is completely illuminating the wall behind it. This completely ruins the purpose of lighting my game. With some experimenting I have found out generally how this bug(?) behaves. It seems that when a sprite is lit by more than two light sources, the left-most source completely illuminates it, and I have noticed that this works with the character's as well as the walls' sprites after moving the lanterns around, and the fairy has this effect when it moves to the left of both the lanterns. Can someone explain how it's doing this and how to stop it? Or possibly if this is due to a parameter on the objects or the engine to increase the limit or whatever a sprite will have of light sources before behaving this way? And as mentioned above, I would like to know how to set a way for overlapping lights to not create brighter regions if possible. I would also like to know if there's a way to get point lights to create this appearance mainly so I can have it so lights don't extend beyond walls and barriers so players don't see into farther areas early.
I tried this kind of lighting. In my game you can place as many blocks as you want, but unity allowed only four lights(at least in vertexlit). Now I am using circular texture with a special shader that lightens pixels behind it and it works fine.
Thanks. That fixed it perfectly. Though I still would prefer if the lighting wasn't additive where it overlaps.
Lights are supposed to be additive, that's how they behave physically. What you're looking for is more like a mask - you probably need a stencil shader.
I've added a Diffuse Sprite Material to my 2d sprite but it still wont illuminate....Any other suggestions?
Hey everyone ! Here is a VERY QUICK tutorial I made on how to get lights work on 2D sprites in Unity !