cycles image texture sequence?

is it possible in cycles to use an image sequence for a texture in cycles?

The answer seems to be no for now, unfortunately. I’m also waiting for this to be implemented. Really eagerly, actually :slight_smile: Does anyone know when we can expect it to show up in build? From a technical standpoint I guess it isn’t a very complicated fix?

I’m planning on using animated textures in a music video project, and I’m checking for updates on this daily. Reeeally want to get started! I’m new to the community so I don’t really know how to stay updated on what features are being worked on and what the priorities are and stuff like that. I’d hate to keep this video project on hold if it means waiting forever on a feature that no one but me cares about…

i had a rush job. i was doing and in my brain i was going to use cycles. what i did was to render the moving textures in blender internal and mask it, come up with some sort of DOF that matched the cycles and DOF and then composited them all back it worked.

I thought about doing that, but it won’t work in my case. I need to feed the video texture through a glass material, and the internal renderer isn’t up to it. I need refraction and stuff. I’m fairly desperate at this point. I would gladly pay someone to implement this feature… But where should I ask? Or is there some other way? Some other free or non-expensive renderer that I could use?

How about a dirty workaround until it’s implemented?

Write a batchfile or shellscript or whatever your OS provides that does this:

for i = 0 to frames
{
copy /imagesequence/frame_[i].png /renderproject/textures/movietexture.png
blender do your render
}

Just overwrite the dummy source texture for each frame you render with the matching image from your image sequence?

Sounds really interesting! I’m on Mac OSX, can it actually be done? I pretty much know my way around scripting languages, but I’ve never scripted any os actions like that before. Can you give me a starting point?

Only, this makes it really hard to preview the animation since you can’t scrub the timeline and see the texture update. It’s back to rendering in the dark.

Hmm. Excuse the noobish question (I am new user), but can’t this be done entirely with a Python script within Blender? It sounds like it should be so simple.

I finally had some time over to experiment with this, and I’ve managed to implement animated textures using Python!

This is a pretty crude first draft of the script, but it works surprisingly well, at least for my purposes. I tried importing a 10 second 29fps image sequence, and it plays along fine without any noticeable lagging or anything. It renders perfectly as well.

import bpy
import os

#load images from folder 
directory = "/bla/bla/bla/bla/" 
files = os.listdir(directory)

seq_image_names = []
for file in files:
    bpy.ops.image.open(filepath = directory + file)
    seq_image_names.append(file)

#append the newly loaded images in the list 'sequence_images'
sequence_images = []
for img_name in seq_image_names:
    for img in bpy.data.images:
        if img_name == img.name:
            sequence_images.append(img)

print("image sequence:")
for seq_img in sequence_images:
    print(seq_img.name) 

#search for objects with custom property "anim" 
anim_texture_objects = []
for obj in bpy.data.objects:
    if "anim" in obj:
            anim_texture_objects.append(obj)
            
#search for image texture nodes named "anim"
anim_texture_nodes = []
for obj in anim_texture_objects:
    for node in obj.active_material.node_tree.nodes:
        if node.name == "anim":
            anim_texture_nodes.append(node)

#frame change listener
def onFrameChange(scene):
    for node in anim_texture_nodes:
        node.image = sequence_images[scene.frame_current % len(sequence_images)]

#add frame change listener once
if len(bpy.app.handlers.frame_change_pre) is 0:
    bpy.app.handlers.frame_change_pre.append(onFrameChange)
else:
    bpy.app.handlers.frame_change_pre[0] = onFrameChange

So the script loads all the images from a folder, and puts them in a list. It then looks for an object in the scene that has a custom property named “anim”, and checks for image texture nodes named “anim” on that object’s material. Then it just steps through the images on the “frame change” event.

There are some limitations, of course. You can’t have more than one animated texture at this point. I guess you could set it up by naming the texture nodes differently and have different sequences linked to them or something, but that will have to wait. :slight_smile: This is a pretty good starting point though, and I’m pretty psyched that I got it to work at all. Please note that I’m completely new to both Blender and Python, so yeah. Feel free to improve on it!

I haven’t gotten into python with blender, but would like to do a video texture in cycles. Can you explain how to implement this script?

Thanks.

Absolutely. It should be pretty simple.

  1. Prepare a folder with alphabetically ordered images (e.g. image_0000.jpg, image_0001.jpg, image_0003.jpg).

  2. Copy the above script and paste it in Blenders text editor. Change the directory variable on row 5 so that it points to your folder. It needs to be the full path. In my case, on my Mac, it looks something like “/Users/tommypreger/Documents/Blender/Project/anim/”. Don’t forget the last “/”. (Question for python veterans: According to docs, bpy.ops.image.open() takes a relative path by default, any idea why it doesn’t work for me?)

  3. Select the object that will have the animated texture and go to the Object properties, and under custom properties, press “Add”. Give your new property the name “anim”.

  4. In node view, select the “Image texture” shader node that will hold the sequence. Press N for properties and give it the name “anim”.

  5. In the text editor, press “Run script”.

If you are using the “Scripting” screen layout you’ll see a message in the top window. If it just says “bpy.ops.text.run_script()” there’s a good chance it worked. Try and scrub the timeline and see if the image updates. But if the message says “Python script fail” in red, well, something went wrong.

For troubleshooting when working with Python in Blender it is useful to have a command window open so you can see printouts and error messages. On mac I achieve this by right clicking on the Blender application file, and choose “show package contentes”, browse to “/Contents/MacOS/” and open the program by double-clicking on the “Blender” file there. Don’t know how it is done on other platforms.

Report back here if it works or not! Good luck!

I’ve gotten the script to run, and the images are appended, but they are not showing up as a texture. Could you take a look at my blend and see where I went wrong?

thanks

nice work Tommy!

At first I couldn’t get any texture to show on your mesh, animated or not. UV-unwrapping solved that. But more importantly, you seem to have skipped step three. You have to give your object a custom property named “anim” for the script to find it. I got animated textures working fine after that.

hi gummifer, just wanted to say thanks for the script and they very clear directions on how to use it. i haven’t done that before but it works great!

I too wanted to thank you for this quick work around. It will be nice to see animated textures fully implemented someday, but for now… just know that you really saved me a huge headache! I’ve adopted a kitten and named it after you as tribute. :cool:

I’m glad you’re finding it useful :slight_smile:

For reals? 0_o Either way: that’s the best compliment I’ve ever heard :slight_smile:

Two questions:

1- Does the script have to be re-run everytime the file is opened (or am I not setting something up correctly)?

2- How plausible is it to set this up for multiple animated textures? I have a scene that needs 4-5 different elements to have animated textures, but I am at a loss as to how best to set that up.

Thanks!

Just mosying around and saw this. Good work dude! Don’t need to use it right now but I will in the future:cool:

Yes, you have to re-run it. The images won’t load if they’re already loaded in the project, so you don’t have to worry about duplicates.

It’s possible, but you need to modify the script a bit so you can link one set of images to one material. I haven’t had the time to go into that yet…

Well it’s still an excellent script. Cheers!