Hot answers tagged

48

Shadow mapping and stencil shadows (shadow volumes) are definitely the big two, as you've mentioned, so I'll stick to comparing the two. And since you've pointed out the most obvious shortcomings of shadow mapping and advantages of stencil shadows, I'll do the opposite. Stencil shadow shortcomings Shadows match the shape of the casting mesh. This is very ...


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


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


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


18

I think everybody's giving way too complicated solutions to this problem.. So first, we have the card (or whatever you want to draw), depicted here by (a). Next, we take a copy of it, fill it in black and run a gaussian blur on it (b). All of this happens in photoshop or whatever your favorite art tool is. Next, in-game, when we want to draw the card, ...


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


10

http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/ gives a nice overview over the basics. http://en.wikipedia.org/wiki/Shadow_mapping links to a multitude of research papers describing different improvements and optimisations. Shadow volumes have been 'the thing' a few years ago. http://en.wikipedia.org/wiki/Shadow_volume ...


9

I'm wondering how the bigger studios get around this problem. They get around it by not using stencil shadow volumes. It's really not a good technique, and it doesn't work very well with deferred rendering, which is the direction a lot of the industry is going in. Yes, it's nice in that it's pixel accurate, unlike shadow maps. But the many downsides (...


8

Regarding the self-shadowing, I'm not sure just what you're referring to - I don't see any "shadow acne" on the crate in your screenshot. If you mean that the faces facing away from the light are dark, well, of course they are - they should be! :) The side face does look a little weird, split down the diagonal into half lit and half shadowed. If you're ...


8

You could apply the bias when rendering the shadow map, instead of when sampling it. I think that's the usual/"standard" approach to shadow map biasing, actually. BTW, if you want tan(acos(something)), it's probably faster to calculate sqrt(1 - something^2) / something, which is equivalent (using some trig identities). Generally if you're combining ...


7

These can be done using shadow mapping. Basically, place the camera at the light source and render the scene into a depth buffer; the resulting buffer identifies all the lit surfaces since they are just the surfaces the light can "see". This texture is then used in the pixel shaders in the main render to mask away light on surfaces behind the shadow map. ...


7

I tried recreating this and to me it seems like the light source is fixed correctly, e.g. here the light source remains to the top right of the figure: So I think maybe what you're doing wrong is the order in which you apply the rotation and the offset. You need to apply the rotation first, and then the translation. (And if you had a scale, it would also ...


7

The problem is that "cheap" lighting is a calculation based solely on the light source and the object it is applied to, any possible intermediate object that would block the light is not a part of the calculation. Therefore a lot of games use such lights coupled with some shadow system.


6

Once you have the position of the shaded point, it's just the same as applying a shadow map in regular forward lighting. You need to convert the shaded point to shadow map screen space, which means getting its world position and then transforming it through the same view and projection matrices used to render the shadow map. You can bake all down into one ...


6

Your alpha-blended objects should not participate in a depth pre-pass. For a given final pixel, its color will be a number of colors blended together at different depths: the portion of the color furthest away from the camera will either be the sky/background or an opaque object, and all the other contributions will be from semi-transparent objects. And if ...


6

You should not shadow the polygons that are back faced from the light. I changed your fragment shader to below code. float CalcShadowFactor(vec4 lightspace_Position) { vec3 ProjectionCoords = lightspace_Position.xyz / lightspace_Position.w; vec2 UVCoords; UVCoords.x = 0.5 * ProjectionCoords.x + 0.5; UVCoords.y = 0.5 * ProjectionCoords.y + ...


6

Finally got it working!!! The problem indeed was in the fragment shader. First of all, there was no need to invert the position, the error came from the UV coordinates. Finally I remembered when I was using XNA the textures where flipped vertically respect to OpenGL, and that was the problem. After flipping the V coordinate and correcting the reversed ...


5

A simple suggestion and something I recently put into my game. For all the horizontal upward faces, find if they are also the base of an adjacent horizontal face. For example, when I'm building my VBOs I run some code like this: Color[] colors = new Color[4]; Color faceColor = GetColorForFace(x, y, z, face); colors[0] = faceColor; //mpp ...


5

As promised, I have written a very long article about how I optimised the shadow renderer in my game "Dark". (source: andrewrussell.net) My article goes into a lot of detail, reaching a whopping 2500 words, plus illustrations, so I won't repost it here. But I will give a quick overview: There are two major things that I had to optimise, for Dark: First ...


5

I did a quick sketch of how it could be done. Yellow round thing is the Sun, obviously, grey things are rays and black ones are boxes. The blue lines are the shadow triangles and yellow dots are the vertex points. You cast rays down from the Sun to the edges of the blocks and through them. Take the vertices where it hit the box and the ground. Then you ...


5

try using a multiplicative "bias" instead of additive: shadowCoordinate.z *= 0.98; If you're doing the sampling yourself rather than using the shadow comparator interpolating the shadow map helps reduce acne a lot. There shouldn't be any shadow visible behind the object as the light should not affect it with the light being completely occluded by the ...


5

In the Unity docs under shader references. Shadow mapping macros Declaring and sampling shadow maps can be very different depending on the platform, so Unity has several macros to help with that: UNITY_DECLARE_SHADOWMAP(tex) - declares a shadowmap texture variable with name “tex”. UNITY_SAMPLE_SHADOW(tex,uv) - samples shadowmap texture “tex” at given “uv”...


5

Realtime shadow maps allocate texels for everything the light can see. Lightmaps allocate texels for everything. This makes a big difference in several cases: faces occluded from the light don't contribute any information to a shadow map - they occupy the same texels as the object occluding them. A lightmap will allocate separate texels to shadowed faces. ...


4

Disadvantages: Lightmaps are very large textures. If you have enough processing to make all shadows dynamic you can probably use the memory for something else. Non unified lighting model. Some lighting models like deferred don't mix well with prebaked shadows. Light mappers are usually very slow. You need to wait few hours to preview lighting changes in the ...


4

Finding the surface and applying ambient light To find which tiles are on the surface and should receive some ambient light, in a very simple way, how about doing a one dimensional (vertical only) flood fill starting from the sky? In other words, you start at the top of your world, one column at a time, and search downwards until you hit a solid tile. All ...


4

One possible solution would be drawing edges along where the terrain changes height in dark black. So, the effect generated would look like height lines.


4

I don't see any special shaders there, just some vertex colors that are generated with an ambient occlusion (or similar) calculation algorithm and perhaps some differently calculated vertex normals. The results remind me of a demo I've seen some time ago which simulated global illumination by "bending" vertex normals and generating occlusion values for ...


4

You should set your far plane to infinity for shadows, instead of setting a far clip distance of 1000. Also, for a ratio of far/near of 1000.0/0.1 you would get better precision with a far plane at infinity anyway. Check this paper out http://www.geometry.caltech.edu/pubs/UD12.pdf ("3 - Projection Matrix Precision").


4

Your problem is that you need to render the scene twice. One from the view of the Light and then the normal rendering pass from the camera point of view. Now, do I even need a fragment shader in this shader pass? Yes. According to your question you are using OpenGL 3.3 which makes it required to define a fragment shader to be able to render anything. ...


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