66

This is one case where it's useful to steal ideas from Hollywood, who have been doing this for decades. Typical hollywood night scene, also related question from Movies.SE The picture above was filmed during the night time, but it's not actually a dark picture. Notice how the actors' faces are very well lit, although the sky is pitch black and the ...


43

Expanding on TomTsagk's correct answer, I thought it might help to describe a bit more about why games work like this. Light in games doesn't really "travel" from the source, to the surface, to the camera, getting obstructed along the way. To figure out how bright to draw each pixel of a surface based on a given light, we use (or approximate) a math ...


39

The attenuation function you've got, att = 1.0 / (1.0 + 0.1*dist + 0.01*dist*dist) is a fairly common one in computer graphics - or, more generally, 1.0 / (1.0 + a*dist + b*dist*dist)) for some tweakable parameters a and b. To understand how this curve works it's helpful to play with the parameters interactively. This curve is nice because it approaches ...


34

specular lighting of directional light more area has specular lighting when camera is far from an object Yep, looks right to me. The specular area for directional lights is supposed to be more or less constant w.r.t. the camera, given the same reflection surface. To compare, we can look at the phenomenon known as sunglint, which is basically specular ...


33

Real-life soft shadows have a shape that depends on the shape of the light source as it appears from the point of view of the shadowed surface. This is because penumbras occur due to partial occlusion of the light source from the shadowed surface's point of view. The shape of the shadow is therefore something like the shape of the occluder convolved with ...


31

Heads-Up: This answer is outdated. Unity now supports point light particles natively. Please see this answer for full details. I'll leave post this here for anyone curious, or using old versions of Unity, or needing more manual control than the native method offers - just note that the native support is likely to be much more efficient and scalable than ...


25

Use an animated texture.* There are some good ones in the store for < $10. Add a Halo. You can use the particle system, or just a transparent glow texture on a billboard in front of the sun with a script to re-position the texture when the camera moves. This hides the aliased edges of the sphere model, allowing you to use a lower poly model, and looks ...


23

This is simply a kind of optimization given that invSqrRadius = 1/SqrRadius, instead of calculating the inverse squared radius for each light every time they simply cache it, the reason is that division is usually a "slow" operation at least when compared to multiplication. This optimization is relevant especially: when the operation is done a huge amount ...


22

Long story short, this happens for performance reasons. When there's a light on the screen, by default it shines on all objects (obstructed or not), so the game would need to make extra calculations to see which object is affected by what. This is easier to solve on static objects by using static and baked lighting, but this is not the same on dynamic ...


21

Light, from point-like sources, falls of with the square of the distance. That's physical reality. Linear attenuation is often stated to appear superior. But this is only true when working in a non-linear colorspace. That is, if you don't have proper gamma correction active. The reason is quite simple. If you're writing linear RGB values to a non-linear ...


21

