public static void BuildTransformPaintContextUVToPaintContextUV(PaintContext src, PaintContext dst, out Vector4 scaleOffset) { // for example: // src = alphaUV // dst = normalUV // dst.uv = src.u * scales.xy + src.v * scales.zw + offset // terrainspace.xz = srcOrigin + src.uv * srcSize // terrainspace.xz = dstOrigin + dst.uv * dstSize // dstOrigin + dst.uv * dstSize = srcOrigin + src.uv * srcSize // dst.uv * dstSize = src.uv * srcSize + srcOrigin - dstOrigin // dst.uv = (src.uv * srcSize + srcOrigin - dstOrigin) / dstSize // dst.uv = (src.uv * srcSize) / dstSize + (srcOrigin - dstOrigin) / dstSize // scales.x = srcSize.x / dstSize.x // scales.yz = 0.0f; // scales.w = srcSize.y / dstSize.y // offset.xy = (srcOrigin.xy - dstOrigin.xy) / dstSize.xy // paint context origin in terrain space // (note this is the UV space origin and size, not the mesh origin & size) float srcOriginX = (src.pixelRect.xMin - 0.5f) * src.pixelSize.x; float srcOriginZ = (src.pixelRect.yMin - 0.5f) * src.pixelSize.y; float srcSizeX = (src.pixelRect.width) * src.pixelSize.x; float srcSizeZ = (src.pixelRect.height) * src.pixelSize.y; // paint context origin in terrain space // (note this is the UV space origin and size, not the mesh origin & size) float dstOriginX = (dst.pixelRect.xMin - 0.5f) * dst.pixelSize.x; float dstOriginZ = (dst.pixelRect.yMin - 0.5f) * dst.pixelSize.y; float dstSizeX = (dst.pixelRect.width) * dst.pixelSize.x; float dstSizeZ = (dst.pixelRect.height) * dst.pixelSize.y; scaleOffset = new Vector4( srcSizeX / dstSizeX, srcSizeZ / dstSizeZ, (srcOriginX - dstOriginX) / dstSizeX, (srcOriginZ - dstOriginZ) / dstSizeZ ); }
// this function sets up material properties used by functions provided in TerrainTool.cginc public static void SetupTerrainToolMaterialProperties( PaintContext paintContext, in BrushTransform brushXform, // the brush transform to terrain space (of paintContext.originTerrain)