Activating a shader?

newmodelsnewmodels Posts: 479Member

So if I write a shader and it's great. But how can I activate it and and turn it off. Can I attach the shader onto the existing material as second pass, then detach it during script?

Comments

  • MegalomaniakMegalomaniak Posts: 3,788Admin

    Kinda depends on what you even mean by 'activating'?

  • newmodelsnewmodels Posts: 479Member

    Turning it off and on again! Lets say I wanted to display the shader in the event that I had a node selected by mouse. The shader draws a visual indicating the object is selected. But then I want to turn it off, because it's no longer selected. Would I just install the shader and then deinstall it from the object's shader material?

  • MegalomaniakMegalomaniak Posts: 3,788Admin

    Yes assigning it as another material pass would be one way to do it. But it would come at a cost of an extra draw call. Another way would be to expose a property in the shader that holds a value for it's state, then program the shader to do your effect conditionally.

  • newmodelsnewmodels Posts: 479Member

    I just realized, that if I add the shader it will cause all objects to highlight, not just the one. The developer news post in their blog for godot, said they where going to work on way to make it possible to color individual 3D objects. It can be done from script now, but it's hard to setup. I guess I'll have to use an icon hanging over the model.

  • cyberealitycybereality Posts: 1,657Moderator

    You can just assign a material (the one with the shader) to one object, and then assign it a standard material to turn it off. Look for how to set a material in GDScript.

  • TwistedTwiglegTwistedTwigleg Posts: 4,589Admin

    If you just need to override a single material in a single object, you could potentially use the material override property.

  • newmodelsnewmodels Posts: 479Member

    I was able to make it work like I wanted using material_orverride. Now I have a shader that shows that the object was clicked on.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file