Hi folks!
I’m trying to wrap my head around how to create really basic shader (Phong-Blinn) in JME. How will I get the position of a light in the shader? I’ve specified “LightMode MultiPass” in my MatDef file but the uniform vec4 g_LightPosition is not set correctly. It works fine if I make the light position hardcoded into the shader…
what kind of light do you use? directional, point, spot?
Right now I’m using a PointLight in world space (5,5,5).
ok …it should work, it works for lighting.j3md.
you have to make sure :
- that you light is added to the scene graph (usually to the root node, or any sub nodes)
- that you have a vec4 g_LightPosition uniform declared in your shader. (x,y,z are position in world space w is 1/lightRadius)
if it doesn’t help, please post your material definition and your shader
Hmm, now it’s working. I found my problem:
Replace:
[java]vec3 LightDirection = (g_ViewMatrixg_LightPosition.xyz- g_WorldViewMatrix * pos).xyz;[/java]
with:
[java]vec3 LightDirection = (g_ViewMatrixvec4(g_LightPosition.xyz,1.0)- g_WorldViewMatrix * pos).xyz;[/java]
Thanks a lot for the clue. Is this sort of things (like the 1/lightRadius thing) documented somewhere or is it just common knowledge?
erm…It’s common knowledge among the core team… at least me and Kirril…
No, i admit there is a lack of documentation on this.
I’m gonna add this to the jme3 and shaders doc
haha,
I saw the newly written documentation on the wiki now
btw it made me realize some inconsistencies about how directional lights are handled…