Unity-Technologies / com.unity.webrtc

WebRTC package for Unity
Other
738 stars 186 forks source link

[REQUEST]: Mipmap support for incoming video streams #1032

Open colindefais opened 1 month ago

colindefais commented 1 month ago

Is your feature request related to a problem?

I'm always frustrated when streaming screen capture video to my Unity WebRTC project the texture looks pixelated if viewed from far: image

Describe the solution you'd like

It would be great if we could enable mipmaps on the texture returned by VideoStreamTrack.OnVideoReceived: image

Describe alternatives you've considered

I have tried to make changes to the package but I only managed to get the first mip level populated (I am not very familiar with low level graphics commands, maybe someone more experimented have an idea where I am wrong)

VideoStreamTrack.CreateRenderTexture():

var tex = new RenderTexture(width, height, 0, format);
tex.useMipMap = true;
tex.autoGenerateMips = false;
tex.Create();

VideoStreamTrack.OnVideoFrameResizeInternal():

var format = WebRTC.GetSupportedGraphicsFormat(SystemInfo.graphicsDeviceType);
Texture = new Texture2D(width, height, format, TextureCreationFlags.MipChain);
track.OnVideoFrameResize(Texture);

VideoDecoderMethods.UpdateRendererTexture():

_command.IssuePluginCustomTextureUpdateV2(callback, texture, rendererId);
Graphics.ExecuteCommandBuffer(_command);
_command.GenerateMips(texture);
_command.Clear();

Additional context

No response