Using pixel shader to implement "paletting"
Hi there,
Is it possible to implement "palettes" for rendering a greyscale image in with any set of colours you want using pixel shaders?
I have a texture map that basically consists of luminosity data and I want to define various user-selectable palettes to view the dataset with. I figured if I just were able to upload a palette texture, upload the luminosity data and fire off a pixel shader program, I might be able to do this. But how? I''m new to pixel shaders.
Any hints would be much appreciated.
Right, so you''re talking about a colour scale re-mapping rather than a traditional indexed colour palette. I hope so at least, as it makes it a lot easier
All you need to do is create a 1d texture with the colours you want given the luminance values. Basically, use the texture u coordinate as the luminance and draw the texture given that.
Now use this pixel shader:
tex t0
texreg2gb t1, t0
mov r0, t1
This reads from sampler stage 0 (which you set to be your luminance texture), then passes the green and blue channels as the u and v coordinates for a look up in sampler stage 1 (which you set to be your ''palette'').
If you''re using, say, an A8 luminance texture instead, then use the texreg2ar instruction as that maps alpha to u and red to v.
btw, don''t worry about what is mapped to v as you''re ignoring that anyway (you''ve got a 1d texture).
NB. If you meant true indexed palettes then it''s harder as you need to emulate bilinear filtering manually using 4 displaced samples.
HTH
Matt Halpin
All you need to do is create a 1d texture with the colours you want given the luminance values. Basically, use the texture u coordinate as the luminance and draw the texture given that.
Now use this pixel shader:
tex t0
texreg2gb t1, t0
mov r0, t1
This reads from sampler stage 0 (which you set to be your luminance texture), then passes the green and blue channels as the u and v coordinates for a look up in sampler stage 1 (which you set to be your ''palette'').
If you''re using, say, an A8 luminance texture instead, then use the texreg2ar instruction as that maps alpha to u and red to v.
btw, don''t worry about what is mapped to v as you''re ignoring that anyway (you''ve got a 1d texture).
NB. If you meant true indexed palettes then it''s harder as you need to emulate bilinear filtering manually using 4 displaced samples.
HTH
Matt Halpin
Hey I got that one already - except I''m using ps11 (GeForce 3) so I''m using texreg2ar t1, t0. Basically, my luminance data is convieniently 16 bit anyway. I bind my 2d palette texture to t1 and off I go Works like a dream. So impressive this ps stuff (this is my first go at ps).
tex t0
texreg2ar t1, t0
mov r0, t1
tex t0
texreg2ar t1, t0
mov r0, t1
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement