in Education by
I've been trying for some time now to get a screen-space pixel (provided by a deferred HLSL shader) to convert to light space. The results have been surprising to me as my light rendering seems to be tiling the depth buffer. Importantly, the scene camera (or eye) and the light being rendered from start in the same position. First, I extract the world position of the pixel using the code below: float3 eye = Eye; float4 position = { IN.texCoord.x * 2 - 1, (1 - IN.texCoord.y) * 2 - 1, zbuffer.r, 1 }; float4 hposition = mul(position, EyeViewProjectionInverse); position = float4(hposition.xyz / hposition.w, hposition.w); float3 eyeDirection = normalize(eye - position.xyz); The result seems to be correct as rendering the XYZ position as RGB respectively yields this (apparently correct) result: The red component seems to be correctly outputting X as it moves to the right, and blue shows Z moving forward. The Y factor also looks correct as the ground is slightly below the Y axis. Next (and to be sure I'm not going crazy), I decided to output the original depth buffer. Normally I keep the depth buffer in a Texture2D called DepthMap passed to the shader as input. In this case, however, I try to undo the pixel transformation by offsetting it back into the proper position and multiplying it by the eye's view-projection matrix: float4 cpos = mul(position, EyeViewProjection); cpos.xyz = cpos.xyz / cpos.w; cpos.x = cpos.x * 0.5f + 0.5f; cpos.y = 1 - (cpos.y * 0.5f + 0.5f); float camera_depth = pow(DepthMap.Sample(Sampler, cpos.xy).r, 100); // Power 100 just to visualize the map since scales are really tiny return float4(camera_depth, camera_depth, camera_depth, 1); This yields a correct looking result as well (though I'm not 100% sure about the Z value). Also note that I've made the results exponential to better visualize the depth information (this is not done when attempting live comparisons): So theoretically, I can use the same code to convert that pixel world position to light space by multiplying by the light's view-projection matrix. Correct? Here's what I tried: float4 lpos = mul(position, ShadowLightViewProjection[0]); lpos.xyz = lpos.xyz / lpos.w; lpos.x = lpos.x * 0.5f + 0.5f; lpos.y = 1 - (lpos.y * 0.5f + 0.5f); float shadow_map_depth = pow(ShadowLightMap[0].Sample(Sampler, lpos.xy).r, 100); // Power 100 just to visualize the map since scales are really tiny return float4(shadow_map_depth, shadow_map_depth, shadow_map_depth, 1); And here's the result: And another to show better how it's mapping to the world: I don't understand what is going on here. It seems it might have something to do with the projection matrix, but I'm not that good with math to know for sure what is happening. It's definitely not the width/height of the light map as I've tried multiple map sizes and the projection matrix is calculated using FOV and aspect ratios never inputing width/height ever. Finally, here's some C++ code showing how my perspective matrix (used for both eye and light) is calculated: const auto ys = std::tan((T)1.57079632679f - (fov / (T)2.0)); const auto xs = ys / aspect; const auto& zf = view_far; const auto& zn = view_near; const auto zfn = zf - zn; row1(xs, 0, 0, 0); row2(0, ys, 0, 0); row3(0, 0, zf / zfn, 1); row4(0, 0, -zn * zf / zfn, 0); return *this; I'm completely at a loss here. Any guidance or recommendations would be greatly appreciated! EDIT - I also forgot to mention that the tiled image is upside down as if the y flip broke it. That's strange to me as it's required to get it back to eye texture space correctly. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I did some tweaking and fixed things here and there. Ultimately, my biggest issue was an unexpectedly transposed matrix. It's a bit complicated as to how the matrix got transposed, but that's why things were flipped. I also changed to D32 depth buffers (though I'm not sure that helped any) and made sure that any positions divided by their W affected all component (including W). So code like this: hposition.xyz = hposition.xyz / hposition.w became this: hposition = hposition / hposition.w After all this tweaking, it's starting to look more like a shadow map. Oh and the transposed matrix was the ViewProjection of the light.

Related questions

0 votes
    // merge.cpp // merges two containers into a third #include #include //for merge() using namespace std; int src1[] = { 2, 3, 4, ... , src1+5, src2, src2+3, dest); for(int j=0; j...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    Which of the following finds the position of a quantile in a dataset? (a) quantile() (b) barplot() (c ... Regression of R Programming Select the correct answer from above options...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    ___________ function gives an error message if the desired package cannot be loaded. (a) Dplyr (b) Require (c ... of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    which of the following statement gives cumulative sum? (a) cumsum(x,na=rm=TRUE) (b) cumprod(x) (c) ... Regression of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    ______ specializes in converting data from wide to long format. (a) gcc (b) reshape (c) reshape2 (d) ... Regression of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    __________ is the best way for communicating the results of data analysis using the R language. (a) Single ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    ______ splits a data frame and results an array (hence the da). Hopefully you're getting the idea here. ... Regression of R Programming Select the correct answer from above options...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    Maps are great to get things done easily, but they are memory hogs and suffer from caching issues. And ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Maps are great to get things done easily, but they are memory hogs and suffer from caching issues. And ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I want something like an std::map, but I only want to see if the item exists or not, I don' ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    In the Wumpus World Problem, the reason for the uncertainty is that the agent's sensor gives only__ Full ... Global Information Full & local information Partial & local Information...
asked Mar 8, 2021 in Technology by JackTerrance
0 votes
    Which concept of Java is a way of converting real world objects in terms of class? (a) Polymorphism ... questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    Which function is accountable for consolidating the results produced by each of the Map() functions/tasks. 1. Reduce 2. Reducer 3. Map 4. All of the mentioned...
asked Aug 7, 2021 in Technology by JackTerrance
0 votes
    Observe the given map and answer the following questions: Division of Europe after World War II. 1.Name two East ... of the United States. Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    I need to load 3DsMax generated animation in DirectX.File type(.X or any..) is doesn't matters. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
...