saltemishel Posted August 24, 2016 Share Posted August 24, 2016 Hi All, I'm trying to implement this gradient shader from that post to my game but I kept having this error. The sample they provided is working well. I'm not sure where I'm going wrong here. I'm using babylon version 2.4. Thanks. VM3135:14 Uncaught TypeError: Cannot read property 'materials' of undefined BABYLON.Effect.ShadersStore.gradientVertexShader = "precision mediump float;attribute vec3 position;attribute vec3 normal;attribute vec2 uv;uniform mat4 worldViewProjection;varying vec4 vPosition;varying vec3 vNormal;void main(){vec4 p = vec4(position,1.);vPosition = p;vNormal = normal;gl_Position = worldViewProjection * p;}"; BABYLON.Effect.ShadersStore.gradientPixelShader = "precision mediump float;uniform mat4 worldView;varying vec4 vPosition;varying vec3 vNormal;uniform float offset;uniform vec3 topColor;uniform vec3 bottomColor;void main(void){float h = normalize(vPosition+offset).y;gl_FragColor = vec4(mix(bottomColor,topColor,max(pow(max(h,0.0),0.6),0.0)),1.0);}"; this.options={width:this.width,height:this.height,depth:this.depth}; this.mesh = BABYLON.MeshBuilder.CreateBox('box', this.options, wgl.game.currentScene); this.shader = new BABYLON.ShaderMaterial("gradient", this.scene, "gradient", {}); this.shader.setFloat("offset", 10); this.shader.setColor3("topColor", BABYLON.Color3.FromInts(0,119,255)); this.shader.setColor3("bottomColor", BABYLON.Color3.FromInts(240,240, 255)); this.mesh.material=this.shader; Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted August 24, 2016 Share Posted August 24, 2016 Hi @saltemishel I don't know anything about shaders, but it sounds lile something is wrong with your mesh. Try to comment out the line this.mesh.material=this.shader; And add this line right above it: console.log(this.mesh); Then check what it outputs in your browser console. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 24, 2016 Share Posted August 24, 2016 Hello, Yes, the setup is probably wrong cause your material is working: http://www.babylonjs-playground.com/debug.html#1D09LK#2 I am suspecting wgl.game.currentScene against this.scene in your setup. saltemishel 1 Quote Link to comment Share on other sites More sharing options...
saltemishel Posted August 25, 2016 Author Share Posted August 25, 2016 Ow! It works! Thanks for the guidance! 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.