Browse Source

[unity] `SkeletonRenderTexture` example components now provide a `shaderPasses` parameter.

Harald Csaszar 1 year ago
parent
commit
98706929d0

+ 1 - 0
CHANGELOG.md

@@ -154,6 +154,7 @@
   - SkeletonGraphic: Added pre-defined SkeletonGraphic material sets for main workflow parameters in folders `spine-unity/Materials` instead of requiring manual copies:
     `SkeletonGraphic-PMATexture` containing materials for premultiplied-alpha texture workflow (`Straight Alpha Texture` disabled) and `SkeletonGraphic-StaightAlphaTexture` containing materials for straight alpha texture workflow (`Straight Alpha Texture` enabled). These directories contain a set of materials with `CanvasGroup Compatible` disabled for usage with `Advanced - PMA Vertex Color` enabled at the component. Each directory also provides a subdirectory `CanvasGroupCompatible` with materials with `CanvasGroup Compatible` enabled for usage with `CanvasGroup` alpha (requiring `Advanced - PMA Vertex Color` disabled at the component).
   - SkeletonGraphic: Added auto-detect functionality for parameters `Advanced` - `Tint Black`, `CanvasGroup Compatible` and `PMA Vertex Color`. If unsure which settings are correct, hit the `Detect` button next to each parameter, in top to bottom order, or the `Detect Settings` to detect all three. Also added automatic material assignment via a `Detect Material` button in the `Advanced` section and a `Detect` button next to the `Material` property at the top of the component Inspector, as well as next to the `Blend Mode Materials` section when using multiple canvas renderers with blend modes. The suitable material is selected based on these three settings, combined with texture settings (PMA or straight alpha texture settings). If you receive incorrect results, likely your texture settings are incorrectly setup for your PMA or Straight alpha texture export settings.
+  - `SkeletonRenderTexture` example components now provide a `shaderPasses` parameter to customize which passes are rendered to the `RenderTexture`. It defaults to `-1` for all passes to keep the existing behaviour. You might want to set it to `0` to only render the first pass e.g. to avoid issues when using a URP shader at the original skeleton.
 
 - **Breaking changes**
 

+ 4 - 2
spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonRenderTexture/SkeletonGraphicRenderTexture.cs

@@ -195,7 +195,8 @@ namespace Spine.Unity.Examples {
 
 		protected void RenderSingleMeshToRenderTexture (Mesh mesh, Material graphicMaterial, Texture texture) {
 			Material meshRendererMaterial = MeshRendererMaterialForTexture(texture);
-			commandBuffer.DrawMesh(mesh, transform.localToWorldMatrix, meshRendererMaterial, 0, -1);
+			foreach (int shaderPass in shaderPasses)
+				commandBuffer.DrawMesh(mesh, transform.localToWorldMatrix, meshRendererMaterial, 0, shaderPass);
 			Graphics.ExecuteCommandBuffer(commandBuffer);
 		}
 
@@ -204,7 +205,8 @@ namespace Spine.Unity.Examples {
 
 			for (int i = 0; i < meshCount; ++i) {
 				Material meshRendererMaterial = MeshRendererMaterialForTexture(textures[i]);
-				commandBuffer.DrawMesh(meshes[i], transform.localToWorldMatrix, meshRendererMaterial, 0, -1);
+				foreach (int shaderPass in shaderPasses)
+					commandBuffer.DrawMesh(meshes[i], transform.localToWorldMatrix, meshRendererMaterial, 0, shaderPass);
 			}
 			Graphics.ExecuteCommandBuffer(commandBuffer);
 		}

+ 5 - 3
spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonRenderTexture/SkeletonRenderTexture.cs

@@ -186,9 +186,11 @@ namespace Spine.Unity.Examples {
 			meshRenderer.GetPropertyBlock(propertyBlock);
 			meshRenderer.GetSharedMaterials(materials);
 
-			for (int i = 0; i < materials.Count; i++)
-				commandBuffer.DrawMesh(meshFilter.sharedMesh, transform.localToWorldMatrix,
-					materials[i], meshRenderer.subMeshStartIndex + i, -1, propertyBlock);
+			for (int i = 0; i < materials.Count; i++) {
+				foreach (int shaderPass in shaderPasses)
+					commandBuffer.DrawMesh(meshFilter.sharedMesh, transform.localToWorldMatrix,
+						materials[i], meshRenderer.subMeshStartIndex + i, shaderPass, propertyBlock);
+			}
 			Graphics.ExecuteCommandBuffer(commandBuffer);
 		}
 

+ 4 - 0
spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonRenderTexture/SkeletonRenderTextureBase.cs

@@ -45,6 +45,10 @@ namespace Spine.Unity.Examples {
 		protected Mesh quadMesh;
 		public RenderTexture renderTexture;
 		public Camera targetCamera;
+		[Tooltip("Shader passes to render to the RenderTexture. E.g. set the first element " +
+			"to -1 to render all shader passes, or set it to 0 to only render the first " +
+			"shader pass, which may be required when using URP.")]
+		public int[] shaderPasses = new int[1] { -1 };
 
 		protected CommandBuffer commandBuffer;
 		protected Vector2Int screenSize;

+ 1 - 1
spine-unity/Assets/Spine Examples/package.json

@@ -2,7 +2,7 @@
   "name": "com.esotericsoftware.spine.spine-unity-examples",
   "displayName": "spine-unity Runtime Examples",
   "description": "This plugin provides example scenes and scripts for the spine-unity runtime.",
-  "version": "4.2.27",
+  "version": "4.2.28",
   "unity": "2018.3",
   "author": {
     "name": "Esoteric Software",