I’ve been spending the last week and a half working on my deferred renderer that I wanted done in the first couple weeks. Other stuff had higher priority and it has been pushed off until now. It took me a while to figure out how all the render target stuff works; I’ve never done anything like that before, but I think I have it all figured out now and wrapped up in a nicely organized DeferredRenderer class.
There is a lot of resource creating and management to be done in a system like this. I have to create three Texture2Ds to store the G-buffer data from the first pass and then three RenderTargetViews so I can write to those textures from the shader, and three ShaderResourceViews so I can read from those textures in the other shaders. The second, shading, pass needs its own texture, render target, and resource view, and then one final set for the output of the renderer that gets passed to the device which combines all incoming render targets like the one being sent from Colin’s GUI system.
I quickly got a directional light up and running and then proceeded to add more lights and more types. First up: point light! Unfortunately, I was getting all sorts of weird artifacts with my point lights; very strange horizontal banding. After much debugging and much anguish, and help from some fellow students and my professor, I’ve figured out that the problem is with the world position of each pixel during the shading pass. The first pass correctly outputs the depth map, but somewhere in the unproject of the screen x, y and depth, the position of the pixel is off. It is somehow related to the near and far clip planes and the position of the camera; something in the projection matrix or the view matrix? I can’t figure it out, I’ve been over the code and it should work. It has been suggested to me to try and use a different approach to recreating the world position, instead of using an inverse view-projection matrix, use the coordinates of the far frustum plane and store positions relative to that. Maybe it is faster since it doesn’t involve a matrix calculation? If it works I won’t care.
Here is the resource I’m going to be using to help me with this new technique.








Post a Comment