From 6de802e7dadfc00e5a4f4af8ab9600ca9c89c9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Pe=C3=B1aranda?= Date: Wed, 14 Aug 2013 11:57:26 -0300 Subject: [PATCH] pass ZB parameters to the shader automatically --- openglcanvas.cpp | 16 +++++++++++----- shaders/test_vertex_shader.vert | 12 ++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/openglcanvas.cpp b/openglcanvas.cpp index b18d881..82bffc1 100644 --- a/openglcanvas.cpp +++ b/openglcanvas.cpp @@ -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); diff --git a/shaders/test_vertex_shader.vert b/shaders/test_vertex_shader.vert index 6f057b2..26a58d7 100644 --- a/shaders/test_vertex_shader.vert +++ b/shaders/test_vertex_shader.vert @@ -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); -- GitLab