Modify textures color and alpha values dynamically

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pakchano
:warning: Old Version Published before Godot 3 was released.

I’m trying to modify the diffuse texture of a VideoPlayer and some Image textures through code, the inspector is not an option since I want to this dynamically.
Textures for both 2d and 3d objects, videos, and images should work the same according to the Godot Docs 2.1 (Texture).

This is what I have (works!):

var texture = player.get_video_texture()
# create a new fixed material
var material = FixedMaterial.new()
# assign the new texture
# TODO: add transparency to diffuse material
material.set_texture(FixedMaterial.PARAM_DIFFUSE, texture)
material.set_flag(Material.FLAG_UNSHADED, true)
# set the texture of the object to the new material
set_material_override(material)

Currently I’m setting a VideoTexture to a FixedMaterial and then adding it to my object. But, before setting the material/texture I would like to modify the opacity of the diffuse material to make the video see through.

Also if someone could explain what are the texture.set() functions for. And what are the available parameters, couldn’t find them anywhere.

Side note: Would be extremely helpful to update the documentation and make it more thoroughly for beginners. Can do it myself once this issue is solved.

Thank you kindly in advance,

:bust_in_silhouette: Reply From: Zylann

Maybe you can do it this way:

material.set_fixed_flag(FixeMaterial.FLAG_USE_ALPHA, true)

And then set the alpha in the color specified for PARAM_DIFFUSE.
http://docs.godotengine.org/en/stable/classes/class_fixedmaterial.html

Which Texture.set() functions are you talking about? All functions are listed here, and in inherited classes:

They are just lacking some examples IMO, it’s not obvious for a complete beginner to guess that they have to provide one of those constants as parameter of a function.

Thanks @Zylann,

I have modified the alpha color with the following:

 # set color to white and alpha to 0.5
 material.set_parameter(0, Color(1,1,1,0.5))

And yes, as you said a lot of this is in the docs but without examples.
Even setting the color material took me a while to complete.
Just picked up Godot a week ago.

pakchano | 2017-08-01 17:56