Changing Shader input in runtime

Hi guys, I have a question.

I want to create a day/night states in my game. It’s not really a problem as far as lightnning is concerned, however I also have a sky shader and I want to change the sky color in a task method. Is it possible to do such a thing? I tried using setShaderInput in the taks method but I get an error.

Well, what error message are you getting?
Are you setting the right shader input - the one you are referencing in your shader?

Yes, basically I just copy the command as it is from the setup method to my task method. And yet, the error I’m getting is:

 TypeError: Arguments must match one of:

setShaderInput(non-const NodePath this, const ShaderInput inp)
setShaderInput(non-const NodePath this, non-const InternalName id)
setShaderInput(non-const NodePath this, string id)
setShaderInput(non-const NodePath this, non-const InternalName id, const Vec4 v)

setShaderInput(non-const NodePath this, non-const InternalName id, const NodePat
h np)
setShaderInput(non-const NodePath this, non-const InternalName id, non-const Tex
ture tex)
setShaderInput(non-const NodePath this, string id, const Vec4 v)
setShaderInput(non-const NodePath this, string id, const NodePath np)
setShaderInput(non-const NodePath this, string id, non-const Texture tex)
setShaderInput(non-const NodePath this, non-const InternalName id, float n1)
setShaderInput(non-const NodePath this, string id, float n1)
setShaderInput(non-const NodePath this, non-const InternalName id, const Vec4 v,
 int priority)
setShaderInput(non-const NodePath this, non-const InternalName id, const NodePat
h np, int priority)
setShaderInput(non-const NodePath this, non-const InternalName id, non-const Tex
ture tex, int priority)
setShaderInput(non-const NodePath this, string id, const Vec4 v, int priority)
setShaderInput(non-const NodePath this, string id, const NodePath np, int priori
ty)
setShaderInput(non-const NodePath this, string id, non-const Texture tex, int pr
iority)
setShaderInput(non-const NodePath this, non-const InternalName id, float n1, flo
at n2)
setShaderInput(non-const NodePath this, string id, float n1, float n2)
setShaderInput(non-const NodePath this, non-const InternalName id, float n1, flo
at n2, float n3)
setShaderInput(non-const NodePath this, string id, float n1, float n2, float n3)

setShaderInput(non-const NodePath this, non-const InternalName id, float n1, flo
at n2, float n3, float n4)
setShaderInput(non-const NodePath this, string id, float n1, float n2, float n3,
 float n4)
setShaderInput(non-const NodePath this, non-const InternalName id, float n1, flo
at n2, float n3, float n4, int priority)
setShaderInput(non-const NodePath this, string id, float n1, float n2, float n3,
 float n4, int priority)

Well, it would be useful to show the line of code that it is choking on.
I’m guessing you didn’t supply enough parameters (You need to either pass a Vec4/VBase4 or four float values. The setShaderInput interface does not support passing float/float2/float3, you need to make it float4.)

When asking a question it’s always good to provide as much information as possible. :slight_smile:

Yeah, you’re right, here it is:

self.BlueLevel = 3
self.skyColor = Vec4(0.5, 0.5, self.BlueLevel, 0)
self.mySky.setShaderInput('mySky', self.skyColor )

It works perfectly, but if I take the 3rd line and copy it to another method, it gives me the error I wrote above.

The code looks correct.
Probably, when you moved that method and it was invoked, self.skyColor happened to be None (or something else) at that time.

I’ll look into that. Thanks. :slight_smile: