depth-buffer

How to get Z values from Z Buffer

ε祈祈猫儿з 提交于 2019-12-07 08:04:31
问题 I'm having problems with drawing in OpenGL and I need to see exactly what values are being placed in the depth buffer. Can anyone tell me how to retrieve these values? Thanks Chris 回答1: Use glReadPixels with format = GL_DEPTH_COMPONENT, for example: float depth; glReadPixels(0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth); Will get the depth of pixel (0, 0). 来源: https://stackoverflow.com/questions/4499999/how-to-get-z-values-from-z-buffer

Implementing depth testing for semi-transparent objects

你离开我真会死。 提交于 2019-12-07 03:38:42
I've been carefully trolling the internet for the past two days to understand depth testing for semi-transparent objects. I've read multiple papers/tutorials on the subject and in theory I believe I understand how it works. However none of them give me actual example code. I have three requirements for my depth testing of semi-transparent objects: It should be order independant. It should work if two quads of the same objects are intersection each other. Both semi-transparent. Imagine a grass object that looks like a X when viewed from above: It should correctly render a semi-transparent

Webgl: alternative to writing to gl_FragDepth

℡╲_俬逩灬. 提交于 2019-12-07 02:21:54
问题 In WebGL, is it possible to write to the fragment's depth value or control the fragment's depth value in some other way? As far as I could find, gl_FragDepth is not present in webgl 1.x, but I am wondering if there is any other way (extensions, browser specific support, etc) to do it. What I want to archive is to have a ray traced object play along with other elements drawn using the usual model, view, projection. 回答1: There is the extension EXT_frag_depth Because it's an extension it might

Rendering to depth texture - unclarities about usage of GL_OES_depth_texture

好久不见. 提交于 2019-12-06 14:21:35
I'm trying to replace OpenGL's gl_FragDepth feature which is missing in OpenGL ES 2.0. I need a way to set the depth in the fragment shader, because setting it in the vertex shader is not accurate enough for my purpose. AFAIK the only way to do that is by having a render-to-texture framebuffer on which a first rendering pass is done. This depth texture stores the depth values for each pixel on the screen. Then, the depth texture is attached in the final rendering pass, so the final renderer knows the depth at each pixel. Since iOS >= 4.1 supports GL_OES_depth_texture , I'm trying to use GL

Linearize depth

元气小坏坏 提交于 2019-12-06 07:59:56
In OpenGL you can linearize a depth value like so: float linearize_depth(float d,float zNear,float zFar) { float z_n = 2.0 * d - 1.0; return 2.0 * zNear * zFar / (zFar + zNear - z_n * (zFar - zNear)); } (Source: https://stackoverflow.com/a/6657284/10011415 ) However, Vulkan handles depth values somewhat differently ( https://matthewwellings.com/blog/the-new-vulkan-coordinate-system/ ). I don't quite understand the math behind it, what changes would I have to make to the function to linearize a depth value with Vulkan? The important difference between OpenGL and Vulkan here is that the

How does WebGL set values in the depth buffer?

拜拜、爱过 提交于 2019-12-06 06:24:59
问题 In OpenGL, depth buffer values are calculated based on the near and far clipping planes of the scene. (Reference: Getting the true z value from the depth buffer) How does this work in WebGL? My understanding is that WebGL is unaware of my scene's far and near clipping planes. The near and far clipping planes are used to calculate my projection matrix, but I never tell WebGL what they are explicitly so it can't use them to calculate depth buffer values. How does WebGL set values in the depth

Rendering multiple depth information with FBOs

喜欢而已 提交于 2019-12-06 01:54:29
I am trying to implement a shader computing the light refraction through two surfaces: the back and front of the object. To do so, I need to render the refractive geometry with the normal depth test (GL_LESS), and the reversed depth test (GL_GREATER). It would allow me to compute the distance from the back face to the front face. Unfortunately, I only manage to render one of those at a time, and I can't figure out how to pass both depth information as textures to the shader. The shader itself shouldn't be a problem, but I'm struggling with setting up opengl so that it gives everything needed

How to get Z values from Z Buffer

偶尔善良 提交于 2019-12-05 12:24:15
I'm having problems with drawing in OpenGL and I need to see exactly what values are being placed in the depth buffer. Can anyone tell me how to retrieve these values? Thanks Chris Use glReadPixels with format = GL_DEPTH_COMPONENT, for example: float depth; glReadPixels(0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth); Will get the depth of pixel (0, 0). 来源: https://stackoverflow.com/questions/4499999/how-to-get-z-values-from-z-buffer

reconstructed world position from depth is wrong

女生的网名这么多〃 提交于 2019-12-05 12:15:26
I'm trying to implement deferred shading/lighting. In order to reduce the number/size of the buffers I use I wanted to use the depth texture to reconstruct world position later on. I do this by multiplying the pixel's coordinates with the inverse of the projection matrix and the inverse of the camera matrix. This sort of works, but the position is a bit off. Here's the absolute difference with a sampled world position texture: For reference, this is the code I use in the second pass fragment shader: vec2 screenPosition_texture = vec2((gl_FragCoord.x)/WIDTH, (gl_FragCoord.y)/HEIGHT); float

Render off screen (with FBO and RenderBuffer) and pixel transfer of color, depth, stencil

社会主义新天地 提交于 2019-12-05 05:41:29
问题 I'have to render off screen in OpenGL and then pass the image to a QImage. Plus, just for exercise I'd like to transfer to the CPU also the depth and the stencil buffer. For drawing offscreen I've used Frame Buffer Object with Render Buffer (and not with texture because I don't need the texture). Pixel transfer operation with color buffers (the actual raw image) works.. I see what I'm expecting. But depth and stencil are not working.. strange image for depth and nothing with for the stencil.