XMaterialComponent.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. import XVideoRawYUV from "./XVideoRawYUV"
  2. import Logger from "./Logger.js"
  3. const planeWidth = 1728
  4. const planeHeight = 1080
  5. window.generateRandomArray = ()=>{
  6. var rnd=[];
  7. for(let i=0;i< planeWidth*planeHeight;i++)
  8. {
  9. rnd[i] = Math.floor(Math.random()*255);
  10. }
  11. return rnd;
  12. }
  13. window.updateTexture = (yuv)=>
  14. {
  15. let Y = yuv.subarray(0, planeWidth*planeHeight);
  16. window._videoRawYTexture.update(Y)
  17. window._videoRawYTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
  18. Y = undefined;
  19. }
  20. const yuv = new Uint8Array(window.generateRandomArray())
  21. const renderCount = 100;
  22. let sub = 0;
  23. const logger = new Logger('XMaterial')
  24. export default class XMaterialComponent {
  25. constructor(e, t) {
  26. E(this, "scene");
  27. E(this, "engine");
  28. E(this, "yuvInfo");
  29. E(this, "shaderMode");
  30. E(this, "_panoInfo");
  31. E(this, "_dynamic_size");
  32. E(this, "_dynamic_babylonpose");
  33. E(this, "_dynamic_textures");
  34. E(this, "_dynamic_shaders");
  35. E(this, "_scenemanager");
  36. E(this, "_videoTexture");
  37. E(this, "_videoElement");
  38. E(this, "_lowModelShader");
  39. E(this, "_defaultShader");
  40. E(this, "_inputYUV420", !0);
  41. E(this, "_inputPanoYUV420", !0);
  42. E(this, "_videoRawYUVTexArray");
  43. E(this, "_isUpdateYUV", !0);
  44. E(this, "initMaterial", async()=>new Promise((resolve,t)=>{
  45. this._initDefaultShader();
  46. if(this.shaderMode == 2){
  47. this.initDynamicData(this._panoInfo.dynamicRange, this._panoInfo.width, this._panoInfo.height).then(()=>{
  48. this._initPureVideoShader();
  49. this._prepareRender(this.yuvInfo);
  50. })
  51. }
  52. else if(this.shaderMode == 1){
  53. this._initPureVideoShader();
  54. this._prepareRender(this.yuvInfo);
  55. }
  56. // else if(this.shaderMode == 0){
  57. // resolve(!0)
  58. // }
  59. resolve(!0)
  60. // this.shaderMode == 2 ? this.initDynamicData(this._panoInfo.dynamicRange, this._panoInfo.width, this._panoInfo.height).then(()=>{
  61. // this._initPureVideoShader(),
  62. // this._prepareRender(this.yuvInfo)
  63. // }
  64. // ) : this.shaderMode == 1 ? (this._initPureVideoShader(),
  65. // this._prepareRender(this.yuvInfo)) : this.shaderMode == 0,
  66. // resolve(!0)
  67. }));
  68. E(this, "_initPureVideoContent", focal_width_height=>{
  69. if(this._inputYUV420){
  70. if(this._videoRawYUVTexArray.getVideoYUVTex(0) != null){
  71. this._lowModelShader.setTexture("texture_video", this._videoRawYUVTexArray.getVideoYUVTex(0));
  72. this._lowModelShader.setFloat("isYUV", 1);
  73. BABYLON.Texture.WhenAllReady([this._videoRawYUVTexArray.getVideoYUVTex(0)], ()=>{
  74. this._changePureVideoLowModelShaderCanvasSize(focal_width_height)
  75. })
  76. }
  77. }
  78. // else{
  79. // this._videoElement = e.videoElement;
  80. // this._videoTexture || (this._videoTexture = new VideoTexture("InterVideoTexture",this._videoElement,this.scene,!0,!1));
  81. // BABYLON.Texture.WhenAllReady([this._videoTexture], ()=>{
  82. // this._changePureVideoLowModelShaderCanvasSize({
  83. // width: this._videoElement.height,
  84. // height: this._videoElement.width,
  85. // fov: e.fov
  86. // })
  87. // });
  88. // this._lowModelShader.setTexture("texture_video", this._videoTexture);
  89. // this._lowModelShader.setFloat("isYUV", 0);
  90. // }
  91. });
  92. E(this, "_changePureVideoLowModelShaderCanvasSize", e=>{
  93. var lowModelShader;
  94. const fov = e.fov || 50
  95. const width = e.width || 720
  96. const height = e.height || 1280
  97. const focus = width / (2 * Math.tan(Math.PI * fov / 360));
  98. (lowModelShader = this._lowModelShader) == null || lowModelShader.setVector3("focal_width_height", new BABYLON.Vector3(focus,width,height))
  99. }
  100. );
  101. E(this, "updateRawYUVData", (stream,width,height,fov=-1)=>{
  102. var o, a;
  103. fov == -1 && (fov = this.yuvInfo.fov);
  104. if (this._isUpdateYUV == !0) {
  105. const s = {
  106. width: width,
  107. height: height,
  108. fov: fov
  109. }
  110. const videosResOriArrayIndex = this._videoRawYUVTexArray.findId(width, height)
  111. const currentVideoId = this._videoRawYUVTexArray.getCurrentVideoTexId();
  112. if(currentVideoId < 0 || videosResOriArrayIndex != currentVideoId || fov != this.yuvInfo.fov)
  113. {
  114. this.yuvInfo.width = width;
  115. this.yuvInfo.height = height;
  116. this.yuvInfo.fov = fov;
  117. this._videoRawYUVTexArray.setCurrentVideoTexId(videosResOriArrayIndex);
  118. this._changeVideoRes(videosResOriArrayIndex);
  119. this._changePureVideoLowModelShaderCanvasSize(s);
  120. this._scenemanager.cameraComponent.cameraFovChange(s);
  121. this._scenemanager.yuvInfo = s;
  122. }
  123. let VideoTexture = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)
  124. if(VideoTexture != null){
  125. VideoTexture.update(stream)
  126. VideoTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
  127. }
  128. //(o = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || o.update(stream),
  129. //(a = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
  130. if(window.testPlane != null){
  131. // if(window.testPlane.material == null){
  132. BABYLON.Effect.ShadersStore['customVertexShader'] = houseShader.vertex
  133. // `
  134. // precision highp float;
  135. // attribute vec2 uv;
  136. // attribute vec3 position;
  137. // varying vec2 vUV;
  138. // uniform mat4 view;
  139. // uniform mat4 projection;
  140. // uniform mat4 world;
  141. // uniform mat4 worldViewProjection;
  142. // void main()
  143. // {
  144. // vUV = uv;
  145. // gl_Position = projection * view * world * vec4(position , 1.0);
  146. // }
  147. // `;
  148. BABYLON.Effect.ShadersStore["customFragmentShader"]= houseShader.fragment
  149. // `
  150. // precision highp float;
  151. // varying vec2 vUV;
  152. // uniform sampler2D chrominanceYTexture;
  153. // void main()
  154. // {
  155. // vec2 uv = vUV;
  156. // vec3 color = vec3(0,0,0);
  157. // color = texture2D(chrominanceYTexture, uv).rgb;
  158. // // const mat4 YUV2RGB = mat4
  159. // // (
  160. // // 1.1643828125, 0, 1.59602734375, -.87078515625,
  161. // // 1.1643828125, -.39176171875, -.81296875, .52959375,
  162. // // 1.1643828125, 2.017234375, 0, -1.081390625,
  163. // // 0, 0, 0, 1
  164. // // );
  165. // // vec4 result = vec4(
  166. // // texture2D( chrominanceYTexture, vec2( uv.x, uv.y * 0.666666 + 0.333333 ) ).x,
  167. // // texture2D( chrominanceYTexture, vec2( uv.x * 0.5, uv.y * 0.333333 ) ).x,
  168. // // texture2D( chrominanceYTexture, vec2( 0.5 + uv.x * 0.5, uv.y * 0.333333 ) ).x,
  169. // // 1
  170. // // ) * YUV2RGB;
  171. // // color = clamp(result.rgb, 0.0, 1.0);
  172. // gl_FragColor = vec4( color, 1.0);
  173. // }
  174. // `;
  175. window.testPlane.material = new BABYLON.ShaderMaterial(
  176. 'customShader',
  177. this.scene,
  178. {
  179. vertex: "custom",
  180. fragment: "custom",
  181. },
  182. {
  183. attributes: ['uv', 'position'],
  184. uniforms: houseShader.uniforms //['view', 'projection', 'worldViewProjection', 'world'],
  185. },
  186. )
  187. window._videoRawYTexture = BABYLON.RawTexture.CreateLuminanceTexture(
  188. null,
  189. planeWidth,
  190. planeHeight,
  191. this.scene,
  192. false,
  193. true,
  194. )
  195. // window.testPlane.material.setTexture('chrominanceYTexture', window._videoRawYTexture)
  196. window.testPlane.material.setTexture('texture_video', window._videoRawYTexture)
  197. window.testPlane.material.setFloat('isYUV', 1)
  198. window.testPlane.material.setVector3('focal_width_height', new BABYLON.Vector3(772.022491, planeWidth, planeHeight / 1.5))
  199. // window.testPlane.material = new BABYLON.StandardMaterial("xsttest",this.scene);
  200. // window.testPlane.material.diffuseTexture = window._videoRawYTexture
  201. window.testPlane.material.backFaceCulling = false;//Allways show the front and the back of an element
  202. // window.updateTexture( new Uint8Array(window.generateRandomArray()) );
  203. ++sub
  204. if(sub< renderCount)
  205. {
  206. window._videoRawYTexture.update(stream)
  207. window._videoRawYTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
  208. }
  209. // this.scene.meshes.forEach(mesh => {
  210. // mesh.material != window.testPlane.material && (mesh.material = window.testPlane.material)
  211. // })
  212. }
  213. // }
  214. }
  215. }
  216. );
  217. E(this, "_changeVideoRes", e=>{
  218. this._lowModelShader.setTexture("texture_video", this._videoRawYUVTexArray.getVideoYUVTex(e))
  219. }
  220. );
  221. E(this, "initDynamicData", (dynamicRange,width,height)=>new Promise((resolve,reject)=>{
  222. this.setDynamicSize(dynamicRange).then(a=>{
  223. if (a) {
  224. for (let s = 0; s < dynamicRange; ++s)
  225. (l=>{
  226. this.initDynamicTexture(l, width, height),
  227. this.initDynamicShaders(l).then(()=>{
  228. this._updatePanoShaderInput(l)
  229. }
  230. )
  231. }
  232. )(s);
  233. resolve(!0)
  234. } else
  235. reject(new XMaterialError(`[Engine] DynamicRoomSize (${dynamicRange}) is too small`))
  236. }
  237. )
  238. }
  239. ).catch(n=>logger.error(`[Engine] ${n}`)));
  240. E(this, "_initDefaultShader", ()=>{
  241. this._defaultShader == null && (this._defaultShader = new BABYLON.GridMaterial("GridShader",this.scene),
  242. this._defaultShader.gridRatio = 50,
  243. this._defaultShader.lineColor = new BABYLON.Color3(0,0,.5),
  244. this._defaultShader.majorUnitFrequency = 1,
  245. this._defaultShader.mainColor = new BABYLON.Color3(.6,.6,.6),
  246. this._defaultShader.backFaceCulling = !1)
  247. }
  248. );
  249. E(this, "_initPureVideoShader", ()=>{
  250. if (this._lowModelShader == null) {
  251. const e = new BABYLON.ShaderMaterial("PureVideoShader",this.scene,{
  252. vertexSource: pureVideoVertex,
  253. fragmentSource: pureVideoFragment
  254. },{
  255. attributes: ["uv", "position", "world0", "world1", "world2", "world3"],
  256. uniforms: ["view", "projection", "worldViewProjection", "world"],
  257. defines: ["#define SHADOWFULLFLOAT"]
  258. });
  259. e.setTexture("shadowSampler", null),
  260. e.setMatrix("lightSpaceMatrix", null),
  261. e.setFloat("haveShadowLight", 0),
  262. e.setTexture("texture_video", null),
  263. e.setFloat("isYUV", this._inputYUV420 ? 1 : 0),
  264. e.setFloat("fireworkLight", 0),
  265. e.setVector3("fireworkLightPosition", new BABYLON.Vector3(0,0,0)),
  266. e.setVector3("focal_width_height", new BABYLON.Vector3(772.022491,720,1280)),
  267. e.backFaceCulling = !1,
  268. this._lowModelShader = e
  269. }
  270. }
  271. );
  272. E(this, "setDynamicSize", e=>new Promise((t,r)=>{
  273. e >= 1 && e <= 100 ? (this._dynamic_size = e,
  274. t(!0)) : (this._dynamic_size = 1,
  275. t(!1))
  276. }
  277. ));
  278. E(this, "_isInDynamicRange", e=>e < this._dynamic_size && e >= 0);
  279. E(this, "initDynamicTexture", (e,t,r)=>{
  280. this._isInDynamicRange(e) && (this._dynamic_textures[e] != null && (this._dynamic_textures[e].dispose(),
  281. this._dynamic_textures[e] = null),
  282. this._dynamic_textures[e] = new BABYLON.RawTexture(null,t,r * 1.5,BABYLON.Engine.TEXTUREFORMAT_LUMINANCE,this.scene,!1,!0,BABYLON.Texture.NEAREST_SAMPLINGMODE,BABYLON.Engine.TEXTURETYPE_UNSIGNED_BYTE),
  283. this._dynamic_textures[e].name = "Pano_Dynamic_" + e + "_" + Date.now())
  284. }
  285. );
  286. E(this, "initDynamicShaders", e=>(logger.info("[Engine] Material init dynamic shader."),
  287. new Promise((t,r)=>{
  288. this._dynamic_shaders[e] != null && this._dynamic_shaders[e].dispose();
  289. const n = new BABYLON.ShaderMaterial("Pano_Shader_" + e,this.scene,{
  290. vertexSource: panoVertex,
  291. fragmentSource: panoFragment
  292. },{
  293. attributes: ["uv", "position", "world0", "world1", "world2", "world3"],
  294. uniforms: ["view", "projection", "worldViewProjection", "world"],
  295. defines: ["#define SHADOWFULLFLOAT"]
  296. });
  297. n.setTexture("texture_pano", null),
  298. n.setVector3("centre_pose", new BABYLON.Vector3(0,0,0)),
  299. n.setFloat("isYUV", this._inputPanoYUV420 ? 1 : 0),
  300. n.setTexture("shadowSampler", null),
  301. n.setMatrix("lightSpaceMatrix", null),
  302. n.setFloat("haveShadowLight", 0),
  303. n.setFloat("fireworkLight", 0),
  304. n.setVector3("fireworkLightPosition", new BABYLON.Vector3(0,0,0)),
  305. n.backFaceCulling = !1,
  306. this._dynamic_shaders[e] = n,
  307. t(!0)
  308. }
  309. )));
  310. this._scenemanager = e,
  311. this.scene = e.Scene,
  312. this.engine = this.scene.getEngine(),
  313. this.shaderMode = 1,
  314. this._dynamic_textures = [],
  315. this._dynamic_shaders = [],
  316. this._dynamic_babylonpose = [],
  317. this._videoRawYUVTexArray = new XVideoRawYUV(this.scene,t.videoResOriArray),
  318. this.shaderMode = t.shaderMode,
  319. t.yuvInfo != null && (this.yuvInfo = t.yuvInfo),
  320. t.panoInfo != null && this.setPanoInfo(t.panoInfo)
  321. window.testPlane = null
  322. this.addPlane()
  323. }
  324. //调试
  325. addPlane(){
  326. //window.testPlane = BABYLON.Mesh.CreatePlane("xstplane", {width: 6, height: 6}, this.scene);
  327. //window.testPlane = BABYLON.Mesh.CreatePlane("xstplane", "6", this.scene);
  328. window.testPlane = BABYLON.MeshBuilder.CreateGround("ground", {width: 6, height: 6}, this.scene);
  329. window.testPlane.rotation.x = Math.PI/2
  330. window.testPlane.position.y = 3;
  331. window.testPlane.position.z = -20;
  332. window.testPlane.position.x = 15;
  333. }
  334. stopYUVUpdate() {
  335. this._isUpdateYUV = !1
  336. }
  337. allowYUVUpdate() {
  338. this._isUpdateYUV = !0
  339. }
  340. setPanoInfo(e) {
  341. this._panoInfo = e
  342. }
  343. _prepareRender(focal_width_height) {
  344. if(focal_width_height){
  345. this._initPureVideoContent(focal_width_height)
  346. this._updatePureVideoShaderInput()
  347. }
  348. }
  349. getPureVideoShader() {
  350. return this._lowModelShader
  351. }
  352. getDefaultShader() {
  353. return this._defaultShader
  354. }
  355. updatePanoPartYUV(e, t, r) {
  356. const n = t.subarray(0, r.width * r.height)
  357. , o = t.subarray(r.width * r.height, r.width * r.height * 1.25)
  358. , a = t.subarray(r.width * r.height * 1.25)
  359. , s = this._panoInfo.width
  360. , l = this._panoInfo.height;
  361. if (this._dynamic_textures[e] != null) {
  362. const u = this._dynamic_textures[e].getInternalTexture();
  363. if (u != null && u != null) {
  364. const c = this.engine._getTextureTarget(u);
  365. this.engine._bindTextureDirectly(c, u, !0),
  366. this.engine.updateTextureData(u, n, r.startX, l * 1.5 - r.startY - r.height, r.width, r.height),
  367. this.engine.updateTextureData(u, o, r.startX * .5, (l - r.startY - r.height) * .5, r.width * .5 - 1, r.height * .5 - 1),
  368. this.engine.updateTextureData(u, a, r.startX * .5 + s * .5, (l - r.startY - r.height) * .5, r.width * .5, r.height * .5),
  369. this.engine._bindTextureDirectly(c, null)
  370. }
  371. }
  372. }
  373. changePanoImg(e, t) {
  374. if (logger.info(`[Engine] changePanoImg, id=${e}, pose=${t.pose.position.x},${t.pose.position.y},${t.pose.position.z}`),
  375. !this._isInDynamicRange(e))
  376. return logger.error(`[Engine] ${e} is bigger than dynamic size set in PanoInfo`),
  377. Promise.reject(new XMaterialError(`[Engine] ${e} is bigger than dynamic size set in PanoInfo`));
  378. const r = ue4Position2Xverse(t.pose.position);
  379. return r && (this._dynamic_babylonpose[e] = {
  380. position: r
  381. }),
  382. new Promise((n,o)=>{
  383. try {
  384. typeof t.data == "string" ? (this.setPanoYUV420(!1),
  385. this._dynamic_textures[e].updateURL(t.data, null, ()=>{
  386. this._dynamic_textures[e].updateSamplingMode(BABYLON.Texture.NEAREST_SAMPLINGMODE)
  387. }
  388. )) : (this.isPanoYUV420() == !1 && this.initDynamicTexture(e, this._panoInfo.width, this._panoInfo.height),
  389. this.setPanoYUV420(!0),
  390. this._dynamic_textures[e].update(t.data),
  391. this._dynamic_textures[e].updateSamplingMode(BABYLON.Texture.NEAREST_SAMPLINGMODE)),
  392. n(this)
  393. } catch (a) {
  394. o(new XMaterialError(`[Engine] ChangePanoImg Error! ${a}`))
  395. }
  396. }
  397. ).then(n=>(t.fov != null && this._scenemanager.cameraComponent.changeCameraFov(t.fov * Math.PI / 180),
  398. this._dynamic_shaders[e].setFloat("isYUV", this._inputPanoYUV420 ? 1 : 0),
  399. this._dynamic_shaders[e].setTexture("texture_pano", this._dynamic_textures[e]),
  400. this._dynamic_shaders[e].setVector3("centre_pose", this._dynamic_babylonpose[e].position),
  401. !0))
  402. }
  403. setYUV420(e) {
  404. this._inputYUV420 = e
  405. }
  406. isYUV420() {
  407. return this._inputYUV420
  408. }
  409. setPanoYUV420(e) {
  410. this._inputPanoYUV420 = e
  411. }
  412. isPanoYUV420() {
  413. return this._inputPanoYUV420
  414. }
  415. getDynamicShader(e) {
  416. return this._dynamic_shaders[e]
  417. }
  418. _updatePureVideoShaderInput() {
  419. /*
  420. var e, t, r, n, o, a, s, l, u, c;
  421. if(this.scene.getLightByName("AvatarLight")){
  422. (e = this._lowModelShader) == null || e.setFloat("haveShadowLight", 1);
  423. n = this._lowModelShader
  424. if(n != null){
  425. t = this.scene.getLightByName("AvatarLight")
  426. if(t == null){
  427. r = void 0
  428. }
  429. else{
  430. r = t.getShadowGenerator()
  431. }
  432. if(r == null){
  433. n.setTexture("shadowSampler",void 0)
  434. }
  435. else{
  436. n.setTexture("shadowSampler",r.getShadowMapForRendering())
  437. }
  438. }
  439. //(n = this._lowModelShader) == null || n.setTexture("shadowSampler", (r = (t = this.scene.getLightByName("AvatarLight")) == null ? void 0 : t.getShadowGenerator()) == null ? void 0 : r.getShadowMapForRendering());
  440. s = this._lowModelShader
  441. if(s != null){
  442. o = this.scene.getLightByName("AvatarLight")
  443. if(o == null){
  444. a = void 0
  445. }
  446. else{
  447. a = o.getShadowGenerator()
  448. }
  449. if(a == null){
  450. s.setMatrix("lightSpaceMatrix",void 0)
  451. }
  452. else{
  453. s.setMatrix("lightSpaceMatrix",a.getTransformMatrix())
  454. }
  455. }
  456. //(s = this._lowModelShader) == null || s.setMatrix("lightSpaceMatrix", (a = (o = this.scene.getLightByName("AvatarLight")) == null ? void 0 : o.getShadowGenerator()) == null ? void 0 : a.getTransformMatrix())
  457. }
  458. else{
  459. (l = this._lowModelShader) == null || l.setTexture("shadowSampler", this._videoTexture);
  460. (u = this._lowModelShader) == null || u.setMatrix("lightSpaceMatrix", new Matrix);
  461. (c = this._lowModelShader) == null || c.setFloat("haveShadowLight", 0);
  462. }
  463. */
  464. let lowModelShader = this._lowModelShader
  465. if(lowModelShader!= null){
  466. if(this.scene.getLightByName("AvatarLight")){
  467. lowModelShader.setFloat("haveShadowLight", 1);
  468. let avatarLight = this.scene.getLightByName("AvatarLight")
  469. let shadow = void 0
  470. if(avatarLight != null){
  471. shadow = avatarLight.getShadowGenerator()
  472. }
  473. if(shadow == null){
  474. lowModelShader.setTexture("shadowSampler",void 0)
  475. lowModelShader.setMatrix("lightSpaceMatrix",void 0)
  476. }
  477. else{
  478. lowModelShader.setTexture("shadowSampler",shadow.getShadowMapForRendering())
  479. lowModelShader.setMatrix("lightSpaceMatrix",shadow.getTransformMatrix())
  480. }
  481. }
  482. else{
  483. lowModelShader.setTexture("shadowSampler", this._videoTexture);
  484. lowModelShader.setMatrix("lightSpaceMatrix", new Matrix);
  485. lowModelShader.setFloat("haveShadowLight", 0);
  486. }
  487. }
  488. if (this.scene.getLightByName("fireworkLight"))
  489. {
  490. this.scene.registerBeforeRender(()=>{
  491. this._lowModelShader.setFloat("fireworkLight", this.scene.getLightByName("fireworkLight").getScaledIntensity());
  492. var fireworkLight = this.scene.getLightByName("fireworkLight")
  493. if(fireworkLight == null){
  494. this._lowModelShader.setVector3("fireworkLightPosition", void 0);
  495. }
  496. else{
  497. this._lowModelShader.setVector3("fireworkLightPosition", fireworkLight.position);
  498. }
  499. //this._lowModelShader.setVector3("fireworkLightPosition", (h = this.scene.getLightByName("fireworkLight")) == null ? void 0 : h.position);
  500. });
  501. }
  502. else {
  503. const pointLight = new BABYLON.PointLight("fireworkLight",new BABYLON.Vector3(0,0,0),this.scene);
  504. pointLight.intensity = 0
  505. }
  506. }
  507. _updatePanoShaderInput(e) {
  508. var t, r, n, o, a, s, l, u, c, h;
  509. if (this._isInDynamicRange(e))
  510. if (this.scene.getLightByName("AvatarLight") ? ((t = this._dynamic_shaders[e]) == null || t.setFloat("haveShadowLight", 1),
  511. (o = this._dynamic_shaders[e]) == null || o.setTexture("shadowSampler", (n = (r = this.scene.getLightByName("AvatarLight")) == null ? void 0 : r.getShadowGenerator()) == null ? void 0 : n.getShadowMapForRendering()),
  512. (l = this._dynamic_shaders[e]) == null || l.setMatrix("lightSpaceMatrix", (s = (a = this.scene.getLightByName("AvatarLight")) == null ? void 0 : a.getShadowGenerator()) == null ? void 0 : s.getTransformMatrix())) : ((u = this._dynamic_shaders[e]) == null || u.setTexture("shadowSampler", null),
  513. (c = this._dynamic_shaders[e]) == null || c.setMatrix("lightSpaceMatrix", new Matrix),
  514. (h = this._dynamic_shaders[e]) == null || h.setFloat("haveShadowLight", 0)),
  515. this.scene.getLightByName("fireworkLight"))
  516. this.scene.registerBeforeRender(()=>{
  517. var f;
  518. this._dynamic_shaders[e].setFloat("fireworkLight", this.scene.getLightByName("fireworkLight").getScaledIntensity()),
  519. this._dynamic_shaders[e].setVector3("fireworkLightPosition", (f = this.scene.getLightByName("fireworkLight")) == null ? void 0 : f.position)
  520. }
  521. );
  522. else {
  523. const f = new BABYLON.PointLight("fireworkLight",new BABYLON.Vector3(0,0,0),this.scene);
  524. f.intensity = 0
  525. }
  526. }
  527. }
  528. var houseShader = {
  529. attributes: ['uv', 'position'],
  530. uniforms: ['view', 'projection', 'world',
  531. 'isYUV', 'focal_width_height', 'texture_video'],
  532. defines: ["#define SHADOWFULLFLOAT", "#define NUM_BONE_INFLUENCERS 0", "#define NUM_MORPH_INFLUENCERS 0"],
  533. samplers: ['shadowSampler', 'texture_video'],
  534. vertex:
  535. `
  536. precision highp float;
  537. varying vec3 ModelPos;
  538. attribute vec2 uv;
  539. attribute vec3 position;
  540. uniform mat4 view;
  541. uniform mat4 projection;
  542. uniform mat4 world;
  543. void main()
  544. {
  545. ModelPos = vec3( view * world * vec4(position , 1.0));
  546. gl_Position = projection * view * world * vec4(position , 1.0);
  547. }
  548. `,
  549. fragment: `
  550. precision highp float;
  551. varying vec3 ModelPos;
  552. uniform float isYUV; // false: 0, true: 1.0
  553. uniform sampler2D texture_video;
  554. uniform vec3 focal_width_height;
  555. vec2 SampleTex(vec3 pt3d)
  556. {
  557. return focal_width_height.x / focal_width_height.yz * pt3d.xy / pt3d.z + 0.5;
  558. }
  559. void main()
  560. {
  561. vec3 color = vec3(0,0,0);
  562. float shadow = 1.0;
  563. vec2 uv = SampleTex( normalize(ModelPos) );
  564. if( isYUV < 0.5 )
  565. {
  566. color = texture2D(texture_video, uv).rgb;
  567. }else{
  568. const mat4 YUV2RGB = mat4
  569. (
  570. 1.1643828125, 0, 1.59602734375, -.87078515625,
  571. 1.1643828125, -.39176171875, -.81296875, .52959375,
  572. 1.1643828125, 2.017234375, 0, -1.081390625,
  573. 0, 0, 0, 1
  574. );
  575. vec4 result = vec4(
  576. texture2D( texture_video, vec2( uv.x, uv.y * 0.666666 + 0.333333 ) ).x,
  577. texture2D( texture_video, vec2( uv.x * 0.5, uv.y * 0.333333 ) ).x,
  578. texture2D( texture_video, vec2( 0.5 + uv.x * 0.5, uv.y * 0.333333 ) ).x,
  579. 1
  580. ) * YUV2RGB;
  581. color = clamp(result.rgb, 0.0, 1.0);
  582. }
  583. if( uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 )
  584. {
  585. color = vec3(0,0,0);
  586. }
  587. gl_FragColor = vec4(shadow * color * 1.0, 1.0);
  588. }
  589. `
  590. }