Kesshi Posted May 17, 2016 Share Posted May 17, 2016 It seems that BabylonJs uses the DirectX convention for normal maps. The problem is that our material database uses the OpenGL convention. The bump direction seems to be inverted now in BabylonJs. How can i switch between OpenGL and DirectX normal maps in BJS? I think the green(y) channel needs to be flipped in order to convert between OpenGL and DirectX normals. I would like to prevent a conversion of our material database because our whole toolchain is based on OpenGL conventions. Would it be possible to add a flag to the material/texture to switch between opengl and directx normal maps? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 18, 2016 Share Posted May 18, 2016 Did not test it but can you try to set bumpTexture.level = -1 ? Quote Link to comment Share on other sites More sharing options...
Kesshi Posted May 18, 2016 Author Share Posted May 18, 2016 4 hours ago, Deltakosh said: Did not test it but can you try to set bumpTexture.level = -1 ? I tried that already. It doesn't work correctly. The direction of the incoming light is also inverted. here a playground: http://www.babylonjs-playground.com/#17QZZM You need to uncomment line 13. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 18, 2016 Share Posted May 18, 2016 here is a way for you to fix it: http://www.babylonjs-playground.com/#17QZZM#1 Quote Link to comment Share on other sites More sharing options...
Kesshi Posted May 18, 2016 Author Share Posted May 18, 2016 1 hour ago, Deltakosh said: here is a way for you to fix it: http://www.babylonjs-playground.com/#17QZZM#1 Thx for your answer. I was thinking about doing it manually with canvas already ... i will keep it in mind as a last resort :-) I was hoping for direct support for different normal maps in babylon js. This could be done with a small define in the default fragment shader i think. BJS would benefit from supporting different kinds of assets without the need for conversion. It would be more universal this way. dbawel 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 18, 2016 Share Posted May 18, 2016 That's true. It was more a fast fix for you. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 18, 2016 Share Posted May 18, 2016 Done: http://www.babylonjs-playground.com/#17QZZM#2 Kesshi 1 Quote Link to comment Share on other sites More sharing options...
Kesshi Posted May 19, 2016 Author Share Posted May 19, 2016 @Deltakosh a very big thank you to you. This makes thing much easier for me. Quote Link to comment Share on other sites More sharing options...
Kesshi Posted May 19, 2016 Author Share Posted May 19, 2016 @Deltakosh i just tried your change but it is not working as expected. It was correct to invert the y component but it seems that also the x component must be inverted. I dont know which convention you implemented for the normal mapping in BabylonJs but it doesn't seem to be DirectX. Here a playground: http://www.babylonjs-playground.com/#17QZZM#3 The light is coming from top-left (see the sphere) but the light on the bump map is coming from top-right. Could you change it please that if useOpenGLNormalMap = true the x and y compenten is inverted? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 19, 2016 Share Posted May 19, 2016 THis is what I did: https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/ShadersInclude/bumpFragmentFunctions.fx#L31 Quote Link to comment Share on other sites More sharing options...
Kesshi Posted May 19, 2016 Author Share Posted May 19, 2016 1 hour ago, Deltakosh said: THis is what I did: https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/ShadersInclude/bumpFragmentFunctions.fx#L31 You flipped y which is correct. But as you can see in my playground, its not enough to support opengl normal maps correctly. x also need to be flipped. So it would be nice if you could flipp x and y. Or even better add two flags to the material, one for x and one for y. This way all kind of normal maps can be supported. i just checked it with CrazyBump:OpenGL x-axis = right y-axis = upDirectX x-axis = right y-axis = downBabylonJS x-axis = left y-axis = down Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 19, 2016 Share Posted May 19, 2016 Boom! http://www.babylonjs-playground.com/#17QZZM#4 Kesshi 1 Quote Link to comment Share on other sites More sharing options...
Kesshi Posted May 19, 2016 Author Share Posted May 19, 2016 Thank you again, maybe i need to send you some flowers or something Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 20, 2016 Share Posted May 20, 2016 Lol..a thank you is enough Quote Link to comment Share on other sites More sharing options...
dbawel Posted May 20, 2016 Share Posted May 20, 2016 @Deltakosh and @Kesshi On 5/19/2016 at 1:32 PM, Kesshi said: Thank you again, maybe i need to send you some flowers or something - Do I see new love blooming here? Too funny, and glad to see you on the forum. We all feel the love for DK. GameMonetize 1 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.