   "Raytracing" Light and Shader. Plus Question.
  Hello, I had an idea on how to make lighting besides using the most common way, the shadowmap. I have not written any code, but just ran some calculations in my head. Thought it would be good to share the idea with game developers so they might want to implement it since the technique could be quite fast, hopefully.Basically the thinking is this. Using a spot light, trace the vectors (which fall in the spot light cone) to the triangles that are effected by the light. You will also need to record the distance in a texture so that any triangle that is behind the closest one to the light gets a shadow. The texture should also contain the angles that a triangle forms by the vectors from the three vertexes to the light. So anything that falls inside that cone and is farther away from the closest triangle would receive a shadow. You can also implement a bounce, or a few, of the light from the triangles that are not in the shadows - sending the light around the scene to light up more objects evenly. There is a site on the internet that might be useful about projecting vectors onto triangles: http://www.euclideanspace.com/maths/geometry/elements/plane/lineOnPlane/index.htmSo that is about it for the shader. The question I have is that, I don't know if any game engines have implemented that "raytrace" yet... Sounds like something that would be in use already. You can think of this shader as the Light Mass in Unreal engine, I just don't know if it actually does something like I've described.Ok thank you for reading, and shoot a comment or two if you would like to share. Laters-Flo0p   
  I believe most people separate "lighting" and "shadows" as two separate concepts. You seem to think of them as the same thing.Mind drawing a picture or explaining it more in depth.Quote:Original post by FlopidUsing a spot light, trace the vectors (which fall in the spot light cone) to the triangles that are effected by the light. You will also need to record the distance in a texture so that any triangle that is behind the closest one to the light gets a shadow. The texture should also contain the angles that a triangle forms by the vectors from the three vertexes to the light. So anything that falls inside that cone and is farther away from the closest triangle would receive a shadow. You can also implement a bounce, or a few, of the light from the triangles that are not in the shadows - sending the light around the scene to light up more objects evenly.Raytracing methods for shadows are generally slow. If you've implemented a raytracer before you'd realize this. The problem of finding if a ray hits a triangle in a mesh is fine, but having to do it per pixel gets to be a bit GPU intensive. Shadow mapping works because it uses rasterization and not raycasting.How are you finding the triangles affected by the light? When you say "You will also need to record the distance in a texture so that any triangle that is behind the closest one to the light gets a shadow." it sounds similar to shadow mapping which makes me believe you're referring to rasterizing the images from the spot light's perspective?   ;  Your idea is not entirely clear to me, but if you're talking about tracing individual rays from a light source then you might want to look into photon mapping. You can get really good images that way, but it's generally nowhere near real-time.If your talking about checking if pixels fall in cone or pyramid shaped volumes created from shadow casting polygons and the light source then you're talking about shadow volumes. These are reasonably common in modern games I think, but they do not lend themselves well to global illumination.Raytracing typically traces rays from camera to objects to light sources and not the other way around. While it's very good at casting sharp accurate shadows the basic algorithm is pretty slow and does not apply to global illumination because the number of rays becomes uncomputable.;  Well, I guess this technique is called shadow volumes. I can see why it could be slow, because when reflecting the light off the triangles in the scene you are basically creating that many more light sources. It seems as though, if all of these "new" lights can be put in a texture using just the vertexes and not each fragment, then it could be fast, and then the new cones could be also computed in the vertex shader. Then later you could use A || B = B x (A x B / |B|) / |B| for the newly formed shadows. See if I had a way to describe the shadow cone with just the three angles then the texture image should not be very large, plus you can overwrite the old texture with a new one in real time (say you have 100,000 triangles, then the texture should be 100,000 x 3 = 300,000, which is only 500 x 500 pixels). That is just one bounce, which could give a sort of good looking effect, I think. just a note to self... 300,000 x 100,000 x 3 = 90,000,000,000 = 520,000 x 520,000... I don't know how much memory this takes up on the GPU. But if a triangle is already fully in a shadow then it doesn't reflect any light. Here is a picture of what I am describing:;  I'm still not getting where you're going with the texture stuff. Even if you can store the volume data in a texture it's still a pretty complex operation to check if a pixel falls within a cone, and I don't think you can magically fix that with shaders. Well shadow volumes use the stencil buffer or something like that to achieve real time direct illumination to begin with, but there's only so much power available and I don't think there's enough to use shadow volumes for global illumination. You might want to look into beam tracing though. It's a resolution independent tracing algorithm that'll give you a better idea of the type of math you'd be dealing with if you do want to try going crazy with cones for global illumination. Also coincidentally another pretty good way to do pixel perfect shadows among other things. I'm really not sure why beam tracing isn't used more unless it's just the fact that's it's a pain to get to work right and also a pain to get to run fast.edit: Beam Tracing ftw: http://www.alrecenk.com/resume/images/BeamTracer/   ;  Well I am just saying textures, because it is a way to store information and compare it with other stuff like pixels on another triangle (books say that texture access is highly optimized and sped up in recent GPUs), but I don't want to use a pixel shader, because like you say it will be a heavy operation. The only thing I can see reasonable to do is only to use the vertex shader. I really don't know if it is possible with only the vertex shader though. I bet if you compare the angles stored in the vertex map (texture) to the vertexes of the underlying triangle you can discard the fragments inside that triangle and skip the rest of the pixel shader for that triangle. And besides if you reflect a cone only a certain percentage of triangles will be inside it so that cuts down the texture size even more. I think it is possible to do at most two bounces, and the effect will be pretty real. I am still working on it, just don't know when it will be done.   ;  Storing depths in a texture is shadow-mapping. Storing the surface angles along with the depths is an extension of shadow-mapping.Bouncing light rays off surfaces is a common part of most ray-traced radiosity algorithms and is way too slow to be done in real-time (most games do not use ray tracing, graphics cards are not designed for it) -- it is commonly used in offline rendering though.Shadow volumes have nothing to do with bounced lighting.Bouncing light rays off the lit pixels from a shadow map *in realtime* is achieved using virtual point lights (VPL), which is what CryEngine3 is using for their bounced lighting -- this seems to be what you're trying to describe.   ;Quote:Original post by HodgmanBouncing light rays off the lit pixels from a shadow map *in realtime* is achieved using virtual point lights (VPL), which is what CryEngine3 is using for their bounced lighting -- this seems to be what you're trying to describe.Cool, good to know. If CryEngine is doing that now, it's most likely way better than anything I could achive in the new millenium : )Thank you for all your posts.   