zhouenguang 3 роки тому
батько
коміт
064ebe4108
1 змінених файлів з 45 додано та 3 видалено
  1. 45 3
      src/XMaterialComponent.js

+ 45 - 3
src/XMaterialComponent.js

@@ -4,7 +4,7 @@ import Logger from "./Logger.js"
 
 window.generateRandomArray = ()=>{
     var rnd=[];
-      for(let i=0;i< 720*1280;i++)
+      for(let i=0;i< 720*1728;i++)
       {
           rnd[i] = Math.floor(Math.random()*255);
       }
@@ -140,7 +140,48 @@ export default class XMaterialComponent {
 
                 if(window.testPlane != null){
                     if(window.testPlane.material == null){
-                        window.testPlane.material = new BABYLON.StandardMaterial("xsttest",this.scene);
+                        
+                        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); 
+                            }
+                        `;
+
+                        // 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.testPlane.material.backFaceCulling = false;//Allways show the front and the back of an element
 
                         window._videoRawYTexture = BABYLON.RawTexture.CreateLuminanceTexture(
@@ -152,7 +193,8 @@ 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.setInterval( ()=>{
                             window.updateTexture( new Uint8Array(window.generateRandomArray()) );