|
@@ -1,10 +1,12 @@
|
|
|
import XVideoRawYUV from "./XVideoRawYUV"
|
|
|
import Logger from "./Logger.js"
|
|
|
|
|
|
+const planeWidth = 1728
|
|
|
+const planeHeight = 1080
|
|
|
|
|
|
window.generateRandomArray = ()=>{
|
|
|
var rnd=[];
|
|
|
- for(let i=0;i< 512*1024;i++)
|
|
|
+ for(let i=0;i< planeWidth*planeHeight;i++)
|
|
|
{
|
|
|
rnd[i] = Math.floor(Math.random()*255);
|
|
|
}
|
|
@@ -13,13 +15,14 @@ window.generateRandomArray = ()=>{
|
|
|
|
|
|
window.updateTexture = (yuv)=>
|
|
|
{
|
|
|
- let Y = yuv.subarray(0, 512*1024);
|
|
|
+ let Y = yuv.subarray(0, planeWidth*planeHeight);
|
|
|
window._videoRawYTexture.update(Y)
|
|
|
window._videoRawYTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
|
|
|
Y = undefined;
|
|
|
}
|
|
|
const yuv = new Uint8Array(window.generateRandomArray())
|
|
|
-
|
|
|
+const renderCount = 100;
|
|
|
+let sub = 0;
|
|
|
const logger = new Logger('XMaterial')
|
|
|
export default class XMaterialComponent {
|
|
|
constructor(e, t) {
|
|
@@ -135,37 +138,56 @@ export default class XMaterialComponent {
|
|
|
//(a = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
|
|
|
|
|
|
if(window.testPlane != null){
|
|
|
- if(window.testPlane.material == null){
|
|
|
- /*
|
|
|
- BABYLON.Effect.ShadersStore['customVertexShader'] = `
|
|
|
- precision highp float;
|
|
|
- attribute vec2 uv;
|
|
|
- attribute vec3 position;
|
|
|
- varying vec2 vUV;
|
|
|
- uniform mat4 view;
|
|
|
- uniform mat4 projection;
|
|
|
- uniform mat4 world;
|
|
|
- uniform mat4 worldViewProjection;
|
|
|
- void main()
|
|
|
- {
|
|
|
- vUV = uv;
|
|
|
- gl_Position = projection * view * world * vec4(position , 1.0);
|
|
|
- }
|
|
|
- `;
|
|
|
- BABYLON.Effect.ShadersStore["customFragmentShader"]=`
|
|
|
- precision highp float;
|
|
|
- varying vec2 vUV;
|
|
|
- uniform sampler2D chrominanceYTexture;
|
|
|
- void main()
|
|
|
- {
|
|
|
- vec2 uv = vUV;
|
|
|
- vec3 color = vec3(0,0,0);
|
|
|
- color = texture2D(chrominanceYTexture, uv).rgb;
|
|
|
- gl_FragColor = vec4( color, 1.0);
|
|
|
- }
|
|
|
- `;
|
|
|
-
|
|
|
+ // if(window.testPlane.material == null){
|
|
|
|
|
|
+ BABYLON.Effect.ShadersStore['customVertexShader'] = houseShader.vertex
|
|
|
+ // `
|
|
|
+ // precision highp float;
|
|
|
+ // attribute vec2 uv;
|
|
|
+ // attribute vec3 position;
|
|
|
+ // varying vec2 vUV;
|
|
|
+ // uniform mat4 view;
|
|
|
+ // uniform mat4 projection;
|
|
|
+ // uniform mat4 world;
|
|
|
+ // uniform mat4 worldViewProjection;
|
|
|
+ // void main()
|
|
|
+ // {
|
|
|
+ // vUV = uv;
|
|
|
+ // gl_Position = projection * view * world * vec4(position , 1.0);
|
|
|
+ // }
|
|
|
+ // `;
|
|
|
+ BABYLON.Effect.ShadersStore["customFragmentShader"]= houseShader.fragment
|
|
|
+ // `
|
|
|
+ // precision highp float;
|
|
|
+ // varying vec2 vUV;
|
|
|
+ // uniform sampler2D chrominanceYTexture;
|
|
|
+ // void main()
|
|
|
+ // {
|
|
|
+ // vec2 uv = vUV;
|
|
|
+ // vec3 color = vec3(0,0,0);
|
|
|
+ // color = texture2D(chrominanceYTexture, uv).rgb;
|
|
|
+
|
|
|
+ // // const mat4 YUV2RGB = mat4
|
|
|
+ // // (
|
|
|
+ // // 1.1643828125, 0, 1.59602734375, -.87078515625,
|
|
|
+ // // 1.1643828125, -.39176171875, -.81296875, .52959375,
|
|
|
+ // // 1.1643828125, 2.017234375, 0, -1.081390625,
|
|
|
+ // // 0, 0, 0, 1
|
|
|
+ // // );
|
|
|
+
|
|
|
+ // // vec4 result = vec4(
|
|
|
+ // // texture2D( chrominanceYTexture, vec2( uv.x, uv.y * 0.666666 + 0.333333 ) ).x,
|
|
|
+ // // texture2D( chrominanceYTexture, vec2( uv.x * 0.5, uv.y * 0.333333 ) ).x,
|
|
|
+ // // texture2D( chrominanceYTexture, vec2( 0.5 + uv.x * 0.5, uv.y * 0.333333 ) ).x,
|
|
|
+ // // 1
|
|
|
+ // // ) * YUV2RGB;
|
|
|
+
|
|
|
+ // // color = clamp(result.rgb, 0.0, 1.0);
|
|
|
+
|
|
|
+ // gl_FragColor = vec4( color, 1.0);
|
|
|
+ // }
|
|
|
+ // `;
|
|
|
+
|
|
|
window.testPlane.material = new BABYLON.ShaderMaterial(
|
|
|
'customShader',
|
|
|
this.scene,
|
|
@@ -175,32 +197,44 @@ export default class XMaterialComponent {
|
|
|
},
|
|
|
{
|
|
|
attributes: ['uv', 'position'],
|
|
|
- uniforms: ['view', 'projection', 'worldViewProjection', 'world'],
|
|
|
+ uniforms: houseShader.uniforms //['view', 'projection', 'worldViewProjection', 'world'],
|
|
|
},
|
|
|
- )*/
|
|
|
+ )
|
|
|
|
|
|
window._videoRawYTexture = BABYLON.RawTexture.CreateLuminanceTexture(
|
|
|
null,
|
|
|
- 512,
|
|
|
- 1024,
|
|
|
+ planeWidth,
|
|
|
+ planeHeight,
|
|
|
this.scene,
|
|
|
+ false,
|
|
|
true,
|
|
|
- true,
|
|
|
- )
|
|
|
+ )
|
|
|
|
|
|
- // window.testPlane.material.setTexture('chrominanceYTexture', window._videoRawYTexture)
|
|
|
+ // window.testPlane.material.setTexture('chrominanceYTexture', window._videoRawYTexture)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- window.testPlane.material = new BABYLON.StandardMaterial("xsttest",this.scene);
|
|
|
- window.testPlane.material.diffuseTexture = window._videoRawYTexture
|
|
|
+ window.testPlane.material.setTexture('texture_video', window._videoRawYTexture)
|
|
|
+ window.testPlane.material.setFloat('isYUV', 1)
|
|
|
+ window.testPlane.material.setVector3('focal_width_height', new BABYLON.Vector3(772.022491, planeWidth, planeHeight / 1.5))
|
|
|
+
|
|
|
|
|
|
+ // window.testPlane.material = new BABYLON.StandardMaterial("xsttest",this.scene);
|
|
|
+ // window.testPlane.material.diffuseTexture = window._videoRawYTexture
|
|
|
+
|
|
|
window.testPlane.material.backFaceCulling = false;//Allways show the front and the back of an element
|
|
|
- window.setInterval( ()=>{
|
|
|
- window.updateTexture( new Uint8Array(window.generateRandomArray()) );
|
|
|
- }, 60);
|
|
|
+
|
|
|
+ // window.updateTexture( new Uint8Array(window.generateRandomArray()) );
|
|
|
+ ++sub
|
|
|
+ if(sub< renderCount)
|
|
|
+ {
|
|
|
+ window._videoRawYTexture.update(stream)
|
|
|
+ window._videoRawYTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
|
|
|
+ }
|
|
|
+
|
|
|
+ // this.scene.meshes.forEach(mesh => {
|
|
|
+ // mesh.material != window.testPlane.material && (mesh.material = window.testPlane.material)
|
|
|
+ // })
|
|
|
}
|
|
|
- }
|
|
|
+ // }
|
|
|
}
|
|
|
}
|
|
|
);
|
|
@@ -530,4 +564,92 @@ export default class XMaterialComponent {
|
|
|
f.intensity = 0
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+var houseShader = {
|
|
|
+
|
|
|
+ attributes: ['uv', 'position'],
|
|
|
+
|
|
|
+ uniforms: ['view', 'projection', 'world',
|
|
|
+ 'isYUV', 'focal_width_height', 'texture_video'],
|
|
|
+
|
|
|
+ defines: ["#define SHADOWFULLFLOAT", "#define NUM_BONE_INFLUENCERS 0", "#define NUM_MORPH_INFLUENCERS 0"],
|
|
|
+
|
|
|
+ samplers: ['shadowSampler', 'texture_video'],
|
|
|
+
|
|
|
+ vertex:
|
|
|
+ `
|
|
|
+
|
|
|
+ precision highp float;
|
|
|
+
|
|
|
+ varying vec3 ModelPos;
|
|
|
+
|
|
|
+ attribute vec2 uv;
|
|
|
+ attribute vec3 position;
|
|
|
+
|
|
|
+ uniform mat4 view;
|
|
|
+ uniform mat4 projection;
|
|
|
+
|
|
|
+ uniform mat4 world;
|
|
|
+
|
|
|
+ void main()
|
|
|
+ {
|
|
|
+ ModelPos = vec3( view * world * vec4(position , 1.0));
|
|
|
+ gl_Position = projection * view * world * vec4(position , 1.0);
|
|
|
+ }
|
|
|
+
|
|
|
+ `,
|
|
|
+
|
|
|
+ fragment: `
|
|
|
+
|
|
|
+ precision highp float;
|
|
|
+
|
|
|
+ varying vec3 ModelPos;
|
|
|
+
|
|
|
+ uniform float isYUV; // false: 0, true: 1.0
|
|
|
+ uniform sampler2D texture_video;
|
|
|
+
|
|
|
+ uniform vec3 focal_width_height;
|
|
|
+
|
|
|
+ vec2 SampleTex(vec3 pt3d)
|
|
|
+ {
|
|
|
+ return focal_width_height.x / focal_width_height.yz * pt3d.xy / pt3d.z + 0.5;
|
|
|
+ }
|
|
|
+
|
|
|
+ void main()
|
|
|
+ {
|
|
|
+ vec3 color = vec3(0,0,0);
|
|
|
+ float shadow = 1.0;
|
|
|
+
|
|
|
+ vec2 uv = SampleTex( normalize(ModelPos) );
|
|
|
+
|
|
|
+ if( isYUV < 0.5 )
|
|
|
+ {
|
|
|
+ color = texture2D(texture_video, uv).rgb;
|
|
|
+ }else{
|
|
|
+ const mat4 YUV2RGB = mat4
|
|
|
+ (
|
|
|
+ 1.1643828125, 0, 1.59602734375, -.87078515625,
|
|
|
+ 1.1643828125, -.39176171875, -.81296875, .52959375,
|
|
|
+ 1.1643828125, 2.017234375, 0, -1.081390625,
|
|
|
+ 0, 0, 0, 1
|
|
|
+ );
|
|
|
+
|
|
|
+ vec4 result = vec4(
|
|
|
+ texture2D( texture_video, vec2( uv.x, uv.y * 0.666666 + 0.333333 ) ).x,
|
|
|
+ texture2D( texture_video, vec2( uv.x * 0.5, uv.y * 0.333333 ) ).x,
|
|
|
+ texture2D( texture_video, vec2( 0.5 + uv.x * 0.5, uv.y * 0.333333 ) ).x,
|
|
|
+ 1
|
|
|
+ ) * YUV2RGB;
|
|
|
+
|
|
|
+ color = clamp(result.rgb, 0.0, 1.0);
|
|
|
+ }
|
|
|
+ if( uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 )
|
|
|
+ {
|
|
|
+ color = vec3(0,0,0);
|
|
|
+ }
|
|
|
+ gl_FragColor = vec4(shadow * color * 1.0, 1.0);
|
|
|
+ }
|
|
|
+ `
|
|
|
}
|