1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#ifndef _SOFTSHADEROOM_COMMON_HEADER_H_
#define _SOFTSHADEROOM_COMMON_HEADER_H_
#include "../core/shader.h"
/************************************************************************/
/* constants */
/************************************************************************/
#define SSR_PI 3.14159265359f
#define SSR_TWO_PI 6.28318530718f
#define SSR_FOUR_PI 12.56637061436f
#define SSR_INV_PI 0.31830988618f
#define SSR_INV_TWO_PI 0.15915494309f
#define SSR_INV_FOUR_PI 0.07957747155f
#define SSR_HALF_PI 1.57079632679f
#define SSR_INV_HALF_PI 0.636619772367f
/************************************************************************/
/* 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; \
mat4_mulvec4(uniforms->mvp, &p, clipcoord); \
}while(0)
#define object2clip(pos, out) mat4_mulvec4(_mvp_matrix, pos, out);
/*need defined _it_model_matrix of model matrix, i-nverse, t-ranspose*/
#define object2world_normal(normal, out) \
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
|