Skip to content

Commit

Permalink
Implement scissor (#1243)
Browse files Browse the repository at this point in the history
Implements scissors. See
BabylonJS/Babylon.js#13960 for changes required
on the JS side.
  • Loading branch information
docEdub authored Jul 21, 2023
1 parent da9bfc0 commit 88d09c8
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 72 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Apps/Playground/ReferenceImages/scissor-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions Apps/Playground/Scripts/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,42 @@
"playgroundId": "#BCYE7J#31",
"referenceImage": "multiCamerasOutputRenderTarget.png"
},
{
"title": "Multi camera rendering with scissors",
"playgroundId": "#1LK70I#35",
"referenceImage": "multiCameraRenderingWithScissors.png"
},
{
"title": "Scissor test",
"renderCount": 10,
"playgroundId": "#W7E7CF#29",
"referenceImage": "scissor-test.png",
"comments": "Reset playgroundId to #W7E7CF#12 when d3d12 mip-map issue is fixed"
},
{
"title": "Scissor test with 0.9 hardware scaling",
"renderCount": 10,
"playgroundId": "#W7E7CF#30",
"referenceImage": "scissorTestWith0.9HardwareScaling.png",
"comments": "Reset playgroundId to #W7E7CF#27 when d3d12 mip-map issue is fixed"
},
{
"title": "Scissor test with 1.5 hardware scaling",
"renderCount": 10,
"playgroundId": "#W7E7CF#31",
"referenceImage": "scissorTestWith1.5HardwareScaling.png",
"comments": "Reset playgroundId to #W7E7CF#28 when d3d12 mip-map issue is fixed"
},
{
"title": "Scissor test with negative x and y",
"playgroundId": "#3L5BCD#2",
"referenceImage": "scissorTestNegativeXandY.png"
},
{
"title": "Scissor test with out of bounds width and height",
"playgroundId": "#3L5BCD#3",
"referenceImage": "scissorTestOobWidthAndHeight.png"
},
{
"title": "setParent",
"playgroundId": "#JD49CT#2",
Expand Down
11 changes: 8 additions & 3 deletions Apps/Playground/Scripts/validation_native.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,22 @@ function compare(test, renderData, referenceImage, threshold, errorRatio) {

let error = (differencesCount * 100) / (size / 4) > errorRatio;

const width = testWidth / engine.getHardwareScalingLevel();
const height = testHeight / engine.getHardwareScalingLevel();

if (error) {
TestUtils.writePNG(referenceData, testWidth, testHeight, TestUtils.getOutputDirectory() + "/Errors/" + test.referenceImage);
TestUtils.writePNG(referenceData, width, height, TestUtils.getOutputDirectory() + "/Errors/" + test.referenceImage);
}
if (saveResult || error) {
TestUtils.writePNG(renderData, testWidth, testHeight, TestUtils.getOutputDirectory() + "/Results/" + test.referenceImage);
TestUtils.writePNG(renderData, width, height, TestUtils.getOutputDirectory() + "/Results/" + test.referenceImage);
}
return error;
}

function saveRenderedResult(test, renderData) {
TestUtils.writePNG(renderData, testWidth, testHeight, TestUtils.getOutputDirectory() + "/Results/" + test.referenceImage);
const width = testWidth / engine.getHardwareScalingLevel();
const height = testHeight / engine.getHardwareScalingLevel();
TestUtils.writePNG(renderData, width, height, TestUtils.getOutputDirectory() + "/Results/" + test.referenceImage);
return false; // no error
}

Expand Down
85 changes: 43 additions & 42 deletions Apps/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Apps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"getNightly": "node scripts/getNightly.js"
},
"dependencies": {
"babylonjs": "^6.4.1",
"babylonjs-gui": "^6.4.1",
"babylonjs-loaders": "^6.4.1",
"babylonjs-materials": "^6.4.1",
"babylonjs": "^6.12.0",
"babylonjs-gltf2interface": "^6.12.0",
"babylonjs-gui": "^6.12.0",
"babylonjs-loaders": "^6.12.0",
"babylonjs-materials": "^6.12.0",
"chai": "^4.3.4",
"jsc-android": "^241213.1.0",
"mocha": "^9.2.2",
Expand Down
24 changes: 15 additions & 9 deletions Core/Graphics/InternalInclude/Babylon/Graphics/FrameBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace Babylon::Graphics
{
class DeviceContext;

struct ViewPort
struct Rect
{
float X{0.0f};
float Y{0.0f};
float Width{1.0f};
float Height{1.0f};
float X{};
float Y{};
float Width{};
float Height{};

bool Equals(const ViewPort& other) const;
bool Equals(const Rect& other) const;
};

class FrameBuffer final
Expand All @@ -36,6 +36,7 @@ namespace Babylon::Graphics

void Clear(bgfx::Encoder& encoder, uint16_t flags, uint32_t rgba, float depth, uint8_t stencil);
void SetViewPort(bgfx::Encoder& encoder, float x, float y, float width, float height);
void SetScissor(bgfx::Encoder& encoder, float x, float y, float width, float height);
void Submit(bgfx::Encoder& encoder, bgfx::ProgramHandle programHandle, uint8_t flags);
void SetStencil(bgfx::Encoder& encoder, uint32_t stencilState);
void Blit(bgfx::Encoder& encoder, bgfx::TextureHandle _dst, uint16_t _dstX, uint16_t _dstY, bgfx::TextureHandle _src, uint16_t _srcX = 0, uint16_t _srcY = 0, uint16_t _width = UINT16_MAX, uint16_t _height = UINT16_MAX);
Expand All @@ -56,11 +57,16 @@ namespace Babylon::Graphics

std::optional<bgfx::ViewId> m_viewId;

ViewPort m_bgfxViewPort;
ViewPort m_desiredViewPort;
Rect m_bgfxViewPort{0.0f, 0.0f, 1.0f, 1.0f};
Rect m_desiredViewPort{0.0f, 0.0f, 1.0f, 1.0f};

Rect m_bgfxScissor;
Rect m_desiredScissor;


bool m_disposed{false};

void SetBgfxViewPort(bgfx::Encoder& encoder, const ViewPort& viewPort);
Rect GetBgfxScissor(float x, float y, float width, float height) const;
void SetBgfxViewPortAndScissor(bgfx::Encoder& encoder, const Rect& viewPort, const Rect& scissor);
};
}
Loading

0 comments on commit 88d09c8

Please sign in to comment.