Re: [PyOpenGL-Users] Difficulty with the shaders tutorial
Brought to you by:
mcfletch
From: Nicolas R. <Nic...@in...> - 2012-02-21 20:49:15
|
You might want to have a look at: gl.glPixelTransferf(gl.GL_ALPHA_SCALE, scale) gl.glPixelTransferf(gl.GL_ALPHA_BIAS, bias) This will control how your texture is mapped from CPU to GPU memory. Have a look at http://code.google.com/p/glumpy/source/browse/glumpy/image/texture.py, this is exactly what is done. Nicolas On Feb 21, 2012, at 20:10 , Derakon wrote: > On Fri, Feb 17, 2012 at 1:44 PM, Derakon <de...@gm...> wrote: >> >> That did it! I have working false-color now; all that remains is to >> integrate it into the rest of my program. > > I've run into some implementation issues now that I'm not dealing with > idealized data. My image data is using the GL_SHORT datatype (16-bit > int). It can actually need anywhere from the full range to only 8 bits > or so, and needs to display properly in all situations. I'm trying to > deal with two things: > > 1) I want the false coloration to be able to use the actual range in > the data, as opposed to being locked to using 0 as the minimum and > 2^15 - 1 as the maximum. > 2) I want to be able to adjust the coloration on the fly, changing > where the min and max are (which would mean that more pixels would be > "off the end" of the spectrum). This is necessary to enhance contrast > in many situations. > > I figured this should be doable by modifying the fragment shader: > > uniform sampler2D texture; > uniform sampler1D color_lut; > uniform vec2 scaling; > void main() { > vec2 uv = gl_TexCoord[0].xy; > vec4 color = texture2D(texture, uv); > gl_FragColor = texture1D(color_lut, > min(.9999999, max(0, (color.a + scaling.x) * scaling.y))); > } > > The "scaling" vec2 includes an offset and a scaling factor that should > let me set the effective minimum (displayed as blue) and maximum > (displayed as red) values in the texture. > > I set scaling.x to 0 and scaling.y to > (2 ** 16 - 1) / float(self.imageData.max() - self.imageData.min()) > That gives the following image: > http://derakon.dyndns.org/~chriswei/temp2/auto.png > > Then I applied the same scaling factor directly to the data before > calling glTexSubImage2D, and left scaling as [0, 1], giving the > following result: > http://derakon.dyndns.org/~chriswei/temp2/manual.png > > What I'm finding is that applying scaling in the shader gives much > worse color resolution than if I manually scale the image -- auto.png > only has two colors in it, while manual.png has many more. My values > are also inverted for some reason, but I'm less worried about that. > > What am I doing wrong? > > -Chris > > ------------------------------------------------------------------------------ > Keep Your Developer Skills Current with LearnDevNow! > The most comprehensive online learning library for Microsoft developers > is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, > Metro Style Apps, more. Free future releases when you subscribe now! > http://p.sf.net/sfu/learndevnow-d2d > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |