Hot answers tagged

62

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 ...


40

When you have a static (non-moving) light in a game, you have two options for rendering this light. You could render it the same as a dynamic light; that is, feed it through the shader pipeline which will calculate its effect on everything around it, every frame, on its way to the screen. This is obviously pretty expensive. Or, an editor can bake the light ...


36

You could overlay a simple glow effect texture with soft transparent edges. If you want lighting/shadows similar to what you may find in a 3d world you could do something like this: http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/. However, if you are new to HLSL, then that may be a little bit too much. edit: I ...


34

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 ...


32

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 ...


25

I'm not sure why so many answers claim this is difficult or impossible. Handling a few dozen dynamic point lights is pretty conventional for a modern deferred rendering pipeline running on PC. Here's a quick example I cooked up: I use this script to dynamically spawn enough lights for my max particles (make sure you adjust your Particle System settings so ...


24

There are generally two methods for dealing with this. Nowadays, they are called forward rendering and deferred rendering. There is one variation on these two that I will discuss below. Forward rendering Render each object once for every light that affects it. This includes the ambient light. You use an additive blend mode (glBlendFunc(GL_ONE, GL_ONE)), so ...


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

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 ...


21

It uses a bloom shader. That's a post-processing effect that makes bright areas of the rendering appear to glow.


20

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 ...


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 ...


16

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 ...


16

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; ...


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

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 between the ...


13

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 ...


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 ...


13

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. ...


12

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 ...


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 ...


10

With the ambient light your objects appear too bright because the diffuse light is added to the ambient light, and the diffuse light defaults to 1.0. This adds up to 1.5, and everything above 1.0 is clamped. Set the diffuse light to 0.5: float difLight0[4] = {0.5f, 0.5f, 0.5f, 1.0f}; glLightfv(GL_LIGHT0, GL_DIFFUSE, difLight0); The second problem is ...


10

Many effects use a standard lighting rig which uses 3 lights similar to how a movie company would film a movie. Here is a wiki link: http://en.wikipedia.org/wiki/Three-point_lighting here is an XNA specific blog about it (concepts can be applied to OpenGL too): http://blogs.msdn.com/b/shawnhar/archive/2007/04/09/the-standard-lighting-rig.aspx


10

Neat idea for the game. The problem is that light really doesn't look like this. Light decay is NOT gausian :). That's for the begining. What i want to propose is adding simple (but relatively physicaly correct) fog or dust. Mean volumetric effect. You will have to implement volumetric raycasting on the gpu. Don't panic. It is not that hard as it might sound....


10

Simplest option is to grab the lighting from the block your standing on (or if possible the lighting on the block in the air that corresponds to the block the pickaxe is in) and use that for lighting the pickaxe/player. Or in other words, calculate the lighting for the pickaxe as if it was a block in that position. To get more realistic shadows you would ...


10

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 ...


10

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. ...


10

Other then the particale system and halo effects Vadim mentioned you could create your own shader effect. There is some introduction to shaders for Unity and the possibilities are endless.


9

Indeed, that is all you need for radiosity. There are two different (but equal) formulations. The first is to "radiate" or shoot light from each patch (in your case probably a face), and the other is to "gather" or receive light into each patch. If you iteratively do this enough times, you get radiosity. The first step is to figure out where light ...



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