[NO BUG] GLSL Shaders crash vid io - TheSandbag - 11-11-2025
The following shader crashes the more-video module as seen by it reshowing the boot screen
Code: #version 100
#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.14159
#define MAX_ITER 20.
uniform vec2 u_resolution;
uniform float u_time;
uniform float u_modulator1;
uniform float u_modulator2;
uniform float u_modulator3;
uniform float u_modulator4;
uniform float u_modulator5;
uniform float u_modulator6;
const vec3 a1 = vec3(0.5, 0.5, 0.5);
const vec3 b1 = vec3(0.5, 0.5, 0.5);
const vec3 c1 = vec3(2.0, 1.0, 0.0);
const vec3 d1 = vec3(0.50, 0.20, 0.25);
const vec3 a2 = vec3(0.5, 0.5, 0.5);
const vec3 b2 = vec3(0.5, 0.5, 0.5);
const vec3 c2 = vec3(1.0, 1.0, 1.0);
const vec3 d2 = vec3(0.00, 0.33, 0.67);
mat2 rotate(float _angle){
return mat2(cos(_angle),-sin(_angle),
sin(_angle),cos(_angle));
}
mat2 scale(vec2 _scale){
return mat2(_scale.x,0.0,
0.0,_scale.y);
}
vec3 palette(in float t, in vec3 a, in vec3 b, in vec3 c, vec3 d)
{
return a + b*cos( 6.283185*(c*t+d) );
}
float check_step(float i, float z, float step_id) {
float is_i = step(0.1, i);
return (is_i * i) + ((1.-is_i) * (step(200., z) * step_id));
}
float julia(vec2 uv){
float j=0.;
float i=0.;
vec2 c=vec2(-0.70176,-0.3842);
for (float i=0.;i<MAX_ITER;i++){
uv=vec2(uv.x*uv.x-uv.y*uv.y,2.0*uv.x*uv.y)+c;
j=check_step(j, length(uv), i);
}
return j;
}
float hash(vec2 p)
{
p = fract( p*0.6180339887 );
p *= 25.0;
return fract( p.x*p.y*(p.x+p.y) );
}
float noise( in vec2 x )
{
vec2 p = floor(x);
vec2 f = fract(x);
f = f*f*(3.0-2.0*f);
float a = hash(p+vec2(0,0));
float b = hash(p+vec2(1,0));
float c = hash(p+vec2(0,1));
float d = hash(p+vec2(1,1));
return mix(mix( a, b,f.x), mix( c, d,f.x),f.y);
}
float fbm ( in vec2 _st) {
float v = 0.0;
float a = 0.5;
const vec2 shift = vec2(100.0);
const mat2 rot = mat2(cos(0.5), sin(0.5),
-sin(0.5), cos(0.50));
v += a * noise(_st);
_st = rot * _st * 2.0 + shift;
a *= 0.5;
v += a * noise(_st);
_st = rot * _st * 2.0 + shift;
a *= 0.5;
v += a * noise(_st);
_st = rot * _st * 2.0 + shift;
a *= 0.5;
v += a * noise(_st);
_st = rot * _st * 2.0 + shift;
a *= 0.5;
v += a * noise(_st);
_st = rot * _st * 2.0 + shift;
a *= 0.5;
v += a * noise(_st);
_st = rot * _st * 2.0 + shift;
a *= 0.5;
v += a * noise(_st);
return v;
}
vec3 smoke(vec2 st){
vec3 color = vec3(0.0);
vec2 q = vec2(0.);
q.x = fbm( st + 0.00*u_time);
q.y = fbm( st + vec2(1.0));
vec2 r = vec2(0.);
r.x = fbm( st + 1.0*q + vec2(1.7,9.2)+ 0.15*u_time );
r.y = fbm( st + 1.0*q + vec2(8.3,2.8)+ 0.126*u_time);
float f = fbm(st+r);
color = mix(vec3(0.101961,0.619608,0.666667),
vec3(0.666667,0.666667,0.498039),
clamp((f*f)*4.0,0.0,1.0));
color = mix(color,
vec3(0.8,0.6,0.164706),
clamp(length(q),0.0,1.0));
color = mix(color,
vec3(0.666667,1.,1.),
clamp(length(r.x),0.0,1.0));
return (f*f*f+.6*f*f+.5*f)*color;
}
float between(float start, float end, float p) {
return step(start, p) * step(p, end);
}
void main(){
vec2 uv=(((2.0*gl_FragCoord.xy)-u_resolution.xy)/u_resolution.y);
vec2 uv2 = uv;
uv2 *= rotate(-fract((u_time / 50.0) * (1.-u_modulator2)) * PI * 2.);
uv *= rotate(fract((u_time / 10.0) * (1.-u_modulator2)) * PI * 2.);
uv *= scale(vec2(1.3 + (1.-u_modulator1) * 0.4));
float foreground_start = (float(MAX_ITER) * ((0.5-u_modulator3)*0.5));
float mandel = 1.;//julia(uv);
vec3 color1 = palette(fbm(vec2(mandel/MAX_ITER, fract(u_time / 500.))*100.),a1,b1,c1,d1);
vec3 middleground = color1;
vec3 smok = (smoke(uv2 * 15.) * 10.) + 0.3;
vec3 background = smok * palette(length(uv2) / 3.,a2,b2,c2,d2) ;
vec3 foreground = smok * palette((length(uv2) / 3.) + 0.6,a2,b2,c2,d2);
gl_FragColor=vec4(background * between(1., foreground_start - 1., mandel), ((1. - u_modulator4))*0.5) + vec4(middleground * between(foreground_start, MAX_ITER, mandel), ((1. - u_modulator5))*0.5)+ vec4(foreground * between(0., .1, mandel), ((1. - u_modulator6))*0.5);
}
RE: GLSL Shaders crash vid io - XORadmin - 11-11-2025
Not a bug but this shader is too heavy for the Video expander and takes too long to compile (most probably due to the too deep 'for loop' involved.)
This takes more than 4 seconds which is the timeout for the watchdog reboot.
Page 118 in the manual: "Good to know: Avoid ‘for’ loops with many loop iterations as these increment the processing time and might cause performance issues. Especially ‘for’ loops that would loop many ten/hundred times will most likely not work properly with the VEX"
RE: GLSL Shaders crash vid io - TheSandbag - 11-11-2025
The same file but with the julia brot calc commented out doesn't crash
(11-11-2025, 04:10 PM)XORadmin Wrote: Not a bug but this shader is too heavy for the Video expander and takes too long to compile (most probably due to the too deep 'for loop' involved.)
This takes more than 4 seconds which is the timeout for the watchdog reboot.
Page 118 in the manual: "Good to know: Avoid ‘for’ loops with many loop iterations as these increment the processing time and might cause performance issues. Especially ‘for’ loops that would loop many ten/hundred times will most likely not work properly with the VEX" Is there a recomended sized / lines to keep them under as i had a similar problem when i unrolled the loop manually to try and optimise
RE: GLSL Shaders crash vid io - XORadmin - 11-11-2025
(11-11-2025, 04:10 PM)TheSandbag Wrote: The same file but with the julia brot calc commented out doesn't crash
Exactly.
Reduce the iterations and it will most probably work as well. Though at a very low framerate I assume.
RE: [NO BUG] GLSL Shaders crash vid io - XORadmin - 11-11-2025
Quote:Is there a recomended sized / lines to keep them under as i had a similar problem when i unrolled the loop manually to try and optimise
Unrolled loop is exactly the same as the loop in GLSL.
The problem is that there is much to compile which means also there is much to compute. It will definitely not work well anyways, so the recommendation is to reduce as much as possible and see how good it works. There is no amount of lines...it can depend on the code and the way you coded itself as well. They are guidelines somewhere in the GLSL documentations and usergroups on what to use and what not.
RE: [NO BUG] GLSL Shaders crash vid io - XORadmin - 11-11-2025
I actually checked the shader and it's not the loop. The Julia function is not even called. It is very heavy by itself. It even runs on a very slow framerate on my laptop. Forget about that, sometimes I got to restart my computer :-) Runs smooth in the computer but is still a heavy one.
Now that I roughly look over it I see that many functions are called many times per frame and these functions call other functions many times as well.
Smoke calls FBM multiple times, FBM calls noise multiple times, noise calls hash multiple times.... There is much going on here.
In fact, calling smoke causes smoke coming out of the VEX, hahaha
RE: [NO BUG] GLSL Shaders crash vid io - TheSandbag - 11-11-2025
Yeah, I stripped that out and left it with just a gradient palette for the background and I have it working reasonably
|