Documentation
¶
Overview ¶
Package texseam is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.
Package texseam checks and repairs image seams and derives tangent-space maps for textures used by the game renderer.
Index ¶
- Constants
- func Fix(img image.Image, opts FixOptions) *image.RGBA
- func Height(img image.Image, blur int, mode SampleMode) *image.Gray
- func Merge(original, edited image.Image, band int) *image.RGBA
- func Normal(height image.Image, strength float64, mode SampleMode, green GreenAxis) *image.NRGBA
- func PowerOfTwoSize(n int) int
- func Roughness(height image.Image, contrast float64) *image.Gray
- func Scale(img image.Image, width, height int, mode SampleMode) *image.RGBA
- type FixOptions
- type GreenAxis
- type SampleMode
- type SeamReport
Examples ¶
Constants ¶
const DefaultThreshold = 1.3
DefaultThreshold is the wrap-edge to interior difference ratio at or below which Check reports a seamless tile.
Variables ¶
This section is empty.
Functions ¶
func Fix ¶
func Fix(img image.Image, opts FixOptions) *image.RGBA
Fix repairs wrap seams by matching opposite edges and feathering the change into the image. It preserves the input dimensions and color-independent deterministic output.
func Height ¶
Height converts an image to luminance height, applying a deterministic box blur with the requested radius before returning an 8-bit grayscale image. The blur samples past the edges with mode: Wrap keeps a seamless tile seamless, Clamp suits sprites.
func Merge ¶
Merge keeps edited pixels only in a feathered vertical and horizontal band around the tile center. Pixels outside those bands remain byte-identical to original.
func Normal ¶
Normal derives an RGBA8 tangent-space normal map from a height image using central differences. A flat area encodes as (128, 128, 255); green selects the sign of the green channel so the map matches lights2d (GreenDown) or render3d (GreenUp).
func PowerOfTwoSize ¶
PowerOfTwoSize returns the smallest power of two at or above n, and 1 for any n at or below 1. A texture axis already a power of two keeps its size.
func Scale ¶
Scale resamples img to a width×height RGBA image with a separable triangle filter. Enlarging interpolates linearly; shrinking averages every source pixel inside an output pixel's footprint, so reducing a tile does not alias away a row or column. mode selects how samples past the edges are taken: Wrap keeps a seamless tile seamless at the new size, Clamp suits sprites. A width or height already equal to the source size is left alone. Output is byte-identical across runs.
Types ¶
type FixOptions ¶
type FixOptions struct {
Band int
}
FixOptions controls seam repair. Band is the number of pixels over which each edge is blended toward the opposite edge. Zero uses roughly one eighth of the smaller dimension, capped at 16 pixels.
type GreenAxis ¶
type GreenAxis uint8
GreenAxis selects which image direction a positive green channel points to in a normal map.
type SampleMode ¶
type SampleMode uint8
SampleMode selects how Height and Normal sample pixels past the image edges.
const ( // Wrap samples the opposite edge, for textures that repeat. Wrap SampleMode = iota // Clamp repeats the nearest edge pixel, for sprites and other images that do not repeat. Clamp )
type SeamReport ¶
type SeamReport struct {
WrapXRatio float64
WrapYRatio float64
InteriorX float64
InteriorY float64
Threshold float64
Pass bool
}
SeamReport contains the wrap-edge and interior differences for both axes. Ratios at or below Threshold pass the tiling check.
func Check ¶
func Check(img image.Image) SeamReport
Check measures the left/right and top/bottom wrap seams using the default threshold. Differences are normalized to the mean difference of interior neighbors on the same axis.
Example ¶
Check compares a texture's opposite edges with its interior and reports whether the tile repeats without a visible seam.
package main
import (
"fmt"
"image"
"image/color"
"github.com/nsgo-dev/game/pkg/tooling/texseam"
)
func main() {
tile := image.NewRGBA(image.Rect(0, 0, 8, 8))
for y := 0; y < 8; y++ {
for x := 0; x < 8; x++ {
v := uint8(((x%7)*31 + (y%7)*17) % 256)
tile.SetRGBA(x, y, color.RGBA{R: v, G: v, B: v, A: 255})
}
}
report := texseam.Check(tile)
fmt.Println(report.Pass)
}
Output: true
func CheckWithThreshold ¶
func CheckWithThreshold(img image.Image, threshold float64) SeamReport
CheckWithThreshold is Check with an explicit ratio threshold.