summaryrefslogtreecommitdiff
path: root/src/shaders
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-02-22 18:17:06 +0800
committerchai <chaifix@163.com>2020-02-22 18:17:06 +0800
commit9c89460e136ed6c6c43704d9a3a15105e0f006b0 (patch)
treecd56f1dfc10650cfbfe7007ee3432ee32227edc3 /src/shaders
parentd49f3d3f73709a9a7c0bce53aa13ed28a2bd27cb (diff)
*wog
Diffstat (limited to 'src/shaders')
-rw-r--r--src/shaders/common.h45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/shaders/common.h b/src/shaders/common.h
index cae9309..7e0ca5f 100644
--- a/src/shaders/common.h
+++ b/src/shaders/common.h
@@ -1,12 +1,33 @@
#ifndef _SOFTSHADEROOM_COMMON_HEADER_H_
#define _SOFTSHADEROOM_COMMON_HEADER_H_
-
-/*
-** Common shader header
-*/
#include "../core/shader.h"
-extern void ssrR_putline(int x0, int y0, int x1, int y1, Color color);
+/************************************************************************/
+/* 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*/
+
+/************************************************************************/
+/* functions */
+/************************************************************************/
/*shader built in functions*/
Vec3 normal_from_color(Color32 c32);
@@ -20,6 +41,8 @@ Vec2 texsize(Texture* texture);
do{ \
if(cond) return 0; \
}while(0)
+#define discard() return 0
+#define keep() return 1
#define MVP_PROCESS \
do{ \
@@ -27,18 +50,16 @@ static Vec4 p; p.xyz = in->vertex->position; p.w = 1; \
mat4_mulvec4(uniforms->mvp, &p, clipcoord); \
}while(0)
-#define _model_matrix (uniforms->model)
-#define _view_matrix (uniforms->view)
-#define _proj_matrix (uniforms->projection)
-#define _mvp_matrix (uniforms->mvp)
-#define _inverse_model_matrix (uniforms->inverse_model)
-
#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;
#endif \ No newline at end of file