Skip to content

Commit

Permalink
feat: rgbd color encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhouston committed Jul 19, 2020
1 parent c2a4d9c commit 3ee1544
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib/shaders/includes/color/encodings/rgbd.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

// reference: http://iwasbeingirony.blogspot.ca/2010/06/difference-between-rgbm-and-rgbd.html
vec3 rgbdToLinear( in vec4 value, in float maxRange ) {
return vec3( value.rgb * ( ( maxRange / 255. ) / value.a ) );
}

vec4 linearToRGBD( in vec3 value, in float maxRange ) {
float maxRGB = max( value.r, max( value.g, value.b ) );
float D = max( maxRange / maxRGB, 1. );
// NOTE: The implementation with min causes the shader to not compile on
// a common Alcatel A502DL in Chrome 78/Android 8.1. Some research suggests
// that the chipset is Mediatek MT6739 w/ IMG PowerVR GE8100 GPU.
// D = min( floor( D ) / 255., 1. );
D = clamp( floor( D ) / 255., 0., 1. );
return vec4( value.rgb * ( D * ( 255. / maxRange ) ), D );
}
12 changes: 12 additions & 0 deletions src/lib/shaders/includes/color/encodings/rgbe.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#pragma include <math/math>

vec3 rgbeToLinear( in vec4 value ) {
return vec3( value.rgb * exp2( value.a * 255. - 128. ) );
}

vec4 linearToRGBE( in vec3 value ) {
float maxComponent = max( max( value.r, value.g ), value.b );
float fExp = clamp( ceil( log2( maxComponent ) ), -128., 127. );
return vec4( value.rgb / exp2( fExp ), ( fExp + 128. ) / 255. );
}

0 comments on commit 3ee1544

Please sign in to comment.