captainleighwalker Posted May 17, 2018 Share Posted May 17, 2018 Hi I have a black and white .jpg image since .png is a bit too big file size. I need to use the black from the image but programmatically make it a different colour (mask). I assume I can still use the normal diffuse colour 'below'? Is this possible? This is to make different colour wood and grain. Thanks in advance Quote Link to comment Share on other sites More sharing options...
Guest Posted May 17, 2018 Share Posted May 17, 2018 We need more info can you try to create a sample on the PG to demonstrate what you want to achieve? Quote Link to comment Share on other sites More sharing options...
captainleighwalker Posted May 17, 2018 Author Share Posted May 17, 2018 (I've just realised I did use a png in 2D on canvas but black and white jpg would be nice ?) It would be very hard to make anything in PG as this is my problem! I'm sure you will understand if I show you in 2D on canvas img = "grain with transparency.png"; var grainCanvas = document.createElement("canvas"); grainCanvas.width = img.naturalWidth; grainCanvas.height = img.naturalHeight; var grainContext = grainCanvas.getContext("2d"); grainContext.drawImage(img, 0, 0); grainContext.globalCompositeOperation = 'source-in'; grainContext.fillStyle = "grain colour"; grainContext.fillRect(0, 0, grainCanvas.width, grainCanvas.height); Then use this canvas as the texture for the material and let the diffuse show through under it. (which is one solution but I would prefer not to make a canvas - just use Babylon textures) Quote Link to comment Share on other sites More sharing options...
Guest Posted May 17, 2018 Share Posted May 17, 2018 I guess then DynamicTextures: http://doc.babylonjs.com/how_to/dynamictexture Quote Link to comment Share on other sites More sharing options...
captainleighwalker Posted May 17, 2018 Author Share Posted May 17, 2018 I'm sure that will do the job thanks. ? GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
captainleighwalker Posted May 18, 2018 Author Share Posted May 18, 2018 Well I've tried! I've made the texture the same size as my bump texture but it seems like the cords are not the same or something? What's missing here? Also I take it you have to set has Alpha to show the diffuseColor below? var texture = new BABYLON.DynamicTexture("slabOutsideTexture", { width: img.naturalWidth, height: img.naturalHeight }, scene); var context = texture.getContext(); context.fillStyle = "white"; context.fillRect(0, 0, img.naturalWidth, img.naturalHeight); context.drawImage(img, 0, 0); Quote Link to comment Share on other sites More sharing options...
captainleighwalker Posted May 18, 2018 Author Share Posted May 18, 2018 This is with uv texture squares map. You can see bump is mapping ok but not texture? Quote Link to comment Share on other sites More sharing options...
captainleighwalker Posted May 18, 2018 Author Share Posted May 18, 2018 I assume the problem is the texture cant tile? Quote Link to comment Share on other sites More sharing options...
Guest Posted May 18, 2018 Share Posted May 18, 2018 The texture can tile..can you make sure that texture.coordinatesIndex is the same as the bump texture Also can you create a repro on the playground? it will be far easier to fix it for you then Quote Link to comment Share on other sites More sharing options...
captainleighwalker Posted May 18, 2018 Author Share Posted May 18, 2018 Finally got a PG Repro. My format code doesn't seem to work. coordinatesIndex is 0 for both textures. https://www.babylonjs-playground.com/#WFLKH#55 You will see it maps ok if applying texture directly. Quote Link to comment Share on other sites More sharing options...
Guest Posted May 18, 2018 Share Posted May 18, 2018 Ok now we talk https://playground.babylonjs.com/#WFLKH#58 The dynamic texture is in clamp mode by default Quote Link to comment Share on other sites More sharing options...
captainleighwalker Posted May 18, 2018 Author Share Posted May 18, 2018 Thanks, it works in chrome but its just black in ie and Edge? Quote Link to comment Share on other sites More sharing options...
Guest Posted May 21, 2018 Share Posted May 21, 2018 Pinging @trevordev who should be able to help Quote Link to comment Share on other sites More sharing options...
trevordev Posted May 21, 2018 Share Posted May 21, 2018 @captainleighwalker this is because Edge is using webGL 1.0 which does not support non-power of two texture width/height (Unfortunately no webGL warning was displayed in console to tell you this). If you use an image with a size of 256 for example this will should work. See https://playground.babylonjs.com/#WFLKH#63 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.