mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] SkeletonRenderTexture components now support automatic down-scaling when required size on screen exceeds max render texture size.
This commit is contained in:
parent
3493de7fe8
commit
661796d2cb
@ -92,6 +92,7 @@
|
|||||||
* Added Spine Preferences setting `Reload SkeletonData after Play`. When enabled, the shared `SkeletonData` of all skeletons in the active scene is reloaded (from the `.json` or `.skel.bytes` file) after exiting play-mode. You can disable this setting to avoid the reloading delay if you can ensure that there are no (accidental) modifications to the shared `SkeletonData` during play-mode (otherwise it would carry over its effect into subsequent plays). Defaults to `true` (the safe setting), which maintains existing behaviour.
|
* Added Spine Preferences setting `Reload SkeletonData after Play`. When enabled, the shared `SkeletonData` of all skeletons in the active scene is reloaded (from the `.json` or `.skel.bytes` file) after exiting play-mode. You can disable this setting to avoid the reloading delay if you can ensure that there are no (accidental) modifications to the shared `SkeletonData` during play-mode (otherwise it would carry over its effect into subsequent plays). Defaults to `true` (the safe setting), which maintains existing behaviour.
|
||||||
* Added `SkeletonAnimationMulti` sample component methods `SetActiveSkeleton(int index)` and getter property `SkeletonAnimations` to more easily apply changes at all SkeletonAnimation instances instead of only the active one.
|
* Added `SkeletonAnimationMulti` sample component methods `SetActiveSkeleton(int index)` and getter property `SkeletonAnimations` to more easily apply changes at all SkeletonAnimation instances instead of only the active one.
|
||||||
* PMA textures now have `sRGB (Color Texture)` disabled by default, the preset template `PMATexturePreset.preset` has been adjusted accordingly. As PMA textures are only allowed with Gamma color space, `sRGB (Color Texture)` shall be disabled to prevent border artifacts when mipmaps are enabled. In Gamma color space having this setting disabled has no drawbacks, only benefits.
|
* PMA textures now have `sRGB (Color Texture)` disabled by default, the preset template `PMATexturePreset.preset` has been adjusted accordingly. As PMA textures are only allowed with Gamma color space, `sRGB (Color Texture)` shall be disabled to prevent border artifacts when mipmaps are enabled. In Gamma color space having this setting disabled has no drawbacks, only benefits.
|
||||||
|
* `SkeletonRenderTexture` and `SkeletonGraphicRenderTexture` components now support automatic down-scaling when required size on screen exceeds `Max Render Texture Size`.
|
||||||
|
|
||||||
* **Breaking changes**
|
* **Breaking changes**
|
||||||
* Made `SkeletonGraphic.unscaledTime` parameter protected, use the new property `UnscaledTime` instead.
|
* Made `SkeletonGraphic.unscaledTime` parameter protected, use the new property `UnscaledTime` instead.
|
||||||
|
|||||||
@ -248,7 +248,8 @@ namespace Spine.Unity.Examples {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector2 targetCameraViewportSize = targetCamera.pixelRect.size;
|
Vector2 targetCameraViewportSize = targetCamera.pixelRect.size;
|
||||||
commandBuffer.SetViewport(new Rect(-screenSpaceMin, targetCameraViewportSize));
|
Rect viewportRect = new Rect(-screenSpaceMin * downScaleFactor, targetCameraViewportSize * downScaleFactor);
|
||||||
|
commandBuffer.SetViewport(viewportRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void AssignMeshAtRenderer () {
|
protected override void AssignMeshAtRenderer () {
|
||||||
|
|||||||
@ -167,7 +167,8 @@ namespace Spine.Unity.Examples {
|
|||||||
commandBuffer.SetProjectionMatrix(targetCamera.projectionMatrix);
|
commandBuffer.SetProjectionMatrix(targetCamera.projectionMatrix);
|
||||||
commandBuffer.SetViewMatrix(targetCamera.worldToCameraMatrix);
|
commandBuffer.SetViewMatrix(targetCamera.worldToCameraMatrix);
|
||||||
Vector2 targetCameraViewportSize = targetCamera.pixelRect.size;
|
Vector2 targetCameraViewportSize = targetCamera.pixelRect.size;
|
||||||
commandBuffer.SetViewport(new Rect(-screenSpaceMin, targetCameraViewportSize));
|
Rect viewportRect = new Rect(-screenSpaceMin * downScaleFactor, targetCameraViewportSize * downScaleFactor);
|
||||||
|
commandBuffer.SetViewport(viewportRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void RenderToRenderTexture () {
|
protected void RenderToRenderTexture () {
|
||||||
|
|||||||
@ -47,8 +47,10 @@ namespace Spine.Unity.Examples {
|
|||||||
public Camera targetCamera;
|
public Camera targetCamera;
|
||||||
|
|
||||||
protected CommandBuffer commandBuffer;
|
protected CommandBuffer commandBuffer;
|
||||||
protected Vector2Int requiredRenderTextureSize;
|
protected Vector2Int screenSize;
|
||||||
|
protected Vector2Int usedRenderTextureSize;
|
||||||
protected Vector2Int allocatedRenderTextureSize;
|
protected Vector2Int allocatedRenderTextureSize;
|
||||||
|
protected Vector2 downScaleFactor = Vector2.one;
|
||||||
|
|
||||||
protected Vector3 worldCornerNoDistortion0;
|
protected Vector3 worldCornerNoDistortion0;
|
||||||
protected Vector3 worldCornerNoDistortion1;
|
protected Vector3 worldCornerNoDistortion1;
|
||||||
@ -89,17 +91,22 @@ namespace Spine.Unity.Examples {
|
|||||||
uvCorner2 = MathUtilities.InverseLerp(screenSpaceMin, screenSpaceMax, screenCorner2);
|
uvCorner2 = MathUtilities.InverseLerp(screenSpaceMin, screenSpaceMax, screenCorner2);
|
||||||
uvCorner3 = MathUtilities.InverseLerp(screenSpaceMin, screenSpaceMax, screenCorner3);
|
uvCorner3 = MathUtilities.InverseLerp(screenSpaceMin, screenSpaceMax, screenCorner3);
|
||||||
|
|
||||||
requiredRenderTextureSize = new Vector2Int(
|
screenSize = new Vector2Int(Math.Abs((int)screenSpaceMax.x - (int)screenSpaceMin.x),
|
||||||
Math.Min(maxRenderTextureSize, Math.Abs((int)screenSpaceMax.x - (int)screenSpaceMin.x)),
|
Math.Abs((int)screenSpaceMax.y - (int)screenSpaceMin.y));
|
||||||
Math.Min(maxRenderTextureSize, Math.Abs((int)screenSpaceMax.y - (int)screenSpaceMin.y)));
|
usedRenderTextureSize = new Vector2Int(
|
||||||
|
Math.Min(maxRenderTextureSize, screenSize.x),
|
||||||
|
Math.Min(maxRenderTextureSize, screenSize.y));
|
||||||
|
downScaleFactor = new Vector2(
|
||||||
|
(float)usedRenderTextureSize.x / (float)screenSize.x,
|
||||||
|
(float)usedRenderTextureSize.y / (float)screenSize.y);
|
||||||
|
|
||||||
PrepareRenderTexture();
|
PrepareRenderTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void PrepareRenderTexture () {
|
protected void PrepareRenderTexture () {
|
||||||
Vector2Int textureSize = new Vector2Int(
|
Vector2Int textureSize = new Vector2Int(
|
||||||
Mathf.NextPowerOfTwo(requiredRenderTextureSize.x),
|
Mathf.NextPowerOfTwo(usedRenderTextureSize.x),
|
||||||
Mathf.NextPowerOfTwo(requiredRenderTextureSize.y));
|
Mathf.NextPowerOfTwo(usedRenderTextureSize.y));
|
||||||
|
|
||||||
if (textureSize != allocatedRenderTextureSize) {
|
if (textureSize != allocatedRenderTextureSize) {
|
||||||
if (renderTexture)
|
if (renderTexture)
|
||||||
@ -135,8 +142,12 @@ namespace Spine.Unity.Examples {
|
|||||||
};
|
};
|
||||||
quadMesh.normals = normals;
|
quadMesh.normals = normals;
|
||||||
|
|
||||||
float maxU = (float)requiredRenderTextureSize.x / (float)allocatedRenderTextureSize.x;
|
float maxU = (float)usedRenderTextureSize.x / (float)allocatedRenderTextureSize.x;
|
||||||
float maxV = (float)requiredRenderTextureSize.y / (float)allocatedRenderTextureSize.y;
|
float maxV = (float)usedRenderTextureSize.y / (float)allocatedRenderTextureSize.y;
|
||||||
|
if (downScaleFactor.x < 1 || downScaleFactor.y < 1) {
|
||||||
|
maxU = downScaleFactor.x * (float)screenSize.x / (float)allocatedRenderTextureSize.x;
|
||||||
|
maxV = downScaleFactor.y * (float)screenSize.y / (float)allocatedRenderTextureSize.y;
|
||||||
|
}
|
||||||
Vector2[] uv = new Vector2[4] {
|
Vector2[] uv = new Vector2[4] {
|
||||||
new Vector2(uvCorner0.x * maxU, uvCorner0.y * maxV),
|
new Vector2(uvCorner0.x * maxU, uvCorner0.y * maxV),
|
||||||
new Vector2(uvCorner1.x * maxU, uvCorner1.y * maxV),
|
new Vector2(uvCorner1.x * maxU, uvCorner1.y * maxV),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user