Search Unity

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

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

  1. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Camera Projection Rendering Toolkit is a plugin that bring some projection & anti-aliasing functionalities:

    • Wide field of view perspective with non-linear projections techniques
    This plugin introduce Stereospherical (Fisheye) and Pannini perspective technique that solve the deformation that can occur with a wide field of view on objects far from the center of the screen.
    I let you judge with these comparative 110° FOV screenshots:
    before after 5.1.png before after 5.3.png
    before after 5.2.png

    StereoSpherical “Fisheye”: this perspective projection is the mathematically most accurate imitation of what the human eyes see.


    Pannini: Inspired by the painter Giovanni Paolo Pannini, this perspective projection isn't very realistic but allows the drawing of wide panorama and gives a pretty good feeling of being small relative to the architectural structures. It has the advantage of keeping the linearity of vertical lines. This projection can be free or horizon-aligned to prevent strange deformations.


    These non-linear perspective projections gives more space to the objects in the center, which has the effect of "zooming" the center pixels. This is why I needed to oversample the rendering with SSAA to avoid blurred/pixelated image. You can expect FPS drops if you use very wide FOV because of the oversampling (110° needs x1.6 SSAA, so a 1920x1080 rendering viewport will become a 3072x1728 one).
    Warning : this is not intended for VR.


    • Super-Sampling Anti-Aliasing (SSAA) / Pixelization

    The plugin allows you to add SSAA to take high resolution screenshots and to add high quality Anti-Aliasing even in deferred rendering (which isn't supported by Unity's MSAA).

    It can be GPU-heavy but this Anti-Aliasing improve image quality on the entire surface, including edges and opaque/transparent textures.

    SSAA quality is currently limited to 2x, which is equivalent to a "better" MSAA 4x. It's quite enough for real-time purposes and can be improved with other Anti-Aliasing techniques.

    It can also pixelize the image to give it a classic "Quake-like" feel.

    oversampling brighter.png

    • Oblique orthographic projections

    If you're not looking for perspective, this plugin can produce oblique orthographic projection and will help you give a more classic look to your game/project.
    orthographicslil.png
    This screenshot shows you the 4 obliques preset, but you can customize them.


    • The plugin hasn't been tested with VR yet
    • It can take high resolution screenshots.
    • The whole plugin is compatible with image effects (glow, FXAA, SMAA…)
    • The final resolution is limited to 16384x16384 pixels (8192x8192 on older hardwares).
    • Interactive inspector window (automatic buttons, warnings)
    • Works with multiple cameras, render textures, forward and deferred rendering, linear and gamma color space, post-processing effects (HDR, Bloom, FXAA...)
    • Tested with Unity 5.6.1 and 5.3.0, not compatible with Unity 5.6.0
    • Comes with PDF documentation and exemple scenes (those seen in screenshots)
    • Supports picking

    Asset Store Page


    ChangeLog
    -1.6
    - Added the pseudo orthographic projection which mimics an orthographic projection with a perspective in order to allow deferred rendering with an orthographic projection.
    - removed a bug when disabling the CPRT component.
    - removed bugs in the CPRT editor.
    -1.5.1 :
    - Improved CPRT compatibility with various external post-process plugins
    - Added an optional CPRTFrustumUpdater script :
    - Some external plugins can interact with the camera during the "OnPreCull" Unity callback, and may be in conflict with CPRT. CPRTFrustumUpdater allows to reorder the CPRT camera handling, and should typically be first so the other scripts can work on CPRT camera settings.
    - Oversampling setting interface has been slitghly reworked :
    - You'll likely need to reconfigure the oversampling in your scenes,
    - To make the setting clearer you now have two sliders : you can either set the render size multiplier or the Min Pixel Samples Count (minimal oversampling in the screen, 1 ensures that the image won't be downsampled at any place even with non-linear projection, 4 produce SSAAx2),
    - programatically, oversamplingFactor stays unchanged but is deprecated, please use renderSizeFactor instead from now on. The minimal oversampling in the screen can be set with the MinPixelSampleCount property,
    - Those changes applies to screenshot settings.
    v1.5 :
    - New "Screenshot Pass Count" settings :

    - Use screenshotPassCount to do successive rendering to help troubleshooting post-processing effects which accumuate samples over frames (like some ambient occlusion or global illumination effects do).
    - Set screenshotPassImproveSSAA to true to gather more antialiasing samples (for a maximum of 64 samples with SSAAx2 enabled).
    - Fixed a compatibility issue with SonicEther's SEGI effect.
    - Enabling / disabling the script should no longer make the camera unusable.
    - FOV can now be changed without calling RefreshEffect and RefreshViewport.
    - Added a CPRT.WorldToViewportPoint method (equivalent of Camera.WorldToViewportPoint), it will help you to project a world point into the screen.
    v1.4 :
    - Added support for AdaptivePannini camera-picking.
    - Adaptive Pannini has been fixed to keep viewport center at screen center, and to feel more natural.
    - CPRT control panel doesn't overstep the inspector width anymore.
    v1.3 :
    - Added support for camera-picking :

    - ScreenPointToRay and ViewportPointToRay are two new method that can help you to pick object from your camera while taking into account the projection distortion,
    - New showcase scene "MultiCamera Picking",
    - Supported projections are the "Stereospheric" and the "Pannini", support for AdaptivePannini will come later.
    - New script "AutoOversamplingScript" which adapt oversampling quality in real-time in accordance with the framerate,
    - Added Diagonal FOV setting (real-life camera common characteristic),
    - New property "RenderingFramerate" which gives the duration between two actual rendering.
    v1.2 :
    - fixed bugs when releasing executable with the plugin
    - made the documentation more user-friendly
    - added a TempRenderTextureManager.cs script that can help you to setup post-CPRT effects
    - added two test scenes
    - Surveillance Screens: demonstrate how to setup realtime render texture
    - Post-CPRT FX: demonstrate how to setup a post-CPRT chromatic aberration effect
    v1.1 :
    - added Horizontal FOV setting,
    - fixed some issues with render textures, you can no longer use the classic "Camera.targetTexture" parameter, you must use the script's "targetTexture" one,
    - fixed a memory leak and did some optimisations.


    I’m trying to make this plugin as simple as possible. Don’t hesitate if you have suggestions, questions, requests or if you encounter any issue.
     
    Last edited: Dec 7, 2020
    OdderOtter likes this.
  2. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    Hi there!

    I'm interested in using your asset in VR (Oculus or Vive), and I was wondering if its geometric transforms are going to work just as fine in VR as well (I'm particulary interested in the Pannini one).

    Do they have any perceivable performance impact?

    What about SSAA? Is it going to work in VR as well, both single pass and multipass? Linear and Gamma color space, deferred or forward rendering?
     
  3. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Hello NeatWolf !

    The geometric transformations part of the pluggin hasn't been specifically created with VR purposes in mind so I can't tell you with certitude what it will look like in a VR environment (I don't have a VR headset to test any of this at the moment, sorry)
    Same answer for SSAA, but my intent is to look into it in the near future, since the SSAA compatibility seems to be a popular demand.

    About the performance impact, since you need to oversample the image to do these transforms, the more you ask from the plugin, the worse the performances will get.
    For exemple, 110° FOV projection will need as much processing as a x1.6 SSAA one (a 1920x1080 rendering viewport become a 3072x1728 one).

    To end on a high note, the whole plugin has been tested with Linear and Gamma color space, deferred and forward rendering and Unity post-processing effects (HDR, Bloom, FXAA...) so you can already roll with theses.

    Note : I just updated the main post with these informations
     
    NeatWolf likes this.
  4. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    Thanks for your answer, for some reason I never received the notification.

    I'm going to buy it right now, and will send you some feedback about VR with different headsets as soon as possible.
    The Pannini projection is really interesting :)

    I'm not sure on how you're handling the projections since the asset is currently only in the cart.
    Do all of them require upscaling to look good?
    Are they fullscreen postFX?
    Which is the correct order in the FX chain? Absolute first?
    Does it interfere with standard screen-space-coordinates raycasting?

    Sorry for all the questions :)
     
  5. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    985
    Take my money! Please! These projections look great! And they work in deferred? You've saved me a ton of time. Thanks!
     
  6. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    @Sluggy
    Thanks for the kind message !


    @NeatWolf
    Not receiving notifications either, no worries !
    Don't hesitate to ask as many questions as you want, I will try to answer them as quickly and precisely as I can.
    So, about your previous questions :
    1. Yes, all the projections require upscaling to look good or else the center of the rendered view will be blurry
    2. The pannini and stereospherical projections are fullscreen postFX but the oblique ones (iso, top down...) are not
    3. For a given camera, the correct position is absolute last (I'd like to change this to be more flexible in the future, I don't know if this will be feasible yet). That said, you can still add your effects (like some glow) on the render texture (Camera.targetTexture) you'll use to draw the screen, effectively applying it after the transformation of the plugin.
    4. Yes it unfortunately interfere with standard screen-space-coordinates raycasting and that's the top item on my todo list. At the moment, the farther you get from the center pixel (or the 4 in the corners) the more error you will get.

    Anyway thank you for your interest and don't hesitate to contact me about the pluggin behavior in a VR environment, I will gladly look into it :)

    PS : I will update the plugin on monday with a fix for a small bug I noticed
     
    Last edited: Aug 5, 2017
    NeatWolf likes this.
  7. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Hi guys,

    Version 1.1 is now available, here are the changes :
    - added Horizontal FOV setting,
    - fixed some issues with render textures, you can no longer use the classic "Camera.targetTexture" parameter, you must use the script's "targetTexture" one,
    - fixed a memory leak and did some optimisations.
     
    NeatWolf likes this.
  8. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    I bought this asset and I'm using it in Unity 5.6.3.p1.

    It's working perfectly in the editor but when I build my project it doesn't work. There are no errors in the log but what I see on the screen is messed up. There is like a blue haze at the bottom of the screen and the actual fov and zoom settings on the camera are all incorrect ....
    upload_2017-8-28_23-53-10.png
     
  9. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    Seems my output log didn't update correctly, I've run it again and now I'm getting a message saying CPRT shader is both missing and not supported on my platform.
     
    Last edited: Aug 29, 2017
  10. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    I believe I found the problem. Nothing references the shaders for this toolkit, so even if you add the script for it to your camera it will not include the shaders in a build, although it will work perfectly fine in the unity editor. The solution was to add the shaders under the "Always Included Shaders" list in ProjectSettings/Graphics.
     
  11. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Hello catfink

    Many thanks for your support and having pointed out that issue. I'm currently working on a fix for it. I've already identified where the problem lies in the code and have found a way to solve it, but for now it's a bit clumsy. I'll update the plugin as soon as I have something proper for you guys.

    I also just fixed a bug that prevented scripts from working outside dev builds and editor. That will come in the same update (hopefully this week).

    Sorry for the inconvenience.
     
  12. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    Hi there Melcx,

    Did you find a workaround for this? Not being able to interact/Raycast from screen space to world space is quite a big limitation for those, as it would be useful just for showcasing. Or, maybe, there is a simpler way to do it that I am missing?
    Having at least a custom "bending" Raycast solution for each non standard visualization would be nice, but I'm not aware of the math required to implement it.

    Cheers,
    Alessandro
     
  13. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    Thanks for the reply. Just for info I also had to play around with the #if UNITY_EDITOR usage inside the scripts as it was throwing an error on the "using UnityEditor" includes. It's not a big deal but it may confuse some less experienced devs.
     
  14. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    @catfink
    Yes, that's exactly the fix I was talking about that will come with the next patch.

    @NeatWolf
    I'm still working on this issue, which is - as you mentioned - quite big, an also not a simple one to solve. This is still my top item on my TODO list, I just took the time to fix the "easier" issue risen by catfink, since I knew right away how to handle it.

    Still have to update a bit the documentation to reflect the recent changes, and I'll upload everything.
    Then I'm back on the raycasting issue :)
     
  15. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    This is a very interesting asset for making a better rendering without distortion. I have 3 questions:
    • Is a post process effect? it renders into a mesh like other solutions ? or is a new way to rendering in the camera, and how is the component attached to the camera?
    • How is the shape of the near and far limits? are just distance plain limits (so object enters and escapes in the center of far objects) or by distance ray length (radial or radius)?
    • Do you think this will work in Unity 2017.2 (or else) OTOY rendering?
     
    Last edited: Sep 1, 2017
  16. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    It is a post effect and uses a shader to render the camera differently. The effect is attached to the camera using a script.
    I know you raised this particular bug to Unity (I voted on it 9 times :D ). I am using this asset as a workaround to that problem.

    https://feedback.unity3d.com/sugges...lanes-instead-of-flat-near-far-clipping-plane

    The scriopt oversamples the screen and allows you to get a much wider field of view than a normal unity camera and without all the horrible distortions. The downside is it is GPU heavy as you have to oversample the screen to achieve the results.

    The author will have to answer your other questions as I haven't looked deeply into how it works although all the source is included in the asset.
     
    AlanMattano likes this.
  17. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    @AlanMattano
    • Yes it is indeed a post-processing effect, asking the camera to render the scene in a different resolution according to the settings.
    • In world space, the near and far limits are planes, like regular cameras, but the perception of a plane is distorded by non-linear projections.
    • I just tested it in Unity 2017.2, it works fine. However, OctaneRender (if that’s what you’re talking about) is based on a completly different renderer, and I highly doubt about its compatibility. Moreover OctaneRender already implements those non-linear projections.

    About the spherical clipping planes, I’m not completely sure how you’d like to achieve this kind of projection, but what I know is that if you try to use the current Unity rendering engine (which uses DirectX and OpenGL) with the GPU rasterizer (without CUDA/OpenCL custom solution) you’d run into two issues:
    • First of all, matrix math can only produce linear transformations, and that’s what creates the rectilinear projection you see in nowadays games. A workaround would be to create a new transformation type to achieve the spherical projection.
    • The second and biggest issue is that a spherical/cylindrical projection will transform some lines into curves. The Unity rendering engine is only able to produce triangles and lines (if we don’t take post-processing effect into account). Meshes are shaped by Vertex Shaders, and Pixel Shaders only setup triangles content. You can’t customize anything between these two steps.
    If you want to change these rules, you’ll have to use or create another rendering engine, not based on DirectX or OpenGL, probably in ray/path tracing to ease the calculations. OctaneRender is a good exemple.


    I just uploaded the CPRT 1.2 version, it will be available as soon as Unity validate it.

    Have a nice weekend!


    Edit : CPRT 1.2 version is now online, here is the changelog :
    - fixed bugs when releasing executable with the plugin
    - made the documentation more user-friendly
    - added a TempRenderTextureManager.cs script that can help you to setup post-CPRT effects
    - added two test scenes
    - Surveillance Screens: demonstrate how to setup realtime render texture
    - Post-CPRT FX: demonstrate how to setup a post-CPRT chromatic aberration effect
     
    Last edited: Sep 6, 2017
    catfink and AlanMattano like this.
  18. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Thx @Melcx & @catfink for the deep explanation. Now I will include this asset and let the player choose it by using the rendering settings.
     
  19. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    @NeatWolf
    Hi there, version 1.3 has just been released and picking is now supported for main projections (Stereospherical & Pannini). Support for AdaptivePannini will come in the next version.

    Here is the complete changelog :
    v1.3 :
    - Added support for camera-picking :
    - ScreenPointToRay and ViewportPointToRay are two new method that can help you to pick object from your camera while taking into account the projection distortion,
    - New showcase scene "MultiCamera Picking",
    - Supported projections are the "Stereospheric" and the "Pannini", support for AdaptivePannini will come later.​
    - New script "AutoOversamplingScript" which adapt oversampling quality in real-time in accordance with the framerate,
    - Added Diagonal FOV setting (real-life camera common characteristic),
    - New property "RenderingFramerate" which gives the duration between two actual rendering.
     
    NeatWolf likes this.
  20. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    Yay! Thanks!

    Pannini is my favourite so far so I'm looking forward the next update as well! :)
     
  21. Bloody-Swamp

    Bloody-Swamp

    Joined:
    Jul 30, 2012
    Posts:
    38
    Hey @Melcx ,

    Does your asset work with a single camera with Depth only clear flags?
    So it will apply the effect only on what that camera renders?

    Cheers!
     
  22. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Hi @Bloody-Swamp,

    Depth-only clear flags shouldn't cause any issue, except if you use old frame buffers to draw the next frame (which was used in old school motion blur for exemple).
    Does that answer your question ? If not, could you tell me more about your concerns ?

    Regards,
    Melcx
     
    Last edited: Nov 8, 2017
  23. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Hi everyone,

    Version 1.4 is now online ! It improves the AdaptivePannini projection and the CPRT control panel :
    - Added support for AdaptivePannini camera-picking.
    - Adaptive Pannini has been fixed to keep viewport center at screen center, and to feel more natural.
    - CPRT control panel doesn't overstep the inspector width anymore.

    Melcx
     
  24. Bloody-Swamp

    Bloody-Swamp

    Joined:
    Jul 30, 2012
    Posts:
    38
    Thank you for the answer Melcx but not exactly.

    Okay, let's just say that I have a camera tha renders the world and then another one on top with Depth only clear flags, and I want to apply the effects only on whatever that camera renders. Is this possible?
     
  25. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    @Bloody-Swamp Yes it is possible. If the non-CPRT camera is used to create a non-postprocessing FX (shadows, surveillance camera...), everything will be natively supported.
    In the case case where this camera would create postprocessing FX, it would need a specific implementation, as explained in section 3.6 of the documentation.

    Don't hesitate if you have any further questions.

    Regards,
    Melcx
     
  26. BloodMarked

    BloodMarked

    Joined:
    Dec 11, 2013
    Posts:
    28
    first of, i really like your asset. it provides a pretty complete package.
    especcialy the Automatic Quality button and the Debug Settings are very helpful.

    but i still have some questions:

    1 - you are using a mesh to distort the image in post processing, which always has the problem that the individual polygons will create straight lines in between the vertexes.
    did you decisively decide against doing the displacement in the fragment shader texture lookup (offset uv coordinates)? and why? the distorted mesh method seems a bit awkward to me

    2 - all other fisheye shaders i came across use roughly something like

    float d = length(xy);
    float z = sqrt(1-d*d);
    float newD = atan2(d,z)/3.1415926536;

    for the displacement.

    you seem to use a different method which creates more curvature in the center and less on the edges. also you scale the effect strength according to the FOV
    i really like your effect, so do you mind saying what math it is based on?
    and could it be ported to be done as UV displacement in the fragment shader instead? (so it has per-pixel precision)

    3 - do you think it would bring a performance benefit to render the peripheral area at a lower resolution and only a smaller FOV at full resolution? similar to how it is done in vr applications. especcially as high FOVs require lots of "oversampling".

    small side note: your current version makes the camera unusable if the script is attached to a camera but is disabled.
    you do some things (p.e. setting the Camera TargetTexture) in Start() which should be done in onEnable() instead. (and reverted in onDisable())
     
    Last edited: Jan 21, 2018
  27. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    @BloodMarked Thanks for your interest.

    1- Yes indeed, the effect creates straight lines to give the "illusion" of curves, however, with a "Mesh Precision" around 40 and more, you can't distinguish the lines since it will be sub-pixel precision.

    I use this mesh-projection technique for two reasons :
    • Performance:
      • The heavy computing is only done for some vertices. The fragment shader only has a division and one mul-add operation + some filtering if needed, whereas just the first line of the shader you posted is already heavier (and "atan2" function is one of the heaviest shader functions).
      • With a mesh, you can vary the poly-count, and choose speed over quality (or the other way around). The fragment shader you have to take the full quality no matter what.
    • It was much easier and obvious for me to implement the "Adaptive Pannini" this way. My work on the "Pannini" is based on the vedutismo perspective construction (http://tksharpless.net/vedutismo/Pannini/panini.pdf , figure 3), from which I change one of the following things :
      • The mesh is rotating with the horizon (with some interpolation effect to hide the singularity at the top and bottom of the camera). This gives the "Adaptive Pannini" effect.
      • The mesh changed from a cylinder to a sphere to give the "Stereospherical" effect.
      • The mesh may be moved with the "Intensity" setting of the projection to interpolate between the linear and distorded projection.
    2- There are many Fish Eye projections out there, the "Stereospherical" (also called stereographic) is only one of them : https://wiki.panotools.org/Fisheye_Projection
    I chose this one because I think it is the best one to avoid distording the shape of the objects at the border of the screen as much as possible (standard fisheye vs stereographic : https://wiki.panotools.org/Stereographic_Projection ).

    3- Yes ! This kind of implementation would be a major performance improvement.
    Unfortunately, as far as I know, Unity doesn't provide the "Simultaneous MultiProjection" nor the "Multi-Resolution Shading" access (https://www.anandtech.com/show/10325/the-nvidia-geforce-gtx-1080-and-1070-founders-edition-review/11). To keep high performance, you'll need to compute vertex shading only once, then do the projection math and the fragment shader on 4 parts of the screen.
    Even if I could access those functionnalies, it would require a lot of work and research to implement it. That is something I could possibly work on in the future but probably not at the moment.

    4- Indeed, thanks for reporting this ! I'll fix it in the next update so you'll be able to enable/disable the script during runtime.

    Cheers!
     
    Last edited: Jan 22, 2018
    IsDon and AlanMattano like this.
  28. BloodMarked

    BloodMarked

    Joined:
    Dec 11, 2013
    Posts:
    28
    awesome, thanks for the quick answer.
    good to know you chose the mesh projection for performance!

    3 is an interesting method but seems to be quite complicated and dependent on specific nvidia 10xx gpu features.
    i was thinking about simpler methods, p.e. these . basically just render the same camera at 2 resolutions and 2 fovs, then combine both
    but the performance gain is likely to depend heavily on whether the scene rendering is vertex or fragment shader heavy.
    at least it would be a solution for low end hardware which doesnt support big rendertextures.
    i will have a deeper look at your script and see if i can make it work
     
  29. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Exactly, this optimisation (foveated rendering) can make things worse if vertices computing is heavy.
    Moreover, for the low-res texture, fragments at the center and borders can be excluded, but there will be depth buffer controls anyway.
    Also, the integration of post-processing effects can be complex because of the masks (for exemple : glow around mask borders).

    I may integrate some of those simpler optimisation in the future (the mask and the checker pattern are inspiring).
     
  30. benboesel

    benboesel

    Joined:
    Jan 21, 2015
    Posts:
    1
    Hey @Melcx ,

    I just bought your Projections asset! It's really great :) So far it's been really easy to use & doing exactly what I hoped it would do!

    Quick question:

    In my app I am using the following logic to determine if an Object is visible to a camera:

    Code (CSharp):
    1. bool IsOnScreen(Vector3 objectPosition)
    2. {
    3. Vector3 screenPoint = camera.WorldToViewportPoint(objectPosition);
    4. bool onScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
    5. }
    This function works perfectly on a normal camera, but not with the Stereospherical camera :(

    When the stereospherical distortion is turned on, the result from the above equation reflects the screen position of normal, undistorted unity camera. Unfortunately this is causing problems in my application when the distortion moves an objects off screen, but the above logic determines it is still on-screen.

    Do you know how I can determine camera.WorldToViewportPoint but with the distortion applied? Or any other clever way to determine if a Vector3 point is visible in the distorted camera frustum?

    Thanks so much,
    Ben
     
  31. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Hi @benboesel,

    Sorry for the late reply, the notification ended in my junk mail.
    I'm glad you like the plugin, thanks for your support !

    I didn't make the "WorldToViewportPoint" method yet, but it's an easy one so I'll do it within the next week and push the update ASAP (I can't work on the plugin just right now, but next week will be fine).

    @everyone don't hesitate to PM me if I seem to not be answering for some time. I may just not have gotten the notification of your message.
     
    Last edited: May 24, 2018
  32. ivanbolcina

    ivanbolcina

    Joined:
    Oct 27, 2013
    Posts:
    41
    Hi.
    I have a question. When I run game in Unity editor, it runs just fine. But when I build it and run as standalone, the cprt camera renders scene as red color.

    Please help.
     

    Attached Files:

    • red.png
      red.png
      File size:
      124.1 KB
      Views:
      1,116
    • normal.png
      normal.png
      File size:
      570.3 KB
      Views:
      1,221
  33. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Hi @ivanbolcina,

    On which platform do you test your standalone build ?
    Are you using any other post-processing plugin at the same time ? (bloom, global illumination, special shaders...)
    Could you send me a screen capture of the CPRT and the Camera panel ?
     
  34. ivanbolcina

    ivanbolcina

    Joined:
    Oct 27, 2013
    Posts:
    41
    On which platform do you test your standalone build ? MacBook Pro
    Are you using any other post-processing plugin at the same time ? (bloom, global illumination, special shaders...)
    Yes (beautify package and antialias), but not on the same camera. Also tried without it.
    I have CPRT camera for background and another one for player/opponents.
    Could you send me a screen capture of the CPRT and the Camera panel ? Below...
     

    Attached Files:

  35. ivanbolcina

    ivanbolcina

    Joined:
    Oct 27, 2013
    Posts:
    41
    Also, problem happens only when running in "windowed" mode (not full screen).
     
  36. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    @ivanbolcina
    I'll check this out as soon as I can.
    In the meantime, could you please (if possible) try on a windows device to see if you get the same problem ?

    A last question : Which version of Unity are you using ?
     
  37. ivanbolcina

    ivanbolcina

    Joined:
    Oct 27, 2013
    Posts:
    41
    Version = 2018.1.1f1
    On Windows it runs without problems.
     
    AlanMattano likes this.
  38. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Hi guys,

    @benboesel , I just finished the CPRT.WorldToViewportPoint method, i'm submitting the update to Unity (It will be available as soon as they finish to review it).

    @ivanbolcina , I'm currently investigating your problem, but since I don't own a Mac device, it's tedious. I tried to emulate it with a VM to test various configurations. Unfortunately, I couldn't replicate your bug yet.
    Could you please try to create a minimal scene with a camera, a few cubes and the CPRT script alone, to see if you still get the bug ?
    If that's the case, you could send it to me (the scene and the build) so I can send it to Unity Support.
    If that's not the case, you can try to progressively implement the same configuration you have in your game (multiple camera, scripts, etc) until you find what cause this bug.
    Thanks in advance.
     
  39. bstockwell

    bstockwell

    Joined:
    Apr 6, 2018
    Posts:
    7
    Hello, I have purchased this asset and I had a question about changing the FOV in code during game play.

    Question 1
    if I use the CPRT.fieldOfView field to change the FOV it does NOT update the camera while the game is running.

    I discovered that I could call CPRT.OnValidate() to get it to update the FOV, and more accurately - calling
    CPRT.RefreshEffect()
    CPRT.RefreshViewport()

    Has the effect of updating the FOV on the camera, however the FOV changes dynamically and it seems that calling these functions 1 time every frame is Very expensive.

    Perhaps that makes sense though, since it needs to recalculate the effects on the screen - but I was wondering if there is a better or faster way to update the FOV on the CPRT script while the game is running.

    Question 2
    Also, I was having trouble DISABLING the CPRT component during Gameplay. I noticed that when I disabled it during gameplay the screen simply went black because there was a texture on the main camera.

    Despite CPRT being disabled, I cannot remove the Render Texture from the main camera.

    This is inconvenient if I want to ENABLE / DISABLE to CPRT script - I thought a Workaround would be to set the Intensity to 0. However, because the FOV changes dynamically - even though the EFFECT is set to 0, the FOV does NOT change unless calling the Refresh functions listed in the previous question (which is very expensive)

    So intensity as a workaround is useless.

    Is there are proper way to quickly ENABLE / DISABLE the CPRT script on a camera? if not please add this.
     
  40. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Do Camera Projection Rendering Toolkit work using multiple cameras? one up to 2 m, second up to 1000m and 3° 25km?
     
  41. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    @AlanMattano
    I can't see why it wouldn't work since CPRT supports multiple cameras in split screen or multiple RenderTextures (as shown in "MultiCamera Picking" and "Surveillance Screens" scenes), but you probably gonna get some issues to display some very far and very small objects (due to the float precision). It's a general 3D engine issue, unrelated to CPRT though.
     
    AlanMattano likes this.
  42. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Hi everyone,

    1.5 version has been released, it brings most of your requested functionnalities :
    - New "Screenshot Pass Count" settings :
    - Use screenshotPassCount to do successive rendering to help troubleshooting post-processing effects which accumuate samples over frames (like some ambient occlusion or global illumination effects do).
    - Set screenshotPassImproveSSAA to true to gather more antialiasing samples (for a maximum of 64 samples with SSAAx2 enabled).​
    - Fixed a compatibility issue with SonicEther's SEGI effect.
    - Enabling / disabling the script should no longer make the camera unusable.
    - FOV can now be changed without calling RefreshEffect and RefreshViewport.
    - Added a CPRT.WorldToViewportPoint method (equivalent of Camera.WorldToViewportPoint), it will help you to project a world point into the screen.

    Please let me know if you guys keep having problems with the enable / disable script behaviour.
     
    AlanMattano likes this.
  43. blackbird

    blackbird

    Joined:
    Aug 9, 2011
    Posts:
    591
    any chance to sell SSAA separately ? and does you SSAA solution has down sampling feature ? some times i need to reduce the resolution by 0.8 or 0.9 et , let me know please
     
  44. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    My intent with this pluggin is to offer a multi purpose "all-in-one" toolbox rather than separate small assets so, sorry but no, I won't do that.
    For your other question, yes you can easily do x0.8/x0.9 downscale with CPRT, and you can even chose filtering type (nearest neightboor / linear interpolation).
     
    blackbird likes this.
  45. skyecrack

    skyecrack

    Joined:
    Jan 5, 2018
    Posts:
    29
    Well, first off, I really like the quality of the asset and it's documentation. I wanted to buy it for quite some time now (since Unity couldn't do anything even remotely serious on this topic and I needed quality fisheye lens), and now that I did, I have encountered quite a bit of issues;
    1. All AA goes haywire: Playdead's TAA doesn't work. At least the frustrum jittering part of it (because it just jitters the whole image instead of subpixel details), in motion it can reconstruct flickering & co pretty well. Chman's SMAA (a bit outdated but it still does wonders) doesn't work properly either, smudging the whole picture (looks like it downsamples it additionaly). Only FXAA works like it should, but it still looks extremely blurry in the end, which brings me to my next point...
    2. Why the hell would you disable running effects after CPRT? Why should stuff like bloom or sharpen in my case be rendered at a higher resolution when you can just run them regularly after? It's a huge waste of resources. I can see that you are trying to push everything into a single package with just one script, but it's highly unpractical.
    3. That being said, I think everyone would benefit from a little bit of flexibility. For example, why not divide CPRT into two scripts, one being all of the projections and the other being SSAA. For example, render everything before SSAA in upscaled, and everything after in a separate default resolution as an overlay, only to be distorted later on when projections script kicks in, and corrected after that. For example, you could have spatial/temporal AA or any kind of screen distorting effect => SSAA => SSR as an overlay in default res (since it doesn't even calculate much stuff in the center of the screen = no waste of quality) => Fisheye bending => Color Correction/Sharpen. That'd be probably the most efficient way to pack this.

    Or not, idk. At least, please do something about the AA and post CPRT effects. :(
    Cheers


    EDIT:

    FXAA doesn't work either. I thought it did since it didn't look nearly as bad as SMAA but now that I tinkered around with increasing SSAA it shows the same symptoms. Looks like both of them pick up what to blur before SSAA but resolve it after the SSAA pass (and both are before the lens distortion pass). Weird.
     
    Last edited: Jun 23, 2018
  46. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    @skyecrack

    1. Indeed, Playdead TAA isn't compatible with CPRT (surely an access conflict while accessing the frustum matrix).
    However, the post-process stack FXAA / TAA and the Chman's SMAA doesn't seem to have any problem with CPRT.
    Remember to put those scripts before CPRT scripts, otherwise they won't work.


    2. CPRT disable any Post-FX after itself on a given camera. However, it's still possible to setup Post-CPRT effects (ie: Glow/Bloom, Sharpen, Tone mapping, etc) in non-upscaled resolution. As for SMAA, you can also technically do it this way, but I don't recommand it since you'll get low quality result (Chman's documentation also states this effect should be first).

    To setup Post-CPRT effects efficiently, you'll need a second rendering, using a second camera that will typically draw a RenderTexture on a full screen quad. This is showcased in the "Post-CPRT FX" sample scene with a Chromatic aberration shader. You can also find more details in section 3.6 of the documentation.

    Other effects like SSAO, SSR, FXAA, SMAA and some implementations of motion blur need deferred buffers (Color/Normal/Depth/Smoothness/Emission buffers). They are currently not supported, but can be rendered in a lower than usual resolution.
    I'm looking for a solution to this issue, but it a non-trivial one.

    3. Non-linear projections must be rendered in a higher resolution to avoid any blurred region. At this point of the rendering, this is indissociable from a SSAA effect since that's when you work with the upscaled image.


    Finally, I didn't manage to reproduce your FXAA/SMAA problem, here is what I get with these effects :


    Your problem may come for a wrong script ordering (CPRT must be last) but I'll need more informations about your configuration to help you fix it.

    Cheers
     
  47. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    As @bstockwell brought to my attention by pm, the post-processing stack v2 has changed a few things.
    The way it works, it forces its rendering before CPRT anyway, but wierdly enough, it now needs to be ordered AFTER CPRT for it to work properly. It will still force himself first, but it won't detect the correct resolution and the screen will appear blurry if you do it the standard way. Don't forget to refer to part 3.6 of the documentation to efficiently setup post-CPRT effects, like Bloom or chromatic abberation, on another camera.
     
  48. skyecrack

    skyecrack

    Joined:
    Jan 5, 2018
    Posts:
    29
    Hey, also want to mention this here, while you're working on your next update. @Melcx have you looked into Lens Matched Shading? (https://developer.nvidia.com/lens-matched-shading-and-unreal-engine-4-integration-part-1) It's a technique they use in VR that enables them to do lens distortion that prioritizes resolution in the center of the view over the borders by splitting the frustum into four bent cascades and stacking them back together. Moreover, I think bros at Nvidia already ported it to Unity through VRWorks. It's a lot more practical than brute forcing full scene super sampling that we have here for non-VR scenarios. Hell, I'd take it even if I didn't need lens distortion, so that'd add even more functionality to your asset. :)

     
  49. Melcx

    Melcx

    Joined:
    Mar 22, 2016
    Posts:
    43
    Yes I know about this technique and already looked if it was possible to implement it in CPRT. The problem is Lens Matched Shading is a feature that, as far I know, isn't directly exposed to C# scripts. It's "contained" in the GfxPluginVRWorks64.dll (which is compiled from C++ native code).
    Another issue is about compatibility, Lens Matched Shading is only compatible with NVidia GPUs and forward rendering.

    Another way to implement it would be to create this rendering technique from scratch, but if you don't have access to deep GPU functionnalities, it would result in processing four little distorded renderings. This would result in a lot of redundant calculations (ie: vertex shaders) and no guarantee that it would speed up the whole rendering.
     
  50. skyecrack

    skyecrack

    Joined:
    Jan 5, 2018
    Posts:
    29
    Just like TXAA was NVidia and deferred exclusive? :D