xxxxxxxxxx
#version 300 es
precision highp float;
precision highp int;
#define norm normalize
#define len length
#define count(i,n) for(int i=0;i<n;i++)
const float ETA= .1234321e-8;
#define nozero(v) (v+ETA)
#define minv(v) min(v.x,min(v.y,v.z))
vec3 axis(vec3 n){
//certain theres better way
n-= sign(n)*minv(abs(n));
n-= sign(n)*minv(abs(n));
return norm(n);
}
uniform mat3 u_m;
uniform vec2 u_mouse;
uniform int N;
uniform int MODE;
in vec3 v_p;
in vec3 v_v;
out vec4 color_out;
void main() {
vec3 p= v_p;
vec3 v= norm(v_v);
vec3 c= vec3(0.);
vec3 n;
float T= 1.;
count(i,N){
//novel cube marcher shadertoy.com/view/Wld3R4
//mod to use single cube instead of voxel field
vec3 dp= sign(v)-p;//delta position to next-edges
vec3 edt= dp/nozero(v);//time to each
float dt= minv(edt);//time to soonest
//dt= max(0.,dt);//no negative time //nevermind negative time is fine
if(dt<0.) T*=.02;
dp= v/dt;
p+= dp;
if(MODE==0)
n= axis(p);
else
n= norm(p*abs(p));
v= reflect(v,-n);
T*= .5;
c+= abs(n)*T * tan(abs(v.z*1.5));
c.xyz= c.zxy;
//allow the normals to sing
}
//c/= float(N);
//c= abs(n);
c*= 3.20; //exposure
c= 1.-1./(.7+c); //tonemap
c= pow(c,vec3(3.2));//gamma
color_out= vec4(c,1.);
}