User avatar
PeterO
Posts: 4940
Joined: Sun Jul 22, 2012 4:14 pm

Fragment shader for waterfall display

Tue May 27, 2014 10:13 pm

The waterfall display in my panadapter currently is in monochrome.
http://www.youtube.com/watch?v=0IZxzm4R1bo

I'm trying to find a "good" algorithm for mapping the 256 values of grey into colours but so far I've had little success,

PeterO
G0DZB
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Yggdrasil
Posts: 138
Joined: Sun Aug 26, 2012 8:45 pm

Re: Fragment shader for waterfall display

Tue May 27, 2014 10:35 pm

Hello,

did you mean a mapping like this?

Code: Select all

varying vec2 tcoord;
uniform sampler2D tex;
void main(void) 
{
    float val = texture2D(tex,tcoord).x;

    vec3 res = vec3( val*25.0, val*49.0, val*3.0+0.75 );
    res = fract(res);
    gl_FragColor = vec4(res, 0.5) ;
}
Regards Yggdrasil

User avatar
PeterO
Posts: 4940
Joined: Sun Jul 22, 2012 4:14 pm

Re: Fragment shader for waterfall display

Wed May 28, 2014 6:46 am

Yggdrasil wrote:Hello,

did you mean a mapping like this?

Code: Select all

varying vec2 tcoord;
uniform sampler2D tex;
void main(void) 
{
    float val = texture2D(tex,tcoord).x;

    vec3 res = vec3( val*25.0, val*49.0, val*3.0+0.75 );
    res = fract(res);
    gl_FragColor = vec4(res, 0.5) ;
}
Regards Yggdrasil
Thanks, but it's not quite what I'm looking for as it doesn't seem to give and sense of the value from the colour. Since the values are "noisy" I end up with a screen of random coloured pixels.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Yggdrasil
Posts: 138
Joined: Sun Aug 26, 2012 8:45 pm

Re: Fragment shader for waterfall display

Wed May 28, 2014 8:12 am

Yes, this shader example uses relativity random colors, but if you reduce the given scaling factors for the r,g,b- values the 'linearity' of the mapping will be increased. It's only necessary to distinct the 1-0 jumps for each the color components. But well, this is the laziest mapping for sure (and still used by me ;) )

Did you have a mapping in mind and just has problems to casting it into a shader?
Or did you just search a good mapping? The second questions has no answer because the quality of the mapping depends one the input data and the 'target information' which should be accent. Well-known is the jet-mapping.
It exists many websites to this topic, i.e. http://cresspahl.blogspot.de/2012/03/ex ... ormap.html ,

User avatar
PeterO
Posts: 4940
Joined: Sun Jul 22, 2012 4:14 pm

Re: Fragment shader for waterfall display

Wed May 28, 2014 6:32 pm

In the end I took a slightly different approach, and decided to use a RGB texture rather than just a Luminance texture. Now I precompute a 256 entry look up table in the ARM and use it to build a 1024x1 RGB texture to update one line of the the waterfall texture. The fragment shader them becomes the "plain texture shader".

Fro the look up I'm using this code

Code: Select all

	bp = wfLut;                    // pointer to start of lookup table
	for(n=0;n<256;n++)
	{
	    nn = (n >> 6) & 3;         // 0..3
	    nnn = (n << 2) & 255;      // 0..252
	    switch(nn)
	    {
	    case 0:		
		rr = 0;		
		gg = nnn;
		bb = (nnn < 16) ? nnn * 16 : 255 ;  // Make lowest values black
		break;
	    case 1:
		rr = 0;
		gg = 255;
		bb = 255 - nnn;
		break;
	    case 2:
		rr = nnn;
		gg = 255;
		bb = 0;
		break;
	    case 3:
		rr = 255;
		gg = 255 - nnn;
		bb = 0;
		break;
	    }
	    *bp++ = rr; *bp++ = gg; *bp++ = bb;
	}


Hmmm so much for "code" maintaining layout !
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

drdoug
Posts: 2
Joined: Mon Dec 29, 2014 10:35 pm

Re: Fragment shader for waterfall display

Mon Dec 29, 2014 10:55 pm

A simple color map that looks nice goes as follows:
Blue: Starts at 0, increases to a max and 1/3 full scale linearly, then decreases linearly to zero at 2/3 full scale
Green: 0 to 1/3 full scale, increases linearly to a max at 2/3 full scale then decreases linearly to 0 at full scale.
Red: 0 to 2/3 full scale, increases linearly to a max at full scale.

User avatar
PeterO
Posts: 4940
Joined: Sun Jul 22, 2012 4:14 pm

Re: Fragment shader for waterfall display

Tue Dec 30, 2014 7:48 am

You are 7 months too late !
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “OpenGLES”