Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Shadows map questions  (Read 2251 times)
0 Members and 1 Guest are viewing this topic.
Offline abcdef
« Posted 2017-06-07 04:38:59 »


I am in the process of implementing shadow maps but I have some questions for those more experienced in this.

When I create light view matrix I am using the equivalent of the gluLookAt (because this is what the general populous seem to do). GluLookAt takes an eye position, but what is the eye position of a directional light? If I had a spot or point light this would be obvious but not so for directional lights.

The perspective matrix for a directional light is orthographic, I am experienced in creating orthographic matrix for ui drawing but no so for light. Should the near far be the same as my normal perspective matrix? What are good parameters for the left right top bottom? People put examples up but they never really explain why they choose the values that did.
Offline ShadedVertex
« Reply #1 - Posted 2017-06-12 07:22:36 »

1) For the eye position, since you're dealing specifically with directional lights, you can make a safe assumption that the light source is extremely far away (similar to the sun). Therefore, depending on what your direction is, you can position the eye such that it is far away.

2) For the left, right, top, bottom, near, far variables, it really depends a whole lot on your scene. Try different parameters, and keep playing around; there will never be a single set of parameters that suits all scenes for shadow mapping, which is why it's pretty troublesome to implement and perfect. Keep tweaking the parameters for the orthographic projection matrix to see what suits your scene.

There is one way to compute the orthographic projection matrix based on your camera's view frustum, which you could try. You'd have to compute the matrix every frame, however. ThinMatrix does this as well in his video tutorials, but his code is more than a little messy, and I don't really follow his tutorials, so his code was pretty difficult for me to read, but you could give that a shot, too. Here's a great explanation of how you can do this, by theagentd:

1. Compute the frustum corners' positions in world space, then transform them to light space. The easiest way of doing this is to compute the inverse of the camera's view-projection-matrix and multiply the vectors (+-1, +-1, +-1) (a total of 8 different combinations to get all 8 corners) and then transforming them by the inverse view-projection-matrix to get the world position. Then just multiply those 8 world space positions with the light view matrix we computed in step 1.

2. At this point you can compute the 3D bounds in view space by simply calculating the min and max of the 8 vectors' components and pass those into an ortho() function directly like this: ortho(minX, maxX, minY, maxY, minZ, maxZ). However, there are a number of quirks. You most likely want to make the width and height of the orthographic matrix the same so you don't get stretching (width=maxX-minX, height=maxY-minY). You also probably want to push the near plane out as well to capture things that are potentially outside the camera frustum but still casting shadows on the camera frustum.

If you're still having trouble, I suggest following 's great tutorial; or maybe ThinMatrix's 2-part tutorial on shadow mapping. If you don't like the quality of your shadows (resolution, etc.) try using Cascaded Shadow Mapping.

Have fun!
Pages: [1]
  ignore  |  Print  

EgonOlsen (44 views)
2018-06-10 19:43:48

EgonOlsen (24 views)
2018-06-10 19:43:44

EgonOlsen (46 views)
2018-06-10 19:43:20

DesertCoockie (200 views)
2018-05-13 18:23:11

nelsongames (126 views)
2018-04-24 18:15:36

nelsongames (125 views)
2018-04-24 18:14:32

ivj94 (866 views)
2018-03-24 14:47:39

ivj94 (127 views)
2018-03-24 14:46:31

ivj94 (770 views)
2018-03-24 14:43:53

Solater (142 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!