happy-turtle / oit-unity

Order-independent Transparency Implementation in Unity with Per-Pixel Linked Lists
Apache License 2.0
181 stars 25 forks source link

Doesn't work on URP #39

Open Ritbulau opened 4 days ago

Ritbulau commented 4 days ago

I tried use this with URP, and it simply does not work...

public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get("Order Independent Transparency");
            var mat = orderIndependentTransparency.Render(cmd, renderingData.cameraData.renderer.cameraColorTargetHandle,
                renderingData.cameraData.renderer.cameraColorTargetHandle);
            if (mat != null)
            {
                Blitter.BlitCameraTexture(cmd, renderingData.cameraData.renderer.cameraColorTargetHandle,
                    renderingData.cameraData.renderer.cameraColorTargetHandle, mat, 0);
            }
            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();
            CommandBufferPool.Release(cmd);
        }

This piece of code creating errors, all they say, that "ScriptableRenderer" does not contain the definition of "cameraColorTargetHandle", and an available extension method "cameraColorTargetHandle" could not be found that accepts the type "ScriptableRenderer" as the first argument (perhaps the using directive or assembly reference was omitted).

I tried everything, even recoding this part myself, but it didn't work out. (Yeah, I know, that I am really bad at coding these things):

        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {

            CommandBuffer cmd = CommandBufferPool.Get("Order Independent Transparency");
            var mat = orderIndependentTransparency.Render(cmd, renderingData.cameraData.renderer.cameraColorTarget,
                renderingData.cameraData.renderer.cameraColorTarget);

            cmd.Blit(renderingData.cameraData.renderer.cameraColorTarget, renderingData.cameraData.renderer.cameraColorTarget, mat, 0);

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();
            CommandBufferPool.Release(cmd);
        }

All my attempts were in vain, and despite strictly following the instructions, I tried to change all possible settings, connect libraries, and so on. Most likely I'm too stupid and I don't see some obvious mistake of mine, but I'll be glad of any help and I'll be happy to provide any additional details, I've spent more than 2 weeks on this!

And sorry for my english, If I wrote something illiterate.

happy-turtle commented 4 days ago

Hey, thanks for trying out the package. 🙂

What Unity and URP version are you using? I think the package is only actually usable on versions from 2022 upwards. cameraColorTargetHandle was only introduced to URP then. The package states Unity 2022 as a requirement, but we probably need to add the correct URP version as well.

Ritbulau commented 4 days ago

I am using Unity 2021.3.21f1 and URP 12.1.10. I think you're right and I should try using the Unity 2022 version.

Ritbulau commented 4 days ago

So, I switched to 2022 version, followed the instructions, but it just does not work. All objects with material, that use shaders from your package, are gust white and does not seem to work as intended. Screenshot_74

happy-turtle commented 4 days ago

It would definitely make sense to add a URP and HDRP version range to indicate which version might be used, that's a good point.

Just from the screenshot I can't really tell what is going wrong there. Did you run it in Play mode as well? And I assume you've added the OIT feature to the Renderer Asset. I can try to reproduce the image on my side, but it's a bit of a guessing game.

Ritbulau commented 4 days ago

I added the OIT render feature and tried to enter Play mode, as well as compile the game. I tried different graphics APIs and different settings of universal render pipeline asset and Universal render data. I am using URP version 14.0.11. You can try to recreate my problem, because all I did was download unity 2022.3.35f1 (latest unity 2022 version available) and created a 3d urp template project and embedded your package in it, following all the instructions. If you can't achieve the same result as me, well, thanks for trying to help!

happy-turtle commented 2 days ago

So I tried this and I can set it up in a project. Here is a recording of the steps I did in a newly created project. I would think the OIT Feature is not assigned on the actual used URP Renderer Asset. I hope it helps.

https://github.com/happy-turtle/oit-unity/assets/18415215/c177f6ea-192d-4bce-9e31-089d85ebb35e

Ritbulau commented 2 days ago

Okay, I think i should've said this earlier, but can issue be with me downloading it directly from github and unpacking into my project folder? I just can't get instalation with package manager to work, even tho with other packages it had no problems. It just say, that "git@github.com:happy-turtle/oit-unity.git" is invalid and doesn't exist. Maybe I am a bit stupid and do something wrong, I don't have that much experience with downlading packages from git using package manager.

happy-turtle commented 1 day ago

For that URL you need SSH correctly set up. Just using http is probably easier, that would be https://github.com/happy-turtle/oit-unity.git. Or you just download the repo code and put it in the Packages folder of your Unity project.