Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
55853117b23477b737f1ede00bd4f9fddf0d9bec
27085dfb0c26c8ccb9b05b69c7a3923d981d9f80
59 changes: 51 additions & 8 deletions package/Editor/AssetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,36 @@ int height

if (rt != null)
{
RenderTexture.active = rt;
RenderTexture sourceForRead = rt;
RenderTexture temp = null;

// Static preview: use the runtime decode material (Rive/UI/Default) in Linear color space.
// This decodes gamma to linear, which works correctly with ReadPixels→Texture2D path.
// We DON'T use the pass-through shader here because the blit+ReadPixels seems to cause issues, and leads to nothing rendering for the static preview.
// TODO: Remove this once we have a proper way to display the texture in Linear color space.
if (Rive.TextureHelper.ProjectNeedsColorSpaceFix)
{
var mat = Rive.TextureHelper.GammaToLinearUIMaterial;
if (mat != null)
{
temp = RenderTexture.GetTemporary(rt.width, rt.height, 0, RenderTextureFormat.ARGB32);
Graphics.Blit(rt, temp, mat);
sourceForRead = temp;
}
}

RenderTexture.active = sourceForRead;

Texture2D tex = new Texture2D(width, height);
tex.ReadPixels(rect, 0, 0);
tex.Apply(true);

RenderTexture.active = prev;
if (temp != null)
{
RenderTexture.ReleaseTemporary(temp);
}
RenderTexture.ReleaseTemporary(rt);
return tex;
}
return null;
Expand Down Expand Up @@ -522,7 +545,7 @@ RenderTexture Render(Rect rect, bool isStatic = false)
rt = temp;
}

RenderTexture.ReleaseTemporary(rt);
// Caller releases the temporary RT
return rt;
}

Expand All @@ -532,15 +555,35 @@ public override void OnPreviewGUI(Rect rect, GUIStyle background)
{
RenderTexture rt = Render(rect);

UnityEditor.EditorGUI.DrawPreviewTexture(
FlipY()
? new Rect(rect.x, rect.y + rect.height, rect.width, -rect.height)
: rect,
rt
);
var drawRect = FlipY()
? new Rect(rect.x, rect.y + rect.height, rect.width, -rect.height)
: rect;

// Live preview: use a simple pass-through shader in Linear color space.
// Rive outputs gamma values, and it looks like EditorGUI.DrawPreviewTexture expects sRGB input.
// We DON'T use the decode material here because it would decode to linear, causing burnt/dark colors.
// The pass-through shader (Hidden/Rive/Editor/SRGBEncodePreview) just returns the texture unchanged.
// TODO: Remove this once we have a proper way to display the texture in Linear color space.
var mat = (Rive.TextureHelper.ProjectNeedsColorSpaceFix ? GetEncodePreviewMaterial() : null);
UnityEditor.EditorGUI.DrawPreviewTexture(drawRect, rt, mat);
RenderTexture.ReleaseTemporary(rt);
}
}

private static Material s_encodePreviewMaterial;
private static Material GetEncodePreviewMaterial()
{
if (s_encodePreviewMaterial != null) return s_encodePreviewMaterial;
var shader = Shader.Find("Hidden/Rive/Editor/SRGBEncodePreview");
if (shader == null) return null;
s_encodePreviewMaterial = new Material(shader)
{
name = "Rive_Editor_SRGBEncodePreview",
hideFlags = HideFlags.HideAndDontSave
};
return s_encodePreviewMaterial;
}

