Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (739)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (820)
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 1146 times)
0 Members and 1 Guest are viewing this topic.
Offline abcdef
« Posted 2017-06-07 04:38:59 »

Hi

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:

Quote
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 learnopengl.com '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  
 
 

 
Ecumene (52 views)
2017-09-30 02:57:34

theagentd (76 views)
2017-09-26 18:23:31

cybrmynd (183 views)
2017-08-02 12:28:51

cybrmynd (182 views)
2017-08-02 12:19:43

cybrmynd (189 views)
2017-08-02 12:18:09

Sralse (197 views)
2017-07-25 17:13:48

Archive (747 views)
2017-04-27 17:45:51

buddyBro (881 views)
2017-04-05 03:38:00

CopyableCougar4 (1429 views)
2017-03-24 15:39:42

theagentd (1319 views)
2017-03-24 15:32:08
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

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org 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‑gaming.org
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!