Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add the time relation in blender cylces nodes shader?

In GLSL there is the gl_Time attribute.
What is the equivilent in blender cylces nodes? I found using the keyframes to be an answer, but I would have to set the keyframes for hundreds of frames per hand (frame 1: value = 1; frame 2 = value = 2; ...)
There has to be a better way to make the texture scrolling over something.

like image 799
harlekintiger Avatar asked Nov 18 '25 10:11

harlekintiger


1 Answers

In a cycles material, you can add a Mapping node and use the location, rotation and scale values to move the texture. These values can be keyframed so that they vary over time, often setting two keyframes is enough to get a continuous scrolling during an animation.

Drivers allow us to programmatically animate a value using a python expression.

Within a node tree, you can add a value input node and set a driver for the value. A shortcut to entering an expression is to edit the value and enter the expression after a #. By entering #frame in the value field you will get a driver that equals the current frame number.

Note that there are dependency issues when using drivers in a node tree. While this has been fixed in 2.80, when using an older version you should enable the new dependancy graph with the --enable-new-depsgraph CLI option.

There is also the option of using a script to create keyframes with a calculated value.

import bpy

scn = bpy.context.scene
node = bpy.context.object.material_slots['Material'].material.node_tree.nodes['Value']

for f in range(scn.frame_start, scn.frame_end):
    node.outputs[0].default_value = f * 1.25
    node.outputs[0].keyframe_insert("default_value", frame=f)
like image 115
sambler Avatar answered Nov 21 '25 09:11

sambler