Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Released] Corgi Raytracing - Built-in Render Pipeline (Forward and Deferred!) RTX Reflections

Discussion in 'Assets and Asset Store' started by funkyCoty, Feb 1, 2021.

  1. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Links!
    Asset store URL: https://assetstore.unity.com/packag...n-render-pipeline-forward-and-deferred-184088

    Documentation: https://docs.google.com/document/d/1csXq_vzZtPvxA64QkdDHi_bfYB3VWu-tGvMg7XCJYmQ/

    Blog post on how it works: https://coty.tips/raytracing-in-unity/

    What's this?!
    I've been really excited about RTX. Raytracing really is the future of rendering! Unfortunately, Unity only provides any sort of rendering support for RTX with their HDRP pipeline. A lot of users are not fans of the new setup, or cannot upgrade their existing projects to use it. I've come up with a solution!

    Why Corgi Raytracing??
    If you find yourself using the built-in render pipeline and really wanted to try out Raytracing, this asset is for you! I've made sure to support both Forward and Deferred, and if you're using the Standard shader: Corgi Raytracing will "just work" for you, with zero programming required!

    If you're a graphics engineer, I've included a lot of useful documentation on how you can extend this plugin for creating your own Raytraced effects. I've kept things reasonably modular, but keeping performance in mind.

    What about URP and HDRP?
    Due to the demand, I have extended this plugin to support URP. For now, HDRP is still not supported. If there is demand, I may reconsider HDRP support.

    Examples, please!!
    I've included videos and screenshots on the Unity Asset store, please check them out!



    upload_2021-2-1_9-24-0.png

    How will it run on my machine?!?!?!
    I've gotten a few emails about this; so I've put together a demo scene. You can download, extract, and run this Unity project to see how Raytracing runs on your machine: https://uploads.coty.tips/CorgiRaytracingDemo.zip
    Please note, the actual performance of your project will vary greatly depending on the complexity you require for your game. I've included a few performance tips in the documentation and even some tools for helping you reach those performance goals in the asset.
     
    Last edited: Oct 10, 2021
  2. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Recent update.

    1.3:
    * Improved support for RTX effects against the Standard shader (emission, fog)
    * Removed some redundant stuff

    1.2:
    * Added the ability to temporally render the effects, with optional temporal reprojection.
    * Added the ability to render all of the effects at a lower resolution, for performance considerations.
    * Added some helpful tools for more quickly adjusting Raytracing settings for existing projects.
    * Added Standard and Standard (Specular) raytracing compatible variants into the project.
    * Updated the documentation on how you can very easily update most Unity built-in shaders to be Corgi Raytracing compatible.
     
    munozpro likes this.
  3. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    munozpro likes this.
  4. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    I, and I'm sure many others would love to get this working in URP.
    If it does work, I definitely will be picking it up for my project :)

    My project uses all procedural geometry and meshes imported at runtime, will Corgi work with those?
    Additionally, does it include a realtime GI solution as well, or just shadows and reflections?
    Thanks!
     
  5. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Hey. I haven't tried getting it to work with URP; but I'll consider this a feature request and spend a weekend on it soon to see if its feasible. I think it should be pretty easy to get working, I just haven't thought anyone wanted that considering HDRP already has a unity provided RTX thing.

    As for your questions: yes, it does work with procedural geometry. I use it in a voxel-terrain side project of mine. The project does not currently have a full realtime GI solution, right now its focused on a post-process-like way of adding RTX shadows, reflections, and god rays.
     
    Lars-Steenhoff likes this.
  6. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    That sounds great! I am using URP for a bunch of other compatibility stuff, so having these advanced features is super useful.
    My concern is that because I am using User-Imported content, that replacing the shaders of their materials is quite tricky.
    Is Corgi limited to just using the provided materials/certain shaders, or will it handle the use of more standard Unity Shaders just fine?

    Thanks!!
     
  7. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    It's possible to define a raytracing pass which all shaders can fall back to; but I really don't recommend it as you get a lot of materials affecting the RTX results which both slows down the whole process and in general gives worse visual results compared to having passes manually written per-shader.

    The process for adding a pass to any shader is here in the documentation: https://docs.google.com/document/d/...3VWu-tGvMg7XCJYmQ/edit#heading=h.81p324o87hqw

    This process assumes that the shader is a standard shader variant, such as most of the built-in shaders or the surface shaders you can create from the right click menu. By assume, this means its looking for textures and floats with the same naming convention. If you're comfy with writing shaders in general, the documentation should have enough info for you to manually add RTX support to any shader by hand. If not, the simple copy/paste of
    Code (CSharp):
    1. #include "../Includes/RaytracedShadowsHitPass.cginc"
    is usually enough.

    Can you elaborate a bit on what you mean by user-imported content? Generally if youre just importing models/textures (like OBJ+MTL) then you have to define a game-included shader anyways, in which case yeah corgi raytracing would be perfectly fine. If you're letting users import entire shaders, you'd have to tell them to include the raytracing passes from corgi raytracing.
     
  8. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    That's very interesting, thank you for the info/snippets!
    I am using an asset called Trilib 2, which can import fbx, obj, and gltf files at runtime, and has shaders that it uses. Now I understand that I can edit those shaders to include Raytracing Passes.

    I look forward to trying it out in the future!
     
  9. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
  10. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Hey, this is due to a recent driver update. It happens for me too. I'm looking into it :(
     
  11. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Worth noting that I don't get similar issues with HDRP's raytracing with these same drivers.
     
  12. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Yeah, I was skimming over their shader source to see why mine had this issue and theirs did not. No dice, on that front. I spent some time combing over the code and slapped my forehead when I saw the issue. I wasn't initializing one of my variables in the raytracing payload struct. Before the driver update: it initialized to zero. After the driver update: it sometimes initializes to 0, sometimes a garbage value. Rookie mistake, haha.

    Anyways, I just pushed the fix to the asset store. If you need a quick fix ASAP, just add this line to the payloads in the raytracing generation shaders:

    Code (CSharp):
    1. // locate this, there are two of them in RaytracedReflections.raytrace:
    2. ReflectionPayload payload;
    3. payload.color = float4(0.0, 0.0, 0.0, 0.0);
    4. payload.bounceCounter = 1;
    5. payload.rayIntensity = 1.0;
    6.  
    7. // add this under it, it will fix the black static-y boxes:
    8. payload.rayType = 0.0;
    Update will be live on the asset store soon, hopefully!

    Edit: I've also just now uploaded an update to the demo, with the fix to verify its now working for you before you buy the asset.

    Same link as before: https://uploads.coty.tips/CorgiRaytracingDemo.zip

    NVIDIA_Share_JHVFPf5bQz.png
     
    Last edited: Aug 2, 2021
    rz_0lento likes this.
  13. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Works nicely now :)
     
    funkyCoty likes this.
  14. Jingle-Fett

    Jingle-Fett

    Joined:
    Oct 18, 2009
    Posts:
    614
    Very glad this asset exists, I can't stand HDRP's terrible UX. Will definitely be keeping an eye on it, if you can get realtime GI working that would be pretty big. Is Corgy Raytracing compatible with Amplify Shader?
     
  15. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    I'm going to look into realtime gi after I finish looking into supporting URP. I agree that HDRP is quite a UX nightmare. I don't think I'll be looking into HDRP support, mostly because there's already Unity's own raytracing solution for HDRP, but if there's some demand for it I'll consider it.
     
    Jingle-Fett likes this.
  16. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    Sounds incredible, looking forward to the URP version!
     
  17. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Is URP support going to be a separate package or included in current one? :)
     
  18. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    I'm going to try and keep it a single asset. If for whatever reason it is a huge pain to do so, if I split it I'd just allow you to get a free copy of the URP if you already own the BuiltIn version.
     
    Lars-Steenhoff and rz_0lento like this.
  19. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    This may be a dumb question, but is Corgi a specifically "RTX" raytracing plugin (that only works on NVIDIA cards) or general ray tracing that will work on AMD cards as well?
    If it only works for NVIDIA cards, if an AMD user runs the app, do you have an idea as to what will happen?
    Crashes? Or just the ray tracing functionality turned off?

    Also, on the demo you shared, which way are the sliders facing? I am getting better quality/lower framerates when they're to the left, and higher framerates/softer shadows to the right, which confused me, lol.

    Thanks!

    PS: Seeing as my game/app is URP only at the moment, I would be happy to pay more/separately for a URP version if/when it does get released, and I'm sure many other URP devs would too! This definitely has the potential to be a game-changer! :D
     
    Last edited: Aug 6, 2021
  20. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Corgi Raytracing should work anywhere Unity internally is supporting RaytracingShaders. For PC, I believe this is only on newer nvidia and amd GPUs. I'm not sure if Unity supports it yet, but if/when they do, it should also work on PS5/the new Xbox.

    There's a demo linked above; if you have an AMD card please give it a go and let me know if it works. I don't have any AMD cards to try it myself, but I'm guessing it should work (albeit slower, since AMD cards do not have RT-Cores, so it'll fallback to a Compute solution, I think).

    If the target hardware does not support it at all, Corgi Raytracing will try to detect that and turn itself off.

    The sliders are kind of dumb, sorry haha. The resolution sliders are "texture reciprocal" values. So your resolution divided by the slider value, which is why its higher quality to the left. The other settings are mostly higher quality to the right.

    Thanks for the kind words. I'm pretty sure a URP raytracing solution is possible, after tinkering a bit. The only bad thing on my end is that I need to completely re-write the c# side just for URP, because of how it works. So, I've been trying to keep it modular like how I have the built-in one working. Luckily, most of the shader code is re-usable!
     
    JudahMantell likes this.
  21. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Quick update; I've made some progress on URP support. Very exciting stuff.

     
  22. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    Looks awesome!
    I know many will disagree with me, but I much prefer SRPs Render Feature workflow over adding a bunch of components to camera objects. Just seems cleaner to me.
    Can't wait!

    Also, I'm very curious about the specs of your PC running Corgi. Could you share them?
     
  23. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    I don't have anything against how the SRP RenderFeature/RenderPass system works yet really, I just really hate how Unity seems to change how everything works so frequently. Keeps us on our toes!

    To answer your question, I've been developing on both a PC and a Laptop.

    PC Specs:
    CPU: Ryzen 3900X (12 core / 24 threads)
    GPU: GTX 2080s
    RAM: 32 GB of DDR4, 4400mhz

    Laptop Specs:
    CPU: some mobile intel chip (~4 core / 8 threads)
    GPU: Mobile GTX 1060
    RAM: 16 GB of DDR3, 1600mhz

    Surprisingly, I've been able to run the demo scene's at ~100-200 fps on my laptop. On my PC, they seem to be over ~200-400fps. The scenes are very simple though, I think performance will vary greatly depending on your scene complexity. In general, you don't want to raytrace against everything, only stuff that gives the most visual impact.

    I know fps isn't a very good metric though. If you'd like I could grab some actual profiler timings.
     
  24. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    That's awesome to hear, I'm very surprised as well that the 1060 can run it at all!
    No need to show profiler timings (for me, anyway), I was just curious about what you were developing/testing.
    Thanks!
     
  25. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    I was surprised it ran, as well! Nvidia must be using a compute solution under the hood, probably after some driver update in the past. If you can try the demo on any 'weird' setups, let me know how it runs! Be sure to play with the sliders, as they affect performance greatly. You'll probably be able to get away with some really nice visuals just by tweaking the resolution slider; but I also have implemented stuff like temporal rendering + reprojection which really goes a long way with performance.
     
    JudahMantell likes this.
  26. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,521
    Is there any chance this will work on MacOS?
     
  27. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Afaik there's no API that supports hardware ray tracing on MacOS. On Linux there would be Vulkan ray tracing but Unity currently supports DXR only on DX12.
     
    funkyCoty likes this.
  28. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    If OSX ever adds a raytracing api to their graphics apis, Unity will likely update to add in support for OSX. If Unity adds in support for RaytracingShaders in OSX, then Corgi Raytracing should automatically work with OSX as well. Until this series of events happens, however, no raytracing is possible on OSX.
     
    Lars-Steenhoff likes this.
  29. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,521
  30. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Then it sounds like the first domino has fallen! When will Unity support it? It's a question to ask them.
     
    Lars-Steenhoff likes this.
  31. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    I've spent this last weekend trying to get URP + VR + Single Pass Instanced all working together. After a lot of frustration and thoroughly reading through the URP source code, I've finally made some progress.



    Now that I've got this working, the next step is making sure it works in basically every permutation URP/builtin/vr/non vr/single pass/multi pass. Once this hard part is done though, I can get to work on getting all the features from builtin ported over to urp and hopefully soon push an update to the asset store so it works in all these places.

    Getting SPI was quite a nightmare, I had to dig into HDRP's source code and see wtf they were doing in a few places, and had to write some macros for corgi raytracing to use which are not available in URP but were in HDRP. hopefully all this pain will be worth it haha
     
    hippocoder, NotaNaN, m0nsky and 2 others like this.
  32. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    OK! The first build for URP support is ready to test. If you're interested in getting an early build, please DM me here (with your invoice) and I'll reply with a google drive link. I just submitted the build to the Unity Asset Store, so if no major issues are found I'll be updating the asset store build very soon.

    v1.4.5 changes:

    Code (CSharp):
    1. * Added experimental URP support
    2. * URP has some limitations, please refer to the documentation's platform limitation section for more info.
    Updated documentation, including URP support information: https://docs.google.com/document/d/1csXq_vzZtPvxA64QkdDHi_bfYB3VWu-tGvMg7XCJYmQ/edit
    Unity_3DlhhK0v6r.png
     
    thelebaron, NotaNaN and rz_0lento like this.
  33. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    851
    Has this been tested at all with the dots hybrid renderer(v2)? Absolutely incredible work though! Also any plans for raytraced gi?
     
  34. NotaNaN

    NotaNaN

    Joined:
    Dec 14, 2018
    Posts:
    325
    @funkyCoty said:
    So if the plan has not changed (and things go well), realtime GI may be somewhere on the horizon. ;)
     
    funkyCoty and thelebaron like this.
  35. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    Oh my gosh, I can't believe I missed these new posts! SO excited for URP, purchasing the asset now :D

    @funkyCoty I actually had a possibly dumb question:
    The asset is advertised as having "Volumetric Shadows," but the documentation says "Volumetric Lighting". What (if any) is the difference? What are you referring to when you use these terms?
    Thanks!
     
    Last edited: Aug 30, 2021
    NotaNaN likes this.
  36. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Haha sorry, I've seen the term used multiple ways and now I'm guilty of it, too. The effect tries to make shadows feel volumetric, by tracing through the volume of the screen to find what is and is not occluded. It's very expensive and really not worth it over traditional screen space methods of solving this, so it's mostly there as another example of how you can write your own effects.


    It's somewhere on the roadmap in my head ;)
     
    NotaNaN likes this.
  37. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    Got it... I think, lol. I've been using this asset for my volumetric lighting and it works great. To clarify, is this the effect you're referring to? I definitely think faking it using assets like this is more efficient, but I'm very interested in seeing an RTX version just for the hell of it.



    Follow up question: With the URP workflow with RenderFeatures/not needing scripts on cameras, will everything work with multiple cameras in the scene? I have one being displayed normally, and one being output to a render texture at all times.

    EDIT: Follow up 2 (Sorry!)
    Aside from specific things that I wouldn't want RTX applied to, I'm basically using the standard lit shader throughout my project. If I modify it/replace it with a compatible shader, will the scene "break" if the RTX options are turned off? Or will it look identical to before, just without the RTX effects?
     
    Last edited: Aug 30, 2021
  38. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    It's kind of the inverse of this. Volumetric lighting tends to make non occluded space and make it very bright. Mine is the reverse, it makes occluded space darker. And yeah, traditional methods are much faster than the RTX implementation. I think the best and most useful for real world usage effect in the package is the RTX reflections.

    Hmm, I believe so, yes.

    Yeah, they'll look normal with the effects off. Definitely needs to work this way, so you can use the same materials on PCs which don't have raytracing capable cards haha.
     
    JudahMantell likes this.
  39. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    Ah, I understand, thanks for the clarification. I might politely suggest making the distinction clear somewhere, because RTX volumetric lighting is also a huge draw to people, and I wouldn't want people to be disappointed because they misunderstood, lol. Just looking out for ya!
     
    funkyCoty likes this.
  40. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    501
    This asset looks amazing!
     
    funkyCoty and NotaNaN like this.
  41. killer1171090

    killer1171090

    Joined:
    Feb 23, 2013
    Posts:
    145
    Does this support Intersection shaders?
    Trying to figure out how to get Intersection shaders working in unity to render AABB's
    Preferably in the Built-In Render Pipeline.
     
  42. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    It's possible to do intersection stuff yourself within this, but I have not yet released anything to make this process easier within the plugin (no fancy macros or anything yet).

    If you know your way around raytracing shaders, it's not too difficult to do, though. There are two parts to it: you need to hook into the render pipeline to have a pass where you just render your intersection shaders as if they are normal shaders (or raytrace them directly and output to the screen), then you need all the raytracing effects to account for your intersection shader (so they show up in reflections, and they themselves reflect things).

    Here's an example of some intersection shader tests I've made using the plugin:
     
    NotaNaN likes this.
  43. killer1171090

    killer1171090

    Joined:
    Feb 23, 2013
    Posts:
    145
    If i purchase could i snatch an Intersection shader example off ya?
     
  44. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Yeah, I can send you what I've got. It's very wip though, not super extensible yet. At the moment I only have it in URP (need to backport to built-in) and it's a bit hacky.
     
    Last edited: Nov 13, 2021
  45. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Pretty close to having something shippable. I have it working pretty well in URP, going to backport to built-in next.

     
    NotaNaN likes this.
  46. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    OK the first release to support procedural intersection shaders has just been submitted to the asset store.

    1.5.0 will have support for easily extendable intersection shaders, with examples on how to use them for BuiltIn's Forward+Deferred, and URP's forward renderer. The builtin deferred support is especially nice in that the raytracing shader will create the proper gbuffers as if the procedural object was rasterized normally, so everything else should just work nicely on top of it there.

    Give it a try!

     
    killer1171090 and NotaNaN like this.
  47. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Just pushed 1.5.1
    * Work around for a Unity 2022+ bug which caused a crash on startup.

    Side note, thanks to rz_0lento, I'm tweaking the reflections to be more physically based. They look a lot nicer now, here's a preview.

    VKOw4SvGJS.gif
     
  48. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    867
    Neat! I'll check this out soon!

    I would be super interested if you could manage Indirect lighting though. Reflections + Indirect lighting is like 90% of the work before dealing with shadow stuff.

    If i could have that and just have to replace some code in my shader that would be awesome.

    Secondly, your shadows seem very noisey, is that a filtering issue? are they only based on direct lighting?
     
  49. MagiJedi

    MagiJedi

    Joined:
    Apr 17, 2020
    Posts:
    32
    Hello and happy holidays! I just got this product, switched my URP to DX12, added the PfbRaytraceDataManager, swapped the shader on my main mats to the Lit(RTX) one, and when I hit play I get the following:

    RenderTexture.Create failed: format unsupported for random writes - Depth (142).
    UnityEngine.StackTraceUtility:ExtractStackTrace ()
    RaytracePassBase:EnsureRT (UnityEngine.Rendering.CommandBuffer) (at Assets/CorgiRaytracing/Scripts/Raytracing/URP/RaytracePassBase.cs:299)
    RaytracePassBase:BuildCommandBuffer (UnityEngine.Rendering.CommandBuffer) (at Assets/CorgiRaytracing/Scripts/Raytracing/URP/RaytracePassBase.cs:155)
    RaytracePassBase:Execute (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Rendering.Universal.RenderingData&) (at Assets/CorgiRaytracing/Scripts/Raytracing/URP/RaytracePassBase.cs:42)
    UnityEngine.Rendering.RenderPipelineManager:DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset,intptr,System.Collections.Generic.List`1<UnityEngine.Camera/RenderRequest>,Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle)

    Can you assist when you get a chance?
     
  50. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    719
    Hey there! Sorry I'm a bit slow to respond, it's the holidays and all that.

    Could you email me more info? coty @ wanderingcorgi.com
    I need to know the exact unity version, urp version, and anything else you can tell me.