I need to modify the value of a value node with a script. How can I do that? Or is there another strategy to modify texturing in a game?
I want something like the Attribute node in Cycles.
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
I solve my problems by write my own shaders. 1) create a material 2) Create a vertex shader
uniform float variable_name;
vec4 co = gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ProjectionMatrix * co;
3) Create a fragment shader
gl_FragColor = vec4(1.0,0,0,1); // RGBA
4) load it
#vertex with open("__path__.vert") as a: vertex_shader_code = a.read() #fragment with open("__path__.frag") as a: frag_shader_code = a.read() import bge own = bge.logic.getCurrentController().owner m = obj.meshes shader = m.materials.getShader() shader.setSource(vertex_shader_code, frag_shader_code, 1)
5) pass variable to GPU over uniform value.
You can use the vertex color (if the property should be shared across all objects with that material), giving you access to three floats.
Or you can use object color, giving you another three floats. This one is per-object, so it generally a lot more useful, though it does require the creation of another material to use as input (shadeless with object color ticked).
The advantage of these two methods are that you do not need to write your own GLSL code so the build in real-time shadows still work. (And you don't need to know GLSL)