From 064a06034a898ad220a421992a742c8b427f1bac Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Wed, 24 Mar 2021 22:23:03 -0400 Subject: [PATCH] Fix shader regression (#44) * Fix shader regression * Snap --- Package.swift | 4 +- .../Resources/shaders/Letter.surface.shader | 16 +- Tests/GameCoreTests/CubeViewTests.swift | 553 ++++++++++++++++++ .../testLetterSurfaceShaderBorderBuffer.1.png | 3 + 4 files changed, 574 insertions(+), 2 deletions(-) create mode 100644 Tests/GameCoreTests/CubeViewTests.swift create mode 100644 Tests/GameCoreTests/__Snapshots__/CubeViewTests/testLetterSurfaceShaderBorderBuffer.1.png diff --git a/Package.swift b/Package.swift index 7dd65bfd..b7df0de2 100644 --- a/Package.swift +++ b/Package.swift @@ -673,7 +673,9 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil { dependencies: [ "GameCore", "TestHelpers", - ] + .product(name: "SnapshotTesting", package: "SnapshotTesting"), + ], + exclude: ["__Snapshots__"] ), .target( name: "GameFeature", diff --git a/Sources/CubeCore/Resources/shaders/Letter.surface.shader b/Sources/CubeCore/Resources/shaders/Letter.surface.shader index 08f2e7c6..9e5c8b7c 100644 --- a/Sources/CubeCore/Resources/shaders/Letter.surface.shader +++ b/Sources/CubeCore/Resources/shaders/Letter.surface.shader @@ -37,4 +37,18 @@ float4 textureColor = lettersTexture.sample( ) ); -_surface.diffuse.rgba = float4(0, 0, 0, textureColor.a); +// NB: This avoids drawing letter pixels in the corner of a face +float borderBuffer = 0.05; +if ( + in.side == 2 + && ( + texcoord.x <= borderBuffer + || texcoord.x >= 1 - borderBuffer + || texcoord.y <= borderBuffer + || texcoord.y >= 1 - borderBuffer + ) +) { + _surface.diffuse.rgba = float4(0, 0, 0, 0); +} else { + _surface.diffuse.rgba = float4(0, 0, 0, textureColor.a); +} diff --git a/Tests/GameCoreTests/CubeViewTests.swift b/Tests/GameCoreTests/CubeViewTests.swift new file mode 100644 index 00000000..94ba922e --- /dev/null +++ b/Tests/GameCoreTests/CubeViewTests.swift @@ -0,0 +1,553 @@ +import ComposableArchitecture +import CubeCore +import SharedModels +import SnapshotTesting +import XCTest + +class CubeViewTests: XCTestCase { + override class func setUp() { + super.setUp() + SnapshotTesting.diffTool = "ksdiff" + } + + func testLetterSurfaceShaderBorderBuffer() throws { + let json = """ + [ + [ + [ + { + "wasRemoved": false, + "top": { + "letter": "R", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "E", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "N", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "S", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "W", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "O", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "Y", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "S", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "A", + "side": 1, + "useCount": 0 + } + } + ], + [ + { + "wasRemoved": false, + "top": { + "letter": "A", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "M", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "R", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "O", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "G", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "O", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "I", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "B", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "E", + "side": 1, + "useCount": 0 + } + } + ], + [ + { + "wasRemoved": false, + "top": { + "letter": "E", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "N", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "H", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "H", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "N", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "M", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "T", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "E", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "L", + "side": 1, + "useCount": 0 + } + } + ] + ], + [ + [ + { + "wasRemoved": false, + "top": { + "letter": "B", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "R", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "N", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "N", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "E", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "A", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "P", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "E", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "J", + "side": 1, + "useCount": 0 + } + } + ], + [ + { + "wasRemoved": false, + "top": { + "letter": "A", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "L", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "B", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "R", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "I", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "E", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "F", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "A", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "A", + "side": 1, + "useCount": 0 + } + } + ], + [ + { + "wasRemoved": false, + "top": { + "letter": "A", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "N", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "F", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "C", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "N", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "J", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "H", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "D", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "K", + "side": 1, + "useCount": 0 + } + } + ] + ], + [ + [ + { + "wasRemoved": false, + "top": { + "letter": "E", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "I", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "S", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "P", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "E", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "B", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "E", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "L", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "T", + "side": 1, + "useCount": 0 + } + } + ], + [ + { + "wasRemoved": false, + "top": { + "letter": "G", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "B", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "C", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "E", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "D", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "F", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "A", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "A", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "E", + "side": 1, + "useCount": 0 + } + } + ], + [ + { + "wasRemoved": false, + "top": { + "letter": "Y", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "Y", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "A", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "I", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "S", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "QU", + "side": 1, + "useCount": 0 + } + }, + { + "wasRemoved": false, + "top": { + "letter": "E", + "side": 0, + "useCount": 0 + }, + "right": { + "letter": "E", + "side": 2, + "useCount": 0 + }, + "left": { + "letter": "T", + "side": 1, + "useCount": 0 + } + } + ] + ] + ] + """ + let cubes = try JSONDecoder().decode(Puzzle.self, from: Data(json.utf8)) + + let view = CubeView( + store: Store( + initialState: .init( + game: .init( + cubes: cubes, + gameContext: .solo, + gameCurrentTime: .mock, + gameMode: .unlimited, + gameStartTime: .mock + ), + nub: nil, + settings: .init() + ), + reducer: .empty, + environment: () + ) + ) + + assertSnapshot( + matching: view, + as: .image(layout: .device(config: .iPhoneXsMax)) + ) + } +} diff --git a/Tests/GameCoreTests/__Snapshots__/CubeViewTests/testLetterSurfaceShaderBorderBuffer.1.png b/Tests/GameCoreTests/__Snapshots__/CubeViewTests/testLetterSurfaceShaderBorderBuffer.1.png new file mode 100644 index 00000000..8025c074 --- /dev/null +++ b/Tests/GameCoreTests/__Snapshots__/CubeViewTests/testLetterSurfaceShaderBorderBuffer.1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a7cdea4306aaa7fa6ac31fc922c525dbb897fdab51fd25a0d2cca936b8b8f7d0 +size 539385