Search Unity

Resolved Video texture with VFX graph

Discussion in 'Visual Effect Graph' started by bjerken, Jul 5, 2020.

  1. bjerken

    bjerken

    Joined:
    Dec 24, 2015
    Posts:
    11
    Hi!
    I have tested running a video texture to VFX graph by using a video player set to a render texture. This changes the color of the particle system but I can not seem to work out how to get the video texture to map properly to a vfx Primitive (Sphere etc). None of the Texture mapping options seems to make complete sense. Has anyone here tried something similar and suceeded? Based on this video it seems like it should be possible.
     
  2. Rafaelski

    Rafaelski

    Joined:
    May 1, 2019
    Posts:
    12
    Man, I´m struggling trying to figure out how to do this. Did you have any luck?
     
  3. ssojyeti2

    ssojyeti2

    Joined:
    Mar 16, 2020
    Posts:
    16
    Also curious
     
  4. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    192
    Thanks for reviving this thread back from the dead :D.
    I'm really not familiar with this kind of workflow that involves video, but for it to work with VFX Graph, you'll have to use a Texture2D as we don't have video type property in VFX Graph. So the Idea would be to render the video on a RenderTexture 2D. You can find some useful information that can be grab on this documentation pages here and here.

    I made a very quick try at this, and here's how I went:

    • Import a Video (in my case Mp4)
    • Use the Transcode Option to convert your video in the format/dimension of your choice.
    • In the SceneView, create an empty GameObject.
    • Add a new VideoPlayer Component to it.
    • Set the different option of the VideoPlayer component to match your need.
    • Set the Render Mode to RenderTexture:
      upload_2023-11-22_17-22-18.png


    • In your project folder, create a Render Texture by right Click > Create> Rendering > Render Texture:
      upload_2023-11-22_17-24-38.png

    • Properly name your Render Texture and reference it in the Target Texture of the VideoPlayer Component.
    • In your VFX Graph, create a Sample Texture 2D operator.
    • Set the Render Texture as the Map to Sample.
    • You require UVs coordinate to know where to sample.
    • In my case, I'm spawning the particles in a grid fashion thanks to the Position Sequential 3D Block.
    • I then use my Position and remap it so that it's between 0-1
    • Use the Position as Uvs coordinate to sample the Texture.
    • Use the Sample Texture to build your effect.
    • Enjoy.

    • Unity_F64Pmetp54_0137-0213_1000x715.gif

      As I mention, I'm no expert with this workflow, and I'm pretty sure that there is a better or more efficient way of doing this.
      I'm joining a small package That should help you get started. It has Prefab that you can drop in your scene that contain the VFX Graph, a Render Texture and the Already filled Game Component with the video player. You will have to provide a Video for this to work. I've added comment to the VFXGraph.

      upload_2023-11-22_17-53-9.png

      To finish, I would suggest that you take a look at the Github repository of Keijiro Takahashi. From what I've seen, you can found several projects that can help you on your journey.

      https://github.com/keijiro/KlakSpout
      https://github.com/keijiro/Dkvfx
      https://github.com/keijiro/DkvfxSketches

      Have a great day
     

    Attached Files:

    XieJiJun, pierre92nicot and ssojyeti2 like this.
  5. ssojyeti2

    ssojyeti2

    Joined:
    Mar 16, 2020
    Posts:
    16
    Dude I literally figured this out the other day and was about to make a tutorial on it! Thanks for the explanation!+1 to using KlakSpout, as it gives a lot of flexibility to the render textures (can use webcam etc)
     
    OrsonFavrel likes this.