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
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()
yeah you could easily apply the sin wave (or some other equation to make ripples and waves for an ocean type of thing… you could even colour/blend maps for the crests based on hight to get foam… just need to figure out how to get the animation working…
hi-- I got the file with shader working by copying and pasting it into an existing example that Penguin3d made and tweaking the settings…using a texture map he found or possibly made… I dunno… I just couldn’t be bothered to change it right now… the original script came off of the lighthouse3d.com/opengl/glsl/index.php?spotlight
I haven’t yet got vertex shaded or pixel shaded lighting working with the shader… but will hopefully get that soon… currently it supports one texture only but you can easliy add in more. Maybe a nice tiling rendered map with highlights of an ocean surface… a better way of making a ocean would be to use realtime displacement maps… but you can only do that with Nvidia cards right now apparantly… plus I’m not sure if blender supports it… but it might…
I also commented on how to change the wave… ie. make it faster… slower, add in more crests etc… if anyone knows how to make another wave (3d penguin?)… ie. another one at a different angle pls. let me know…
I also commented on how to change the wave… ie. make it faster… slower, add in more crests etc… if anyone knows how to make another wave (3d penguin?)… ie. another one at a different angle pls. let me know…
Just add it like that:
v.z = sin( v.y*16. + time )/20.;
v.z += sin( v.x*16. + time )/20.;
If you want the “wind” from an arbitrary direction, compute the respective vector as an input. The basic function stays the same. I hope that helped. I’ll be back tomorrow, if you have further questions.
@3d penguin… compute the huh, the who.? .vectors.? lol Yeah I have no idea how to use vectors really… the most I understand is the basic concept… shot for the blend and script!! It’s really awesome!!
If you could show me how to change the direction that would be awesome thanks:D
Hi I made a simple textured ocean… (got help with the wave script from 3d penguin on how to add in two waves)… anyway the ocean has two waves moving at different times… a texture that flows over the surface and a point light… and a very quick sun… It’s far from perfect but it was just a little demo to see if I could get it working:
The GLSL shader needs some fog for the waves and a bump map too… if anyone knows how to add this to the existing shader please tell me! You can use whatever… but if you use the cube map or textures… all I ask is for put is to be put in any credits… I made the Cube map from a panaramic photograph from another free site… and edited it to suit my needs.
Enjoy… oh yes feedback…!!! does it look shite? could it look better…and how? How does it effect the frame rate? Does it work at all… etc etc? Did I pack the textures etc. (yes the textures are quite big at the moment)
screenshot
EDIT: New version with only script changes for ATI cards…(I think it should work on both ATI and NVIDIA cards that support GLSL …now) okay just checked… this kills the texture animation… so get the old one for animating textures. http://www.savefile.com/files/636151
thanks Poof… yeah good idea… like some sort of loading screen or menu screen thing… maybe for that guys pirate game? 10 Downloads of the file and your the first to comment appreciate the feedback.
It’s pretty easy to change the speed of the 2 waves…it’s commented in the script… I’m going to try using realtime displacement if I can ever figure out how to use it… you can get sweet looking waves with high detail with that…
Know any cool sound sites I could get a sweet looping ocean sound and maybe some sea gulls?
Heh, nice to see you got hooked on shader design kirado I was really excited about this, but sadly it doesn’t work. Perhaps it’s another graphics card compatibility issue. Your previous demos worked, but this ocean wave doesn’t. The plane doesn’t deform at all.
@PSK131… aw that sucks… hmm not sure why? What does the command prompt say? Are you getting any errors? i’ve been getting problems with uniform variables hooked to blender not being picked up/noticed by blender… looks like I can’t set more than one…
Yeah I downloaded shader designer… much easier to play about in there/learn concepts etc… and then try to get it working in blender…
Did the glsl blender graphics demo with the wavy spiky things work on your pc/gfx card?.. all I used was a sin wave thing… nothing different there… and the point light code I got from you… and the moving the texture, I added in… that could be the problem maybe?
---- GLSL Program ----
Warning: built-in varying gl_TexCoord[0] has mismatched access semantics between
the vertex and fragment shader
Varying texcoords read in fragment shader, but not written to in vertex shader.
Link failed.
---- GLSL program failed to link ----
Vertex wave from Blender 2.43 graphics demos works perfectly.
@James XVI…thanks… yeah I tried that too… I knew it wasn’t going to work… but I still had to give it a try…lol… yeah it would be sweet… I think it might be possible to get the vertex positions out of the shader… like the height of the waves… and use it to move objects around… or I could try and move an object on one axis using the same wave equation thing so it would look like it was flowing over the waves… then slow parent an object to that… so you get a bobbing effect??..
@PSK131
Hmm so it was the texture thing…? You can write the textures bit in a different way… maybe that will work… I’ll give it try if I have time and post a blend.
@PSK131. .thanks… I’ve made the changes and posted an updated version next to the orignal ocean in post no.9 Looks like I need to test on two graphics cards… Nvidia and Ati…
just checked and adding that to script kills the texure from moving over the ocean…