mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-22 04:49:12 -06:00
68 lines
2.9 KiB
Plaintext
68 lines
2.9 KiB
Plaintext
/*****************************************************************************************
|
|
* *
|
|
* OpenSpace *
|
|
* *
|
|
* Copyright (c) 2014 *
|
|
* *
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
|
* software and associated documentation files (the "Software"), to deal in the Software *
|
|
* without restriction, including without limitation the rights to use, copy, modify, *
|
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
|
* permit persons to whom the Software is furnished to do so, subject to the following *
|
|
* conditions: *
|
|
* *
|
|
* The above copyright notice and this permission notice shall be included in all copies *
|
|
* or substantial portions of the Software. *
|
|
* *
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
|
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
|
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
****************************************************************************************/
|
|
|
|
#ifndef POWERSCALING_MATH_HGLSL
|
|
#define POWERSCALING_MATH_HGLSL
|
|
|
|
const float k = 10.0;
|
|
const float FLT_MAX = 1e38; // Not max but large enough for the purpose
|
|
|
|
float log10(float x) {
|
|
return log(x) / log(10);
|
|
}
|
|
|
|
vec4 psc_normalization(vec4 v) {
|
|
vec4 v2 = v;
|
|
float l = length(v.xyz);
|
|
v2.xyz = v.xyz / l;
|
|
v2.w = v.w - log10(1.0/l);
|
|
return v2;
|
|
}
|
|
|
|
vec4 psc_addition(vec4 v1, vec4 v2) {
|
|
float ds = v2.w - v1.w;
|
|
if(ds >= 0) {
|
|
float p = pow(k,-ds);
|
|
return vec4(v1.x*p + v2.x, v1.y*p + v2.y, v1.z*p + v2.z, v2.w);
|
|
} else {
|
|
float p = pow(k,ds);
|
|
return vec4(v1.x + v2.x*p, v1.y + v2.y*p, v1.z + v2.z*p, v1.w);
|
|
}
|
|
}
|
|
|
|
vec4 z_normalization(vec4 v_in) {
|
|
vec4 v_out = v_in;
|
|
if(v_out.z > 0.0) {
|
|
v_out.z = 1;
|
|
} else if(v_out.z < 0.0) {
|
|
v_out.z = 1;
|
|
} else {
|
|
float tmp = max(max(abs(v_out.x), abs(v_out.y)),0);
|
|
if(tmp == 0.0)
|
|
v_out.s = FLT_MAX;
|
|
}
|
|
return v_out;
|
|
}
|
|
|
|
#endif |