summaryrefslogtreecommitdiff
path: root/src/shaders
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-12-23 23:59:02 +0800
committerchai <chaifix@163.com>2019-12-23 23:59:02 +0800
commitd49f3d3f73709a9a7c0bce53aa13ed28a2bd27cb (patch)
tree3fc2cca442106a56fc151c5faffbb24217ca83f5 /src/shaders
parentec111247c614663d8231245a17c314b9b8b4a28c (diff)
*misc
Diffstat (limited to 'src/shaders')
-rw-r--r--src/shaders/common.c7
-rw-r--r--src/shaders/common.h21
-rw-r--r--src/shaders/pbr.c2
3 files changed, 26 insertions, 4 deletions
diff --git a/src/shaders/common.c b/src/shaders/common.c
index f36e272..3b58524 100644
--- a/src/shaders/common.c
+++ b/src/shaders/common.c
@@ -19,3 +19,10 @@ Mat3 mat3(Vec3* c1, Vec3* c2, Vec3* c3) {
};
return m;
}
+
+Vec2 texsize(Texture* texture) {
+ Vec2 size = {texture->width, texture->height};
+ return size;
+}
+
+
diff --git a/src/shaders/common.h b/src/shaders/common.h
index 8b74bec..cae9309 100644
--- a/src/shaders/common.h
+++ b/src/shaders/common.h
@@ -1,13 +1,14 @@
#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);
-/*
-** shader built in functions
-*/
+/*shader built in functions*/
Vec3 normal_from_color(Color32 c32);
Mat4 mat4(Vec4* c1, Vec4* c2, Vec4* c3, Vec4* c4);
@@ -26,4 +27,18 @@ 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)
+
+
+
#endif \ No newline at end of file
diff --git a/src/shaders/pbr.c b/src/shaders/pbr.c
index bd78c8b..6db3d68 100644
--- a/src/shaders/pbr.c
+++ b/src/shaders/pbr.c
@@ -22,7 +22,7 @@
static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* clipcoord) {
static Vec4 p; p.xyz = in->vertex->position; p.w = 1;
- mat4_mulvec4(uniforms->mvp, &p, clipcoord);
+ object2clip(&p, clipcoord);
Vec4 normal = {
in->vertex->normal.x,
in->vertex->normal.y,