-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support 0->1 depth range in GLSL #76
Comments
With A more discoverable API might be to have it as a property on the I'm trying to think of other intrinsic functions that could make use of this and coming up blank. That's probably just because it's late :) It does seem like a useful piece of metadata to have. |
In my mind, it would be a preprocessor condition that is used but not defined in the shader code, e.g.: gl_Position = output_.Position;
#if !DEPTH_RANGE_ZERO_TO_ONE
gl_Position.z = gl_Position.z * 2.0 - gl_Position.w;
#endif By default, nothing would be change, but you could do something like this on the C# side: string defines = string.Empty;
if (GraphicsDevice.IsDepthRangeZeroToOne)
{
defines = "DEPTH_RANGE_ZERO_TO_ONE";
}
byte[] shaderBytes = LoadShader("myShader.vert", defines); // Add defines into the text and return bytes (Prototype of that API in this Veldrid branch)
I'm trying to think of a way that you can write your shader in a "portable" way, such that it will work under both depth range schemes. If we had a more robust "configuration system", perhaps you could just tell ShaderGen to spit out both versions of the shader -- but that's much more complicated.
I think there might need to be some kind of builtin function that does depth comparisons for you, based on whether or not that define is set. |
In order to support the reverse-depth-buffer optimization, I would like to support a 0->1 depth range, even in GLSL. Given that the
glClipControl
extension isn't universally supported, and given that folks will still likely use the default depth range in OpenGL, we should support both depth ranges somehow. Also, OpenGL ES and WebGL do not supportglClipControl
at all. Perhaps the best way to accomplish this is conditional compilation -- ifDEPTH_RANGE_ZERO_TO_ONE
is defined, we will not transform the depth range. Otherwise we will, as we do today.We should think about how such a preprocessor define could be utilized in other intrinsic functions that could allow you to write code that is portable to both depth range schemes.
@tgjones Any thoughts here?
The text was updated successfully, but these errors were encountered: