Hi
I try to use a lookup table (LUT) in a shader. (I went to that because I discovered that on my android device, I could not use a regular buffer
In the shader, I added the lines:
{
// uniform float[256];
void main() {
float color = texture2D(lut, tex_coord0).r / 255.0;
gl_FragColor = vec4(vec3(color), 1.0);
}
expecting to have a horizontal gray variation as the LUT size will be (1, 256), increasing from 0 to 255.
and in my widget code I put:
{
def __init__(self, **kwargs):
# Instead of using canvas, we will use a RenderContext,
# and change the default shader used.
self.canvas = RenderContext(use_parent_projection=True,
use_parent_modelview=True,
use_parent_frag_modelview=True)
# call the constructor of parent
# if they are any graphics object, they will be added on our new canvas
super(ShaderWidget, self).__init__(**kwargs)
# Linear LUT
self.lut = range(256)
self.tex = Texture.create(size=(1,256), colorfmt='luminance')
BindTexture(texture=self.tex, index=1)
self.tex.add_reload_observer(self.populate_texture)
self.populate_texture(self.tex)
self.canvas['lut'] = 1
def populate_texture(self, texture):
# data = b''.join(map(bytes,self.lut))
data = struct.pack('h'*len(self.lut), *self.lut)
texture.blit_buffer(data, size=(1,256), colorfmt='luminance')
}
My widget remains desperately black. What am I missing ? (Elsewhere in the code I set the shader, this has already been tested without the LUT and is working fine.)
It is not clear what the index in BindTexture should be. Could it be arbitrary (e.g. 4 in this example) ? I think that at least it should be the same as in the line self.canvas['lut'] =
Thanks in advance.