0 votes

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,

in Engine by (16 points)

1 Answer

+1 vote

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:
http://docs.godotengine.org/en/stable/classes/class_texture.html
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.

by (27,166 points)

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories