Improve normal packing and unpacking

This commit is contained in:
2025-11-11 21:47:39 +00:00
parent 4121bfb468
commit ce1937c78e
3 changed files with 8 additions and 8 deletions
+5 -5
View File
@@ -439,7 +439,7 @@ pokeJustV :: Float -> Point3 -> Point4 -> Ptr Float -> Int -> Point3 -> IO Int
{-# INLINE pokeJustV #-}
pokeJustV xdata cp col ptr nv sh = do
pokeByteOff ptr (nv * shapeVerxSize) (V4 x y z xdata)
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (normalToColor8 $ V4 nx ny nz 1)
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (normalTo8 $ V4 nx ny nz 1)
pokeByteOff ptr (nv *shapeVerxSize + 5 * floatSize) (toColor8 col)
return (nv + 1)
where
@@ -457,17 +457,17 @@ pokeFlatV ::
{-# INLINE pokeFlatV #-}
pokeFlatV xdata pnorm col ptr nv sh = do
pokeByteOff ptr (nv * shapeVerxSize) (V4 x y z xdata)
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (normalToColor8 $ V4 nx ny nz 1)
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (normalTo8 $ V4 nx ny nz 1)
pokeByteOff ptr (nv *shapeVerxSize + 5 * floatSize) (toColor8 col)
return (nv + 1)
where
V3 x y z = sh
V3 nx ny nz = (sh - pnorm) - V3 x y z
normalToColor8 :: Point4 -> Color8
normalToColor8 = over each f . normalize
normalTo8 :: Point4 -> V4 Int8
normalTo8 = over each f . normalize
where
f x = floor $ (x + 1) * 127.5
f x = floor $ x * 127
pokeLayVerxs ::
MV.MVector (PrimState IO) (Shader, VBO) ->