Why does this basic Shader Node fail?

Ah, I forgot about the properties panel.

Also thank you for investigating.

I’ve got another problem:

This time, I’m trying to use the LightDirection WorldParameter and it’s always 0.
I confirmed this with a basic MoveNode which, well, moves stuff based on the input. If I select LightDirection as input, my model doesn’t move.

I’ve added ‘LightMode MultiPass’ directly under the ‘Technique {’ line manually.
My test scene has a directional light, which is confirmed by a neighbouring model using the common Lighting.j3md.

Should I go furhter into detail on my situation or can you provide me with a simple working example using LightDirection?

The only one i know is Lighting.j3md.
I’ll look into this.

Thank you.

I really want to try it, because I think it’s the last thing separating me from a shader for DirectionalLighting using ShaderNodes :slight_smile:

Oh my god.

I just solved it.
My shader was correct.

But somewhere in the docs I found:

g_LightPosition : the position of the light use for DirectionalLight : strangely enough it's used for the direction of the light…this might change though.

What the fuck?!
I often say how awesome this community is and how fast and good questions get answered. Which is true. Great work guys; I really mean it!

But it’s stuff like this that sometimes annoyes the heck out of me.
Why can’t just be the light direction in LightDirection?! Or some notice appear somewhere that for DirectionalLighting this is reversed?

Ahrg…

Please forgive me my little rant. I’m just upset that the cause was this trivial on the one hand and this hard to find on the other.

Sorry, I knew about that.
But for the record you were talking about AmbientLightColor from the beginning, you never mentioned g_LightPosition. It may seems obvious to you but describing the obvious may get you correct answers faster.

The history of this thing is that when the lighting shader was implemented, only point and directional light were implemented.
One need the light direction and the other the light position. Since both of those variable are vec3 and, for the sake of optimization the same variable has been used. And it was called g_LightPosition.

Then one day I implemented spot light … and spot light need both position and direction. So I introduced a second variable g_LightDirection and to avoid breaking user code I did not change the DirectionalLight inconsistency.

But that’s good you’re talking about it because 3.1 is gonna break user code anyway. So I’m gonna change this.

@nehon said:

Since both of those variable are vec3 and, for the sake of optimization the same

Drivers are allowed to remove unused uniforms. I know that my OSX do it. Don’t know about mobile but for desktop I don’t think there was any optimization achieved :slight_smile:

There was in the shader code. Because what ever the light type the relevant data was in the same variable.
This avoided branching in the shader.

@nehon said: There was in the shader code. Because what ever the light type the relevant data was in the same variable. This avoided branching in the shader.

Aaah, I see. That makes sense.

@m41q said: I've got another problem:

This time, I’m trying to use the LightDirection WorldParameter and it’s always 0.
I confirmed this with a basic MoveNode which, well, moves stuff based on the input. If I select LightDirection as input, my model doesn’t move.

@m41q said: Should I go furhter into detail on my situation or can you provide me with a simple working example using LightDirection?
@nehon said: But for the record you were talking about AmbientLightColor from the beginning, you never mentioned g_LightPosition.

For the record, I was talking about AmbientLightColor from the beginning, but then made a post about LightDirection. Maybe I should’ve split the thread…

Anyways, it’s okay. I fixed it in my code and you’ll fix it in 3.1, so everything’s good now.

Well sorry I might have slip through the post and my brain replaced LightDirection with AbientLightColor

1 Like

I finished my Directional Lighting Shader using shader nodes:

The result:

It supports diffuse and and specular lighting as well as different light colors and and a diffuse color. Since it’s made with ShaderNodes, this is easily tweakable however.

My implementation is very simple and basic. However if someone else wants to use it/improve it, I can of course upload the Nodes as well as the final .j3md.

2 Likes

Cool!! nice work