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ā¦
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
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;
}
}
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ā¦