texseam

package
v0.4.0-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Examples

Constants

View Source
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

func Height(img image.Image, blur int, mode SampleMode) *image.Gray

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

func Merge(original, edited image.Image, band int) *image.RGBA

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

func Normal(height image.Image, strength float64, mode SampleMode, green GreenAxis) *image.NRGBA

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

func PowerOfTwoSize(n int) int

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 Roughness

func Roughness(height image.Image, contrast float64) *image.Gray

Roughness derives an inverted, contrast-stretched grayscale roughness map.

func Scale

func Scale(img image.Image, width, height int, mode SampleMode) *image.RGBA

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.

const (
	// GreenDown points +G toward increasing image y (screen down), the convention lights2d.ShadeNormalMap decodes.
	GreenDown GreenAxis = iota
	// GreenUp points +G toward decreasing image y (up, -V), the glTF convention render3d's NormalTexture uses.
	GreenUp
)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL