summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libs/din/din.c24
-rw-r--r--src/libs/din/din.h5
-rw-r--r--src/modules/swab/swab.c13
3 files changed, 23 insertions, 19 deletions
diff --git a/src/libs/din/din.c b/src/libs/din/din.c
index 2293c30..95c0398 100644
--- a/src/libs/din/din.c
+++ b/src/libs/din/din.c
@@ -63,9 +63,9 @@ void din_free(din_t *din)
}
-static inline float dotgradient(const din_t *din, int x, int y, int z, const v3f_t coordinate)
+static inline float dotgradient(const din_t *din, int x, int y, int z, const v3f_t *coordinate)
{
- v3f_t distance = v3f_sub(&coordinate, &(v3f_t){.x = x, .y = y, .z = z});
+ v3f_t distance = v3f_sub(coordinate, &(v3f_t){.x = x, .y = y, .z = z});
return v3f_dot(&din->grid[z * din->width * din->height + y * din->width + x], &distance);
}
@@ -96,28 +96,28 @@ static inline float smootherstep(float edge0, float edge1, float x) {
/* coordinate is in a unit cube of -1...+1 */
-float din(din_t *din, v3f_t coordinate)
+float din(din_t *din, v3f_t *coordinate)
{
int x0, y0, z0, x1, y1, z1;
float i1, i2, ii1, ii2;
float tx, ty, tz;
float n0, n1;
- coordinate.x = 1.f + (coordinate.x * .5f + .5f) * (float)(din->width - 2);
- coordinate.y = 1.f + (coordinate.y * .5f + .5f) * (float)(din->height - 2);
- coordinate.z = 1.f + (coordinate.z * .5f + .5f) * (float)(din->depth - 2);
+ coordinate->x = 1.f + (coordinate->x * .5f + .5f) * (float)(din->width - 2);
+ coordinate->y = 1.f + (coordinate->y * .5f + .5f) * (float)(din->height - 2);
+ coordinate->z = 1.f + (coordinate->z * .5f + .5f) * (float)(din->depth - 2);
- x0 = floorf(coordinate.x);
- y0 = floorf(coordinate.y);
- z0 = floorf(coordinate.z);
+ x0 = floorf(coordinate->x);
+ y0 = floorf(coordinate->y);
+ z0 = floorf(coordinate->z);
x1 = x0 + 1.f;
y1 = y0 + 1.f;
z1 = z0 + 1.f;
- tx = coordinate.x - (float)x0;
- ty = coordinate.y - (float)y0;
- tz = coordinate.z - (float)z0;
+ tx = coordinate->x - (float)x0;
+ ty = coordinate->y - (float)y0;
+ tz = coordinate->z - (float)z0;
n0 = dotgradient(din, x0, y0, z0, coordinate);
n1 = dotgradient(din, x1, y0, z0, coordinate);
diff --git a/src/libs/din/din.h b/src/libs/din/din.h
index 2e06072..baa3ebb 100644
--- a/src/libs/din/din.h
+++ b/src/libs/din/din.h
@@ -1,13 +1,12 @@
#ifndef _DIN_H
#define _DIN_H
-#include "v3f.h"
-
typedef struct din_t din_t;
+typedef struct v3f_t v3f_t;
din_t * din_new(int width, int height, int depth);
void din_free(din_t *din);
void din_randomize(din_t *din);
-float din(din_t *din, v3f_t coordinate);
+float din(din_t *din, v3f_t *coordinate);
#endif
diff --git a/src/modules/swab/swab.c b/src/modules/swab/swab.c
index e4c3670..2b80d95 100644
--- a/src/modules/swab/swab.c
+++ b/src/modules/swab/swab.c
@@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
@@ -37,6 +38,10 @@ typedef struct color_t {
float r,g,b;
} color_t;
+typedef struct v3f_t {
+ float x, y, z;
+} v3f_t;
+
/* convert a color into a packed, 32-bit rgb pixel value (taken from libs/ray/ray_color.h) */
static inline uint32_t color_to_uint32(color_t color) {
@@ -122,11 +127,11 @@ static void swab_render_fragment(void *context, unsigned cpu, fb_fragment_t *fra
uint32_t pixel;
float t;
- t = din(ctxt->din, (v3f_t){ .x = (float)x * xscale * .5f, .y = (float)y * yscale * .5f, .z = -z2 }) * 33.f;
+ t = din(ctxt->din, &(v3f_t){ .x = (float)x * xscale * .5f, .y = (float)y * yscale * .5f, .z = -z2 }) * 33.f;
- color.r = din(ctxt->din, (v3f_t){ .x = (float)x * xscale * .7f, .y = (float)y * yscale * .7f, .z = z1 }) * t;
- color.g = din(ctxt->din, (v3f_t){ .x = (float)x * xscale * .93f, .y = (float)y * yscale * .93f, .z = -z1 }) * t;
- color.b = din(ctxt->din, (v3f_t){ .x = (float)x * xscale * .81f, .y = (float)y * yscale * .81f, .z = z2 }) * t;
+ color.r = din(ctxt->din, &(v3f_t){ .x = (float)x * xscale * .7f, .y = (float)y * yscale * .7f, .z = z1 }) * t;
+ color.g = din(ctxt->din, &(v3f_t){ .x = (float)x * xscale * .93f, .y = (float)y * yscale * .93f, .z = -z1 }) * t;
+ color.b = din(ctxt->din, &(v3f_t){ .x = (float)x * xscale * .81f, .y = (float)y * yscale * .81f, .z = z2 }) * t;
pixel = color_to_uint32(color);
fb_fragment_put_pixel_unchecked(fragment, x, y, pixel);
© All Rights Reserved