XMaterialComponent.js 29 KB

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