Commit 6de802e7 by Luis Penaranda

pass ZB parameters to the shader automatically

1 parent d8c970c0
......@@ -709,11 +709,17 @@ void OpenGLCanvas::setShaders() {
GLuint p = glCreateProgram();
// Bind attributes zblambda and zbR to the vertex shader
glVertexAttrib1f(0,zblambda);
glBindAttribLocation(p,0,"zblambda");
glVertexAttrib1f(1,zbR);
glBindAttribLocation(p,1,"zbR");
// Bind attributes zblambda and zbR to the vertex shader. Nvidia hardware
// only leaves attributes 1 and 7 unreserved; attributes 8 to 15 are
// reserved for textures.
// TODO: we use attributes 14 and 15, which work for Nvidia; we need to
// test with other hardware.
#define ZBL_ATTR 14
#define ZBR_ATTR 15
glVertexAttrib1f(ZBL_ATTR,zblambda);
glBindAttribLocation(p,ZBL_ATTR,"zblambda");
glVertexAttrib1f(ZBR_ATTR,zbR);
glBindAttribLocation(p,ZBR_ATTR,"zbR");
glAttachShader(p,v);
glAttachShader(p,f);
......
......@@ -6,9 +6,7 @@ float u, v, x, y, z;
varying float r, theta, s;
float lambda, phi;
float extent, scale, vis_mode, center_lambda, center_phi;
float zbr,zbalpha,zbrho;
/*attribute*/ float zblambda;
/*attribute*/ float zbR;
attribute float zblambda,zbR;
void main(void){
......@@ -87,11 +85,9 @@ void main(void){
u=x/(-z);
v=y/(-z);
// Z-B transformation
zblambda=0.1;
zbR=1.0;
zbalpha=atan(v,u);
zbr=sqrt(u*u+v*v);
zbrho=(zblambda*zbr/zbR)+(1.0-zblambda)*(zbR*(sqrt(zbr*zbr+1.0)-1.0))/(zbr*(sqrt(zbR*zbR+1.0)-1.0));
float zbalpha=atan(v,u);
float zbr=sqrt(u*u+v*v);
float zbrho=(zblambda*zbr/zbR)+(1.0-zblambda)*(zbR*(sqrt(zbr*zbr+1.0)-1.0))/(zbr*(sqrt(zbR*zbR+1.0)-1.0));
u=zbrho*cos(zbalpha);
v=zbrho*sin(zbalpha);
gl_Position = vec4(u/extent,v/extent,z,1.0);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!