Skip to content

Commit

Permalink
[code] move decode32 to unpack.chunk (#12823)
Browse files Browse the repository at this point in the history
  • Loading branch information
jk20012001 committed Sep 22, 2022
1 parent f72898a commit 72219a2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <common/common-define> // decode32
#include <common/data/unpack> // decode32
#include <builtin/uniforms/cc-morph>

/**
Expand Down
18 changes: 4 additions & 14 deletions editor/assets/chunks/common/common-define.chunk
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,7 @@
#pragma define CC_HANDLE_RT_SAMPLE_FLIP(uv) uv = cc_cameraPos.w > 1.0 ? vec2(uv.x, 1.0 - uv.y) : uv
#pragma define CC_HANDLE_GET_CLIP_FLIP(uv) uv = cc_cameraPos.w == 0.0 ? vec2(uv.x, -uv.y) : uv

#pragma define STEP_FINT_128(v) (step(128.0, (v) + 0.5))
#pragma 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;
}

float isNan(float val) {
return (val <= 0.0 || 0.0 <= val) ? 0.0 : 1.0;
}
// CC_USE_LIGHTMAP Values
#define CC_LIGHTMAP_DISABLED 0
#define CC_LIGHTMAP_ALL_IN_ONE 1
#define CC_LIGHTMAP_CC_LIGHTMAP_INDIRECT_OCCLUSION 2
12 changes: 12 additions & 0 deletions editor/assets/chunks/common/data/unpack.chunk
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.

#pragma define STEP_FINT_128(v) (step(128.0, (v) + 0.5))
#pragma 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;
}


vec4 packRGBE (vec3 rgb) {
highp float maxComp = max(max(rgb.r, rgb.g), rgb.b);
highp float e = 128.0;
Expand Down
3 changes: 2 additions & 1 deletion editor/assets/chunks/legacy/skinning.chunk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <common/common-define>
#include <common/data/unpack> //decode32
#include <builtin/uniforms/cc-skinning>
#include <builtin/functionalities/skinning-animation-lbs>
//#include <builtin/functionalities/skinning-animation-dqs>
//#include <builtin/functionalities/skinning-animation-dqs>

0 comments on commit 72219a2

Please sign in to comment.