In traditional Blinn/Phong shading, you calculate the diffuse term for a pixel by measuring the cosine of the angle between the normal at the surface and the direction of the light. So, in this case, a simple shader would look something like this: float DiffuseCoeff(in float3 pos, in float3 normal, in float3 lightPos) { float3 lightDir = lightPos - pos; ...


18

After initially being puzzled about this question, because it felt natural that objects don't change their brightness depending on the distance to the eye (or camera), but only depending on the distance to the light source, I did a quick google search and found this great article. It is about this exact topic in photography and explains why the distance ...


17

I've implemented something similar to this. I wrote up a post about it on my blog: byte56.com/2011/06/a-light-post. But I'll go into a little more detail here. While the codeflow article linked in another answer is pretty interesting. From what I understand, it's not how Minecraft does its lighting. Minecraft lighting is more cellular automata then ...


17

This is a much bigger topic than can be covered in an answer, but briefly: Physically-based shading means leaving behind phenomenological models, like the Phong shading model, which are simply built to "look good" subjectively without being based on physics in any real way, and moving to lighting and shading models that are derived from the laws of physics ...


17

Physically-Based Rendering You're on the right track when you say "it tries to mimic how light reflects in real life, which is it usually gets split to two components, specular and diffuse depending on the type of material." But we've been modelling materials with specular and diffuse in games & computer graphics for a long time. The trick is that we ...


15

How do objects show color? Well, an 100% red object looks red because it absorbs all other wavelengths of light (orange,yellow,green..you know, a rainbow) and reflects only red. So what if you shone pure blue light on a pure red surface? Well it would absorb the blue light and reflect.. nothing. Hence black. I'm sorry for the terrible picture


14

There are a huge number of ways of doing this. These will require the use of a shader and I am presuming that you are already doing per-pixel lighting. The following are some suggestions, however finding the technique that's right for you might take a lot more research. Quick and Dirty You can specify bounding boxes which define interior areas. If the ...


14

I imagine if I was going to build such a shader there are certain phenomenas that I will start with. First the sunlight is directional, meaning it does't have position nor attenuation. Second the diffuse component is simply calculated by taking a dot product between the sun direction and the surface normals, adding normal mapping might add to the detail. ...


13

Select the Light object Go to Inspector Light And change rendered mode "Auto" to "important"


13

Amit Patel has written a very nice article on 2D ray casting. This involves casting rays to each of the vertices inside the range of the light source to build a light mesh. All of the visual examples are interactive in the post and very easy to understand. You don't have to limit yourself to a box either, the perimeter you trace can be any shape you like....


13

Your lighting equation is physically correct. However, in real life, one almost never sees highly pure colors. (An exception is when lasers are involved.) That's probably why your intuition is that red * blue = violet - a more realistic red might be something like (1, 0.1, 0.1), and a blue (0.1, 0.1, 1). Multiply those and you get (0.1, 0.01, 0.1), which ...


12

I don't know what you're programming in, but this is how I handled it in XNA: On the draw call, a List<Light> object is created/cleared. During the tile draw loop, each tile is checked to see if it has any Lights associated with it. If it does, the Light objects are appended to the List<Light>. The tiles are drawn onto their own RenderTarget2D. ...


12

Going to try and doodle up what I mean here as soon as I finish typing this, but: What about merging the two? Use the second (occlude by base) for everything that isn't a wall and the first (occlude by tops) for lighting the walls? You actually did this by accident in your second example, with the wall that goes off the bottom of the image. Extending ...


11

Assuming you don't want to use standard shadow mapping, you could use a signed distance field to do it. This involves building a texture that tells you, for each pixel, the distance to the nearest opaque surface in any direction. The distances are negative when you're inside an opaque object and positive when outside (this allows the surfaces to be ...


11

The colors in a normal map represent the normals at each point. If a normal is (x, y, z), the corresponding pixel in the normal map will have each of x, y, and z mapped from the range (-1,1) to (0,255) to get the red, green, and blue components respectively. Now the z-axis is typically used as the direction away from the surface. A perfectly flat surface, ...


11

In deferred shading all the material properties are rendered into the G-buffer, e.g. albedo, normals, roughness, metalness, etc. that are needed for BRDF evaluation. After this step shading is performed for pixels within light volumes using light and material properties as input to the BRDF. The problem with deferred shading is that more complex BRDF's (e.g. ...


11

It's a peak in a function defined in polar or spherical coordinates. If we look at the function y = cos(x) in rectangular coordinates, it looks like a wave, with peaks at 0 and 2pi: If we look at the function r = cos(theta) + 1 in polar coordinates, it looks like a bulge, or "lobe" that's greatest at 0: (Images above via Wolfram MathWorld) The same thing ...


11

The Cell Shader To create a similar effect you will need two or three diffuse textures for the same number of brightness steps. Use smoothstep with a small range to soften the colour band transitions. As BotW uses different colour hues not just brightness steps for the dark and bright areas of each "colours" you need different diffuse textures. You can't ...


10

Okay here is one very simple method to create some simple and smooth 2D lightning, render in three passes: Pass 1: the game world without lightning. Pass 2: the Lightning without the world Combination of the 1. and 2. pass which is displayed on the screen. In pass 1 you draw all the sprites and the terrain. In pass 2 you draw a second group of sprites ...


10

The reason to use spherical harmonics is to approximate the incoming light distribution around a point—typically indirect light calculated by some global illumination algorithm. Then the BRDF is also approximated with spherical harmonics, to allow efficiently calculating the outgoing light seen by the viewer, by taking the dot product of the incoming light ...


Only top voted, non community-wiki answers of a minimum length are eligible