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.
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)