Light Prepass Shadow Mapping
Ok, update on my Light Prepass journey. Shadow mapping is actually new to me, let alone ever using it in a deferred rendering. In fact this my first time to probably nail this thing to its head. Currently, its a simple shadow mapping... no magic.. no fancy footwork. The image you see here has a point light(w/ attenuation) casting shadow with 5x5 PCF (percent closer filtering). At this point, its all raw-brute-coding, definitely screaming for optimization. And obviously, I'm hiding all the shadow errors with a neat camera angle.
The model rendering however exhibits sound optimation. I've managed to remove all matrix computation in the pixel shader on the light passes (full screen quad and light convex mesh - I call these guys 'light blobs'). The mathematics here was such a nose bleed. The key here is making View Space your battle ground. Good thing the graphics gurus are around... MJP, Drilian, Engel, etc. Here's the link.
In terms of prepass packing, specifically the normals, the Cryengine 3 suggestion seem to produce some inaccuracies when I error check it with the fresh untouch normals. I added a weird value just to remove the error. Here's the code.
float4 PackDepthNormal(in float z, in float3 normal)
{
float4 output; normal = normalize(normal);
normal.x *= 1.000000000000001f; //<--- my nasty mod
output.xy = normalize(normal.xy) * sqrt(normal.z * .5f + .5f);
return PackDepth(output, z);
}
Anyway, I need to investigate this further. I find Pat Wilson's idea on converting normals to spherical coord better. I haven't profiled this but this seem to be a more optimized approach.
Back to shadows, my target is to use Cascaded Shadow Maps. Hopefully, in a few days time I can post the results.
Comments
Musta. Love what you're doing so far. Keep it up. I also tried doing Deferred Shading after seeing the Killzone 2 demo. I love the fact that you can have lots and lots of lights in a scene without the multipass hit in forward rendering. Lack of decent translucency and MSAA almost killed it for me though, but nevertheless I feel this is where many games will use in the near future. I never did try to take it seriously as you did though. I got as far as compressing them all in 32-bit surfaces and using exp2/log2 encoding, and making a simple lighting editor, but that's it. I haven't done those things you've done so far, so now you're miles ahead of me on that one. I'll be waiting for your next entry ;) ...
Yup. Thats the limitation of Full Deferred rendering. Light Prepass on the other hand is a diet slim down version of Deferred. When the prepass and light pass are done, you will do a forward render. Here you can turn on MSAA. Not sure about transluncy though, but it should work with a bit of trick.
Currently, I'm drowning myself with math RE:Cascading Shadow Map. I'm basing my implementation on Shader X5-6 and maybe if I get my hands on X7 that also.
I also included the exp2/log2 but apparently, this will be tricky with the tone mapping. But according to the graphics GURUs there's a way.... there's always a way.
waaaah... mga master (and fafa) ng buhay ko! hehehe. Si sir dave ang magiging future wolfgang at si sir ryan naman ang future carmack. Ako naman eh babalik na lang sa probinsya namin at magtatanim ng kamote.
(ps3 fanboy mode)
Ndi kakayanin ng 360 deferred shading o light prepass!!
(sabay takbo)
My masters will always be 'da masters.
(fan_boy mode)
Batuhin kita ng ps3-radioactive lollipop!!!
(serious mode) People do say PS3 had some mechanisms that would speed up deferred/light prepass. I saw a white paper regarding this, but I did not read because I wasn't interested, since (fan boy mode) ps3 sucks (prepares for incoming onslaught).
Arrggh, must... not... touch... graphics code. Must... complete... shmup engine... ;_;
Mga kawal! Hulihin ang uhm.. anti-ps3 boy!
(pero regarding sa deferred sa ps3) kaya pansin mo usually deferred/pre-pass o anumang variation nun ang gamit ng mga first party dev ng sony (i.e. insomniac, guerilla, tska ung phyre engine nila na panlaban kuno sa xna). Although games like dead space and bad company which according to wolfgang, uses also a variation of light prepass, runs well on 360. Ah well, sige na nga... project natal ftw!! hehehe
Now KILL!!! KILL!!! KILL!!...lah.
RE: Light Prepass
I just thought of a way to make the lightpass rendering faster.
IDEA A: (LOW-RES Lights then BLUR) Render the lights on a lower resolution. And do a slight blurring after all light accumulation. Before doing the Forward rendering.
IDEA B: (GROUP LIGHTS then do IDEA A on furthest group) Segregate rendering of lights by distance from the camera in groups. The furthest group render them in a lower resolution buffer. And the closer group into a higher resolution. Something like Pseudo-Cascade Lightpass technique. I guess this is a way to reduce fill-rate bottleneck... if it works ofcourse.
@ps3 goons: i owned a PSP. That still makes me a sony ally. If you arrest me, you'll cause very serious diplomatic issues.