Thibault Posted May 9, 2018 Share Posted May 9, 2018 Hello, I've searched and didn't find an answer, apologize if it was already asked, I'm fairly new to the shader world. I'm working on a custom material shader for a height ground mesh that gets a different texture depending on elevation , slope ... I have a prototype working, but now I want to add some light to my scene and I'm struggling to figure out how to replicate the same behaviour as the standard material fragment shader. I have only one Hemi Light in my scene and I want only diffuse lighting, I tried to do as the Phong example in the CYOS, compute the angle between normal and light vector, and it works, but this is behaving like a PointLight, not HemiLight Here is the example with StandardMaterial (the lighting I want): https://tdurand.github.io/3d-experiments/postlighting-withstandardmaterial.html Here is the example with my CustomMaterial: https://tdurand.github.io/3d-experiments/postlighting-withcustommaterial.html The shader code: https://github.com/tdurand/3d-experiments/blob/gh-pages/terrain.fragment.fx#L22 Could you point me to some ressources to get the fragment shader behave like the standard material for an HemiLight ? What is exactly the difference between an HemiLight and a point light far away? I tried to investigate the code of the standard material fragment shader without success for now: https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/default.fragment.fx Thanks, Thibault Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted May 9, 2018 Share Posted May 9, 2018 http://cyos.babylonjs.com/#B0VYMZ Maybe I should read... you already did this my bad. Quote Link to comment Share on other sites More sharing options...
Thibault Posted May 9, 2018 Author Share Posted May 9, 2018 Yes I already tried this great example . I think my main question is how to modify this to take in input an Hemi Light and not a Point Light Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted May 10, 2018 Share Posted May 10, 2018 https://github.com/hughsk/glsl-hemisphere-light/blob/master/index.glsl Quote Link to comment Share on other sites More sharing options...
Thibault Posted May 10, 2018 Author Share Posted May 10, 2018 Great ! thanks, I'll give it a shot tomorrow and I'll let you know Quote Link to comment Share on other sites More sharing options...
Thibault Posted May 10, 2018 Author Share Posted May 10, 2018 Really good, for the record the hemi light is mixing influence of both ground and light source. I could replicate the same effect as in Standard material by setting the ground color to black and the sky to white. The crucial part of the fragment shader was: // Compute diffuse weight from normal and light vector float diffuseWeight = 0.5 * dot(vNormalW, lightVectorW) + 0.5; // Mix black, white with our diffuse weight vec3 diffuseColor = mix(vec3(0.0,0.0,0.0), vec3(1.0,1.0,1.0), diffuseWeight); // Apply diffuse effect to final color gl_FragColor = color * vec4(diffuseColor, 1.0); Thanks a lot Pryme8 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.