Talk:Depth buffer

From Valve Developer Community
Jump to: navigation, search

Scaling the depth output

This section doesn't make any sense. What does "scaling" the output mean? I would have thought making the depth 'fog' extend further, yet the page doesn't say that. And then what exactly are we being told to do? "Render all opaque geometry in a scene with modified shaders" is incredibly vague, and the rest of the section is apparently telling us all about something we can't do?

Can you provide screens and code, please? --TomEdwards 12:14, 16 January 2011 (UTC)

As you noticed, the available range of the default depth buffer is very short. 'Scaling the depth output' simply means adjusting the range - do you think the term 'quantify' would make it clearer then? This has nothing to do with 'fog' at all - I was wondering why you would want to compare it anyway. All of the things I mentioned can be done, I personally didn't try the third option of shader replacement yet, that's all, but if standard filesystem rules apply it should be possible. I can provide screenshots of a larger depthbuffer in source with 32bit precision or anyone could take a look at zeno clash's depth buffer which has increased range, yet 8bit precision -> strong colour banding, but I don't think that's necessary as it looks the same (well, my depth is inverted), it just has another range.
I tried explaining how it works with more detail, for anyone who could care about that anyway, that part should make clear why 'scaling/quantifying' the output should be the correct term. --Biohazard 12:40, 16 January 2011 (UTC)
What kind of code would you want to see exactly? Other than changing the line I mentioned, recompiling the shaders and then using SDK_ shaders instead of default ones there's nothing else to do. --Biohazard 12:40, 16 January 2011 (UTC)
OK, I'm getting a clearer picture. I thought you were giving us two solutions to extend range, but in fact they are both part of the same one. There is only one thing I still don't understand: of the three options given in your first para, which one is the modification of OO_DESTALPHA_DEPTH_RANGE? It reads like it's impossible to override the standard shaders right now... (A screen of a proper depth buffer in Source would be great, upload away!) --TomEdwards 13:29, 16 January 2011 (UTC)
The second one is the modification - "the definition should be changed to this:"
Since i'm not using this myself at all (8bit limitation due to backbuffer format) I have to recompile all shaders first etc, so I will upload it later today. I can also provide code on how to reallocate the depth buffer texture, so anti-aliasing does not break. But you will see that the colour banding is a huge issue for effects like SSAO, just DoF could maybe get away with that.
"It reads like it's impossible to override the standard shaders right now" This is kinda hard to explain I think, sorry, I will try it again though; you can't override default shaders like UnlitGeneric with a custom shader dll, it will give you an error if you try to do so. So the most stable solution would be to change all 'UnlitGeneric' in vmt files to SDK_UnlitGeneric (same goes for every other opaque and $alphatest material, since $translucent does not draw depth). My idea was to override the .vcs files in Sourcemods/modname/shader/fxc with custom compiled ones - so the default UnlitGeneric shader would load a custom .vcs, but this would be unstable since you must ensure that the combos are setup the excat same way. Maybe it doesn't even work, I didn't try it out, but it would be the easiest solution if you were just to change the depth range. --Biohazard 13:38, 16 January 2011 (UTC)

Shaders

Would you want to add to the article a list of shaders/effects that can/would utilize the depth buffer? I know of SSAO and DoF but nothing else specific. Thelonesoldier 06:31, 18 January 2011 (UTC)

@Thelonesoldier Shadowmapping, more accurate godrays, soft water, soft particles (they work, but only up to 128 units according to the page on here, even though depth is 192.) --Legend286 00:00, 8 April 2011 (UTC)

This belongs specialized. Make that list elsewhere, perhaps close to Shader Authoring.--1/4 Life 08:38, 18 January 2011 (UTC)

The 192 units depth distance

The page talks about the buffering distance being set to 192 units. Where in the code is this defined? Darnias (talk) 21:46, 8 February 2021 (PST)

_rt_FullFrameDepth_Alt initialization code doesn't work

No idea if this page is active, but the code to create an alternate _rt_FullFrameDepth rendertarget in the "Fixing the depth buffer texture" section doesn't seem to be functional in Source 2013. In all my testing, _rt_FullFrameDepth_Alt will be black using that code. But after playing around and looking at how _rt_FullFrameDepth is initialized in the engine, I came up with this, which does produce a functional depth buffer:

	static int flags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT | TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_RENDERTARGET;

	materials->BeginRenderTargetAllocation();
	materials->CreateNamedRenderTargetTextureEx( "_rt_FullFrameDepth_Alt", 1, 1, RT_SIZE_FULL_FRAME_BUFFER, IMAGE_FORMAT_R32F, MATERIAL_RT_DEPTH_SHARED, flags, 0 );
	materials->EndRenderTargetAllocation();

Can anyone else confirm this? I'd like to replace the code in the article with this since I've looked at it multiple times in the past and have gotten nowhere with it on a mod whose viewrender code is basically vanilla, whereas mine works perfectly.