riidefi / RiiStudio

Editor for various 3D model formats
https://riidefi.github.io/RiiStudio/
94 stars 16 forks source link

Expose material texture sampler "effect matrix" in UI #76

Open riidefi opened 1 week ago

riidefi commented 1 week ago

When a material references textures (those references, "samplers"), a transformation matrix is computed, allowing mesh UV coordinates to be manipulated per-material. For instance, water materials often use the same texture twice at varying levels of magnification (scale x, scale y). BRRES files do not directly expose this texture matrix, however, instead just providing artists with controls for "scale", "rotation" and "translation" (SRT).

However, the GPU supports any affine transformation in homogenous coordinates/projective space, not just SRT:

  1. "skew": Also called "shear," skew is a type of linear transformation that maps rectangles to parallelograms. Two parameters, one representing the interior angle of the parallelogram, another representing the ratio of the lengths of the two sides.
  2. "perspective": A linear*** transform that maps rectangles to trapezoids, and parallelograms to convex quadrilaterals. Starting from a parallelogram, two parameters, representing a 2D displacement to only one vertex. Effect such a displacement would have on the vertex's adjacent line segments: the angle between those two line segments ("FOV"; must be < 180 degrees to remain convex) and the ratio of those side lengths ("aspect ratio") (?)

Taken together with SRT, the GPU supports the full Perspective Warp tool in Photoshop, mapping a unit square to any arbitrary convex quadrilateral.

BRRES files support specifying a direct matrix, an "effect matrix," to be applied before the SRT transform (left-multiplied with the SRT matrix before sent to GPU), thereby allowing full perspective warp. While this is not typically exposed to artists and only accessible to game programmers, there may be one or two uses in SMG? (.bmd/.bdl)

** Only linear in projective space*--nonlinear in Euclidean space.