EDIT update for ATI cards…but with NO texture animation link on post no.9… please say if you have problems with the shader and what graphics card you have.:eyebrowlift2:
EDIT to get the ocean wave demo go to to my post with the thumbnails in it… the one that looks like an ocean… look for post no.9… has texture animation.
EDIT to get the working file go down to the my third post…
hi I’ve been following some GLSL tuts… I have cube that gets flattended and scaled and has a wave distort it’s vertices all via a GLSL script… Now I wanted to get the sin wave deforming the wave animating over time… now I’ve read the tuts… I’ve looked at other peoples blendfiles that do the same thing… I’ve even copied and pasted in their code but nothing seem to work to make the wave animated…
I know I have to declare a uniform float called “time” in the fragment shader… which I’ve done… and I also know that I have to declare it in the python script as such…
shader.setUniform1f('time', obj.time)
…so that blender can start a timer… which I’ve also done… the timer is on the object to be deformed by the GLSL script… anyway I can’t get it to work: So if there anything I’ve missed or am doing wrong here please have a look… thanks:D
a link to the blendfile:
http://www.savefile.com/files/626965
the GLSL script
import GameLogic as g
cont=g.getCurrentController()
own=cont.getOwner()
objlist = g.getCurrentScene().getObjectList()
##g.setLogicTicRate(60.0)
# -------------------------------------
ShaderObjects = [ objlist['OBsquish'] ]
MaterialIndexList = [0]
# -------------------------------------
# -------------------------------------
# -------------------------------------
VertexShader = """
<b> uniform float time;</b>
void main(){
vec4 v = gl_Vertex;
v.x = sin(2.0*v.y + (time*0.1))*0.5; // sin(wavelength*axis)*amplitude
//a.x = a.x * 0.5; //scale in x
//a.y = a.y * 2.0; //scale in y
//a.z = a.z * Scale; //scale in z using uniform float scale
gl_Position = gl_ModelViewProjectionMatrix * v;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
"""
FragmentShader = """
uniform sampler2D map;
void main() {
gl_FragColor = texture2D(map, gl_TexCoord[0].st);
}
"""
def MainLoop ():
# for each object supplied
for obj in ShaderObjects:
mesh_index = 0
mesh = obj.getMesh(mesh_index)
while mesh != None:
# for each material in the mesh
for mat in mesh.materials:
# sanity check..
# is the use blender materials option checked?
if not hasattr(mat, "getMaterialIndex"):
return
# 0->15 avaiable
mat_index = mat.getMaterialIndex()
# find an index from the list
found = 0
for i in range(len(MaterialIndexList)):
if mat_index == MaterialIndexList[i]:
found=1
break
if not found: continue
shader = mat.getShader()
if shader != None:
if not shader.isValid():
shader.setSource(VertexShader, FragmentShader,1)
<b>shader.setUniform1f('time', obj.time)</b>
shader.setSampler('map', 0) ## gets name of declared sampler from the fragment shader
mesh_index += 1
mesh = obj.getMesh(mesh_index)
## call it
MainLoop()