Skip to content

Commit

Permalink
Use the MATLAB Jet colormap for displaying depth data.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Aug 28, 2016
1 parent 84d58f7 commit d1b7d0e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
22 changes: 20 additions & 2 deletions glsl/color.frag
@@ -1,6 +1,21 @@
varying vec4 vColor;
uniform bool EnableDepthPreview;

float jet_r(float x)
{
return x < 0.7 ? 4.0 * x - 1.5 : -4.0 * x + 4.5;
}

float jet_g(float x)
{
return x < 0.5 ? 4.0 * x - 0.5 : -4.0 * x + 3.5;
}

float jet_b(float x)
{
return x < 0.3 ? 4.0 * x + 0.5 : -4.0 * x + 2.5;
}

void main()
{
float depth = gl_FragCoord.z;
Expand All @@ -10,8 +25,11 @@ void main()

if (EnableDepthPreview)
{
// Front of the depth buffer is at 0, but we want to render it as bright
gl_FragColor = vec4(vec3(1.0 - gl_FragDepth), 1.0);
float x = 1.0 - gl_FragDepth;
float r = clamp(jet_r(x), 0.0, 1.0);
float g = clamp(jet_g(x), 0.0, 1.0);
float b = clamp(jet_b(x), 0.0, 1.0);
gl_FragColor = vec4(r, g, b, 1.0);
}
else
gl_FragColor = vColor;
Expand Down
22 changes: 20 additions & 2 deletions glsl/rgba.frag
Expand Up @@ -3,6 +3,21 @@ uniform bool EnableDepthPreview;

varying vec4 vTexCoord;

float jet_r(float x)
{
return x < 0.7 ? 4.0 * x - 1.5 : -4.0 * x + 4.5;
}

float jet_g(float x)
{
return x < 0.5 ? 4.0 * x - 0.5 : -4.0 * x + 3.5;
}

float jet_b(float x)
{
return x < 0.3 ? 4.0 * x + 0.5 : -4.0 * x + 2.5;
}

void main()
{
vec4 c = texture2D(DiffuseTexture, vTexCoord.st);
Expand All @@ -17,8 +32,11 @@ void main()

if (EnableDepthPreview)
{
// Front of the depth buffer is at 0, but we want to render it as bright
gl_FragColor = vec4(vec3(1.0 - gl_FragDepth), 1.0);
float x = 1.0 - gl_FragDepth;
float r = clamp(jet_r(x), 0.0, 1.0);
float g = clamp(jet_g(x), 0.0, 1.0);
float b = clamp(jet_b(x), 0.0, 1.0);
gl_FragColor = vec4(r, g, b, 1.0);
}
else
gl_FragColor = c;
Expand Down
22 changes: 20 additions & 2 deletions glsl/shp.frag
Expand Up @@ -8,6 +8,21 @@ varying vec2 vTexMetadata;
varying vec4 vChannelMask;
varying vec4 vDepthMask;

float jet_r(float x)
{
return x < 0.7 ? 4.0 * x - 1.5 : -4.0 * x + 4.5;
}

float jet_g(float x)
{
return x < 0.5 ? 4.0 * x - 0.5 : -4.0 * x + 3.5;
}

float jet_b(float x)
{
return x < 0.3 ? 4.0 * x + 0.5 : -4.0 * x + 2.5;
}

void main()
{
vec4 x = texture2D(DiffuseTexture, vTexCoord.st);
Expand All @@ -30,8 +45,11 @@ void main()

if (EnableDepthPreview)
{
// Front of the depth buffer is at 0, but we want to render it as bright
gl_FragColor = vec4(vec3(1.0 - gl_FragDepth), 1.0);
float x = 1.0 - gl_FragDepth;
float r = clamp(jet_r(x), 0.0, 1.0);
float g = clamp(jet_g(x), 0.0, 1.0);
float b = clamp(jet_b(x), 0.0, 1.0);
gl_FragColor = vec4(r, g, b, 1.0);
}
else
gl_FragColor = c;
Expand Down

0 comments on commit d1b7d0e

Please sign in to comment.