Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED] Camera Projection Rendering Toolkit (Non-linear perspectives, oblique projections, SSAA)

Discussion in 'Assets and Asset Store' started by Melcx, Jul 14, 2017.

  1. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,370
    Hey @Melcx ,

    I'm absolutely loving the tool. It's working great.

    One thing I'm getting in Unity 2017.3.1f1 is a warning when CPRT is enabled:
    OnRenderImage() possibly didn't write anything to the destination texture!

    When I disable CPRT, the warning stops. Any idea how to stop this from generating each frame?

    Thanks!
     
  2. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    36
    Hi @Tryz,

    Sorry for the late reply.
    This warning is a known issue and has no real impact on the released game (it is just logged in the editor and in Debug builds).
    The problem is I don't use a classic rendering method (I'm "redirecting" the rendering from one buffer to another to have access to higher resolution), and Unity think nothing seems to be drawn on the render texture. I've not found a way to remove this warning yet.
    However, it is only logged a few times in my test scenes. I'm not sure how you end up getting this warning every single frame. Could give me more details about your implementation please ? (this might be related to repeated enabling/disabling of a camera or RenderTexture / resolution changes).

    Best regards
     
  3. sasob8

    sasob8

    Joined:
    Jul 11, 2017
    Posts:
    16
    Hey @Melcx,

    Your script is limited to 160 fov? I need a solution for about 240 fov.
    For now i made camera rig with 5 cameras (45 fov, 1920x1200) with overlapping, so final resolution will be 6000x1200 (panorama style - cylindrical). I render to a texture with a recorder, so i don't need real time performance.
    It would be so much easier if i could do it with one camera. Especaially cause of post effect (some of them are repeating, cause of 5 cameras).

    Can it be done with your tool? If not, do you plan to update?

    Thank you
     
  4. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    36
    Hello @sasob8,

    Sorry to disappoint but you wont be able to achieve that with CPRT. It is limited to 160 FOV because you get an anomaly around 180, and the way it works, it can't technically go over 180 with a single camera (it just wouldn't work because that's a limitation of the classic 3D APIs). Trying to go over 180, FOV would require an entirely different technique and it would probably be a terrible idea to base it on CPRT. That would strictly be a different plugin, which couldn't even be used on the Unity rendering engine.

    About your issue at hand, the way you're approaching it is good. Maybe you should try to split your post fx ? You could keep applying the ones not causing issue as you're doing right now, and try to delay the problematic ones to a later stage, on the final composing rendering (ie : bloom can be done that way if you keep the HDR format). I don't know if that's going to help you out but I don't have any other idea at the moment.

    Best of luck with your project,
    Regards
     
    Last edited: Aug 28, 2018
  5. skyecrack

    skyecrack

    Joined:
    Jan 5, 2018
    Posts:
    29
    Hey @Melcx have you taken a look at this?

    Also example

    Just stumbled upon it, looks like it would be really easy to implement, with only drawback being either having to write custom tessellation shaders or just increasing polygon count on all of the meshes from the start, but even with that the performance gain would be massive over what we currently have here. Moreover, combine that with SSAA and voila, you actually benefit from supersampling under 2x :D
     
    AlanMattano likes this.
  6. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    36
    As you said, Vertex Displacement for linear projection is an option and could give pretty good results on screen with not too shabby performances (of course, it would vary depending on the project)

    That said, doing so wouldn't be about helping configure camera and rendering, but about applying vertex shaders for every single 3D object.
    On my side I'd have to create shaders for every custom projection and replace all the corresponding unity standard shaders, and on the user side, if a single object doesn't have that new shader type, the rendering would lose its coherence (that would make using external plugins very tedious). Moreover, you'd have multiple technical issues : ie Surface Shaders and Unity Shadows which aren't meant to work in that way.

    Again, thank you for showing such an interest in the development of this plugin, but this is way out of scope for what I intended to do at the beginning, and would require too much time and effort on my part for it to be worthwhile.
     
  7. Yumby

    Yumby

    Joined:
    Aug 17, 2012
    Posts:
    13
    I'm getting a strange linker error with CPRT when compiling in XCode using Unity 2018.2.14f1. If I don't include CPRT.cs, CPRTFrustrumUpdater.cs and CPRTHelper.cs, everything builds fine. With those files included, everything runs fine in the editor but when trying to compile in XCode, I'm getting:

    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    Odd since this plugin is provided as source code.
     
    Last edited: Mar 1, 2019
  8. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    36
    Sorry, I don't have an Apple setting to test that precise use case.
    That said, from what I can see, this error shows up because the compiler doesn't find a "static extern function", which is strange since I didn't use any in my plugin. It must be used indirectly by something outside of CPRT.
    Could you give me more information on this error ? If you look in the log, you should find a line which would tell me which function isn't supported. Something like : << Symbol: _OBJC_CLASS_$_[AnyFunctionName] >> or << "_OBJC_CLASS_$_[AnyFunctionName]" referenced from : >>

    Also, while I was checking online to see if someone else had had a similar issue, I found that some of them solved their problems by upgrading their 3rd party frameworks, so you may want to try this.

    Finally, could you try to test this with an updated version of Unity ? The current version is 2018.3.f6. You could even try 2018.2.20 if you want to stay on the ".2 series" for whatever reason.

    Cheers.
     
  9. philspitlerSF

    philspitlerSF

    Joined:
    Oct 10, 2018
    Posts:
    31
    Hi, does this plugin work on iOS ?

    I have a new iPad and would love to use this plug on my 360 video in Unity

    Cheers

    Phil
     
  10. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    36
    Hello @philspitlerSF

    As mentioned in my previous answer, I don't have any apple device to test this so I can't say for sure. However what I can do is refund you if you find out that the plugin doesn't work at all for you. Just let me know by mail.

    Cheers and a happy new year to all of you :)
     
    Last edited: Jan 6, 2020
  11. philspitlerSF

    philspitlerSF

    Joined:
    Oct 10, 2018
    Posts:
    31
    I will answer my own question here in case others are curious.

    It works great so far in iOS.
     
    AlanMattano likes this.
  12. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    134
    So I can trick unity's deferred rendering pipeline, to be orthographic? How much overhead will this be, resolution wise? Theoretically, faking unity's orthographic projection, wouldn't require more resolution, since the perspective shrinks? Not sure about that though ^-^
     
  13. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,321
    I'm a Windows user.
    Does support URP?
    Does support HDRP?
    Does support Build in Standard PBR 2017 to 2020?
    Sorry if this was asked before
     
  14. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    36
    Hello there !

    @Zyblade As long as you stay with orthographic projections (top down, isometric, etc) the plugin won't need anything more than the base resolution you're using.
    If you start using Stereospherical or Pannini though, it will be another story, and SSAA will have to be involved.

    @AlanMattano
    Sorry to disappoint, but this plugin was made before URP and HDRP were added to Unity and it unfortunately uses methods that you don't have access to while using URP/HDRP. I don't plan to adapt CPRT for it to work in these ways.
    That said, I just tested again to be sure, and I can confirm you that the Built-in Render Pipeline still works without any issue in the latest versions of Unity.

    Sorry for the late reply, it's been a while since there was any activity on this thread.

    Cheers!

    Edit : The answer to Zyblade was invalid : orthographic camera in deferred rendering cannot be achieved, even with CPRT.
     
    Last edited: Nov 22, 2020
    Zyblade and AlanMattano like this.
  15. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,321
    That's fine since Unity now supports it in URP and HDRP as a post-process effect.
    From
    https://forum.unity.com/threads/per...lution-new-scriptable-render-pipeline.517617/
    Documentation
    URP https://docs.unity3d.com/Packages/c...manual/Post-Processing-Panini-Projection.html
    HDRP https://docs.unity3d.com/Packages/c...manual/Post-Processing-Panini-Projection.html
     
  16. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    36
    I guess if you're only interested in panini, you could do it without using CPRT, but you may run into some limitations like (correct me if I'm wrong) the lack of SSAA will make the middle of your screen blurry.

    Anyway, CPRT isn't just about panini, so making it work for URP and HDRP would require more than just adapting the methods used for panini.
     
    AlanMattano likes this.
  17. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    134
    I just bought the asset and tried it out. Sadly, I can't trick unity's deferred rendering pipeline, to be orthographic with it....
    The Asset says, I need to switch the camera to be orthographic, to use orthographic projection :/ And I can't use deferred rendering with unitys internal orthographic camera mode.

    Correct me if I'm wrong. But if not, I can't use the asset at all :/
     
  18. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    36
    @Zyblade
    Ok, I double checked what I said to you last time and realised I'm an idiot. I misunderstood your question and completely forgot that the specific case of deferred rendering + orthographic views is a no-go in Unity. This might be possible with URP in most recent Unity versions, but as I said to Allan Mattano, CPRT was made before URP so it is not intended for its use either...

    So yeah, CPRT won't be able to help you for what you're trying to achieve. I'll edit my previous answer and the plugin description too, and obviously gonna give you a full refund.
    To do this I'll need you to send me your customer "invoice number". You should find it in the bill Unity sent you after your purchase. (don't post this here obviously, send me a PM). I'll contact Unity as soon as I get this and will ask them to do the refund.
    I'm deeply sorry for the time loss.

    Before you go, I can give you this piece of advice (I owe you that at least) : From what I see, a common "trick" to fix your issue (granted I understand it well !) would be to use a perspective camera, placing it very far from the scene, and with a high "near plane distance" (eg. far plane distance / 2).

    Good luck for your project and have a nice day.
     
    Zyblade likes this.
  19. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    134
    That's very kind of you, but you don't have to. All in all, it's a nice asset. Maybe I can use it in another project some day.

    Nah, it's alright. I just imported it, checked "orthographic projection" and saw it didn't work with deferred rendering mode. That was pretty fast ^-^

    Yeah, that should work. But with a very far camera, my shadow quality is pretty low(even on close fit, due to the large bounds from drawmeshInstancedIndirect). I got a workaround, where I set the bounds from my instances to 0 and setting the Camera.cullingMatrix very high. This way, using close fit, I could render them at high quality(my for isometric low resolution needs), independent of the camera distance. But now, the local lights won't affect my instances ones they are out of those 0 bounds >.<
    So yea, my camera is far away from my objects anyway, I could use it. Just need to trick out unitys internal culling for local lights and object bounds : S

    edit: I could reduce my far clipping plane and shrink the bounds a little and it might work now^^
     
    Last edited: Nov 23, 2020
  20. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    36
    @Zyblade
    Well, thank you for your kind words and I hope you will find some use for CPRT :)

    That said this discussion got me thinking, so I took some time early this week to try to find a way to implement all of this in my plugin, and... I found one !

    Basically I'm adding a "pseudo orthographic projection" option which will do what we discussed earlier while keeping light sources and shadows in check :
    - it will be mimicking orthographic behavior by using a very far from the scene perspective
    - deferred rendering will be supported
    - but you won't be able to use this with oblique projections (obviously, since you're simulating orthogonal projection by just getting far away, it won't be able to do the deformations required to get oblique projections).

    Here's an example of what you should be able to achieve :
    upload_2020-11-25_16-32-55.png

    I'll finalize this as soon as I can and submit it to Unity. Expect this to be available next week or the one after. I'll post an update here anyway.

    Cheers !
     
    OdderOtter and Zyblade like this.
  21. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    134
    Wow, really nice!
    Can I set a custom "zoom-size", independent from the camera distance?
    I'd need to fake an orthographic "Size" of 13.5 (resolution height->1080 / px per unit->40 / 2).
    I'm gonna find out a way to fake the size on my own. But you're obviously more into the projection term, so you might know it right off the bat.

    Oh, and another question. Is the camera angle a thing, which is baked into the projection or used from the camera directly? Currently I work with 30,0,0 angle for my isometric view (objects are at 45deg so the camera's y angle can stay a 0 for better calculate some movement rounding stuff). If I get this right, the camera angle can be any arbitrary number, because it won't make the projection any "Oblique?
     
    Last edited: Nov 27, 2020
  22. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    36
    I just submited the new version of the plugin to Unity, hopefully it won't take too long to get validated.

    So, there are 2 new parameters (orthographicSize and perspectiveOffset) which allow you to set the orthographic size you're talking about, and the camera distance, independently.
    More in the documentation.

    About camera angle, you can use whatever you want. No constraint here but you won't be able to have oblique perspective obviously (deferred rendering wouldn't accept it).

    Have a nice day !
     
    Last edited: Nov 30, 2020
    Zyblade likes this.
  23. OdderOtter

    OdderOtter

    Joined:
    Aug 16, 2015
    Posts:
    35
    Just wanted to drop in to express my thanks for the pseudo orthographic update!
     
    Melcx likes this.
  24. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    134
    Yup, really appreciated you implemented it =)
     
    Melcx likes this.
unityunity