[UPBGE0.36]Render to Texture (Python)

Опубликовано: 05 Май 2026
на канале: Blender [BGE] (Light Rays Underwater)
138
9

Download .blend's files
https://drive.google.com/drive/folder...

##############################################
import bge

def create_texture_camera():
scene = bge.logic.getCurrentScene()

Get the camera and the object that will show the texture
texture_camera = scene.objects.get('Camera_Texture')
object_with_texture = scene.objects.get('Plane')

if not texture_camera or not object_with_texture:
print("Camera or Plane object not found!")
return None

Use the correct material name from the debug output
material_id = bge.texture.materialID(object_with_texture, "MAMAMAMaterial")

if material_id == -1:
print("Material not found or incorrect material name!")
return None

Create the texture render object
render_to_texture = bge.texture.Texture(object_with_texture, material_id)

Set up the texture camera to render to this texture
render_to_texture.source = bge.texture.ImageRender(scene, texture_camera)

Force a texture refresh
render_to_texture.refresh(True)

Return the created texture object
return render_to_texture


def main():
cont = bge.logic.getCurrentController()
own = cont.owner

Check if the texture has been created already, if not, create it
if 'render_texture' not in own:
render_texture = create_texture_camera()
if render_texture:
own['render_texture'] = render_texture
else:
print("Failed to create texture!")
return

Refresh the texture every frame
own['render_texture'].refresh(True)

main()