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
|
#include "visualize.h"
#include "../shaders/common/core.h"
// varying
#define _color reg_v4_00
static void vert( Vertex* in, Vec4* clipcoord) {
static Vec4 p; p.xyz = in->position; p.w = 1;
object2clip(&p, clipcoord);
color_tocolor32(in->color, _color);
}
static bool frag( Color32* color) {
*color = *_color;
return 1;
}
static Program line_shader = {
vert, frag,
VARYING_V4_00
};
void draw_tbn(Mesh* mesh, uint mask, int length) {
Color COLOR_RED = 0xffff0000;
Color COLOR_GREEN = 0xff00ff00;
Color COLOR_BLUE = 0xff0000ff;
Vertex* vert_list = NULL;
int vert_index = 0;
int* lines = NULL;
for (int i = 0; i < mesh->vert_count; ++i) {
Vertex* vert = &mesh->vertices[i];
Vec3 normal = vert->normal;
Vec4 tangent = vert->tangent;
//Vec4 tangent = vec4(1,0,0,1);
if (mask & VISUAL_NORMAL)
{
Vertex v0 = { vert_index++, vert->position, vec3zero, vec4zero, vec2zero, COLOR_BLUE };
Vertex v1 = { vert_index++, vec3_plus(vert->position, vec3_scale(normal, length)), vec3zero, vec4zero, vec2zero, COLOR_BLUE };
darray_push(vert_list, v0);
darray_push(vert_list, v1);
darray_push(lines, vert_index - 2);
darray_push(lines, vert_index - 1);
}
if (mask & VISUAL_TANGNET)
{
Vertex v0 = { vert_index++, vert->position, vec3zero, vec4zero, vec2zero, COLOR_RED };
Vertex v1 = { vert_index++, vec3_plus(vert->position, vec3_scale(tangent.xyz, length)), vec3zero, vec4zero, vec2zero, COLOR_RED };
darray_push(vert_list, v0);
darray_push(vert_list, v1);
darray_push(lines, vert_index - 2);
darray_push(lines, vert_index - 1);
}
if (mask & VISUAL_BITANGENT)
{
Vec3 bitangent = vec3_cross(normal, tangent.xyz);
Vertex v0 = { vert_index++, vert->position, vec3zero, vec4zero, vec2zero, COLOR_GREEN };
Vertex v1 = { vert_index++, vec3_plus(vert->position, vec3_scale(bitangent, length)), vec3zero, vec4zero, vec2zero, COLOR_GREEN };
darray_push(vert_list, v0);
darray_push(vert_list, v1);
darray_push(lines, vert_index - 2);
darray_push(lines, vert_index - 1);
}
}
ssr_bindvertices(vert_list, darray_size(vert_list));
ssr_bindindices(lines, darray_size(lines)* 0.5f);
ssr_matrixmode(MATRIX_MODEL);
ssr_loadidentity();
ssr_useprogram(&line_shader);
//ssr_disable(ENABLE_DEPTHTEST);
ssr_draw(PRIMITIVE_LINE);
ssr_unuseprogram();
ssr_enable(ENABLE_WRITEDEPTH);
darray_free(vert_list);
darray_free(lines);
}
void draw_wire(Mesh* mesh) {
}
|