Search Unity

Manually reset path tracer sampling

Discussion in 'High Definition Render Pipeline' started by alejobrainz, Oct 31, 2021.

  1. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Hi. We are implementing a system to record customized animated characters in runtime using the path tracer but have noticed some oddities. It seems to start sampling when things in the scene change like for example camera movements or when manually evaluating a time change in a timeline. For the last case though, it seems to reset one frame prior to the actual timeline frame change making it sample the previous timeline frame once, creating a ghosting effect in the final converged frame.

    This can be easily avoided by resetting the path tracer sampling. But for now I’m “solving” it by moving the camera slightly on the update after changing the timeline frame.

    mid there is no actual method to force it to reset sampling, I’d love to know what else can trigger a sampling reset, other than moving the camera. Any pointers are appreciated.
     
  2. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Hey, thanks for the feedback !

    There is indeed a mechanism to check if the scene is dirty to reset the pathtracer accumulation. This mechanism is disabled when you are in a recording to be able to be able to keep accumulating and hopefully have a converged image.

    There's function in PathTracer.cs that is called "ResetPathTracing()" that does exactly what you want but as you can see, it's internal for now. If it's really needed, we could make it public.

    But I'd like to try and solve the timeline issue first. I tried on my side but I'm not a 100% sure I understand the problem correctly, do you happen to have a small repro of the issue that we could easily try?
     
  3. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Sure. I’ll open a ticket. Strangely enough it does not happen on 2020 but it does on the latest 2021.
     
    chap-unity likes this.
  4. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    It would be fabulous to make it public as there might be use cases where you want to make certain that the path tracer accumulation is cleared.
     
    chap-unity likes this.
  5. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Thanks, when you do it, please drop the case number in here :)
     
  6. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Hi. case number is 1126233
     
    chap-unity likes this.
  7. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    I also reported on that ticket an issue on the test project where path tracing will remain stuck on startup for nearly 10s on 2021.2.0, but start automatically on 2020.3.21. I attached videos and sample projects.
     
  8. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Thanks, are you sure about your case number ? this (1126233) points to an older case created two years ago :|

    In the meantime, the method to reset pathtracer have been made public in this PR
     
    Last edited: Nov 4, 2021
  9. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    That is an enterprise support ticket (I'm with Jam City). I'll PM the zendesk link.
     
    chap-unity likes this.
  10. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Excellent! I'm currently using Package Manager to access HDRP. Is the source version from Github compatible with unity 2020.3.21 or 2021.2.0?
     
    Last edited: Nov 4, 2021
  11. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    unfortunately, no. The source version from github master is only compatible with latest alphas (2022.1.0a...)

    However, this will be backported to 2021.2 in the next package.

    Also, what you can do in any package is remove the "internal" keyword just before the decalaration of the ResetPathTracing() function to be able to use it outside the package. (exactly like it's done in the PR)
     
    fuzzy3d likes this.
  12. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Thanks. will do that!
     
  13. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Hi,

    in my archviz projects I have a functionality to save (hig-res) screenshots using rendertexture.
    In the past years I used builtin-pipeline and everything was easy.

    When I switched to HDRP with raytracing I realized that my screenshots looked fuzzy and I now had to converge the screenshot across multiple frames before saving.
    Customizing the provided FrameManager.cs I am now able to save highres and sharp images.
    Also it was easy to implement a simple progressbar (m_Iteration / samples).

    Now I want to do the same with a pathtraced image and here I have a problem with my progressbar:

    It looks to me that the pathtracing-process is kind of an internal process with no public API.
    PrepareSubFrameCallBack etc is called internal and therefore getting the current frame is not possible.

    So instead of starting the pathtracing accumulation process by code (don´t know how, missing examplescript!) I simply enable the volumeoverride with "pathtracing.enable.value = true;"

    In the same frame I enable a bool named "pathtracerRunning" which allows a counter in the Updateloop to calculate the progress:

    Code (CSharp):
    1. void Update()
    2. {
    3.    if(pathtracerRunning)
    4.   {
    5.       frame ++;
    6.       progress = (float)frame / (float)samples;
    7.       progressslider.value = progress;
    8.   }
    9. }
    The comprehensible problem is that this counter is not in sync with the real accumulation-process of the pathtracer.

    What I would need is a method like "HDRenderPipeline.currentIteration" or even better "HDRenderPipeline.progress".

    Can anyone help me here?
     
    Last edited: Aug 1, 2022
  14. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    What I believe you are trying to do is done properly using the accumulation framework in the documentation here.
    Basically, when added to a gameobject, you can right click on the script and start to save images with a number of samples set in the script (like 128 spp for the pathtracer).

    Let me know if that fits your needs.
     
  15. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Not fully.
    The documentation scripts presume that the pathtracer is already enabled - right?
    At least I don´t see any code that activates it.

    In my case my app starts with no pathtracer active.
    Then I have a toggle or button that activates pathtracer.

    The problem is after enabling the volumeoverride ("pathtracing.enable.value = true;") it automatically starts processing the image. This makes it impossible to run the code from the docs which would cause a second parallel accumulation.
    I have no access to the current frame / sample and therefore I can´t calculate the progress.
    (We only get this semi transparent progressbar on the bottom with no access for customizing it).

    I need something like Pathtracer.Start(), Pathtracer.Stop(), Pathtracer.Reset() and Pathtracer.progress.
     
    Last edited: Aug 3, 2022
  16. PavlosM

    PavlosM

    Unity Technologies

    Joined:
    Oct 8, 2019
    Posts:
    31
    I understand that querying the path tracer directly for the frame count would be more convenient, but I'm wondering why the counter in the code you posted is not in sync. Perhaps if you move this code in the PrepareSubFrameCallBack callback (assuming you have a beginFrameRendering callback like in the examples) would solve the issue?

    In the future we could provide an API to query the actual progress, but the start/stop calls are not easy with the existing design (because the path tracing is controlled by the "volume system" in HDRP, so the camera position might affect the path tracing parameters, including the on/off status).
     
    chap-unity and Cascho01 like this.
  17. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Another issue I have, although it maybe not the best place to post it here:

    While accululating my final screenshot I display the current state of the accumulation in a rendertexture using a rawimage.
    A 4k rendertexture allocates ~4GB of VideoRAM (works fine: shot takes 3 seconds) but an 8K Rendertexture completely slows down the rendering process (takes several minutes) allocating ~16GB on my 8GB graphicscard:

    upload_2022-9-16_9-48-17.png

    My question is if there´s a more efficient way to display and save a highres accumulated screenshot.

    Thank you!
     
    Last edited: Sep 16, 2022