{"id":1661,"date":"2016-06-04T17:41:45","date_gmt":"2016-06-04T15:41:45","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1661"},"modified":"2016-06-04T17:41:45","modified_gmt":"2016-06-04T15:41:45","slug":"reference-signal-source-unity-3d-integration","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1661","title":{"rendered":"Reference Signal Source: Unity 3D Integration"},"content":{"rendered":"<p>This is not really practical &#8211; just some fun stuff and attempt to make use of a readily available code snippet. So&#8230; reference signal in Unity 3D game engine through Media Foundation and Direct3D 11.<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2016\/06\/Clipbrd7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1662\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2016\/06\/Clipbrd7-800x426.png\" alt=\"Reference signal in Unity 3D\" width=\"648\" height=\"345\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2016\/06\/Clipbrd7-800x426.png 800w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2016\/06\/Clipbrd7-320x171.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2016\/06\/Clipbrd7-768x409.png 768w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2016\/06\/Clipbrd7.png 1180w\" sizes=\"auto, (max-width: 648px) 100vw, 648px\" \/><\/a><\/p>\n<p>It is basically <a href=\"http:\/\/docs.unity3d.com\/Manual\/NativePluginInterface.html\">Low-Level Native Plugin example project<\/a> (limited to Direct3D 11 and Visual Studio 2015), which works together with DirectShowReferenceSource-x64.dll doing a few things:<\/p>\n<ol>\n<li>commented out standard plugin example inner loop rendering<\/li>\n<li>plugin does COM instantiation of <code>VideoMediaSourceTextureReader<\/code> class of <code>DirectShowReferenceSource<\/code> project and passes a texture for further updates:\n<ul>\n<li>the helper class instantiates Media Foundation media source and initializes compatible resolution<\/li>\n<li>also instantiates <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/dd940436\">Source Reader<\/a> to conveniently read from media source<\/li>\n<li>starts producing video frames<\/li>\n<\/ul>\n<\/li>\n<li>plugin rendering loop does <code>IVideoMediaSourceTextureReader::Update<\/code> calls passing Unity time; the helper class matches generated frames against requested time and updates texture respectively<\/li>\n<\/ol>\n<p>The scene thus contains a plane with custom material updated on the backend with Media Foundation produced data.<\/p>\n<p>The demo is not really about performance because so many things can be done to improve it and make it well&#8230; done right. Threading, tighter Direct3D integration, use of proper Direct2D render target etc. The demo is really about integration itself. Nevertheless, 2K texture is streamed well at full rate.<\/p>\n<h3>Download links<\/h3>\n<ul>\n<li>Binaries:\n<ul>\n<li>32-bit: <a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/DirectShowReferenceSource\/_Bin\/DirectShowReferenceSource-Win32.dll\">DirectShowReferenceSource-Win32.dll<\/a><\/li>\n<li>64-bit: <a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/DirectShowReferenceSource\/_Bin\/DirectShowReferenceSource-x64.dll\">DirectShowReferenceSource-x64.dll<\/a><\/li>\n<li>Sample code: <a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/DirectShowReferenceSource\/Sample\/\">SVN<\/a>, <a href=\"https:\/\/www.alax.info\/trac\/public\/browser\/trunk\/Utilities\/DirectShowReferenceSource\/Sample\/\">Trac<\/a><\/li>\n<li>License: This software is free to use<\/li>\n<\/ul>\n<\/li>\n<li>Unity 3D related:\n<ul>\n<li>Unity plugin code and project: <a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/DirectShowReferenceSource\/Sample\/Unity01\/\">SVN<\/a>, <a href=\"https:\/\/www.alax.info\/trac\/public\/browser\/trunk\/Utilities\/DirectShowReferenceSource\/Sample\/Unity01\/\">Trac<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This is not really practical &#8211; just some fun stuff and attempt to make use of a readily available code snippet. So&#8230; reference signal in Unity 3D game engine through Media Foundation and Direct3D 11. It is basically Low-Level Native Plugin example project (limited to Direct3D 11 and Visual Studio 2015), which works together with&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1661\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[524,408,424,523,522,486],"class_list":["post-1661","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-direct2d","tag-direct3d","tag-media-foundation","tag-texture","tag-unity","tag-video"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=1661"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1661\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}