I want to create a dark scene. The player just got a torch in his hands so this is the only light in the scene.
So the rest of the area should have no lights in it. Maybe it's a cave or a dark forest?
In Pokemon you had this effect in dungeons
Here is a rough sketch how I imagine it
So when I want to set the directional light of the scene to complete black color, you can still see good enough.
How can I archieve these effects of having a dark world?
I don't want to use a texture around the player or something like that. Maybe you can still see through darkness but really really badly.
Use this scene as an example of how to do that:
https://github.com/Galandil74/Unity-Spotlights-Example
Basically, as Lestat already said, you set the overall brightness by changing RenderSettings.ambientLight, then to create the torch effect, you use a directional light game object with a texture cookie in order to illuminate only a portion/shape of the screen.
Remember that to get full illumination through the cookie texture, the light must have its intensity propriety set to 1 - RenderSettings.ambientLight.grayScale (if it's a directional light).
I prefer to use directional light because you can then control the effect via the alpha channel of the cookie texture.
And if you're using sprites (for background, etc.), if you want them to be affected by the ambient light, remember to use the Sprites/Diffuse material.
Related
I made a simple game menu in unity, but it's looking way too dark in the game view (and in runtime), I tried:
Window->Rendering->Lightning Settings and set the Environment Lightning's Source to color and Light Grey color, also checked the Auto Generate option in Lightmapping settings but nothing of the above worked, it still looks way too dark. Is there any fix for this?
Sorry for the small image in the first link but I think it's very noticeable the difference in the colors anyway.
In the scene tab, you have to check the little sun ☼ next to the "Shaded" drop down so as to see the real lightning of your scene.
Since you have no light in your scene (except the ambient one) your models look very dark. Add a directional light to your scene (GameObject > Light > Directional Light)
I have a power-up GameObject with a light component attached to it.
The sprite shows up fine, however, the halo effect does not work when the GameObject is placed over another sprite (eg a background wall).
I think its a problem with the material (as I have tried other things such as changing the culling mask, ordering layer, etc) - however, I don't know which properties to change in order to make the light visible.
I am using an area light.
I hope I saw correctly your game is 2D. If so, check out 2D Lights
I am trying to make my lighting similar to Terraria's, block-lighting. Now, I know how to make blocks darker, I can assign blocks to a certain lightlevel, but, how would I make an actual light entity, that emits light in a round shape (Can be diamond-shaped too)?
Help would be greatly appreciated, also, if I wasn't clear in my question, feel free to ask.
Basic 2D lighting is very simple. Just do a distance check from your block, to your light, and use that value to scale your light.
This is something you could do fairly simple, since Spritebatch.Draw has a nice Color tint parameter [link]
A pseudo function could be
distance = (block.position - light.position). Length();
lightPower = distance / light.MaxDistance;
finalTint = light.Color * lightPower;
Render Block, with finalTint
For more nice looking light, you could replace "distance / light.MaxDistance" with a more smooth effect.
If you also want lights to go through a few blocks like Terraria, you could count all blocks between your block and the light source. Scale your lightPower down by that amount, and you get the same effect like Terraria has.
Of course, this is a non optimized way of doing it, but should work.
The latest Terraria version however seems to have smooth per pixel lighting instead of per block [preview]. For that I assume they used a second render target and/or Pixel Shader to keep fast performance. This could be a little difficult if you are not familiar with rendering pipelines though.
Hope this helps!
I'm working on a game with a similar lighting model, and the way we do it is this:
Draw the scene, without lighting, to a render target (called the 'Scene Buffer')
Draw the scene's lights, represented as grayscale gradients of any required shape, to a second render target (called the 'Light Map')
Draw the Scene Buffer to the screen, passing in the Light Map as a parameter to the pixel shader
In the pixel shader, query the value of the Light Map at each pixel and adjust the color of the final pixel up or down as necessary.
This also gives you the ability to have colored lighting; all you have to do is tint the light gradients that you render to the Light Map. Just remember to use additive alpha blending.
The downside of this approach is that it's rather naive, and provides no easy way to occlude the lights (that is to say, they pass through walls). In our case, this isn't an issue; you might decide otherwise.
I have a 3D Modell of a house, where the roof is invisible so that the rooms can be seen
(like here)
But (for now) I have no textures and each surface has the same color, e.g.,
var myMaterial = new DiffuseMaterial (new SolidColorBrush(myColor))
If I view it in a WPF Viewport3D, I want to be able to differentiate between the surfaces.
e.g., I want to see when the floor ends and the wall starts.
This should be possible by lighting the object. I already tried:
Ambient light doesn't work, because all surfaces would look equally colored:
myViewport3D.Children.Add(new ModelVisual3D(){Content = new AmbientLight(Colors.White)})
And if I use directional light and stick its position to the moving camera, some surface normals are sometimes nearly perpendicular to the camera/light and so are nearly black, which looks even more unnatural.
So what is a good way to distinguish the surfaces of a single-colored 3DObject in a WPF Viewport3D?
Edited after user "jdv" wrote his comment
Personally, I find that this can be accomplished the "best" by a combination of two lights.
A dim (maybe 30% lit) ambient light. This always shows all surfaces.
A directional light, at about 80% white, which follows the camera, but is off by 30 degrees or so. I find a light "over the camera's left shoulder" tends to be what people often expect.
Also, if your surface normals are not always going to be correct, you can use a third light - another directional light pointing the opposite direction of the first. This will light the back faces of the surfaces if you've got inappropriate normals.
Since you can use 2 light sources, I would try using a dim light to act as an ambient background light and a somewhat stronger directional light to give contrast to the surfaces.
I am not a 3d expert, but would think of it this way:
In a dark room (no ambient light), with a flashlight (the directional light), you will see dramatic differences based on the angle of the surface to your flashlight. Add some ambient lighting and the harshness of those differences decreases as your ambient light source gets stronger, until at some point, it overpowers the flashlight and everything appears evenly lit.
Good luck, hope you are able to achieve the effect you are after.
HI all,
I'm developing a software to control light show ( through DMX protocol ), i use C# and wpf to develop my main software (.net 4.0)
To help people preview their show, i would like to make a live 3D visualizer...
First, i thought that i could use wpf 3D to make the visualizer, but i need to work with light ..
My main application should send property ( beam angle, orientation (X,Y), position(X,Y), Brush ( color,shape,effect)) to the 3D visualizer
But i would like to be able to move light (position in the scene) by mouse during execution and had value in return...
So ..
Does XNA is the easiest way to doing that ?
Can you help me for that :
Generating light (orientation , bitmap like filter in front of light )
Dynamically moving object with mouse and get position in return
Dynamically add or remove fixture
All of your advice, sample, example are very welcome ... I don't espect to have a perfect result at the first time but i need to understand the main concepts for doing that
Thank You !!
XNA does not contain any functionality for managing a "scene" - you will have to implement that yourself. For example: you might make a Light class containing the information about your light (position, orientation, etc), and then have a List<Light> of them, which you update and render yourself.
I will now assume that you have a 3D model of a "Light" (as in: the metal box containing the lightbulb) and also a 3D model of a stage. And that you can figure out how to render them - there are plenty of tutorials online for simple model rendering in XNA. Here is a starting point.
So your 3rd requirement ("Dynamically add or remove fixture") should be fairly simple once you can render things. Just add and remove Lights from your List of them based on user input. See the Input namespace.
And your 2nd requirement ("Dynamically moving object with mouse and get position in return") should also be simple. If you want your user to move lights by clicking and dragging, just keep track of the mouse position between frames and apply that as an adjustment to the clicked Light's position (or rotation).
To figure out which Light the user clicks in the first place, a good starting point is the Picking Sample.
I am assuming here that the user will click the Light (metal box) itself to move/rotate it. If you would rather have the user click and drag the endpoint of the light (the spot it projects) - that is more difficult. One idea that comes to mind: Intersect a ray from your Light with the stage to find the centre of the projected spot. At that point draw a dummy "handle" object (like a sphere) that the user can click and drag around. When the user finishes dragging, figure out the new orientation for the Light to make that the new centre.
Finally your 1st requirement ("Generating light (orientation , bitmap like filter in front of light )") is the tricky one. My understanding of this is that you want a way to draw the endpoint of the beam of light on your stage model? If so, what you are looking for is called Projective Texture Mapping. Presumably you will have a circular texture for basic lights, and perhaps other textures for gobos.
The quick-and-dirty way to do this would be to draw your stage model, once for each light, with additive blending (so that each light added with the other lights and the black had no effect), with a colour set to whatever you want the light colour to be, and with a black and white texture (a white circle on black background) drawn with TextureAddressMode.Clamp, with a shader that draws the texture with projective texture mapping which is set up with the light as the projection point.