My GLSL application runs well with nVidia and Intel GPU. But I encountered a problem with Radeon HD5400 and latest drivers on Windows XP SP3.
In a vertex shader, this code does not work correctly.
-----------------------------------------------
void main()
{
float caz = 1;
float saz = 0;
mat4 Rz = mat4(caz, saz, 0, 0, -saz, caz, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
-----------------------------------------------
Instead, this code works correctly.
-----------------------------------------------
void main()
{
float caz = 1;
float saz = 0;
mat4 Rz = mat4(vec4(caz, saz, 0, 0), vec4(-saz, caz, 0, 0), vec4(0, 0, 1, 0), vec4(0, 0, 0, 1));
-----------------------------------------------
It seems to me that following code behaves almost identically to the first code.
(Note that 3rd row of 4th column is one)
-----------------------------------------------
void main()
{
float caz = 1;
float saz = 0;
mat4 Rz = mat4(vec4(caz, saz, 0, 0), vec4(-saz, caz, 0, 0), vec4(0, 0, 1, 0), vec4(0, 0, 1, 1));
-----------------------------------------------
What exactly are the effects of the problem you are experiencing? All we see are some assignments. Are there any compile error messages?
Here is original VS code.
No compiler error nor GL error reported.
I narrowed problems and I ended up with mat4 constructor and arithmetic assignments.
-------------------------------
const float kDepthRange = 3.0;
uniform float SizeX;
uniform float SizeY;
uniform float Aspect;
uniform float Divergence;
uniform float RotX, RotY, RotZ;
uniform float PosX, PosY;
void main()
{
mat4 proj, model, m;
{ // model
// rotation (Y*X*Z)
float a, ca, sa;
// rotation (Y)
a = radians(RotY);
ca = cos(a);
sa = sin(a);
model = mat4(ca, 0, -sa, 0,
0, 1, 0, 0,
sa, 0, ca, 0,
0, 0, 0, 1);
// rotation (X)
a = radians(RotX);
ca = cos(a);
sa = sin(a);
model *= mat4(1, 0, 0, 0,
0, ca, sa, 0,
0, -sa, ca, 0,
0, 0, 0, 1);
// rotation (Z)
a = radians(RotZ);
ca = cos(a);
sa = sin(a);
model *= mat4(ca, sa, 0, 0,
-sa, ca, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
}
// projection
if (0.0 < Divergence)
{
float dist = 1.0 / tan(radians(Divergence));
float near = max(dist * 0.1, dist - kDepthRange);
float far = dist + kDepthRange;
// float corner = near / dist;
proj =
// glFrustum(-corner, corner, -corner, corner, near, distance + kDepthRange);
mat4(dist,0,0,0,
0,dist,0,0,
0,0,-(far+near)/(far-near),-1,
0,0,-2.0*far*near/(far-near),0) *
// glTranslatef(0, 0, -distance);
mat4(1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,-dist,1);
}
else
{
proj =
// glScalef(1.0, 1.0, 0.0); // no depth
mat4(1,0,0,0,
0,1,0,0,
0,0,0,0,
0,0,0,1);
}
{
m =
/* projection aspect
glScalef(1.0f, aspect, 1.0f);
*/
mat4(1,0,0,0,
0,Aspect,0,0,
0,0,1,0,
0,0,0,1) *
/* position */
mat4(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
PosX, PosY, 0, 1) *
proj * model *
/* placement
glScalef(mSizeX, mSizeY, 1);
*/
mat4(SizeX,0,0,0,
0,SizeY,0,0,
0,0,1,0,
0,0,0,1) *
/* model aspect
glScalef(1.0f, 1.0f / aspect, 1.0f);
*/
mat4(1,0,0,0,
0,1.0/Aspect,0,0,
0,0,1,0,
0,0,0,1);
}
gl_Position = m * gl_Vertex;
gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(0.5*(gl_Vertex.x + 1.0), 0.5*(gl_Vertex.y + 1.0), 0, 1);
}
It looks to me that Rz[2] is not correct. Thanks for your feedback. We will fix it soon.