// Only allow generated normals for material format 2 aka Integrated #if MATERIAL_FORMAT != 2 #ifdef GENERATED_NORMALS #undef GENERATED_NORMALS #endif #endif //Common Functions// float GetLuminance(vec3 color) { return dot(color,vec3(0.299, 0.587, 0.114)); } float pow2(float x) { return x * x; } vec2 pow2(vec2 x) { return x * x; } vec3 pow2(vec3 x) { return x * x; } float pow1_5(float x) { // Faster pow(x, 1.5) approximation (that isn't accurate at all) if x is between 0 and 1 return x - x * pow2(1.0 - x); // Thanks to SixthSurge } vec2 pow1_5(vec2 x) { return x - x * pow2(1.0 - x); } vec3 pow1_5(vec3 x) { return x - x * pow2(1.0 - x); } bool CheckForColor(vec3 albedo, vec3 check) { // Thanks to Builderb0y vec3 dif = albedo - check * 0.003921568; return dif == clamp(dif, vec3(-0.001), vec3(0.001)); } float GetMaxColorDif(vec3 color) { vec3 dif = abs(vec3(color.r - color.g, color.g - color.b, color.r - color.b)); return max(dif.r, max(dif.g, dif.b)); } float smoothstep1(float x) { return x * x * (3.0 - 2.0 * x); } vec2 smoothstep1(vec2 x) { return x * x * (3.0 - 2.0 * x); } vec3 smoothstep1(vec3 x) { return x * x * (3.0 - 2.0 * x); } float sqrt1(float x) { // Faster sqrt() approximation (that isn't accurate at all) if x is between 0 and 1 return x * (2.0 - x); // Thanks to Builderb0y } vec2 sqrt1(vec2 x) { return x * (2.0 - x); } vec3 sqrt1(vec3 x) { return x * (2.0 - x); } vec4 sqrt1(vec4 x) { return x * (2.0 - x); } float sqrt3(float x) { x = 1.0 - x; x *= x; x *= x; x *= x; return 1.0 - x; } vec2 sqrt3(vec2 x) { x = 1.0 - x; x *= x; x *= x; x *= x; return 1.0 - x; } vec3 sqrt3(vec3 x) { x = 1.0 - x; x *= x; x *= x; x *= x; return 1.0 - x; } vec4 sqrt3(vec4 x) { x = 1.0 - x; x *= x; x *= x; x *= x; return 1.0 - x; } float min1(float x) { return min(x, 1.0); } float max0(float x) { return max(x, 0.0); } float clamp01(float x) { return clamp(x, 0.0, 1.0); } vec2 clamp01(vec2 x) { return clamp(x, vec2(0.0), vec2(1.0)); } vec3 clamp01(vec3 x) { return clamp(x, vec3(0.0), vec3(1.0)); }