Announcement

Collapse
No announcement yet.

Update Reflection Capture on Runtime

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Originally posted by roberteker View Post
    Is this still true in 4.21?

    If it is, how do you do a real-time day/night cycle?

    (Unreal is supposed to be great at graphics, so I hope this topic is missing some vital information, because in Unity, you can basically update a reflection probe on tick if you want to.)
    This would be dynamic lighting. We were talking about static lighting.
    www.s-dot.de/viz
    ArchViz User Interface :: UE4 Marketplace.

    Comment


      #17
      Originally posted by S-Dot View Post

      This would be dynamic lighting. We were talking about static lighting.
      If the original question mentioned static lighting, I missed that.

      Regardless of lighting, a reflection probe just takes a shapshot of the current scene, regardless of how it is lit.

      If it really is true that Unreal can't do this at runtime, that's pretty amazing.

      I can't even get my skybox to show up in my spherical captures, so I really hope I'm missing something big here and that someone can tell me.

      Comment


        #18
        So, I have build something...



        Pros
        • It updates the reflection captures
        Cons
        • It does NOT work in the packaged game! (because of this check in ReflectEnvironmentCapture.cpp (line 1439))
        Code:
        if (FPlatformProperties::RequiresCookedData())
        {
            UE_LOG(LogEngine, Warning, TEXT("No built data for %s, skipping generation in cooked build."), *CaptureComponent->GetPathName());
            return;
        }
        • It's hacky
        • short hickup (which was to be expected)



        Code:
        for (ULevel* Level : World->GetLevels())
        {
            if (Level->bIsVisible)
            {
                if (Level->MapBuildData)
                {
                    Level->MapBuildData->InvalidateReflectionCaptures(nullptr);
                }
            }
        }
        
        FScene* Scene = (FScene*) World->Scene;
        if (Scene)
        {
            TArray<UReflectionCaptureComponent*> ReflectionCapturesToUpdate;
            for (TObjectIterator<UReflectionCaptureComponent> Itr; Itr; ++Itr)
            {
                if (IsValid(*Itr))
                {
                    ReflectionCapturesToUpdate.Add(*Itr);
                }
            }
        
            bool bOldIsEditorScene = Scene->bIsEditorScene;
            Scene->bIsEditorScene = true;
            World->Scene->AllocateReflectionCaptures(ReflectionCapturesToUpdate, TEXT("UpdateReflectionRuntime"), false);
            Scene->bIsEditorScene = bOldIsEditorScene;
        }
        else
        {
            // IT DIDN'T WORK
         }

        Using UE4.21 btw


        If anyone can figure out how to get it to work in the packaged game without editing engine source code I'd be very grateful!

        Comment


          #19
          It's kind of baffling that the engine still doesn't support updating reflection captures at runtime out of the box.
          ArtStation

          Comment


            #20
            The reason why this doesn't work in packaged games is because capture data is compressed and packed into texture arrays as part of the level lighting data, so all the code that does that is part of the editor and not the runtime. Also, a crucial element of reflection capture processing is generating the mip maps, which AFAIK is pretty expensive since you can't simply downsize each cubemap side as you'd do on a 2D texture: it needs to be resampled in spherical space to be able to blur correctly across the cube face boundaries.

            Comment


              #21
              Originally posted by Manoel.Neto View Post
              The reason why this doesn't work in packaged games is because capture data is compressed and packed into texture arrays as part of the level lighting data, so all the code that does that is part of the editor and not the runtime. Also, a crucial element of reflection capture processing is generating the mip maps, which AFAIK is pretty expensive since you can't simply downsize each cubemap side as you'd do on a 2D texture: it needs to be resampled in spherical space to be able to blur correctly across the cube face boundaries.
              the point is that it shouldn't need to be compressed and packed into the level lighting data, I don't see why it can't be a part of a texture array that simply lives on memory.
              also reflection capture processing already generates the mipmaps. yes it's someone expensive but that's part of the hiccup anyone would expect. and IIRC doing something like TobiGroth does already makes the proper calls and generates mipmaps, since it's all part of the same chain.

              also TobiGroth's experiment is updating all captures at the same time. I've always argued this is something that could be done "in turns" capturing one at a time (based on different criteria like how close it is to the camera, and how long since it hasn't been recaptured), and subdividing the entire capture process into smaller process chunks that could be deferred into multiple frames.
              I don't think anyone expects to update all captures every frame (unless you require a hard lighting transition, but you can hide that under a loading screen). I recon most games would need this for slow day cycles, so if we could dedicate a small portion of the frame budget (say 1-2ms) to slowly but constantly update captures over time, it could be a feature that would be functional and kept within budget.
              Follow me on Twitter!
              Developer of Elium - Prison Escape

              Comment


                #22
                Originally posted by TobiGroth View Post
                So, I have build something...



                Pros
                • It updates the reflection captures
                Cons
                • It does NOT work in the packaged game! (because of this check in ReflectEnvironmentCapture.cpp (line 1439))
                Code:
                if (FPlatformProperties::RequiresCookedData())
                {
                UE_LOG(LogEngine, Warning, TEXT("No built data for %s, skipping generation in cooked build."), *CaptureComponent->GetPathName());
                return;
                }
                • It's hacky
                • short hickup (which was to be expected)



                Code:
                for (ULevel* Level : World->GetLevels())
                {
                if (Level->bIsVisible)
                {
                if (Level->MapBuildData)
                {
                Level->MapBuildData->InvalidateReflectionCaptures(nullptr);
                }
                }
                }
                
                FScene* Scene = (FScene*) World->Scene;
                if (Scene)
                {
                TArray<UReflectionCaptureComponent*> ReflectionCapturesToUpdate;
                for (TObjectIterator<UReflectionCaptureComponent> Itr; Itr; ++Itr)
                {
                if (IsValid(*Itr))
                {
                ReflectionCapturesToUpdate.Add(*Itr);
                }
                }
                
                bool bOldIsEditorScene = Scene->bIsEditorScene;
                Scene->bIsEditorScene = true;
                World->Scene->AllocateReflectionCaptures(ReflectionCapturesToUpdate, TEXT("UpdateReflectionRuntime"), false);
                Scene->bIsEditorScene = bOldIsEditorScene;
                }
                else
                {
                // IT DIDN'T WORK
                }

                Using UE4.21 btw


                If anyone can figure out how to get it to work in the packaged game without editing engine source code I'd be very grateful!
                Can you please share where do you enter this code?
                are you replacing the code after line 1439?

                Comment


                  #23
                  Originally posted by bayanm9 View Post

                  Can you please share where do you enter this code?
                  are you replacing the code after line 1439?

                  You just place the big code block in any actor you like. Trigger it with a key or a timer ever 5 seconds to test maybe.

                  Comment


                    #24
                    I am also looking for a similiar technique like the "Environment Probe" in CryEngine. Because there you could have multiple level/layers with different times of day and it automatically updates the reflection capture when switching the lighting conditions. Currently I always have to rebuild reflection capture when I unhide a certain level with another time of day(Directional light in it) to get a proper reflection in the scene. Or is there a different way to achieve this in UE4?
                    https://www.artstation.com/eike

                    Comment


                      #25
                      Originally posted by frezer748 View Post
                      I am also looking for a similiar technique like the "Environment Probe" in CryEngine. Because there you could have multiple level/layers with different times of day and it automatically updates the reflection capture when switching the lighting conditions. Currently I always have to rebuild reflection capture when I unhide a certain level with another time of day(Directional light in it) to get a proper reflection in the scene. Or is there a different way to achieve this in UE4?
                      Are you using lighting scenarios?

                      https://docs.unrealengine.com/en-us/...htingScenarios
                      www.s-dot.de/viz
                      ArchViz User Interface :: UE4 Marketplace.

                      Comment

                      Working...
                      X