Files
cocos4/editor/assets/chunks/common.chunk
T
2021-04-28 21:46:41 +08:00

38 lines
1.4 KiB
Plaintext

// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
// common module
// constant value
#define PI 3.14159265359
#define PI2 6.28318530718
#define EPSILON 1e-6
#define LOG2 1.442695
// common function
#define saturate(a) clamp(a, 0.0, 1.0)
#define FP_MAX 65504.0
#define FP_SCALE 0.0009765625
#define FP_SCALE_INV 1024.0
// runtime constants
#pragma define CC_DEVICE_SUPPORT_FLOAT_TEXTURE default(1)
#pragma define CC_DEVICE_MAX_FRAGMENT_UNIFORM_VECTORS default(1024)
#pragma define CC_DEVICE_MAX_VERTEX_UNIFORM_VECTORS default(1024)
#pragma define CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS default(128)
#pragma define CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS default(128)
// When sampling RTs, Y-flip is needed if the screen space sign Y is positive (pointing upwards)
#define CC_HANDLE_RT_SAMPLE_FLIP(uv) uv = cc_cameraPos.w > 1.0 ? vec2(uv.x, 1.0 - uv.y) : uv
#define CC_HANDLE_GET_CLIP_FLIP(uv) uv = cc_cameraPos.w == 0.0 ? vec2(uv.x, -uv.y) : uv
#define STEP_FINT_128(v) (step(128.0, (v) + 0.5))
#define MOD_FINT_128(v) (mod(float(int((v) + 0.5)), 128.0))
highp float decode32 (highp vec4 rgba) {
rgba = rgba * 255.0;
highp float Sign = 1.0 - STEP_FINT_128(rgba[3]) * 2.0;
highp float Exponent = 2.0 * MOD_FINT_128(rgba[3]) + STEP_FINT_128(rgba[2]) - 127.0;
highp float Mantissa = MOD_FINT_128(rgba[2]) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;
return Sign * exp2(Exponent - 23.0) * Mantissa;
}