Skip to content

Using date.w to display milliseconds, it always returned zero value #276

Description

@TheKingFireS

However, if I import subsecond uniform and replace iDate.w with subsecond specifically for milliseconds, it worked and will return milliseconds value like intended. Is this bug?

Imported from "iDate" shader from Shadertoy
https://www.shadertoy.com/view/ldKGRR

Click to expand
#version 300 es
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
precision highp int;
#else
precision mediump float;
precision mediump int;
#endif

out vec4 fragColor;

uniform vec2  resolution;
uniform float time;
uniform int   frame;
uniform vec2  touch;
uniform vec2  touchStart;
uniform vec4  date;

vec3  iResolution;
float iTime;
int   iFrame;
vec4  iMouse;
vec4  iDate;

#define resolution stemu_resolution
#define time       stemu_time
#define frame      stemu_frame
#define touch      stemu_touch
#define touchStart stemu_touchstart
#define date       stemu_date

// ============= iChanneli =============
// uniform samplerName TheNameOfFunction

// #define iChannel0 TheNameOfFunction
// #define iChannel1 TheNameOfFunction
// #define iChannel2 TheNameOfFunction
// #define iChannel3 TheNameOfFunction
// ============= iChanneli =============

// ====== vv Replace this vv ======

float D(vec2 p, float n) {  // display digit
    int i=int(p.y), b=int(exp2(floor(30.-p.x-n*3.)));
    i = ( p.x<0.||p.x>3.? 0:
    i==5? 972980223: i==4? 690407533: i==3? 704642687: i==2? 696556137:i==1? 972881535: 0 )/b;
 	return float(i-i/2*2);
}
float N(vec2 p, float v) {  // display number
    for (float n=3.; n>=0.; n--)  // print digit 3 to 0 ( negative = fractionals )
        if ((p.x-=4.)<3.) return D(p,floor(mod(v/pow(10.,n),10.))); 
    return 0.;
}    

void mainImage( out vec4 O, vec2 U )
{
    U /= iResolution.xy;
    float t,s;
      U.y>6./7. ? t = iDate.x,    s = 2050.
    : U.y>5./7. ? t = iDate.y+1.0,    s = 12.
    : U.y>4./7. ? t = iDate.z,    s = 31.
    : U.y>3./7. ? t = floor(iDate.w/3600.),        s = 24.
    : U.y>2./7. ? t = floor(mod(iDate.w/60.,60.)), s = 60.
    : U.y>1./7. ? t = floor(mod(iDate.w,60.)),     s = 60.
    :            (t = fract(iDate.w)*1000.,        s = 1000.); // strange bug: () needed or wrong s,t
                      // here, this is milliseconds function

    O = vec4(U.x < t/s); // bars
    
    O += N(vec2(U.x,mod(U.y,1./7.))*iResolution.xy/6., t ) *vec4(1,-1,-1,1); //digits

}

// ====== ^^ Replace this ^^ ======

#undef resolution
#undef time
#undef frame
#undef touch
#undef touchStart
#undef date

void main() {
	iResolution = vec3(resolution, 1.0);
	iTime = time;
	iFrame = frame;
	iMouse = vec4(touch, touchStart);
	iDate = date;
	mainImage(fragColor, gl_FragCoord.xy);
}

And yes, I wrote my shadertoy compatibility with almost proper iMouse support.
https://gist.github.com/TheKingFireS/db8ed049d515aaefddadfc8d87d817fa

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions