Change the texture through the texture index (slots)

I saw in the cubemap shader the link to the texture index … can I change the textures that are already in the index using Python?
For when the cursor on the plane - the text has changed to “B”, outside the plane again “A”…

test example - test.blend (480 KB)

Thank you for attention.

A brief skim throuh the api hints this cant be done in bfbge. However, it can be done in UPBGE by setting the bindCode of the texture:

  • OK, but if through the shader you can assign textures (like the Cubеmap from Martins Upitis) - the diff, lightmap, normal … then you can reboot the shader and change the textures themselves.
    If someone would help to do this - the shader “texture change” from the texture slot … It’s all real, but not for me.
    to UPBGE yet do not want to go, I’m waiting for Blender 2.8

This code would do that would work independently - that’s all.

mesh = own.meshes[0]
for mat in mesh.materials:
    shader = mat.getShader()
    if shader != None:
        if not shader.isValid():
            shader.setSource(VertexShader, FragmentShader, 1)
        shader.setUniformDef('ModelMatrix', g.MODELMATRIX)
        shader.setUniformDef('cameraPos', g.CAM_POS)

Thank you for your reply.

Here I tried to switch in real time between the two shader from Martins Upitis - everything works, even the eye does not notice the transition. So how can I throw out Cubemap from Cubemap shader? :smiley:
And you do not know if hypothetically to create a texture shader, it did not work faster than simple (default) texturing?

So yes, if you use a custom GLSL shader then you can switch the uniform definitions. This doesn’t switch the texure slots, it switches the images sampled from the shader side. (Effectively).
So you can do this just by re-running the 'setSampler('uniformName, tex_slot) lines - changing the integer (which is the texslotid)

But in BFBGE you cannot do so for normal materials, and if i remember corectly, there were some odd thing when doing so in UPBGE.

  • OK, but I do not know how to do it. I saw how Goran Milovanovic wrote a parallax shader - custom parallax … here he was able to do this, for him it’s like a morning warm-up. And my brains is out:no:. And if solve such a question, is this the easiest way to switch between textures of different resolutions?

p.s. so you can do this just by re-running the 'setSampler('uniformName, tex_slot) lines - changing the integer (which is the texslotid) - are you sure that this is addressed to me?:eek:

You should know, that in 2.8, there might not be any BGE.

  • that is - absolutely none? Or will there be a slightly different theme with the game engine? Where does this information come from?

Probably, then a lot of people will come to Holland, and they will all be long and tiring conversations, explain to one person that the BGE should be live - maybe using the legs …
Tone, do not do this … otherwise we will remember you. :no: And when I remember you, I’ll listen to Metallica - Unforgiven

different resolutions

Why do you want to change your texture resolution. If it’s to save RAM/VRAM, then you should load the needed one from disk using bge.texture.ImageFFMPEG(), and dump it in the correct texture slot. Having them in different texture slots means that both will be in RAM/VRAM all the time. The code to replace a texture with one from disk is:

def show_picture(obj, path, mat_id=0, tex_id=0):
    '''Loads a picture into a texture'''
    # The texture has to be stored in a place associated with other game data
    # so we store it in a game property. This name inlucdes the mat ID's and
    # tex ID's so that a single object with a complex setup does not have the
    # textures overwrite each other.
    # If a bge.texture object already exists for this object/mat_id/tex_id, then
    # we retrieve that.
    prop_name = 'SHOW_PICTURE{}:{}'.format(mat_id, tex_id)
    if prop_name not in obj:
        tex = bge.texture.Texture(obj, mat_id, tex_id)
        obj[prop_name] = tex
        tex = obj[prop_name]

    # Load the image from the path
    raw = bge.texture.ImageFFmpeg(os.path.join(path))

    # Check to see that it loaded
    if raw.status == bge.texture.SOURCE_ERROR:
        # Error in loading image
        bge.log.error("Unable to load image at {}".format(path))
        raise ValueError("Unable to load image at {}".format(path))

    # Assign the new image to the texture and update the texture.
    tex.source = raw

Be aware that this is slow (reading from disk) so it not suitable for doing at run-time.

If you want to do it at run-time, say, based on distance - you can use a node shader to fade between images based on camera distance. I don’t have a demo of this handy, but can make you one if you like.

  • this is to change the localization (texture) and texture quality in future games.
    Here’s how I did it - simple multilanguage interface
    But your code seems to me more relevant - then I’ll explore it, now there is no time. When I investigate and test your code, I will definitely subscribe.
    Thank you for attention.

Be careful to end any custom textures that you load in python. BGE doesn’t always clean up after itself when you’re using the texture module to set textures and the result can be a hard crash of Blender when it tries to exit. (blender 2.7x)

From the conversations between the Upbge devs and Ton. But if any GE comes back, it will be UpBge.

  • As if … thanks for the warning, but what to do, that it did not happen?
  • The Ton is very strange, he’s like that girl on his first date - he wants to, then he does not. Or just loves intrigues … and then brazenly smiles, like - “here you are fools!”. :wink: This is a simple trolling, with the enjoyment of the public’s confusion.:stuck_out_tongue: …God of Blender! Oh, huh.

Well the bge will be removed and replaced with a new one. :slight_smile:

  • well, you said it… dude! Delete, and return back … this is called an upgrade - one small word - upgrade! And how many scribbles … Are you by any chance a friend of Ton? You also take out the brains like he does :).

Nope, but from conversation with a lot of hints. :slight_smile: But i was hoping for UPBGE to replace bge in 2.8…

  • come on man… :no:

What do you mean?