Announcement

Collapse
No announcement yet.

On Pre Render Event?

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

    On Pre Render Event?

    Unity3D has a script callback for when a camera starts rendering the scene. Is there a similar event in UE4? I want to be able to change the materials of some objects in the scene depending what camera is being used to render them.

    http://docs.unity3d.com/ScriptRefere...PreRender.html

    #2
    I need this too for similar reasons. Any help on this appreciated

    Comment


      #3
      Perhaps look at the camera class in the engine to see if there are any virtual methods you could "sneak" in some code on top of. Worst case is you have to modify the function of the camera class that UE4 uses to get its transform before rendering to be virtual, then add a little pre-super code to change the materials.
      My work: Iron Rain - Space Games' Finest Hour

      Comment


        #4
        Originally posted by spychiatrist View Post
        Perhaps look at the camera class in the engine to see if there are any virtual methods you could "sneak" in some code on top of. Worst case is you have to modify the function of the camera class that UE4 uses to get its transform before rendering to be virtual, then add a little pre-super code to change the materials.
        I didn't have a terrible amount of luck going through this approach when I first started investigating. Unfortunately I don't know enough about UE4 as an engine to know if I'm just looking the wrong place or if for whatever reason this isn't a notion in the engine.

        Comment


          #5
          I'm still looking for good solutions to this too. I tried what spychiatrist said, but this is not a good place as its called for all active cameras before any rendering is done.
          I need camera1 prerender, camera1 render, camera2 prerender, camera2 render, etc
          I was thinking to look at creating a custom FViewport and implement the BeginRenderFrame function.
          Does anyone know if each camera has a viewport or it's shared ?

          Comment


            #6
            Originally posted by MorphingDragon View Post
            I want to be able to change the materials of some objects in the scene depending what camera is being used to render them.
            You should possibly check the viewtarget for the current playercontroller.

            Say there are 2 camera actors placed in your scene then if your player is viewing through Camera 1 then the player controller's view target should be camera 1 Actor. If you are using a camera component in a pawn or character (lets call it player pawn) then the view target will be PlayerPawn Actor.

            Now just check the view target your player controller has to determine which camera is scene currently being rendered with.

            EDIT:As an alternative to keep things efficient and simple you'd want to set the material and other things just as you change the camera using "SetViewTargetWithBlend"

            Comment


              #7
              Processing on Game thread and Render thread happens simultaneously, but Render thread is one frame behind Game thread.

              This allows engine to take advantage of multi-core, at the cost of Game thread not actually knowing if actor has been rendered or not. Hence, there is no easy way to implement callback on Game thread 'before' item has been rendered.


              However, there are several things you can do, to achieve what you need:

              Every actor has Tick() function that you can override and make it execute each frame (and it will always be before rendering of that frame begins). If you need one global processor, you can have one actor without rendering components, just so it can tick each frame and do whatever you need done across the game.

              You could also implement this functionality in your level's Tick().

              If you have specific actor that needs to do something, and for performance reasons you only want this done when its rendered, you could do a check inside Tick() for when was this actors LastRenderTime -- see AActor::GetLastRenderTime()

              You could do something like this in Actor's Tick:
              Code:
              if (GetWorld()->TimeSince(GetLastRenderTime()) <= 1.f)
              {
                  // do stuff only when this actor is rendered
              }
              • Follow me on twitter
              • Visit our website traverse.world
              • Checkout our game's forum thread

              Comment


                #8
                Thanks for your reply xulture, but i don't think this will work for what i have in mind.
                Basically I would like to render a "normal" visible image and an infrared image for the same game time.
                This is for a simulation, so performance not critical.

                Something like below is what i'm after:

                Tick
                <change materials here>
                Render Visible Image
                <change materials here>
                Render Infrared Image
                Tick
                <change materials here>
                Render Visible Image
                <change materials here>
                Render Infrared Image
                ...

                Comment


                  #9
                  Post above me sounds like what you need to do is either create a new GBuffer and render to that, or do it via a Post-Process material that you can modify on the fly. The latter is the easiest method, especially with the new Custom Depth channels we got recently.

                  As Xulture says though, there is no overrideable pre-render function in UE4.

                  Comment

                  Working...
                  X