【溫故知新】——BABYLON.js學習之路·前輩經驗
阿新 • • 發佈:2018-12-19
BABYLON.Effect.ShadersStore["customVertexShader"]= "\r\n"+ "precision highp float;\r\n"+ "attribute vec3 position;\r\n"+ "attribute vec2 uv;\r\n"+ "uniform mat4 worldViewProjection;\r\n"+ "varying vec2 vUV;\r\n"+ "void main(void) {\r\n"+ " gl_Position = worldViewProjection * vec4(position, 1.0);\r\n"+ " vUV = uv;\r\n"+ "}\r\n"; BABYLON.Effect.ShadersStore["customFragmentShader"]= "\r\n"+ "precision highp float;\r\n"+ "varying vec2 vUV;\r\n"+ "uniform sampler2D textureSampler;\r\n"+ "void main(void) {\r\n"+ " gl_FragColor = texture2D(textureSampler, vUV);\r\n"+ "}\r\n"; //---------------------------------------------------------------------- var shaderMaterial = newBABYLON.ShaderMaterial("shader", scene, { vertex: "custom", fragment: "custom", }, { attributes: ["position", "normal", "uv"], uniforms: ["world", "worldView", "worldViewProjection", "view", "projection"] }); var mainTexture = new BABYLON.Texture("amiga.jpg", scene); shaderMaterial.setTexture("textureSampler", mainTexture);