Sign in to follow this  
3DModelerMan

Additive blending artifacts

Recommended Posts

I'm trying to setup forward rendering with additive blending, and I'm running into some problems with blending. I'm getting weird artifacts when I render my lighting pass. The first stage is a depth pre-pass that just outputs ambient light from the pixel shader (and renders any shadeless/special single pass materials). The second stage is multiple forward lighting passes, I only have one directional light setup in the screenshot, but for some reason, when I output anything in the lighting passes, I end up with blue background pixels randomly showing through. I also tested with a lighting shader that just outputs a plain white color, and it still gives artifacts, so I'm pretty sure it's not some sort of weird alpha blending bug. If I just leave my lighting pass disabled, then no artifacts appear. Does anyone have an idea what could be causing these? I've attached a screenshot of the artifacts, and a screenshot from GPU Perf Studio showing my render states.

Share this post


Link to post
Share on other sites

Sounds like Z-fighting to me.  The most likely reason for this is that you may not be using the same transforms in your VS for the pre-pass as you're using in the additive passes, so you end up getting slightly different Z values for each pass.  Maybe you tried to optimize by pre-calculating a matrix on the CPU in one pass that you do a per-vertex calculation on the GPU in the other passes?

 

I also saw this with D3D9 and on certain hardware if I used triangles via indexed primitives for one pass and triangle strips via non-indexed primitives for another pass, so it's important that the setup be the same too.

Edited by mhagain

Share this post


Link to post
Share on other sites

I just checked the transform matrices in Perf Studio... They're identical for every single draw call. Interestingly, the artifacts don't show up as bad when the model is closer to the camera, I also tried moving it further away, and they got worse the further I moved it. I just tested with quite a sizable depth bias too and got the same results.

Share this post


Link to post
Share on other sites

Wow... Alright, for other people's future reference, that pattern is what it looks like when you output the wrong type to SV_TARGET. It doesn't give you a warning or anything, it'll compile just fine. It turns out there was a bug in my shader generator that left the 4 off of the return type. Hopefully no one else will spend 5 hours debugging depth buffers now only to find it was a simple return value issue.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this