Hey.
Long time AppGameKit user, but I abandoned it long ago after it....well, let's be kind and say on the PC front couldn't keep up!
One of my frustrations was the rubbish lighting, and only basic directional shadows. I know Janbo and Evolved have release their own shader (I own the shdaer pack), but these seem way way too complicated to include, especially since all TGC need to do is give us access to a couple of matrices that they must be generating internally anyway. I asked Rick a couple of times, but never got any answer.
What I mean is, if we take a simple billboard shader (from Bing co-pilot):
#version 150
in vec4 gxl3d_Position;
in vec4 gxl3d_TexCoord0;
// GLSL Hacker automatic uniforms:
uniform mat4 gxl3d_ModelViewProjectionMatrix;
uniform mat4 gxl3d_ModelViewMatrix;
uniform mat4 gxl3d_ProjectionMatrix;
uniform mat4 gxl3d_ViewMatrix;
uniform mat4 gxl3d_ModelMatrix;
uniform int spherical; // 1 for spherical; 0 for cylindrical
out vec4 Vertex_UV;
void main() {
mat4 modelView = gxl3d_ModelViewMatrix;
// Remove rotations for spherical billboarding
modelView[0][0] = 1.0;
modelView[0][1] = 0.0;
modelView[0][2] = 0.0;
if (spherical == 1) {
modelView[1][0] = 0.0;
modelView[1][1] = 1.0;
modelView[1][2] = 0.0;
}
// Apply the modified modelView matrix
gl_Position = gxl3d_ProjectionMatrix * modelView * gxl3d_Position;
// Pass texture coordinates
Vertex_UV = gxl3d_TexCoord0;
}
So looking at this, this is what I have deduced from what TCG make available in shaders, to this code:
uniform mat4 gxl3d_ModelViewProjectionMatrix; = mat4 agk_ViewProj
uniform mat4 gxl3d_ModelViewMatrix; = mat4 agk_View
uniform mat4 gxl3d_ProjectionMatrix; = mat4 agk_Proj
uniform mat4 gxl3d_ViewMatrix; = ???
uniform mat4 gxl3d_ModelMatrix; = ???, but not needed anyway in this shader
Anyone any ideas? The code below works fine, but only while the object is placed at 0,0....as soon as you move it, the effect just goes all over the place. I am fairly sure this is because the gxl3d_ProjectionMatrix is wrong, or the position is wrong.
#version 150
attribute highp vec3 position;
attribute mediump vec3 normal;
attribute mediump vec2 uv;
varying highp vec3 posVarying;
varying mediump vec3 normalVarying;
varying mediump vec2 uvVarying;
varying mediump vec3 lightVarying;
uniform highp mat3 agk_WorldNormal;
uniform highp mat4 agk_World; //A matrix to transform 3D object verticies from object space to 3D world space
uniform highp mat4 agk_Proj; //A matrix to transform from camera space to window space
uniform highp mat4 agk_View; //A matrix to transform from 3D world space to camera space
uniform highp mat4 agk_ViewProj; //A combination of the View and Proj matrices, transforms from 3D world space to window space
uniform highp mat4 agk_WorldViewProj; // A combination of the World, View, and Proj matrices, transforms from object space to window space
uniform mediump vec4 uvBounds0;
uniform vec3 CameraPos;
uniform vec3 obPos;
mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );
uniform vec4 billbrd_pos;
void main()
{
mat4 modelView = agk_View;
// First colunm.
modelView[0][0] = 1.0;
modelView[0][1] = 0.0;
modelView[0][2] = 0.0;
//if (spherical == 1)
//{
// // Second colunm.
// modelView[1][0] = 0.0;
// modelView[1][1] = 1.0;
// modelView[1][2] = 0.0;
//}
// Third colunm.
modelView[2][0] = 0.0;
modelView[2][1] = 0.0;
modelView[2][2] = 1.0;
highp vec4 pos = agk_World * vec4(position,1.0);
vec4 P = modelView * pos;
gl_Position = agk_Proj * P;
uvVarying = uv * uvBounds0.xy + uvBounds0.zw;
mediump vec3 norm = normalize(agk_WorldNormal * normal);
posVarying = pos.xyz;
normalVarying = norm;
lightVarying = GetVSLighting( norm, posVarying );
}