1. 程式人生 > >【溫故知新】——BABYLON.js學習之路·前輩經驗

【溫故知新】——BABYLON.js學習之路·前輩經驗

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 = new
BABYLON.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);