Skip to content

Instantly share code, notes, and snippets.

@McbeEringi
Last active October 16, 2021 13:26
Show Gist options
  • Save McbeEringi/481058339e90b0110b9ba0c4f7e65efb to your computer and use it in GitHub Desktop.
Save McbeEringi/481058339e90b0110b9ba0c4f7e65efb to your computer and use it in GitHub Desktop.
decimal display for utility shader
/*
precision mediump float;
uniform float time;
uniform vec2 res;
void main(){
vec2 p=gl_FragCoord.xy/res;
p*=7.;
float a=31.;
float b=21.;
float c=31.;
float d=1.;
float s=0.5;
for(float i=0.;i<5.;i++){
a*=.5;b*=.5;c*=.5;
float ps=step(i,p.y-2.)*step(p.y-2.,i+1.);
s=mix(s,1.,step(.2,fract(a))*ps*step(2.+d,p.x)*step(p.x,3.+d));
s=mix(s,1.,step(.2,fract(b))*ps*step(3.+d,p.x)*step(p.x,4.+d));
s=mix(s,1.,step(.2,fract(c))*ps*step(4.+d,p.x)*step(p.x,5.+d));
a=floor(a);b=floor(b);c=floor(c);
}
s=mix(s,1.,d*step(2.,p.y)*step(p.y,7.)*step(0.+d,p.x)*step(p.x,1.+d));
s=mix(s,.5,step(0.,p.y)*step(p.y,1.)*step(0.,p.x)*step(p.x,7.));
gl_FragColor=vec4(s);
}
*/
vec4 rs(vec4 col){
vec2 p=(fract(cPos.xz*vec2(1,-1))*4.-1.5)*7.;
float a=31.;float b=17.;float c=31.;
float d=0.;float s=0.;
if(.45>=color.r&&color.r>.3 ){a=0.;b=31.;c=0.;}
if(.5 >=color.r&&color.r>.45){a=23.;b=21.;c=29.;}
if(.55>=color.r&&color.r>.5 ){a=21.;b=21.;c=31.;}
if(.58>=color.r&&color.r>.55){a=28.;b=4.;c=31.;}
if(.6 >=color.r&&color.r>.58){a=29.;b=21.;c=23.;}
if(.65>=color.r&&color.r>.6 ){a=31.;b=21.;c=23.;}
if(.7 >=color.r&&color.r>.65){a=16.;b=16.;c=31.;}
if(.75>=color.r&&color.r>.7 ){a=31.;b=21.;c=31.;}
if(.78>=color.r&&color.r>.75){a=29.;b=21.;c=31.;}
if(.8 >=color.r&&color.r>.78){d=1.;}
if(.85>=color.r&&color.r>.8 ){d=1.;a=0.;b=31.;c=0.;}
if(.9 >=color.r&&color.r>.85){d=1.;a=23.;b=21.;c=29.;}
if(.95>=color.r&&color.r>.9 ){d=1.;a=21.;b=21.;c=31.;}
if(.98>=color.r&&color.r>.95){d=1.;a=28.;b=4.;c=31.;}
if(1. >=color.r&&color.r>.98){d=1.;a=29.;b=21.;c=23.;}
for(float i=0.;i<5.;i++){
a*=.5;b*=.5;c*=.5;
float ps=step(i,p.y-2.)*step(p.y-2.,i+1.);
s=mix(s,1.,step(.2,fract(a))*ps*step(2.+d,p.x)*step(p.x,3.+d));
s=mix(s,1.,step(.2,fract(b))*ps*step(3.+d,p.x)*step(p.x,4.+d));
s=mix(s,1.,step(.2,fract(c))*ps*step(4.+d,p.x)*step(p.x,5.+d));
a=floor(a);b=floor(b);c=floor(c);
}
s=mix(s,1.,d*step(2.,p.y)*step(p.y,7.)*step(0.+d,p.x)*step(p.x,1.+d));
s=mix(s,.5,step(0.,p.y)*step(p.y,1.)*step(0.,p.x)*step(p.x,7.));
return mix(col,vec4(1),s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment