rive-app / rive-unity

MIT License
104 stars 11 forks source link

Building a Unity URP project to WebGL DOES NOT render Rive Assets #50

Closed trdroid closed 4 months ago

trdroid commented 6 months ago

Hi,

I recreated the DrawToCube Scene in a Unity URP Project and I am able to see the Rive Asset when I hit play in the Unity Editor; See below:

image

But when I build the project to WebGL, the Rive Asset DOES NOT appear anymore, see below:

image

I was wondering if there is a workaround for this.

The version of Rive-Unity Runtime that I am using is v0.1.112

chris-crucible commented 6 months ago

I am having similar issues with WebGL using the latest Rive Unity version 0.1.146. I'm on Unity 2023.2.19f1. I am actually able to get the "DrawToCubeScene" in the getting-started samples to render correctly (see screenshot below).

Screenshot 2024-05-16 at 2 21 39 AM

However, if I run the minion demo, the textures fail to render in the same way you show above, perhaps because of this error which I see in the console: RenderTexture.Create failed: format unsupported for random writes - RGBA8 sRGB

Screenshot 2024-05-16 at 2 21 15 AM

I have attempted to patch Unity's version of Empscripten as recommended here: https://github.com/rive-app/rive-unity/blob/main/WEBGL.md But I'm not sure how to verify whether this is being picked up, or whether it's related to the problem.

Can anyone shed light on whether creating render textures from code with random write enabled (as is done in the minions demo) should work on WebGL? Disabling random write when creating the texture produces a completely black screen, so that doesn't seem to be an option.

chris-crucible commented 6 months ago

I just confirmed that the Emscripten patch is being picked up, but the if block provided in the readme is never getting entered. Is the issue that random writes should be disabled on WebGL, and this patch should be fixing the issue of the black screen? If so, is the suggested patch incorrect for more recent versions of Rive Unity?

trdroid commented 6 months ago

Hi @chris-crucible, I think that your DrawToCube Scene renders in WebGL because it is a Non-URP Unity Project. Since the minions example is a URP Unity Project, it DOES NOT render in WebGL, which is the reason why I specifically created this work item as Rive Assets in a Unity URP Project do not render in WebGL as of yet.

damzobridge commented 6 months ago

We're looking into this, it seems the WebGL build works with the built-in render pipeline, but not URP at the moment.

We recently pushed a version that removes the need to use the Emscripten patch for WebGL, so you shouldn't have to worry about that once we've fixed the URP issue.

chris-crucible commented 6 months ago

Thanks @trdroid and @damzobridge for the extra context. This makes sense, though for our particular use case I'm still a bit unclear on a couple of things. I don't want to pollute this thread too much if it's unrelated so let me know if I should open a separate issue.

The getting-started demo provided in the Rive Unity examples, which uses the built-in render pipeline, works correctly on WebGL as suggested, but this sample renders Rive assets by assigning a command buffer to a particular camera. The minions demo, in contrast, does not assign the command buffer to a camera, but just calls Submit() on the Rive renderer in the Update method of the game object. This latter approach is what we would like to use for a couple of reasons, but it seems this doesn't work on WebGL, even when using the built-in render pipeline. If we modify the getting-started demo to use this approach, it no longer renders properly in WebGL, but works fine in the editor.

So I'm wondering if the URP fix mentioned will also allow us to use the renderer.Submit() approach with the built-in render pipeline, or if this is a separate issue. Apologies if I have conflated some issues, but it's not completely clear to me how these factors interact.

trdroid commented 6 months ago

@chris-crucible, I share the same set of questions as you've mentioned. It did occur to me as to why we need two ways of rendering Rive Assets: the command buffer way for the built-in render pipeline Unity Projects and the Submit() way for the URP Unity Projects. Perhaps this has to do with the internals of Unity and Rive that is best suited for someone from the Rive team to answer.

damzobridge commented 5 months ago

Unfortunately, due to the way the render pipelines are set up, we have to use slightly different approaches to accommodate the discrepancies between them.

Thanks for the feedback! Ideally, we'd like to get to a point where you don't have to think about this at all when using the API.

trdroid commented 5 months ago

Hi @damzobridge, I was wondering if you have an update on this. It'd be great if you could specify a tentative timeline as to when this issue could be addressed so that I can decide if I should proceed with a Unity Project with a Standard Render Pipeline or with a URP.

damzobridge commented 4 months ago

Hi @trdroid , we're working on a larger update that will include high-level components that handle rendering across built-in RP, URP, and HDRP. However, for that, we'll be moving away from the Submit() approach and integrating a bit closer with the different SRP pipelines.

In the meantime, the updated RiveTexture script here should address the black texture problem. Let me know if that isn't the case on your end!

trdroid commented 4 months ago

Hi @damzobridge, I tried drawing a Rive texture on a Cube in a URP Unity Project using Rive-Unity version v0.1.195. It works within the Unity Editor BUT NOT when built to WebGL (the same issue that I posted in my very first post in this work item). In WebGL, I just see a dark screen as shown below:

image

When played within the Unity Editor, I see the Rive Texture drawn on the Cube: image

This is the zipped Unity Project that I created: RiveURPWebGL.zip

Based on my observation, I STILL COULD NOT RENDER RIVE ASSETS in WEBGL in a Unity URP Project.

damzobridge commented 4 months ago

Hi @trdroid , thanks for sending over the Unity project. It looks like you're still using the old version of the RiveTexture script in your project. I changed it to the new RiveTexture script I mentioned earlier, and it builds and renders properly. Let me know if that fixes things for you!

URPWebGLBuildTestSnapshot

Also, in terms of package versions, I recommend using the ones on the releases page as those are usually more stable.

trdroid commented 4 months ago

Hi @damzobridge, thank you so much! I have it working with the release version of Rive-Unity. I even have the script working with the click listener wherein I could interact with the stars on the Rive Texture.

A follow up question:

Apart from how we render Rive Textures in a Unity URP Project, are there differences in what features of Rive are supported across the Standard Render Pipeline and the URP? To elaborate a bit, are there features specific to Rive (let's say, state machines) that ONLY work in a Standard Pipeline but not in URP?

damzobridge commented 4 months ago

Glad to hear it's working for you @trdroid . Apart from slightly different rendering approaches, everything else works the same feature-wise across render pipelines!