Re: [PyOpenGL-Users] Difficulty with the shaders tutorial
Brought to you by:
mcfletch
From: Derakon <de...@gm...> - 2012-02-21 19:10:49
|
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 |