diff options
author | chai <chaifix@163.com> | 2020-07-12 13:31:28 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-07-12 13:31:28 +0800 |
commit | a0439c8d387579a1727ad00c2e105e7602aedbb6 (patch) | |
tree | 8ea09b13e179a7d8cd9ac6518410cd10035f48f4 /src/shaders/common/core.h | |
parent | ec7aa42781a9108901fbde7210d8285bbbeaf5fc (diff) |
+mathlib
Diffstat (limited to 'src/shaders/common/core.h')
-rw-r--r-- | src/shaders/common/core.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/shaders/common/core.h b/src/shaders/common/core.h new file mode 100644 index 0000000..623409e --- /dev/null +++ b/src/shaders/common/core.h @@ -0,0 +1,72 @@ +#ifndef _SOFTSHADEROOM_COMMON_HEADER_H_ +#define _SOFTSHADEROOM_COMMON_HEADER_H_ +#include "../../core/shader.h" +#include "mathlib.h" + +/************************************************************************/ +/* variables */ +/************************************************************************/ + +#define _model_matrix (uniforms->model) +#define _view_matrix (uniforms->view) +#define _proj_matrix (uniforms->projection) +#define _mvp_matrix (uniforms->mvp) +#define _it_model_matrix /*inverse-transpose model matrix if needed*/ + +// near +// far +// fov +// aspect +Vec4 _proj_params; + +// dt +// duration +Vec2 _time; + +// width +// height +// 1 / width +// 1 / height +Vec4 _screen_params; + +/************************************************************************/ +/* functions */ +/************************************************************************/ + +/*shader built in functions*/ +Vec3 unpacknormal(Color32 c32); + +Mat4 mat4(Vec4* c1, Vec4* c2, Vec4* c3, Vec4* c4); +Mat3 mat3(Vec3* c1, Vec3* c2, Vec3* c3); + +Vec2 texsize(Texture* texture); + +#define discardif(cond) \ +do{ \ +if(cond) return 0; \ +}while(0) +#define discard() return 0 +#define keep() return 1 + +#define MVP_PROCESS \ +do{ \ +static Vec4 p; p.xyz = in->vertex->position; p.w = 1; \ +internal_mat4_mulvec4(uniforms->mvp, &p, clipcoord); \ +}while(0) + +#define object2clip(pos, out) internal_mat4_mulvec4(_mvp_matrix, pos, out); + +/*need defined _it_model_matrix of model matrix, i-nverse, t-ranspose*/ +#define object2world_normal(normal, out) \ +internal_mat4_mulvec4(_it_model_matrix, normal, out) + +/*take sample from normal map and translate to normal*/ +#define unpack_normal(color, out_v3) \ +out_v3->x = color.x * 2 - 1; \ +out_v3->y = color.y * 2 - 1; \ +out_v3->z = color.z * 2 - 1; + +float linear01depth(float depth); +float lineareyedepth(float depth); + +#endif
\ No newline at end of file |