Hi,
I’m trying to simulate the look of lake-water in the Blender Game Engine using a python script.
The problem is that I can’t make the GLSL material semi-transparent once the shader is running.
How do you make a GLSL material support transparency?
Here’s my code:
import GameLogic as g
objlist = g.getCurrentScene().getObjectList()
g.setLogicTicRate(60.0)
-------------------------------------
ShaderObjects = [ objlist[‘OBWater’] ]
MaterialIndexList = [0]
GlobalAmbient = [0.39,0.35,0.32,1]
AmbF = 0.5
-------------------------------------
cont = g.getCurrentController() act = cont.getActuator('timer') if act.getValue() == '': time = 0.0if act.getValue() != ‘’:
time = float(act.getValue())
if time < 60.0:
time += 0.01
if time == 60.0:
time = 0
act.setValue(str(time))
g.addActiveActuator(act,1)
VertexShader = “”"
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
“”"
FragmentShader = “”"
uniform sampler2D colorMap;
uniform sampler2D noiseMap;
uniform float timer;
void main(void)
{
vec2 displacement = gl_TexCoord[0].st;
float scaledTimer = timer*0.1;
displacement.x += scaledTimer;
displacement.y -= scaledTimer;
vec3 noiseVec = normalize(texture2D(noiseMap,displacement.xy).xyz2.0-1.0)*.035;
vec4 color = texture2D(colorMap,gl_TexCoord[0].st + noiseVec.xy).rgba;
gl_FragColor = color;
}
“”"
def MainLoop ():
for each object
for obj in ShaderObjects:
mesh_index = 0
mesh = obj.getMesh(mesh_index)
while mesh != None:
for mat in mesh.materials:
# regular TexFace materials do NOT have this function
if not hasattr(mat, "getMaterialIndex"):
return
mat_index = mat.getMaterialIndex()</b>
# find an index
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)
shader.setSampler(‘colorMap’,0)
shader.setSampler(‘noiseMap’,1)
shader.setUniform1f(‘timer’,time)
mesh_index += 1
mesh = obj.getMesh(mesh_index)
# -------------------------------------
MainLoop()