-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. ); | ||
} |