xushiting 3 tahun lalu
induk
melakukan
74f4846ca9
1 mengubah file dengan 57 tambahan dan 4 penghapusan
  1. 57 4
      src/XMaterialComponent.js

+ 57 - 4
src/XMaterialComponent.js

@@ -139,9 +139,61 @@ export default class XMaterialComponent {
                 //(a = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
 
                 if(window.testPlane != 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){
-                        window.testPlane.material = new BABYLON.StandardMaterial("xsttest",this.scene);
-                        window.testPlane.material.backFaceCulling = false;//Allways show the front and the back of an element
+                        //window.testPlane.material = new BABYLON.StandardMaterial("xsttest",this.scene);
+                        window.testPlane.material = new BABYLON.ShaderMaterial(
+                            'customShader',
+                            this.scene,
+                            { 
+                              vertex: "custom",
+                              fragment: "custom",
+                            },
+                            {
+                              attributes: ['uv', 'position'],
+                              uniforms: ['view', 'projection', 'worldViewProjection', 'world'],
+                            },
+                          )
+
 
                         window._videoRawYTexture = BABYLON.RawTexture.CreateLuminanceTexture(
                             null,
@@ -152,8 +204,9 @@ export default class XMaterialComponent {
                             true,
                           )
 
-                        window.testPlane.material.diffuseTexture = window._videoRawYTexture
-
+                        //window.testPlane.material.diffuseTexture = window._videoRawYTexture
+                        window.testPlane.material.setTexture('chrominanceYTexture', 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);