diff options
author | chai <chaifix@163.com> | 2020-07-18 03:25:53 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-07-18 03:25:53 +0800 |
commit | 4984946caf0397a13da7605bc1ee406ea7354628 (patch) | |
tree | 0e87b71ae7639b8f12dbf3e8ec94e2087390acef /src | |
parent | e5e995103377f9bb79123ef8257d8680ed0945fc (diff) |
-VertexShaderIn
Diffstat (limited to 'src')
-rw-r--r-- | src/core/device.c | 10 | ||||
-rw-r--r-- | src/core/device.h | 2 | ||||
-rw-r--r-- | src/core/shader.h | 8 | ||||
-rw-r--r-- | src/core/vert.h | 4 | ||||
-rw-r--r-- | src/example/03_texture/03_texture.c | 2 | ||||
-rw-r--r-- | src/example/04_bloom/04_bloom.c | 4 | ||||
-rw-r--r-- | src/example/04_bloom/postprocess.c | 6 | ||||
-rw-r--r-- | src/example/04_bloom/preprocess.c | 6 | ||||
-rw-r--r-- | src/extend/mesh.c | 6 | ||||
-rw-r--r-- | src/extend/mesh.h | 4 | ||||
-rw-r--r-- | src/gizmo/gizmo.c | 12 | ||||
-rw-r--r-- | src/math/math.h | 2 | ||||
-rw-r--r-- | src/shaders/common/core.h | 2 | ||||
-rw-r--r-- | src/shaders/default.c | 10 | ||||
-rw-r--r-- | src/shaders/pbr.c | 10 | ||||
-rw-r--r-- | src/shaders/unlit.c | 10 |
16 files changed, 48 insertions, 50 deletions
diff --git a/src/core/device.c b/src/core/device.c index 923a2fa..8284315 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -44,7 +44,7 @@ static struct { StencilFunc stencil_func; StencilOp stencil_failop, stencil_dpfailop, stencil_passop; - Vert* verts; uint vert_count; + Vertex* verts; uint vert_count; uint* indices; uint prim_count; Program* program; @@ -457,7 +457,7 @@ void ssrU_blend( out->a = src->a + dst->a; } -void ssr_bindvertices(Vert* verts, int vert_count, uint* indices, int prim_count) { +void ssr_bindvertices(Vertex* verts, int vert_count, uint* indices, int prim_count) { ssr_assert(verts && indices); state.verts = verts; state.vert_count = vert_count; @@ -474,7 +474,6 @@ void ssr_unuseprogram() { state.program = NULL; } -VertexShaderIn ssr_vert_in; FragmentShaderIn ssr_frag_in; static struct { @@ -659,13 +658,12 @@ void ssr_draw(ssr_PrimitiveType primitive) { /*vertex operation*/ VertexShader vert_shader = state.program->vertexshader; for (int i = 0; i < state.vert_count; ++i) { - Vert* vert = &state.verts[i]; - ssr_vert_in.vertex = vert; + Vertex* vert = &state.verts[i]; /*set register pointers*/ if (use_extra_varyings) { ssrS_setupregisterpointers(vert->index); } - vert_shader(&state.uniforms, &ssr_vert_in, &clip_coords.coords[i]); + vert_shader(&state.uniforms, vert, &clip_coords.coords[i]); } /*set register pointer to frag-in*/ diff --git a/src/core/device.h b/src/core/device.h index 0b27b70..79ffd4b 100644 --- a/src/core/device.h +++ b/src/core/device.h @@ -118,7 +118,7 @@ void ssr_disable(uint mask); bool ssr_isenable(uint mask); /* 绑定顶点数据 */ -void ssr_bindvertices(Vert* verts, int vert_count, uint* indices, int prim_count); +void ssr_bindvertices(Vertex* verts, int vert_count, uint* indices, int prim_count); void ssr_unbindvertices(); void ssr_useprogram(Program* program); diff --git a/src/core/shader.h b/src/core/shader.h index 71f26e4..043ba1e 100644 --- a/src/core/shader.h +++ b/src/core/shader.h @@ -38,11 +38,11 @@ typedef struct { #define REG_V3_COUNT 12 #define REG_V4_COUNT 8 -typedef struct { - Vert* vertex; -} VertexShaderIn; +//typedef struct { +// Vertex* vertex; +//} Vertex; -typedef void(*VertexShader)(UniformCollection* uniforms, VertexShaderIn* in, Vec4* homocoord); +typedef void(*VertexShader)(UniformCollection* uniforms, Vertex* in, Vec4* homocoord); typedef struct { float num[REG_NUM_COUNT]; diff --git a/src/core/vert.h b/src/core/vert.h index 6c968b5..c733baa 100644 --- a/src/core/vert.h +++ b/src/core/vert.h @@ -22,7 +22,7 @@ Color color32_tocolor(Color32* c); void color_tocolor32(Color c, Color32* out); void color32_saturate(Color32* c); -typedef struct Vert { +typedef struct { uint index; Vec3 position; Vec3 normal; @@ -34,6 +34,6 @@ typedef struct Vert { Vec4 joint; Vec4 weight; */ -} Vert; +} Vertex; #endif
\ No newline at end of file diff --git a/src/example/03_texture/03_texture.c b/src/example/03_texture/03_texture.c index 09d8f97..2e9d6f1 100644 --- a/src/example/03_texture/03_texture.c +++ b/src/example/03_texture/03_texture.c @@ -10,7 +10,7 @@ static int cube[] = { 2, 6, 3, 3, 6, 7 }; -static Vert verts[] = { +static Vertex verts[] = { {0, {1, 1, 1}, {1, 1, 1}, zerovec3, {1, 1}, 0xffff0000}, {1, {-1, 1, 1}, {-1, 1, 1}, zerovec3, {0, 1},0xff00ff00}, {2, {-1, -1, 1}, {-1, -1, 1}, zerovec3, {0, 0}, 0xff0000ff}, diff --git a/src/example/04_bloom/04_bloom.c b/src/example/04_bloom/04_bloom.c index 037a9e1..8115fcf 100644 --- a/src/example/04_bloom/04_bloom.c +++ b/src/example/04_bloom/04_bloom.c @@ -10,7 +10,7 @@ static int cube[] = { 2, 6, 3, 3, 6, 7 }; -static Vert verts[] = { +static Vertex verts[] = { {0, {1, 1, 1}, {1, 1, 1}, zerovec4, {1, 1}, 0xffff0000}, {1, {-1, 1, 1}, {-1, 1, 1}, zerovec4, {0, 1},0xff00ff00}, {2, {-1, -1, 1}, {-1, -1, 1}, zerovec4, {0, 0}, 0xff0000ff}, @@ -79,7 +79,7 @@ void onupdatebloom(void*data) { static void renderquad() { /*全屏特效*/ - static Vert verts[] = { + static Vertex verts[] = { {0, {1, 1, 0}, zerovec3, zerovec3, {1, 1}, 0}, {1, {-1, 1, 0}, zerovec3, zerovec3, {0, 1},0}, {2, {-1, -1, 0}, zerovec3, zerovec3, {0, 0}, 0}, diff --git a/src/example/04_bloom/postprocess.c b/src/example/04_bloom/postprocess.c index c305726..fe58b96 100644 --- a/src/example/04_bloom/postprocess.c +++ b/src/example/04_bloom/postprocess.c @@ -9,10 +9,10 @@ static float weight[5] = { 0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162 }; -static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* clipcoord) { - clipcoord->xyz = in->vertex->position; +static void vert(UniformCollection* uniforms, Vertex* in, Vec4* clipcoord) { + clipcoord->xyz = in->position; clipcoord->w = 1; - *_texcoord = in->vertex->texcoord; + *_texcoord = in->texcoord; } static bool frag(UniformCollection* uniforms, Color32* color) { diff --git a/src/example/04_bloom/preprocess.c b/src/example/04_bloom/preprocess.c index 8dd2170..f02195f 100644 --- a/src/example/04_bloom/preprocess.c +++ b/src/example/04_bloom/preprocess.c @@ -5,10 +5,10 @@ /*varyings*/ #define _color reg_v4_00 -static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* clipcoord) { - static Vec4 p; p.xyz = in->vertex->position; p.w = 1; +static void vert(UniformCollection* uniforms, Vertex* in, Vec4* clipcoord) { + static Vec4 p; p.xyz = in->position; p.w = 1; internal_mat4_mulvec4(uniforms->mvp, &p, clipcoord); - color_tocolor32(in->vertex->color, _color); + color_tocolor32(in->color, _color); } /*multi target*/ diff --git a/src/extend/mesh.c b/src/extend/mesh.c index 394a7e8..56b1afe 100644 --- a/src/extend/mesh.c +++ b/src/extend/mesh.c @@ -60,7 +60,7 @@ static Mesh *build_mesh( mesh = (Mesh*)malloc(sizeof(Mesh)); mesh->triangles = ssrM_newvector(int, 3 * num_faces); int nvert = DARRAY_OCCUPIED(positions); - Vert* vertices = ssrM_newvector(Vert, nvert); + Vertex* vertices = ssrM_newvector(Vertex, nvert); for (i = 0; i < num_indices; i++) { int position_index = position_indices[i]; @@ -202,7 +202,7 @@ typedef struct { } Triangle; typedef struct { - Vert props; // position, normal, texcoord etc + Vertex props; // position, normal, texcoord etc int* related_triangles; } MeshVertexInfo; @@ -412,7 +412,7 @@ Mesh* build_mesh(MeshInfo* mesh_info) { mesh->triangles[3 * i + 2] = mesh_info->triangles[i].vertices[2]; } mesh->tris_count = num_of_face; - mesh->vertices = malloc(sizeof(Vert) * darray_size(mesh_info->vertices)); + mesh->vertices = malloc(sizeof(Vertex) * darray_size(mesh_info->vertices)); for (int i = 0; i < darray_size(mesh_info->vertices); ++i) { mesh->vertices[i] = mesh_info->vertices[i].props; } diff --git a/src/extend/mesh.h b/src/extend/mesh.h index 6bbb571..d7a519e 100644 --- a/src/extend/mesh.h +++ b/src/extend/mesh.h @@ -4,7 +4,7 @@ #include "../core/vert.h" /* typedef struct { - Vert* vertices; + Vertex* vertices; uint vert_count; uint* triangles; uint tris_count; @@ -12,7 +12,7 @@ typedef struct { } SubMesh; */ typedef struct { - Vert* vertices; + Vertex* vertices; uint vert_count; uint* triangles; uint tris_count; diff --git a/src/gizmo/gizmo.c b/src/gizmo/gizmo.c index 20c28e1..adf5e43 100644 --- a/src/gizmo/gizmo.c +++ b/src/gizmo/gizmo.c @@ -47,10 +47,10 @@ void gizmo_ondraw() { // varying #define _color reg_v4_00 -static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* clipcoord) { - static Vec4 p; p.xyz = in->vertex->position; p.w = 1; +static void vert(UniformCollection* uniforms, Vertex* in, Vec4* clipcoord) { + static Vec4 p; p.xyz = in->position; p.w = 1; object2clip(&p, clipcoord); - color_tocolor32(in->vertex->color, _color); + color_tocolor32(in->color, _color); } static bool frag(UniformCollection* uniforms, Color32* color) { *color = *_color; @@ -64,7 +64,7 @@ static Program line_shader = { void gizmo_grid() { const int field = 1000; int vCount = 80 + 4; - Vert verts[84] = {0};//4*field/100*2 + Vertex verts[84] = {0};//4*field/100*2 int grid[84] = {0}; int vertCount; int i = 0; @@ -121,7 +121,7 @@ void gizmo_grid() { } void gizmo_axis() { - Vert verts[] = { + Vertex verts[] = { {0, {-10000, 0, 0}, vec3zero, vec4zero, vec2zero, 0xffff0000}, {1, {10000, 0, 0}, vec3zero, vec4zero, vec2zero, 0xffff0000}, {2, {0, -10000, 0}, vec3zero, vec4zero, vec2zero, 0xff00ff00}, @@ -140,7 +140,7 @@ void gizmo_axis() { } void gizmo_line(Vec3 start, Vec3 end, Color32 color) { - Vert verts[] = { + Vertex verts[] = { {0, start, vec3zero, vec4zero, vec2zero, color32_tocolor(&color)}, {1, end, vec3zero, vec4zero, vec2zero, color32_tocolor(&color)}, }; diff --git a/src/math/math.h b/src/math/math.h index b520f9e..d175574 100644 --- a/src/math/math.h +++ b/src/math/math.h @@ -156,7 +156,7 @@ bool internal_mat4_toeuler(Mat4* in, Euler* out); /* 计算YXZ旋转矩阵的欧拉角 */ void internal_mat4_toquat(Mat4* in, Quat* out); /*in是正交矩阵*/ #define ROWMAT(A, ...)\ -Mat4 A={__VA_ARGS__};internal_mat4_transpose(&A, &A); + Mat4 A={__VA_ARGS__};internal_mat4_transpose(&A, &A); void internal_mat3_multvec3(Mat3* m, Vec3* v, Vec3* out); void internal_mat3_multmat3(Mat3* m1, Mat3* m2, Mat3* out); diff --git a/src/shaders/common/core.h b/src/shaders/common/core.h index 69ff48b..2e895c5 100644 --- a/src/shaders/common/core.h +++ b/src/shaders/common/core.h @@ -50,7 +50,7 @@ if(cond) return 0; \ #define MVP_PROCESS \ do{ \ -static Vec4 p; p.xyz = in->vertex->position; p.w = 1; \ +static Vec4 p; p.xyz = in->position; p.w = 1; \ internal_mat4_mulvec4(uniforms->mvp, &p, clipcoord); \ }while(0) diff --git a/src/shaders/default.c b/src/shaders/default.c index e05d15d..efd9f25 100644 --- a/src/shaders/default.c +++ b/src/shaders/default.c @@ -11,13 +11,13 @@ /*varyings*/ #define rough reg_num_00 -static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* clipcoord) { - static Vec4 p; p.xyz = in->vertex->position; p.w = 1; +static void vert(UniformCollection* uniforms, Vertex* in, Vec4* clipcoord) { + static Vec4 p; p.xyz = in->position; p.w = 1; internal_mat4_mulvec4(uniforms->mvp, &p, clipcoord); Vec4 normal = { - in->vertex->normal.x, - in->vertex->normal.y, - in->vertex->normal.z, + in->normal.x, + in->normal.y, + in->normal.z, 1 }; Vec4 worldnormal; internal_mat4_mulvec4(object2world, &normal, &worldnormal); diff --git a/src/shaders/pbr.c b/src/shaders/pbr.c index 556208e..1c74feb 100644 --- a/src/shaders/pbr.c +++ b/src/shaders/pbr.c @@ -19,14 +19,14 @@ #define _world_tangent reg_v3_03 #define _world_bitangent reg_v3_04 -static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* clipcoord) { - static Vec4 p; p.xyz = in->vertex->position; p.w = 1; +static void vert(UniformCollection* uniforms, Vertex* in, Vec4* clipcoord) { + static Vec4 p; p.xyz = in->position; p.w = 1; object2clip(&p, clipcoord); - Vec3 worldnormal = mat4_mulvec3(*_object2world, in->vertex->normal); + Vec3 worldnormal = mat4_mulvec3(*_object2world, in->normal); worldnormal = vec3_normalize(worldnormal); //*rough = 1 - internal_vec3_dot(&worldnormal, light); - //*vnormal = in->vertex->normal; - *_texcoord = in->vertex->texcoord; + //*vnormal = in->normal; + *_texcoord = in->texcoord; _clip_pos->x = clipcoord->z; _clip_pos->y = clipcoord->w; } diff --git a/src/shaders/unlit.c b/src/shaders/unlit.c index 0b92c8c..c6a258b 100644 --- a/src/shaders/unlit.c +++ b/src/shaders/unlit.c @@ -8,13 +8,13 @@ /*varyings*/ #define rough reg_num_00 -static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* clipcoord) { - static Vec4 p; p.xyz = in->vertex->position; p.w = 1; +static void vert(UniformCollection* uniforms, Vertex* in, Vec4* clipcoord) { + static Vec4 p; p.xyz = in->position; p.w = 1; internal_mat4_mulvec4(uniforms->mvp, &p, clipcoord); Vec4 normal = { - in->vertex->normal.x, - in->vertex->normal.y, - in->vertex->normal.z, + in->normal.x, + in->normal.y, + in->normal.z, 1 }; Vec4 worldnormal; internal_mat4_mulvec4(object2world, &normal, &worldnormal); |