binyan Posted July 6, 2014 Share Posted July 6, 2014 I'm using a custom material which is pretty similar to the ground material used in WorldMonger demo.The problem is that I don't get a shadows on it. Well it's not a big surprise, because I'm overriding the _effect property of the base material.The question is how can I get both my effect with a base material effect without copy-pasting the code from base material.I mean how can I get shadows while using additional effects? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 7, 2014 Share Posted July 7, 2014 If you want shadows in your own shader, you have to use the light.getShadowGenerator().getShadowMap() shadowMap Then do like in this shader:https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Shaders/default.fragment.fxfloat computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness){ vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w; vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5); if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0) { return 1.0; } float shadow = unpack(texture2D(shadowSampler, uv)); if (depth.z > shadow) { return darkness; } return 1.;} Quote Link to comment Share on other sites More sharing options...
binyan Posted July 7, 2014 Author Share Posted July 7, 2014 So as I understand there is no way to combine shaders? If I want to use 2 shaders I must create a new one which implements their both functionality? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 8, 2014 Share Posted July 8, 2014 Yep this is correct Quote Link to comment Share on other sites More sharing options...
jCarrasco Posted January 8, 2016 Share Posted January 8, 2016 Hi,Following this topic, I'm trying to get shadows in my custom shader, but can't manage to make it work.I setup a shadowGenerator and add the mesh to the render list. It know it works ok because with a StandardMaterial I can see the shadows. With my ShaderMaterial, I pass a mat4 lightMatrix0, a sampler2D shadowSampler0 and a vec3 shadowsInfo0 (I only want one light) I feed this data in the next way:customMaterial.setTexture("shadowSampler0", light.getShadowGenerator().getShadowMapForRendering());customMaterial.setMatrix("lightMatrix0", light.getShadowGenerator().getTransformMatrix());customMaterial.setVector3("shadowsInfo0", light.getShadowGenerator().getDarkness(), light.getShadowGenerator().getShadowMap().getSize().width, light.getShadowGenerator().bias);With this uniforms I feed the computeShadow function, as in the default shader code. I have tested lightMatrix0 and shadowsInfo0 have the correct values. But nothing is displaying. The returned value of computeShadow is always 1.0 Any idea on what am I missing? I have tried with .getShadowMapForRendering() and getShadowMap() and nothing works. Any clue? Quote Link to comment Share on other sites More sharing options...
jCarrasco Posted January 9, 2016 Share Posted January 9, 2016 By the way, this is what I get from getShadowMap(). Shouldn't it look more like a depth map? Quote Link to comment Share on other sites More sharing options...
igitz Posted December 5, 2017 Share Posted December 5, 2017 sorry to dig this up, but is this issue solved? is there a working example? the provided link does not work https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Shaders/default.fragment.fx Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted December 5, 2017 Share Posted December 5, 2017 hi @igitz we r on it this is happen after we get new typescript (npm) and we see some error in custom material that maybe take a time for ready new version of custom material Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 5, 2017 Share Posted December 5, 2017 It is now fixed https://www.babylonjs-playground.com/#3WN9C6#5 NasimiAsl 1 Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted December 5, 2017 Share Posted December 5, 2017 really thanks 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.