glsl question for snail rose

hello, great job on compile of ge. Question: Ive never programmed or donw anything with glsl shaders, but I did download a program called shader designer, where it appears it generates code after you mess with certain settings and see the shader created in realtime. It has some shaders already with it that i checked out, like wood and bumpmapping. Anyways, how do i get this code into blender GE to get the effects on my models?
ex.
varying float LightIntensity;
varying vec3 MCposition;
uniform int TIME_FROM_INIT;
uniform sampler3D Noise;
vec3 Offset = vec3(0,0,0);
uniform vec3 SkyColor; // (0.0, 0.0, 0.8)
uniform vec3 CloudColor; // (0.8, 0.8, 0.8)

void main (void)
{
float offset = float(TIME_FROM_INIT) *0.0001;
Offset = vec3(-offset,offset,offset); // uncomment this line for animation
vec4 noisevec = texture3D(Noise, MCposition + Offset);
float intensity = (noisevec[0] + noisevec[1] +
noisevec[2] + noisevec[3] + 0.03125) * 1.5;
vec3 color = mix(SkyColor, CloudColor, intensity) * LightIntensity;
color = clamp(color, 0.0, 1.0);
gl_FragColor = vec4 (color, 1.0);

}

this is the code it generated for clouds, where to i put this script in blender so I can put it on a skysphere? Thanks

Hey thanks,
to get this shader running:



# set shaders as strings
VERTEX_SHADER = """
void main(){
	// your vertex shader code
}
""

FRAGMENT_SHADER= """
void main(){
	// your fragment shader code
}
"""
import GameLogic
Objects = GameLogic.getCurrentScene().getObjectList()

obj_to_set = Objects['OBobj_to_set']

def main():
  mesh_index = 0
  mesh = obj_to_set.getMesh(mesh_index)
  while mesh != None: 
    for mat in mesh.materials:
        shader = mat.getShader()
        if not shader.isValid():
            apply = 1
            shader.setSource(VERTEX_SHADER, FRAGMENT_SHADER, apply)
            shader.setNumberOfPasses(1) # one atm
        #------------
        # set uniform variables/samplers
        # here

    mesh_index += 1
    mesh = obj_to_set.getMesh(mesh_index) 	

main()

that’s be the basic set up.
you need to specify the uniform variables in the program

so:
uniform int TIME_FROM_INIT;
would be:


shader.setUniform1i('TIME_FROM_INIT', obj_to_set.timer_property)

the colors
would be 1:


 shader.setUniform3f('SkyColor', red_value, green_value, blue_value)

2:


pylist =  [red_value, green_value, blue_value]
shader.setUniformfv('SkyColor',pylist )

the uniform calls are:
shader.setUniform3i(name, (3 ints))
shader.setUnifor4f(name (4 floats))
shader.setUniformfv(name list( float - 2|3|4))
shader.setUniformiv(name list( int - 2|3|4))
… (print dir(shader) for more)

there is one problem with this shader though. 3D textures are not supported atm so, the ‘sampler3D’ will not work correct. Valid samplers are sampler2D and samplerCube.

to get samplers running one of two things need to happen
1: if there is no material connected to the object, the sampler image will come from the texface. Being that its there is no material, the sampler index will need to be 0
2: if there is a material connected to the object the first image in the material panel will start with the index 0 and increment from there

shader.setSampler(name index)
so to access a second texture in the material panel it would be shader.setSampler(‘name’, 1)

A samplerCube would be shader.setSampler(‘name’,index_of_envmap_image)

There still are bugs with this interface which need to be worked out. If you spot something out of place please, let me know.

thanks,
snailrose

thanks