From 6ca1c6957a4e949caed92ee5c427feca75367122 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 24 Jun 2015 17:46:56 -0600 Subject: [PATCH] light: fence texture tracing: fix handling of negative texture coords --- light/trace.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/light/trace.c b/light/trace.c index 8e4d1b5c..bdc0bbfb 100644 --- a/light/trace.c +++ b/light/trace.c @@ -170,6 +170,20 @@ MiptexForFace(const bsp2_dface_t *face, const bsp2_t *bsp) return miptex; } +vec_t fix_coord(vec_t in, int width) +{ + if (in > 0) + { + return (int)in % width; + } + else + { + vec_t in_abs = fabs(in); + int in_abs_mod = (int)in_abs % width; + return width - in_abs_mod; + } +} + static int SampleTexture(const bsp2_dface_t *face, const bsp2_t *bsp, const vec3_t point) { @@ -191,8 +205,8 @@ SampleTexture(const bsp2_dface_t *face, const bsp2_t *bsp, const vec3_t point) miptex = (miptex_t*)(bsp->dtexdata.base + miplump->dataofs[tex->miptex]); - x = (int)texcoord[0] % miptex->width; - y = (int)texcoord[1] % miptex->height; + x = fix_coord(texcoord[0], miptex->width); + y = fix_coord(texcoord[1], miptex->height); data = (byte*)miptex + miptex->offsets[0]; sample = data[(miptex->width * y) + x];