Help with setting up video player with custom shader material

Hello!

I know there have already been a few questions raised about this on the forums before but I’ve been struggling to get this working on my own project. I am trying to get a video player working with Needle through a custom ShaderGraph material that displays the video in my scene, but it does not seem to be working, despite my other ShaderGraph materials working perfectly fine.

Things I have tried so far:

  • Made sure the material is unlit
  • Added the ā€˜ExportShader’ label to my relevant shaders and materials
  • Tried to load the video through a VideoClip reference and a URL, neither of which seem to work
  • Put all of my scene objects under a GLTF object parent (saw this in a few tutorial videos but I also noticed this was not used in any of the sample scenes, I’m using Unity 6).

Any help would be appreciated! First time using Needle and it’s been great so far, video playing has been the only thing I’ve struggled on so far…

I’m sorry, I couldn’t find a response but notified the team :exploding_head:

Hi, the VideoPlayer component sets the ā€œmapā€ property on the shader (which is the standard texture slot name for three.js color texture)

This means you need to create a ā€œmapā€ texture property in your custom shader (ShaderGraph) and it should work. That being said I havent tried Videos with custom shaders (Unlit) yet. Do you have a specific reason for going that route vs using standard materials/shaders?

You can use ?debugvideo in your URL to see some debug info in the browser console

Quick update:

  • VideoPlayer does currently only set map property
  • Custom Shaders don’t expose map
  • I’ve added a fix for the next update so your VideoPlayer will automatically work with custom shaders if you name your property ā€œmapā€ in Unity (ShaderGraph)

Workaround for right now until the fix is released (next week):

  • Add this script to the same object as your VideoPlayer and Renderer
import { Behaviour, Renderer, VideoPlayer } from "@needle-tools/engine";

export class VideoTextureFix extends Behaviour {

    start() {
        const tex = this.gameObject.getComponent(VideoPlayer)?.videoTexture;
        const mat = this.gameObject.getComponent(Renderer)?.sharedMaterial;
        if(mat) mat["_map"] = tex;
    }

}

Hi, thank you so much for the speedy reply!

Renaming my ā€˜MainTex’ property to ā€˜map’ (and then force-renaming the reference to ā€˜map’ as well, without the _ in front) fixed the video player and it seems to all be working perfectly now I think. I feel a bit silly having not discovered this until now lol

I’m planning to create an environment with a video player TV object that alternates between different distortion shader effects over time. I’m hoping I might be able to have the material of the video player switched out based on a timer, though I’ve yet to experiment with this yet so I’ll see what happens…

Huge thanks again for the help!

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.