Viewport: create a shader to show depth images linearized
This commit is contained in:
@@ -135,6 +135,7 @@ data_to_c_simple(shaders/gpu_shader_2D_smooth_color_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_2D_smooth_color_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_modulate_alpha_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_rect_modulate_alpha_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_depth_linear_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_image_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_flat_color_vert.glsl SRC)
|
||||
|
||||
@@ -104,6 +104,7 @@ typedef enum GPUBuiltinShader {
|
||||
/* basic image drawing */
|
||||
GPU_SHADER_3D_IMAGE_MODULATE_ALPHA,
|
||||
GPU_SHADER_3D_IMAGE_RECT_MODULATE_ALPHA,
|
||||
GPU_SHADER_3D_IMAGE_DEPTH,
|
||||
/* points */
|
||||
GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR,
|
||||
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_SMOOTH,
|
||||
|
||||
@@ -56,6 +56,7 @@ extern char datatoc_gpu_shader_2D_smooth_color_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_3D_image_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_image_modulate_alpha_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_image_rect_modulate_alpha_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_image_depth_linear_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_3D_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_3D_flat_color_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_3D_smooth_color_vert_glsl[];
|
||||
@@ -109,6 +110,7 @@ static struct GPUShadersGlobal {
|
||||
/* for drawing images */
|
||||
GPUShader *image_modulate_alpha_3D;
|
||||
GPUShader *image_rect_modulate_alpha_3D;
|
||||
GPUShader *image_depth_3D;
|
||||
/* for simple 2D drawing */
|
||||
GPUShader *uniform_color_2D;
|
||||
GPUShader *flat_color_2D;
|
||||
@@ -669,6 +671,14 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
|
||||
NULL, NULL, NULL, 0, 0, 0);
|
||||
retval = GG.shaders.image_rect_modulate_alpha_3D;
|
||||
break;
|
||||
case GPU_SHADER_3D_IMAGE_DEPTH:
|
||||
if (!GG.shaders.image_depth_3D)
|
||||
GG.shaders.image_depth_3D = GPU_shader_create(
|
||||
datatoc_gpu_shader_3D_image_vert_glsl,
|
||||
datatoc_gpu_shader_image_depth_linear_frag_glsl,
|
||||
NULL, NULL, NULL, 0, 0, 0);
|
||||
retval = GG.shaders.image_depth_3D;
|
||||
break;
|
||||
case GPU_SHADER_2D_UNIFORM_COLOR:
|
||||
if (!GG.shaders.uniform_color_2D)
|
||||
GG.shaders.uniform_color_2D = GPU_shader_create(
|
||||
@@ -937,6 +947,11 @@ void GPU_shader_free_builtin_shaders(void)
|
||||
GG.shaders.image_rect_modulate_alpha_3D = NULL;
|
||||
}
|
||||
|
||||
if (GG.shaders.image_depth_3D) {
|
||||
GPU_shader_free(GG.shaders.image_depth_3D);
|
||||
GG.shaders.image_depth_3D = NULL;
|
||||
}
|
||||
|
||||
if (GG.shaders.uniform_color_2D) {
|
||||
GPU_shader_free(GG.shaders.uniform_color_2D);
|
||||
GG.shaders.uniform_color_2D = NULL;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
#if __VERSION__ == 120
|
||||
varying vec2 texCoord_interp;
|
||||
#define fragColor gl_FragColor
|
||||
#else
|
||||
in vec2 texCoord_interp;
|
||||
out vec4 fragColor;
|
||||
#define texture2D texture
|
||||
#endif
|
||||
|
||||
uniform float znear;
|
||||
uniform float zfar;
|
||||
uniform sampler2D image;
|
||||
|
||||
void main()
|
||||
{
|
||||
float depth = texture2D(image, texCoord_interp).r;
|
||||
|
||||
/* normalize */
|
||||
fragColor.rgb = vec3((2.0f * znear) / (zfar + znear - (depth * (zfar - znear))));
|
||||
fragColor.a = 1.0f;
|
||||
}
|
||||
Reference in New Issue
Block a user