Snow Bars Posted August 29, 2016 Share Posted August 29, 2016 Hello. I try apply shader to simple object but have webgl warning and black model. On http://www.babylonjs.com/cyos/#1UJ9WV shader is work. Please tell me where error? I try place shaders in head of page like <script type="application/vertexShader" id="vertexShaderCode"> precision highp float; // Attributes attribute vec3 position; attribute vec2 uv; // Uniforms uniform mat4 worldViewProjection; // Normal varying vec2 vUV; void main(void) { gl_Position = worldViewProjection * vec4(position, 1.0); vUV = uv; } </script> <script type="application/fragmentShader" id="fragmentShaderCode"> precision highp float; varying vec2 vUV; uniform sampler2D textureSampler; void main(void) { gl_FragColor = texture2D(textureSampler, vUV); } </script> and call it like var amigaMaterial = new BABYLON.ShaderMaterial("amiga", $rootScope.scene, { vertexElement: "vertexShaderCode", fragmentElement: "fragmentShaderCode" }, { attributes: ["position", "normal", "uv"], uniforms: ["world", "worldView", "worldViewProjection", "view", "projection"] }); sphere1.material = amigaMaterial; Strange but on http://www.babylonjs-playground.com/#25OIA it not work totaly... Sory for my english... Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 29, 2016 Share Posted August 29, 2016 Here you go: http://www.babylonjs-playground.com/#25OIA#8 you cannot pass directly the shader code in, it is expecting a source. Also the uniforms, attributes did not match as well as the missing sampler and the texture definition :-) Quote Link to comment Share on other sites More sharing options...
Snow Bars Posted August 30, 2016 Author Share Posted August 30, 2016 Thanks Sebavan =) Work fine now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.