commit fdc9717a405a6ebd3fe8835fbca53f040d675743
parent 7b7d005583773071edb3a1b58d8fb572a0e77db0
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 26 Mar 2015 12:25:33 +0100
Update the trace ray test scene
Diffstat:
5 files changed, 146 insertions(+), 112 deletions(-)
diff --git a/src/s3d_primitive.c b/src/s3d_primitive.c
@@ -57,8 +57,8 @@ s3d_primitive_get_attrib
return RES_BAD_ARG;
/* Unormalized barycentric coordinates */
- w = 1.f - uv[0] - uv[1];
- if(uv[0] < 0.f || uv[1] < 0.f || w < 0.f || w > 1.f)
+ w = CLAMP(1.f - uv[0] - uv[1], 0.f, 1.f);
+ if(uv[0] < 0.f || uv[1] < 0.f)
return RES_BAD_ARG;
if(prim->igeom__ == RTC_INVALID_GEOMETRY_ID) {
diff --git a/src/test_s3d_cbox.h b/src/test_s3d_cbox.h
@@ -36,8 +36,15 @@
#include <rsys/rsys.h>
#include <stdint.h>
-static const float cbox_verts[] = {
- /* Box */
+struct cbox_desc{
+ const float* vertices;
+ const unsigned* indices;
+};
+
+/*******************************************************************************
+ * Box
+ ******************************************************************************/
+static const float cbox_walls[] = {
552.f, 0.f, 0.f,
0.f, 0.f, 0.f,
0.f, 559.f, 0.f,
@@ -45,8 +52,23 @@ static const float cbox_verts[] = {
552.f, 0.f, 548.f,
0.f, 0.f, 548.f,
0.f, 559.f, 548.f,
- 552.f, 559.f, 548.f,
- /* Short block */
+ 552.f, 559.f, 548.f
+};
+
+const unsigned cbox_walls_ids[] = {
+ 0, 1, 2, 2, 3, 0, /* Bottom */
+ 4, 5, 6, 6, 7, 4, /* Top */
+ 1, 2, 6, 6, 5, 1, /* Left */
+ 0, 3, 7, 7, 4, 0, /* Right */
+ 2, 3, 7, 7, 6, 2 /* Back */
+};
+
+static const struct cbox_desc cbox_walls_desc = { cbox_walls, cbox_walls_ids };
+
+/*******************************************************************************
+ * Short/tall blocks
+ ******************************************************************************/
+static const float cbox_short_block[] = {
130.f, 65.f, 0.f,
82.f, 225.f, 0.f,
240.f, 272.f, 0.f,
@@ -54,8 +76,10 @@ static const float cbox_verts[] = {
130.f, 65.f, 165.f,
82.f, 225.f, 165.f,
240.f, 272.f, 165.f,
- 290.f, 114.f, 165.f,
- /* Tall block */
+ 290.f, 114.f, 165.f
+};
+
+static const float cbox_tall_block[] = {
423.0f, 247.0f, 0.f,
265.0f, 296.0f, 0.f,
314.0f, 456.0f, 0.f,
@@ -65,51 +89,37 @@ static const float cbox_verts[] = {
314.0f, 456.0f, 330.f,
472.0f, 406.0f, 330.f
};
-const unsigned cbox_nverts = (unsigned)(sizeof(cbox_verts)/(sizeof(float[3])));
-const uint32_t cbox_ids[] = {
- /* Box */
- 0, 1, 2, 2, 3, 0, /* Bottom */
- 4, 5, 6, 6, 7, 4, /* Top */
- 1, 2, 6, 6, 5, 1, /* Left */
- 0, 3, 7, 7, 4, 0, /* Right */
- 2, 3, 7, 7, 6, 2, /* Back */
- /* Short block */
- 12, 13, 14, 14, 15, 12,
- 9, 10, 14, 14, 13, 9,
- 8, 11, 15, 15, 12, 8,
- 10, 11, 15, 15, 14, 10,
- 8, 9, 13, 13, 12, 8,
- /* Tall block */
- 20, 21, 22, 22, 23, 20,
- 17, 18, 22, 22, 21, 17,
- 16, 19, 23, 23, 20, 16,
- 18, 19, 23, 23, 22, 18,
- 16, 17, 21, 21, 20, 16
+static const unsigned cbox_block_ids[] = {
+ 4, 5, 6, 6, 7, 4,
+ 1, 2, 6, 6, 5, 1,
+ 0, 3, 7, 7, 4, 0,
+ 2, 3, 7, 7, 6, 2,
+ 0, 1, 5, 5, 4, 0
};
-const unsigned cbox_nids = (unsigned)(sizeof(cbox_ids)/sizeof(uint32_t));
-const unsigned cbox_ntris = (unsigned)(sizeof(cbox_ids)/sizeof(uint32_t)/3);
+/*******************************************************************************
+ * Callbacks
+ ******************************************************************************/
static INLINE void
cbox_get_ids(const unsigned itri, unsigned ids[3], void* data)
{
const unsigned id = itri * 3;
- (void)data;
- CHECK(itri < cbox_ntris, 1);
- CHECK(id + 2 < cbox_nids, 1);
- ids[0] = cbox_ids[id + 0];
- ids[1] = cbox_ids[id + 1];
- ids[2] = cbox_ids[id + 2];
+ struct cbox_desc* desc = data;
+ NCHECK(desc, NULL);
+ ids[0] = desc->indices[id + 0];
+ ids[1] = desc->indices[id + 1];
+ ids[2] = desc->indices[id + 2];
}
static INLINE void
cbox_get_position(const unsigned ivert, float position[3], void* data)
{
- (void)data;
- CHECK(ivert < cbox_nverts, 1);
- position[0] = cbox_verts[ivert*3 + 0];
- position[1] = cbox_verts[ivert*3 + 1];
- position[2] = cbox_verts[ivert*3 + 2];
+ struct cbox_desc* desc = data;
+ NCHECK(desc, NULL);
+ position[0] = desc->vertices[ivert*3 + 0];
+ position[1] = desc->vertices[ivert*3 + 1];
+ position[2] = desc->vertices[ivert*3 + 2];
}
static INLINE void
diff --git a/src/test_s3d_scene.c b/src/test_s3d_scene.c
@@ -61,6 +61,12 @@ main(int argc, char** argv)
CHECK(s3d_scene_attach_shape(scn, shapes[0]), RES_OK);
CHECK(s3d_scene_attach_shape(scn, shapes[0]), RES_BAD_ARG);
+ CHECK(s3d_scene_detach_shape(NULL, NULL), RES_BAD_ARG);
+ CHECK(s3d_scene_detach_shape(scn, NULL), RES_BAD_ARG);
+ CHECK(s3d_scene_detach_shape(NULL, shapes[0]), RES_BAD_ARG);
+ CHECK(s3d_scene_detach_shape(scn, shapes[0]), RES_OK);
+ CHECK(s3d_scene_detach_shape(scn, shapes[0]), RES_BAD_ARG);
+
FOR_EACH(i, 1, nshapes) {
CHECK(s3d_scene_attach_shape(scn, shapes[i]), RES_OK);
CHECK(s3d_shape_ref_put(shapes[i]), RES_OK);
diff --git a/src/test_s3d_shape.c b/src/test_s3d_shape.c
@@ -44,6 +44,9 @@ main(int argc, char** argv)
struct s3d_scene* scn;
struct s3d_vertex_data attribs[4];
float pos[3];
+ const unsigned cbox_ntris = sizeof(cbox_walls_ids) / sizeof(unsigned[3]);
+ const unsigned cbox_nverts = sizeof(cbox_walls) / sizeof(float[3]);
+ void* data = (void*)&cbox_walls_desc;
char c;
(void)argc, (void)argv;
@@ -82,122 +85,122 @@ main(int argc, char** argv)
attribs[0].get = cbox_get_position;
attribs[1] = S3D_VERTEX_DATA_NULL;
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, 0, NULL, 0, NULL, NULL), RES_BAD_ARG);
+ (NULL, 0, NULL, 0, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, 0, NULL, 0, NULL, NULL), RES_BAD_ARG);
+ (shape, 0, NULL, 0, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, cbox_ntris, NULL, 0, NULL, NULL), RES_BAD_ARG);
+ (NULL, cbox_ntris, NULL, 0, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, NULL, 0, NULL, NULL), RES_BAD_ARG);
+ (shape, cbox_ntris, NULL, 0, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, 0, cbox_get_ids, 0, NULL, NULL), RES_BAD_ARG);
+ (NULL, 0, cbox_get_ids, 0, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, 0, cbox_get_ids, 0, NULL, NULL), RES_BAD_ARG);
+ (shape, 0, cbox_get_ids, 0, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, cbox_ntris, cbox_get_ids, 0, NULL, NULL), RES_BAD_ARG);
+ (NULL, cbox_ntris, cbox_get_ids, 0, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, cbox_get_ids, 0, NULL, NULL), RES_BAD_ARG);
+ (shape, cbox_ntris, cbox_get_ids, 0, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, 0, NULL, cbox_nverts, NULL, NULL), RES_BAD_ARG);
+ (NULL, 0, NULL, cbox_nverts, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, 0, NULL, cbox_nverts, NULL, NULL), RES_BAD_ARG);
+ (shape, 0, NULL, cbox_nverts, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, cbox_ntris, NULL, cbox_nverts, NULL, NULL), RES_BAD_ARG);
+ (NULL, cbox_ntris, NULL, cbox_nverts, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, NULL, cbox_nverts, NULL, NULL), RES_BAD_ARG);
+ (shape, cbox_ntris, NULL, cbox_nverts, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, 0, cbox_get_ids, cbox_nverts, NULL, NULL), RES_BAD_ARG);
+ (NULL, 0, cbox_get_ids, cbox_nverts, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, 0, cbox_get_ids, cbox_nverts, NULL, NULL), RES_BAD_ARG);
+ (shape, 0, cbox_get_ids, cbox_nverts, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, cbox_ntris, cbox_get_ids, cbox_nverts, NULL, NULL), RES_BAD_ARG);
+ (NULL, cbox_ntris, cbox_get_ids, cbox_nverts, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, cbox_get_ids, cbox_nverts, NULL, NULL), RES_BAD_ARG);
+ (shape, cbox_ntris, cbox_get_ids, cbox_nverts, NULL, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, 0, NULL, 0, attribs, NULL), RES_BAD_ARG);
+ (NULL, 0, NULL, 0, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, 0, NULL, 0, attribs, NULL), RES_BAD_ARG);
+ (shape, 0, NULL, 0, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, cbox_ntris, NULL, 0, attribs, NULL), RES_BAD_ARG);
+ (NULL, cbox_ntris, NULL, 0, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, NULL, 0, attribs, NULL), RES_BAD_ARG);
+ (shape, cbox_ntris, NULL, 0, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, 0, cbox_get_ids, 0, attribs, NULL), RES_BAD_ARG);
+ (NULL, 0, cbox_get_ids, 0, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, 0, cbox_get_ids, 0, attribs, NULL), RES_BAD_ARG);
+ (shape, 0, cbox_get_ids, 0, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, cbox_ntris, cbox_get_ids, 0, attribs, NULL), RES_BAD_ARG);
+ (NULL, cbox_ntris, cbox_get_ids, 0, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, cbox_get_ids, 0, attribs, NULL), RES_BAD_ARG);
+ (shape, cbox_ntris, cbox_get_ids, 0, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, 0, NULL, cbox_nverts, attribs, NULL), RES_BAD_ARG);
+ (NULL, 0, NULL, cbox_nverts, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, 0, NULL, cbox_nverts, attribs, NULL), RES_BAD_ARG);
+ (shape, 0, NULL, cbox_nverts, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, cbox_ntris, NULL, cbox_nverts, attribs, NULL), RES_BAD_ARG);
+ (NULL, cbox_ntris, NULL, cbox_nverts, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, NULL, cbox_nverts, attribs, NULL), RES_BAD_ARG);
+ (shape, cbox_ntris, NULL, cbox_nverts, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, 0, cbox_get_ids, cbox_nverts, attribs, NULL), RES_BAD_ARG);
+ (NULL, 0, cbox_get_ids, cbox_nverts, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, 0, cbox_get_ids, cbox_nverts, attribs, NULL), RES_BAD_ARG);
+ (shape, 0, cbox_get_ids, cbox_nverts, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (NULL, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, NULL), RES_BAD_ARG);
+ (NULL, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, NULL), RES_OK);
+ (shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, data), RES_OK);
attribs[0] = S3D_VERTEX_DATA_NULL;
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, NULL), RES_BAD_ARG);
+ (shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, data), RES_BAD_ARG);
attribs[0].type = S3D_FLOAT3;
attribs[0].usage = S3D_POSITION;
attribs[0].get = S3D_KEEP;
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, NULL), RES_OK);
+ (shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, data), RES_OK);
attribs[0].get = cbox_get_position;
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_OK);
+ (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, data), RES_OK);
attribs[0].type = S3D_FLOAT3;
attribs[0].usage = S3D_ATTRIB_0;
attribs[0].get = cbox_get_normal;
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_BAD_ARG);
+ (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, data), RES_BAD_ARG);
attribs[1].type = S3D_FLOAT3;
attribs[1].usage = S3D_POSITION;
attribs[1].get = S3D_KEEP;
attribs[2] = S3D_VERTEX_DATA_NULL;
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_OK);
+ (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, data), RES_OK);
attribs[2].type = S3D_FLOAT2;
attribs[2].usage = S3D_ATTRIB_2;
attribs[2].get = cbox_get_uv;
attribs[3] = S3D_VERTEX_DATA_NULL;
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_OK);
+ (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, data), RES_OK);
attribs[0].get = S3D_KEEP;
attribs[1].get = S3D_KEEP;
attribs[2].get = S3D_KEEP;
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, 2, S3D_KEEP, cbox_nverts, attribs, NULL), RES_BAD_ARG);
+ (shape, 2, S3D_KEEP, cbox_nverts, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, S3D_KEEP, cbox_nverts+1, attribs, NULL), RES_BAD_ARG);
+ (shape, cbox_ntris, S3D_KEEP, cbox_nverts+1, attribs, data), RES_BAD_ARG);
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_OK);
+ (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, data), RES_OK);
attribs[2].type = S3D_FLOAT3;
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_BAD_ARG);
+ (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, data), RES_BAD_ARG);
attribs[0].get = cbox_get_position;
attribs[2] = S3D_VERTEX_DATA_NULL;
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_OK);
+ (shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, data), RES_OK);
CHECK(s3d_scene_attach_shape(scn, shape), RES_OK);
diff --git a/src/test_s3d_trace_ray.c b/src/test_s3d_trace_ray.c
@@ -37,8 +37,8 @@
#include <rsys/image.h>
#include <rsys/float3.h>
-#define IMG_WIDTH 512
-#define IMG_HEIGHT 512
+#define IMG_WIDTH 640
+#define IMG_HEIGHT 480
struct camera {
float pos[3];
@@ -48,8 +48,8 @@ struct camera {
static void
camera_init(struct camera* cam)
{
- const float pos[3] = { 0.f, -1500.f, 0.f };
- const float tgt[3] = { 0.f, 0.f, 0.f };
+ const float pos[3] = { 178.f, -1000.f, 273.f };
+ const float tgt[3] = { 178.f, 0.f, 273.f };
const float up[3] = { 0.f, 0.f, 1.f };
const float proj_ratio = (float)IMG_WIDTH/(float)IMG_HEIGHT;
const float fov_x = (float)PI * 0.25f;
@@ -92,7 +92,9 @@ main(int argc, char** argv)
struct s3d_shape* shape;
struct s3d_vertex_data attribs[4];
struct camera cam;
+ struct cbox_desc desc;
unsigned char* img = NULL;
+ unsigned ntris, nverts;
size_t ix, iy;
float org[3] = { 0.f, 0.f, 0.f };
float dir[3] = { 0.f, 1.f, 0.f };
@@ -115,8 +117,12 @@ main(int argc, char** argv)
attribs[0].get = cbox_get_position;
attribs[1] = S3D_VERTEX_DATA_NULL;
+ ntris = sizeof(cbox_walls_ids)/sizeof(unsigned[3]);
+ nverts = sizeof(cbox_walls)/sizeof(float[3]);
+ desc.vertices = cbox_walls;
+ desc.indices = cbox_walls_ids;
CHECK(s3d_mesh_setup_indexed_vertices
- (shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, NULL), RES_OK);
+ (shape, ntris, cbox_get_ids, nverts, attribs, &desc), RES_OK);
CHECK(s3d_scene_attach_shape(scn, shape), RES_OK);
CHECK(s3d_scene_trace_ray(NULL, NULL, NULL, NULL, NULL), RES_BAD_ARG);
@@ -156,29 +162,40 @@ main(int argc, char** argv)
f3(dir, 1.f, 1.f, 1.f);
CHECK(s3d_scene_trace_ray(scn, org, dir, range, &hit), RES_BAD_ARG);
+ ntris = sizeof(cbox_block_ids)/sizeof(unsigned[3]);
+ nverts = sizeof(cbox_short_block)/sizeof(float[3]);
+ desc.vertices = cbox_short_block;
+ desc.indices = cbox_block_ids;
+ CHECK(s3d_mesh_setup_indexed_vertices
+ (shape, ntris, cbox_get_ids, nverts, attribs, &desc), RES_OK);
- CHECK(s3d_scene_create(dev, &scn2), RES_OK);
+ CHECK(s3d_scene_build(scn), RES_OK);
- f3(org, -560.f, 0.f, -556.f);
+ desc.vertices = cbox_tall_block;
+ CHECK(s3d_mesh_setup_indexed_vertices
+ (shape, ntris, S3D_KEEP, nverts, attribs, &desc), RES_OK);
CHECK(s3d_shape_ref_put(shape), RES_OK);
- CHECK(s3d_scene_instantiate(scn, &shape), RES_OK);
- CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK);
- CHECK(s3d_instance_set_position(shape, org), RES_OK);
- f3(org, 7.f, 0.f, -556.f);
+ desc.vertices = cbox_short_block;
+ CHECK(s3d_shape_create_mesh(dev, &shape), RES_OK);
+ CHECK(s3d_mesh_setup_indexed_vertices
+ (shape, ntris, cbox_get_ids, nverts, attribs, &desc), RES_OK);
+ CHECK(s3d_scene_attach_shape(scn, shape), RES_OK);
CHECK(s3d_shape_ref_put(shape), RES_OK);
- CHECK(s3d_scene_instantiate(scn, &shape), RES_OK);
- CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK);
- CHECK(s3d_instance_set_position(shape, org), RES_OK);
- f3(org, -560.f, 0.f, 7.f);
+ desc.indices = cbox_walls_ids;
+ desc.vertices = cbox_walls;
+ nverts = sizeof(cbox_walls)/sizeof(float[3]);
+ ntris = sizeof(cbox_walls_ids)/sizeof(unsigned[3]);
+ CHECK(s3d_shape_create_mesh(dev, &shape), RES_OK);
+ CHECK(s3d_mesh_setup_indexed_vertices
+ (shape, ntris, cbox_get_ids, nverts, attribs, &desc), RES_OK);
+ CHECK(s3d_scene_attach_shape(scn, shape), RES_OK);
CHECK(s3d_shape_ref_put(shape), RES_OK);
- CHECK(s3d_scene_instantiate(scn, &shape), RES_OK);
- CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK);
- CHECK(s3d_instance_set_position(shape, org), RES_OK);
- f3(org, 7.f, 0.f, 7.f);
- CHECK(s3d_shape_ref_put(shape), RES_OK);
+ CHECK(s3d_scene_create(dev, &scn2), RES_OK);
+
+ f3(org, -100.f, 0.f, -2.f);
CHECK(s3d_scene_instantiate(scn, &shape), RES_OK);
CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK);
CHECK(s3d_instance_set_position(shape, org), RES_OK);
@@ -202,8 +219,7 @@ main(int argc, char** argv)
img[ipix+0] = img[ipix+1] = img[ipix+2] = 0;
}
} else {
- float wi[3], N[3], cos_theta, len;
- unsigned char color;
+ float N[3], len, w;
struct s3d_attrib attr;
float pos[3];
@@ -213,7 +229,7 @@ main(int argc, char** argv)
CHECK(attr.usage, S3D_POSITION);
f3_add(pos, f3_mulf(pos, dir, hit.distance), org);
CHECK(f3_eq_eps
- (pos, attr.value, 1.e-2f/*Sic O_o!! Really bad precision!*/), 1);
+ (pos, attr.value, 1.e-3f/*Sic O_o!! Really bad precision!*/), 1);
len = f3_normalize(N, hit.normal);
NCHECK(len, 0);
@@ -228,11 +244,10 @@ main(int argc, char** argv)
if(!img)
continue;
- cos_theta = f3_dot(f3_minus(wi, dir), N);
- color = (unsigned char)(cos_theta * 255.f);
- img[ipix+0] = color;
- img[ipix+1] = color;
- img[ipix+2] = color;
+ w = CLAMP(1.f - hit.uv[0] - hit.uv[1], 0.f, 1.f);
+ img[ipix+0] = (unsigned char)(hit.uv[0] * 255.f);
+ img[ipix+1] = (unsigned char)(hit.uv[1] * 255.f);
+ img[ipix+2] = (unsigned char)(w * 255.f);
}
}
}