1
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

I solve my problems by write my own shaders. 1) create a material 2) Create a vertex shader

uniform float variable_name; void main() { vec4 co = gl_ModelViewMatrix * gl_Vertex; gl_Position = gl_ProjectionMatrix * co; }

3) Create a fragment shader

void main(void) { 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[0]
shader = m.materials[0].getShader()
shader.setSource(vertex_shader_code, frag_shader_code, 1)

5) pass variable to GPU over uniform value.

shader.setUniform1f("variable_name", 10)

$\endgroup$
0
$\begingroup$

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)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.