Skip to content

Instantly share code, notes, and snippets.

@calben
Last active June 25, 2021 20:24
Show Gist options
  • Save calben/163b8e64180a344bba7ae41889d69e14 to your computer and use it in GitHub Desktop.
Save calben/163b8e64180a344bba7ae41889d69e14 to your computer and use it in GitHub Desktop.
Rendering Video with an Alpha Channel in Unreal Engine 4.14+

Rendering Video with an Alpha Channel in Unreal Engine 4.14+

Creating a supported video file

Video clips need to be in an AVI file format with Channels: RGB + Alpha and Premultiplied Colour. For those of us not versed in the dark arts of video formats, you can use the Keylight tool and then export from After Effects with the above settings to quickly get a video with transparency.

Setting up a media texture with transparency

  1. Importing the video
  2. The UE4 Media Framework does not directly import video but creates a stub to reference the video. Move to import your video file to create a File Media Source.
  3. The File Media Source needs to be accessed by a media player. You can make this by creating "Media -> Media Player".
  4. Once the media player is created, select the AVI video source.
  5. Create a Media Texture by right clicking the Media Player and selecting "Create Media Texture." Note that the Media Texture and Media Player are linked.
  6. Create a material from the media texture
  7. You may set the material to be either masked or translucent. Masked seems to produce better results.

Adding the Material to an Object

Add the material to an object in the scene. A plane or a cube will work best for a video converted from green screen.

Playing a clip in the level

See the documentation here https://docs.unrealengine.com/latest/INT/Engine/MediaFramework/HowTo/FileMediaSource/

Casting Dynamic Shadows

Translucent materials don't support dynamically cast shadows, but masks should work well with shadows. Soft raycast lighting does not seem to work. To cast shadows with the material ensure the primitive on which the material plays has shadows disabled and enable dyanmic shadows on the material.

@wifiovermybody
Copy link

so this allows us to layer different videos on top of each other in unreal?

@calben
Copy link
Author

calben commented Jun 13, 2019

Oh boy blast from the past! This would let you render videos on top of each other and would also let you render them as separated layers in 3D space if you wanted to. For just layering a few different videos, I'd probably do that with a material that performs that overlayment. Should look something like a material that takes in several textures that are controlled by media players and then blends those textures.

@wifiovermybody
Copy link

amazing! I didn't know AVIs could be used this way in unreal. thank you for help!~

@calben
Copy link
Author

calben commented Jun 15, 2019

No problem. Also I know the description I gave for a material setup is super vague, so if you end up doing it and need further help, feel free to shoot me a message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment