Force material update OpenGL render active viewport

Sometimes doing OpenGL render active viewport is a very fast way of rendering an animation, especially 2D animations, when no lighting or fancy shading is needed.

There is a problem where materials don’t update in the viewport, like switching textures or animating UV’s.

This little script helped me to fix that problem for both scrubbing through the timeline, and rendering/playblasting the viewport:

Tested in Blender v2.77. Just run it once after opening the .blend you are working on.

import bpy

mats =

def my_handler(scene):
	for m in mats:
		m.invert_z = False

It adds a custom handler that loops through all the materials and sets a material property so Blender thinks it needs an update. I just picked invert_z because it has that value by default, and it doesnt ruin anything else.

I hope this helps some other people out!

Edit: Thanks for the code wrapping tip MCHammond and proxe!

Please remove cursor indicator after you paste the code in the thread below. The code in this thread is incorrect. See below.




When I tried to enable the script, I could not get it to load. Any suggestions? Sammey, sorry about the mistakes in my posts. I was not sure what you meant by tab and was looking for some clarification. Is the quotation mark supposed to be in the script? I am not a code guy. Once the script is enabled what is the procedure with the addon? Thanks

Thank you for your tip :slight_smile:

import bpy

mats =

def my_handler(scene):
    for m in mats:
        m.invert_z = False

Indeed, Sammey you need to encase the properly formatted text in CODE brackets or edit your post and click Go Advanced properly format the code, select it and click the # in the toolbar region of the editor.

Thanks for the share :slight_smile:

so if I want to do this for 1 geometry?.. how would it be when there is a linked character?

Exactly what I was looking for! :wink:
Really helpfull
This script should be directly included!

Thanks! It’s the first time I copy/paste a script code inside Blender :smiley:

If someone could do a .py file of it, it will be cool. I tried and failed (lol)

I want a .py script file cause I could add it to my user preference. (Actually we have to copy paste the script each time we launch blender…)

Hi thanks a lot for the little script ! i didn’t have a chance to test it yet, but this is super useful !
Does it work with animated texture ? this has always been a problem in the viewport in blender for me…
Anyway i put together a little installable script (like any other addon) which put a texture icon in the down header of the 3d view. It’s an on off toggle for the forcing of materials update, i thought it could be great as an addon but you don’t need it all the time, and the handler can make performance decrease in playback… Feel free to modify it in any way !
and thanks again !

edit : i confirm, it works perfectly with video texture, i tested the script in 2.78 and 2.79 on mac so far, when playing (not going frame to frame with right or left arrow, when playback with shift A), it allows to update the video texture :smiley:
glad to find this script after 1 year of existence !

1 Like

Thanks for the addon, I still use 2.77 and it works fine :yes:

It’s really helpful :wink:

1 Like

Thank you! I’ve been looking for a solution to this problem FOREVER. It’s such a pain in the ass as an animator having to export OpenGL renders to After Effects and animate the transparency of layers just to get an idea of how your timings are going to work. Even more so when you have multiple object and layers and you have to work out how to stack you layers in 2d to get the effect you need. I seriously hope this gets addressed in 2.8 is a default feature of Eevee. Anyway this little script should save me HOURS of work on every project. So again thanks so much for sharing your knowledge in this thread :smile:

1 Like

Nice to read morritzio! :slight_smile: And I trust this will not be a problem anymore with Eevee. Good luck with your projects!

Can somebody reupload the .py ?

It will be cool to also add all the BL info otherwise the .py doesn’t show up…


here s the addon file ! what do you mean about bl info ? it doesnt work anymore ?

Thanks, exactly what I wanted :grinning:

I’ll save it on my external HDD too :grinning:

Hi ! This script is indeed SUPER useful.
Would it be possible to make it work also whenever a bone is moved? I am driving a Hue-Saturation node with a bone, and the viewport doesnt update unless I move frames, which is annoying. I have no idea how to modify your code to take the “bone moving” event in account. Can anyone help?
thanks !

Hello pataz,

Nice to hear you like the script.
You can add another handler that monitors scene changes and forces the same redraw:

and remove it at unregister, just like the other handler is removed:

I tried it with a driver on UV that moves according to a bone position, and seems to work like expected!
I hope this helps you out.

ps. If you dont use the script on github but copied the script from my first post, than you just have to add this line at the bottom:
1 Like

Thank you so much ! testing :slight_smile: