Xeonzinc Posted December 15, 2014 Share Posted December 15, 2014 Hi, I'm having a lot of fun working with the shaders, the tutorials around here are great! I'm stuck what I'm hoping is a simple problem • I have a X number of meshes (all the same), but each also contains a variable (say an integer from 1-100)• Currently i can create X versions of the material (passing the variable in the material constructor) - which then displays the texture differently on each object • I'm trying to create a single material which can take a property of the mesh it's applied to (and therefore only ever need to create one version of the material instead of X) I imagine this must be possible as the shader is already getting the position etc... of the mesh it is applied to, I just want to access another single variable, but have no idea how! Thanks, Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 15, 2014 Share Posted December 15, 2014 That's a good question actually! You can either inherit from ShaderMaterial and redefine the bind function to add your own code. But I'm thinking about adding a callback to allow you to do this easily like shaderMaterial.onBind = ... Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 15, 2014 Share Posted December 15, 2014 I added a material.onBind callbackYou will be able to do: myMaterial.bind = function(mat) {mat.getEffect().setColor3(...} Quote Link to comment Share on other sites More sharing options...
FreeFrags Posted December 18, 2014 Share Posted December 18, 2014 Maybe a noob question but whats the difference between the solution above and using: shadedMaterial.setFloat("myVar", 1.0); and defining this in your vertex shader uniform float myVar; Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 18, 2014 Share Posted December 18, 2014 Both work for me:) 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.