private void UnloadPreview()
{
m_stateMachine = null;
Expand Down
54 changes: 41 additions & 13 deletions package/Editor/Components/TexturePanelRendererEditor.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
using Rive.Components;
using UnityEditor;


namespace Rive.EditorTools
{
[CustomEditor(typeof(RiveTextureRenderer), true)]
internal class TexturePanelRendererEditor : PanelRendererInspector
{

}
}

using Rive.Components;
using UnityEditor;
using UnityEngine.UIElements;


namespace Rive.EditorTools
{

[CustomEditor(typeof(RiveTextureRenderer), true)]
internal class TexturePanelRendererEditor : PanelRendererInspector
{
public override VisualElement CreateInspectorGUI()
{
var root = base.CreateInspectorGUI() ?? new VisualElement();

// For worldspace renderers, we display a button to convert materials on the current mesh renderer, if needed.
// Makes it easier for users to switch to Rive materials without having to know the right ones to pick.
var textureRenderer = (RiveTextureRenderer)target;
if (textureRenderer != null && textureRenderer.Renderer != null)
{
System.Action clickAction = () =>
{
// This will replace any non-Rive materials with Rive equivalents, even if the existing materials are not Unity defaults.
MaterialConversionUtility.ReplaceMaterialsWithRive(textureRenderer.Renderer);
};
var convertButton = new Button(() => clickAction())
{
text = "Replace Materials with Rive Materials"
};
convertButton.name = "RiveConvertMaterialsButton";
convertButton.userData = clickAction; // allow tests to invoke without event system/panel
convertButton.style.marginTop = 6;
root.Add(convertButton);
}

return root;
}

}
}

4 changes: 2 additions & 2 deletions package/Editor/Menu/SupportInfoMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static string GenerateSupportInfo()
string operatingSystem = SystemInfo.operatingSystem;
string graphicsDevice = SystemInfo.graphicsDeviceName + " (" + SystemInfo.graphicsDeviceType + ")";

string riveVersion = GetPackageVersion(PackageInfo.PACKAGE_NAME);
string riveVersion = GetPackageVersion(Rive.EditorTools.PackageInfo.PACKAGE_NAME);

return
"Rive Unity Support Info\n" +
Expand All @@ -57,7 +57,7 @@ private static string GenerateSupportInfo()
$"Render Pipeline: {renderPipeline}\n" +
$"OS: {operatingSystem}\n" +
$"GPU: {graphicsDevice}\n" +
$"Rive Plugin: {PackageInfo.PACKAGE_NAME} {riveVersion}\n";
$"Rive Plugin: {Rive.EditorTools.PackageInfo.PACKAGE_NAME} {riveVersion}\n";
}

private static string GetRenderPipelineDescription()
Expand Down
4 changes: 2 additions & 2 deletions package/Editor/PackageVersionChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static void OnPackagesRegistered(PackageRegistrationEventArgs args)
// Check if the Rive package was updated
foreach (var changedPackage in args.changedTo)
{
if (changedPackage.name == PackageInfo.PACKAGE_NAME)
if (changedPackage.name == Rive.EditorTools.PackageInfo.PACKAGE_NAME)
{
ShowRestartDialog(changedPackage.version);
break;
Expand All @@ -42,7 +42,7 @@ private static void ShowRestartDialog(string newVersion)
);

DebugLogger.Instance.LogWarning(
$"[{PackageInfo.PACKAGE_NAME}] Package updated to {newVersion}. " +
$"[{Rive.EditorTools.PackageInfo.PACKAGE_NAME}] Package updated to {newVersion}. " +
"Please restart the Unity Editor to make sure the new version is fully loaded. If you skip this step, you might run into issues, and riv files may not work properly."
);
}
Expand Down
8 changes: 8 additions & 0 deletions package/Editor/Shaders.meta

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

60 changes: 60 additions & 0 deletions package/Editor/Shaders/SRGBEncodePreview.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Editor-only shader for Rive asset preview in the Unity Inspector.
// This is a simple pass-through shader used ONLY for live preview in Linear color space projects in AssetEditor.cs.
//
// Why pass-through?
// - Rive outputs gamma into the RenderTexture
// - EditorGUI.DrawPreviewTexture expects sRGB input for correct display
// - We just pass the values through unchanged to avoid color conversion issues
//
// Note: Static preview uses a different path (Rive/UI/Default decode material + ReadPixels) so this shader is not used there.
Shader "Hidden/Rive/Editor/SRGBEncodePreview"
{
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Overlay" }
Pass
{
ZWrite Off
Cull Off
ZTest Always
Blend One Zero

HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};

struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};

v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}

sampler2D _MainTex;

float4 frag(v2f i) : SV_Target
{
// Simple pass-through: Rive RenderTexture contains gamma values,
// return them unchanged for correct display in EditorGUI preview
float4 c = tex2D(_MainTex, i.uv);
return c;
}
ENDHLSL
}
}
}
9 changes: 9 additions & 0 deletions package/Editor/Shaders/SRGBEncodePreview.shader.meta

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

Loading