From b8367da7e235036e9c1a9834de50a0a604ec69d8 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 11 Jul 2022 01:06:07 +0900 Subject: [PATCH] internal/graphics: optimize imageSrcNUnsafeAt --- internal/graphics/shader.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/graphics/shader.go b/internal/graphics/shader.go index d26b11356..2b3b9ab86 100644 --- a/internal/graphics/shader.go +++ b/internal/graphics/shader.go @@ -93,11 +93,9 @@ func imageSrc%[1]dUnsafeAt(pos vec2) vec4 { func imageSrc%[1]dAt(pos vec2) vec4 { // pos is the position in texels of the source texture (= 0th image's texture). - return texture2D(__t%[1]d, %[2]s) * - step(__textureSourceRegionOrigin.x, pos.x) * - (1 - step(__textureSourceRegionOrigin.x + __textureSourceRegionSize.x, pos.x)) * - step(__textureSourceRegionOrigin.y, pos.y) * - (1 - step(__textureSourceRegionOrigin.y + __textureSourceRegionSize.y, pos.y)) + // If pos is in the region, the result is (1, 1). Otherwise, either element is 0. + in := step(__textureSourceRegionOrigin, pos) - step(__textureSourceRegionOrigin + __textureSourceRegionSize, pos) + return texture2D(__t%[1]d, %[2]s) * in.x * in.y } `, i, pos) }