Hi, Im a bit of a shader noob myself but I'v been experimenting with some of the examples found in the fourm and the Teie1 stuff is starting to make sence but I'm still very lost with shader code, anyhow, heres a breakdown:
this is a shader (2D Normalmapping.ps found on the fourm)
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
uniform sampler2D texture0;
uniform sampler2D texture1;
varying vec2 uvVarying;
varying vec2 posVarying;
uniform vec4 LightPos;
uniform vec4 LightColor;
uniform vec4 LightPos2;
uniform vec4 LightColor2;
uniform vec4 LightPos3;
uniform vec4 LightColor3;
uniform vec4 Resolution;
uniform vec4 AmbientColor;
uniform vec3 Falloff;
vec3 light(vec4 TLightPos, vec4 TLightColor)
{
TLightPos.y = Resolution.y - TLightPos.y;
vec3 normal = texture2D(texture1, uvVarying.xy).rgb;
vec3 LightDir = vec3(TLightPos.xy - gl_FragCoord.xy, TLightPos.z);
vec3 LDIR=normalize(LightDir);
normal = normal * 2.0 - 1.0;
vec3 NDIR=normalize(normal);
float distance = length(LightDir);
float Attenuation = clamp((1.0 / (Falloff.x +(Falloff.y * distance) +(Falloff.z * distance * distance))) * TLightPos.w,0.0,1.0);
return TLightColor.rgb * max(dot(NDIR, LDIR), 0.0) * Attenuation;
}
void main()
{
vec4 diffuse = texture2D(texture0, uvVarying.xy);
vec3 PLight = light(LightPos,LightColor) + light(LightPos2,LightColor2) + light(LightPos3,LightColor3);
gl_FragColor = diffuse * (AmbientColor + vec4(PLight,0.0));
}
and in AppGameKit, load the shader and set the variables
// load
loadspriteshader(1,"2D Normalmapping.ps")
// set enviorment
SetShaderConstantByName( 1, "Resolution", GetVirtualWidth(),GetVirtualHeight(),0.0, 0.0 )
SetShaderConstantByName( 1, "AmbientColor", 0.1,0.1,0.1, 1.0 )
SetShaderConstantByName( 1, "Falloff", 0.1,0.01,0.001, 0.0 )
SetShaderConstantByName( 1, "Threshold", 0.5,0.0,0.0, 0.0 )
// set lights
// LightColor or LightColor2 or LightColor3
SetShaderConstantByName( 1, "LightColor", 1.0,0.8,0.6, 1.0 )
LightX#=getpointerx()
LightY#=getpointery()
LightZ#=10.0
// LightPos or LightPos2 or LightPos3
SetShaderConstantByName( 1, "LightPos", LightX#,LightY#,LightZ#, 100.0 )
// apply shader to sprite
setspriteshader(1,1)
// now your sprite is shaded
^^ thats about the basic nuts and bolts to getting a shader working the AppGameKit side is easy but the shader side will take a bit of research, hope that was of some help, I know it took me a while to get my head round it!