I try to use the Attr.LightColor but as I tested its value (outColor=LightColor) it seems to flicker and give random results depending on the camera movements instead of a uniform value
in UniforBinding.java, it says “The light color when rendering in multi pass mode”, so there is a pass for each light ?
how does it work, how can I tell witch light is used in the fragment shader ?
I saw in the repository LightColor is used as a material parameter, but I wanted to get the real color of each light
[edit : just noticed I had the same issue with Attr.AmbientLightColor]
any help ?
thanks
And by the way, those parameters are actually World Material Parameters and not Attributes.
you have to user WorldParam.LightColor and WorldParam.AmbientLightColor
but the compiler cannot find LightColor, LightPosition nor AmbientLightColor in WorldParam
they should be available as uniforms…
in the repository, shaders use “uniform vec4 g_LightPosition;” but no j3dm file define LightPosition
I dont get it
Caused by: com.jme3.material.plugins.MatParseException: Error On line 29 : lightPosition=WorldParam.LightPosition.xyz
->Could not find a World Parameter named LightPosition
how can I detecting the genre of light (point, directional…) for dir light, there is not light pos
how can I get the number of lights, cos if I blend them all I need to use some factor that sums to 1.0 in the end, or I just use an alpha factor for each pass and let it add up even if it saturates…?
If you want to make your own lighting shader, tbh I don’t recommend Shader nodes yet.
There might be issues with light data (it looks like from your post), and there is still a lot to do to make them a usabel solution.
You’d better make your own shader, and look how the lighting shader is done.
In multi pass mode, your shader is called once per light/per object rendered (actually for each vertex and for each pixel).
Light data is encoded and passed to the shader in Material.java here
There is a lot of legacy in this code that makes it inconsistent, but I won’t go into the details of why.
For directional lights, the direction is passed as the LigthPosition parameter (in the shader you have to declare it a g_LightPosition “g_” for global).
Pointlight has a position passed as LightPosition and the w component contains the inverse radius of the light.
LightDirection is set to 0.
Spot light had both LightPosition (with inv range like inv radius for point light in w component) and LightDirection with the spot angle cos encoded in the w component. see lighting.frag to see how to decode it.
Light type is encoded in the w component of the LightColor.
We are thinking of ways to enhance the rationale of all this for future versions of JME. Also we want to make it more flexible.
g_LightPosition is not an array. it’s a vec4.
Multipass does one render pass per geometry and per light, so in that mode you only have one light sent to the GPU.
yes but I now what it’s like to have a mountain of work to do, so I understand
my concern would be to be able to update the platform so it has the latest bug fixes
but without having regression on other parts of jme
Well it’s a bit complicated right now.
The changes I did were on several separate files in the engine, so you can’t just take the Generator class and hope for the best.
IMO the best way to do it is to pull the 3.0 branch and cherry pick the fixes from master.
There is a trick…we actually don’t know.
we pass the light type in the 4th channel of the lightColor. ( as @Paul_Culkin said)
if you look in lighting.frag the is a lightComputeDir function (maybe in the vert file actually)
this funciton does some math tricks to compute the light dirrection and attenuation. Attenuation just resolves to 0 if it’s a directional light or a spot light.
Then in the lighting.frag, we compute the spotfalloff for the spot light. The angle cosines are packed into the 4th channel of the lightDirection. The spot falloff also resolves to 0 for a directional light.
So basically we compute everything for any types of light. That’s a lot faster in a shader than doing branching to check the light type.