ok so im teaching myself how to use glsl shaders in blender and so far i understand it but i have run into a problem
## test1---------------------------------
import GameLogic as gl
cont = gl.getCurrentController()
ow = cont.getOwner()
olist = gl.getCurrentScene().getObjectList()
gl.setLogicTicRate(60.0)
lamp = olist['OBLamp']
ShaderObjects = [olist['OB*****']]
MaterialIndexList = [0, 1]
GlobalAmbient = [0.4, 0.4, 0.4, 1]
AmbF = 0.5
#--------------------------------------------
Vertshader = '''
varying vec3 LightDir;
varying vec3 EyeDir;
varying vec3 Normal;
uniform vec3 LightPosition;
uniform float Scale;
void main(void)
{
vec4 pos = gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vec3 eyeDir = vec3(pos);
gl_TexCoord[0] = gl_MultiTexCoord0;
vec3 n = normalize(gl_NormalMatrix * gl_Normal);
vec3 t = normalize(cross(vec3(1.141, 2.78, 3.14), n));
vec3 b = cross(n, t);
vec3 v;
v.x = dot(LightPosition, t);
v.y = dot(LightPosition, b);
v.z = dot(LightPosition, n);
LightDir = normalize(v);
v.x = dot(eyeDir, t);
v.y = dot(eyeDir, b);
v.z = dot(eyeDir, n);
EyeDir = normalize(v);
}
'''
Fragshader = '''
varying vec3 LightDir;
varying vec3 EyeDir;
varying vec3 Normal;
const vec3 color = vec3(0.7, 0.6, 0.18);
//const float Density = 16.0;
//const float Size = 0.25;
uniform float Density;
uniform float Size;
//uniform float Scale;
const float SpecularFactor = 0.5;
void main (void)
{
vec3 litColor;
vec2 c = Density * (gl_TexCoord[0].xy);
vec2 p = fract(c) - vec2(0.5);
float d = (p.x * p.x) + (p.y * p.y);
if (d >= Size)
p = vec2(0.0);
vec3 normDelta = vec3(-p.x, -p.y, 1.0);
litColor = color * max(0.0, dot(normDelta, LightDir));
float t = 2.0 * dot(LightDir, normDelta);
vec3 reflectDir = t * normDelta;
reflectDir = LightDir - reflectDir;
// vec3 reflectDir = LightDir - 2.0 * dot(LightDir, normDelta) * normDelta;
float spec = max(dot(EyeDir, reflectDir), 0.0);
spec = spec * spec;
spec = spec * spec;
spec *= SpecularFactor;
litColor = min(litColor + spec, vec3(1.0));
gl_FragColor = vec4(litColor, 1.0);
// gl_FragColor = vec4(Scale);
}
'''
def MainLoop():
for obj in ShaderObjects:
mesh_index = 0
mesh = obj.getMesh(mesh_index)
while mesh != None:
for mat in mesh.materials:
if not hasattr(mat, "getMaterialIndex"):
return
mat_index = mat.getMaterialIndex()
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(Vertshader, Fragshader, 1)
shader.setUniform1f('Scale', 1)
shader.setUniformfv('LightPosition', lamp.getPosition())
mesh_index += 1
mesh = obj.getMesh(mesh_index)
MainLoop()
when i use this code it returns an error invalid uniform value: scale
so i was wondering if anyone could help me debug this and get it to work
and no i did not write this it is straight out of shader designer from typhoon labs