mob-sakai / UIEffect

UIEffect is an effect component for uGUI element in Unity. Let's decorate your UI with effects!
https://github.com/mob-sakai/UIEffect
MIT License
5.62k stars 773 forks source link

v3.2.0 Unity 2019.2.0f1 LWRP UICapturedEffectImage doesn't capture during play mode #186

Open amartinez1660 opened 5 years ago

amartinez1660 commented 5 years ago

Currently testing only on PC. On the editor, the capture button does work. However during play mode it doesn't. Gives back a black image. The canvas where the Capture Image component is attached is in screen overlay mode (no 3d no cameras attached for UI).

Let me know what more info would be useful.

mob-sakai commented 5 years ago

Hi @amartinez1660 Thank you for your reporting!

mob-sakai commented 5 years ago

Try to modify UIEffectCapturedImage.cs (line 360) as following:

// s_CommandBuffer.Blit(BuiltinRenderTextureType.BindableTexture, s_CopyId); // BEFORE
s_CommandBuffer.Blit(BuiltinRenderTextureType.CurrentActive, s_CopyId); // AFTER

To be honest, I don't know if this modify works correctly...

amartinez1660 commented 5 years ago

I think the issue is that there's a mix about what constitutes #if UNITY_EDITOR. Changing line 360 has no effect whether we hit play or not because it's still inside UNITY_EDITOR defines. I think the issue is more here: Line block starting at 392, `

if UNITY_EDITOR

if (!Application.isPlaying) { Graphics.ExecuteCommandBuffer(s_CommandBuffer); UpdateTexture(); return; }

endif

`

Because if the application is NOT playing inside the editor, then the coroutine that captures the next frame "_CoUpdateTextureOnNextFrame" which calls UpdateTexture(); won't execute the command buffer: // Line 542 ` void UpdateTexture() {

if !UNITY_EDITOR

        // Execute command buffer.
        Graphics.ExecuteCommandBuffer (s_CommandBuffer);

endif

        _Release(false);
        texture = capturedTexture;
        _SetDirty();
    }`

EDIT: Formatting. Can't get the code 'newline' to be visible. Excuse me that. EDIT2: Just commenting the line at 393 if (!Application.isPlaying) makes it work during play mode.

Can I do further tests on a couple if devices, would you like me to try that?

mob-sakai commented 5 years ago

@amartinez1660 Thanks. I found that in most environments it doesn't work. I think that UIEffectCapturedImage needs to be completely renovated...

mob-sakai commented 5 years ago

@amartinez1660 Try this script. It works in my environments (Mac editor/Mac standalone/WebGL) with default LWRP asset. UIEffectCapturedImage.cs.zip

antpaw commented 4 years ago

unfortunately android is still affected by this