View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0006121 | Spring engine | General | public | 2019-01-23 13:36 | 2019-01-23 22:53 |
| Reporter | lhog | Assigned To | Kloot | ||
| Priority | low | Severity | text | Reproducibility | always |
| Status | closed | Resolution | no change required | ||
| Product Version | 104.0 +git | ||||
| Summary | 0006121: Reason to have shadowParams in the engine and shaders | ||||
| Description | Hi again! I'm relatively new when it comes to OpenGL/shaders, therefore I learn stuff from the books or online guides. It has always puzzled me why spring calculates the shadowmap sampling coordinates in the following unusual way: shadowTexCoord = shadowMat * vertexWorldPos; shadowTexCoord.xy *= (inversesqrt(abs(shadowTexCoord.xy) + shadowParams.zz) + shadowParams.ww); shadowTexCoord.xy += shadowParams.xy; What most (all?) guides do instead is that they multiply by viewProj light matrix, so: shadowTexCoord = shadowMat * vertexWorldPos; And then do perspective division shadowTexCoord /= shadowTexCoord.w; And then [-1, 1] to [0,1] range remapping: shadowTexCoord = shadowTexCoord * 0.5 + 0.5; I've checked the 'standard' way of doing things and it gives incorrect results in spring. I then have dug a bit further and plot the spring way of getting shadowTexCoord in Mathematica only to find out it's numerically equivalent to simple shadowTexCoord.xy = shadowTexCoord.xy + 0.5. Therefore code might be simplified to: shadowTexCoord = shadowMat * vertexWorldPos; shadowTexCoord /= shadowTexCoord.w; shadowTexCoord.xy = shadowTexCoord.xy + 0.5; Another weird thing is that second line (perspective division) doesn't seem to be required as the final result of shadow mapping is same with or without that line. It would be nice if you can comment on three questions: 1) Why arcane formulae instead of just +0.5? 2) Why just +0.5 and not (xy*0.5 + 0.5) as in most online sources? 3) Why perspective division is not required? P.S. Figuring this out because in Percentage-Closer Soft Shadows they do a lot of stuff with shadow coordinates, so would be nice to understand what I'm doing in the first place. Thanks, | ||||
| Tags | No tags attached. | ||||
| Checked infolog.txt for Errors | |||||
|
|
1) the story behind this dates back to Spring's prehistory, just read "1" whenever you see it 2) the 0.5 scale-factor is prebaked into shadowMat, again for ancient reasons 3) look up what shadow2DProj does |
|
|
I sprinkle ashes upon my head on 0000003. P.S. Is there a better way to communicate with you than forum/mantis by a chance? Meaning chat/discord here. Thanks & close pls. |
|
|
sure, PM me a browser-joinable discord channel. |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2019-01-23 13:36 | lhog | New Issue | |
| 2019-01-23 19:22 | Kloot | Note Added: 0019681 | |
| 2019-01-23 19:32 | lhog | Note Added: 0019682 | |
| 2019-01-23 22:53 | Kloot | Assigned To | => Kloot |
| 2019-01-23 22:53 | Kloot | Status | new => closed |
| 2019-01-23 22:53 | Kloot | Resolution | open => no change required |
| 2019-01-23 22:53 | Kloot | Note Added: 0019683 |