--[[--/* MoreCubesForTheCubeLovers.fuse Based on https://www.shadertoy.com/view/mslfR2 a WebGL shader created by mrange. Converted to DCTL and embeddet into a Lua Fuse by JiPi (https://www.youtube.com/c/JiPi_YT). Place this file in your Fusion's and/or DaVinci Resolve's 'Fuses/' folder to use it. */--]]-- -- /* local ShaderFuse = require("Shaderfuse/ShaderFuse") ShaderFuse.init() -- // ------------------------------------------------------------------------ -- // Registry declaration -- // ------------------------------------------------------------------------ FuRegisterClass(ShaderFuse.FuRegister.Name, CT_SourceTool, { ShaderFuse.FuRegister.Attributes, REG_NoObjMatCtrls = true, REG_NoMotionBlurCtrls = true, REG_Source_GlobalCtrls = false, REG_Source_SizeCtrls = true, REG_Source_AspectCtrls = true, REG_Source_DepthCtrls = true, REG_OpNoMask = true, REG_TimeVariant = true, }) -- // ------------------------------------------------------------------------ -- // DCTL kernel parameters -- // ------------------------------------------------------------------------ -- */ ShaderParameters = [[ float iResolution[2]; float iTime; float iMouse[4]; bool BACKSTEP; bool BOUNCE_ONCE; bool BOXY; bool FLAIR; float GlowCol[4]; float SunCol[4]; float DiffCol[4]; float BKG1[4]; float BKG2[4]; float BKG3[4]; float BKG4[4]; float ViewDXY[2]; float ViewDZ; float ViewXY[2]; float ViewZ; float RoadXY[2]; float RoadZ; float LAYERS; float TOLERANCE; float MAX_RAY_LENGTH; float hoff; float RoadDimW; float ZOOM; float fixed_radius2; float min_radius2; float folding_limit; float scale; int DF; int MAX_RAY_MARCHES_LO; int MAX_RAY_MARCHES_HI; int width,height; int compOrder; ]] -- /* -- // ------------------------------------------------------------------------ -- DCTL kernel compatibility code -- // ------------------------------------------------------------------------ -- */ ShaderCompatibilityCode = [[ #if defined(DEVICE_IS_METAL) #define in #define out thread #define inout thread #else #define in #define out #define inout #endif #undef USE_NATIVE_METAL_IMPL #undef USE_NATIVE_CUDA_IMPL #undef USE_NATIVE_OPENCL_IMPL // 0 to use the generic implementations; 1 for Metal, OpenCL, Cuda specific code if existing #if 1 #if defined(DEVICE_IS_METAL) #define USE_NATIVE_METAL_IMPL 1 #elif defined(DEVICE_IS_CUDA) #define USE_NATIVE_CUDA_IMPL 1 #elif defined(DEVICE_IS_OPENCL) #define USE_NATIVE_OPENCL_IMPL 1 #endif #endif #if defined(USE_NATIVE_METAL_IMPL) #define swi2(A,a,b) (A).a##b #define swi3(A,a,b,c) (A).a##b##c #define swi2S(a,b,c,d) a.b##c = d #else #define swi2(A,a,b) to_float2((A).a,(A).b) #define swi3(A,a,b,c) to_float3((A).a,(A).b,(A).c) #define swi2S(a,b,c,d) {float2 tmp = d; (a).b = tmp.x; (a).c = tmp.y;} #endif // ---------------------------------------------------------------------------------------------------------- // mat2 implementation // ---------------------------------------------------------------------------------------------------------- #if defined(USE_NATIVE_METAL_IMPL) typedef float2x2 mat2; #define to_mat2(A,B,C,D) mat2((A),(B),(C),(D)) #define mul_f2_mat2(A,B) ((A)*(B)) #else typedef struct { float2 r0; float2 r1; } mat2; __DEVICE__ inline mat2 to_mat2 ( float a, float b, float c, float d) { mat2 t; t.r0.x = a; t.r0.y = b; t.r1.x = c; t.r1.y = d; return t; } __DEVICE__ inline float2 mul_f2_mat2( float2 v, mat2 m ) { float2 t; t.x = v.x*m.r0.x + v.y*m.r0.y; t.y = v.x*m.r1.x + v.y*m.r1.y; return t; } #endif // end of mat2 implementation // ---------------------------------------------------------------------------------------------------------- // mat3 implementation // ---------------------------------------------------------------------------------------------------------- #if defined(USE_NATIVE_METAL_IMPL) typedef float3x3 mat3; __DEVICE__ inline mat3 to_mat3( float a, float b, float c, float d, float e, float f, float g, float h, float i) { return mat3(a,b,c,d,e,f,g,h,i); } __DEVICE__ inline float3 mul_mat3_f3( mat3 B, float3 A) { return (B*A); } __DEVICE__ inline float3 mul_f3_mat3( float3 A, mat3 B) { return (A*B); } __DEVICE__ inline mat3 mul_mat3_mat3( mat3 A, mat3 B) { return (A*B); } #else typedef struct { float3 r0; float3 r1; float3 r2; } mat3; __DEVICE__ inline mat3 to_mat3( float a, float b, float c, float d, float e, float f, float g, float h, float i) { mat3 t; t.r0.x = a; t.r0.y = b; t.r0.z = c; t.r1.x = d; t.r1.y = e; t.r1.z = f; t.r2.x = g; t.r2.y = h; t.r2.z = i; return t; } __DEVICE__ inline float3 mul_mat3_f3( mat3 B, float3 A) { float3 C; C.x = A.x * B.r0.x + A.y * B.r1.x + A.z * B.r2.x; C.y = A.x * B.r0.y + A.y * B.r1.y + A.z * B.r2.y; C.z = A.x * B.r0.z + A.y * B.r1.z + A.z * B.r2.z; return C; } __DEVICE__ inline float3 mul_f3_mat3( float3 A, mat3 B) { float3 C; C.x = A.x * B.r0.x + A.y * B.r0.y + A.z * B.r0.z; C.y = A.x * B.r1.x + A.y * B.r1.y + A.z * B.r1.z; C.z = A.x * B.r2.x + A.y * B.r2.y + A.z * B.r2.z; return C; } __DEVICE__ mat3 mul_mat3_mat3( mat3 B, mat3 A) { float r[3][3]; float a[3][3] = {{A.r0.x, A.r0.y, A.r0.z}, {A.r1.x, A.r1.y, A.r1.z}, {A.r2.x, A.r2.y, A.r2.z}}; float b[3][3] = {{B.r0.x, B.r0.y, B.r0.z}, {B.r1.x, B.r1.y, B.r1.z}, {B.r2.x, B.r2.y, B.r2.z}}; for( int i = 0; i < 3; ++i) { for( int j = 0; j < 3; ++j) { r[i][j] = 0.0f; for( int k = 0; k < 3; ++k) { r[i][j] = r[i][j] + a[i][k] * b[k][j]; } } } mat3 R = to_mat3(r[0][0], r[0][1], r[0][2], r[1][0], r[1][1], r[1][2], r[2][0], r[2][1], r[2][2]); return R; } #endif // end of mat3 implementation #if defined(USE_NATIVE_METAL_IMPL) #define fract_f2(A) fract(A) #define fract_f3(A) fract(A) #define mod_f(a,b) fmod((a),(b)) #define mod_f2f2(value,divisor) fmod(value,divisor) #define mod_f3f3(value,divisor) fmod(value,divisor) #define sin_f2(i) sin(i) #define tanh_f3(i) tanh(i) #define abs_f2(a) _fabs(a) #define abs_f3(a) _fabs(a) #define sqrt_f3(a) _sqrtf(a) #define exp2_f3(a) _exp2f((a)) #define mix_f3(v,i,m) mix(v,i,m) #define pow_f3(a,b) pow(a,b) #else #if defined(USE_NATIVE_OPENCL_IMPL) #define reflect(I,N) (I-2.0f*dot(N,I)*N) #define fract(a) ((a)-_floor(a)) // oder Pointer bauen: gentype fract(gentype x, gentype *itpr) #define fract_f2(A) to_float2(fract((A).x),fract((A).y)) #define fract_f3(A) to_float3(fract((A).x),fract((A).y),fract((A).z)) #define mod_f(a,b) _fmod(a,b) #define mod_f2f2(value,divisor) _fmod(value,divisor) #define mod_f3f3(value,divisor) _fmod(value,divisor) #define sin_f2(i) sin(i) #define tanh_f3(i) tanh(i) #define abs_f2(a) fabs(a) #define abs_f3(a) fabs(a) #define sqrt_f3(a) _sqrtf(a) #define exp2_f3(a) _exp2f((a)) #define mix_f3(v,i,m) mix(v,i,m) #define pow_f3(a,b) pow(a,b) #else // Generic #if defined(DEVICE_IS_OPENCL) __DEVICE__ float3 reflect(float3 I, float3 N) {return I - 2.0f * dot(N, I) * N;} #endif #define fract(a) ((a)-_floor(a)) #define fract_f2(A) to_float2(fract((A).x),fract((A).y)) #define fract_f3(A) to_float3(fract((A).x),fract((A).y),fract((A).z)) #define mod_f(a,b) ((a)-(b)*_floor((a)/(b))) #define mod_f2f2(value,divisor) to_float2(mod_f((value).x, (divisor).x),mod_f((value).y, (divisor).y)) #define mod_f3f3(value,divisor) to_float3(mod_f((value).x, (divisor).x),mod_f((value).y, (divisor).y),mod_f((value).z, (divisor).z)) #define sin_f2(i) to_float2( _sinf((i).x), _sinf((i).y)) #define tanh_f3(i) to_float3(_tanhf((i).x), _tanhf((i).y), _tanhf((i).z)) #define abs_f2(a) to_float2(_fabs((a).x), _fabs((a).y)) #define abs_f3(a) to_float3(_fabs((a).x), _fabs((a).y),_fabs((a).z)) #define sqrt_f3(a) to_float3(_sqrtf((a).x),_sqrtf((a).y),_sqrtf((a).z)) #define exp2_f3(a) to_float3(_exp2f((a).x), _exp2f((a).y), _exp2f((a).z)) #define mix_f3(v,i,m) to_float3(_mix((v).x,(i).x,(m).x),_mix((v).y,(i).y,(m).y),_mix((v).z,(i).z,(m).z)) #define pow_f3(a,b) to_float3(_powf((a).x,(b).x),_powf((a).y,(b).y),_powf((a).z,(b).z)) #endif #endif ]] -- /* -- // ------------------------------------------------------------------------ -- DCTL kernel implementation -- // ------------------------------------------------------------------------ -- */ ShaderKernelCode = [[ // ---------------------------------------------------------------------------------- // - Common - // ---------------------------------------------------------------------------------- #define texture(ch,uv) _tex2DVecN(ch, (uv).x, (uv).y, 15) __DEVICE__ mat3 transpose(mat3 m) { return(to_mat3(m.r0.x,m.r1.x,m.r2.x, m.r0.y,m.r1.y,m.r2.y, m.r0.z,m.r1.z,m.r2.z)); } __DEVICE__ inline mat3 to_mat3_n( float A) { mat3 D; D.r0 = to_float3(A,0.0f,0.0f); D.r1 = to_float3(0.0f,A,0.0f); D.r2 = to_float3(0.0f,0.0f,A); return D; } // ---------------------------------------------------------------------------------- // - Image - // ---------------------------------------------------------------------------------- // Connect Image 'Texture: Audio' to iChannel0 // CC0: More "cubes" for the cube lovers // Tinkering around with glow effects and one bounce reflections // Produced a few interesting "cubes" that some might enjoy. // Song : Rush Connection - Culture Shock // Try different approximations of "cubes" by changing between DF0-DF7 //#define DF2 // Some "cubes" can be more or less boxy // define or comment out // #define BOXY // Some "cubes" have flair variants // define or comment out //#define FLAIR #define TIME iTime #define RESOLUTION iResolution #define PI 3.141592654f #define TAU (2.0f*PI) #define ROT(a) to_mat2(_cosf(a), _sinf(a), -_sinf(a), _cosf(a)) //#define LAYERS 5.0f #define TTIME (TAU*TIME) // //#define TOLERANCE 0.0001 //#define MAX_RAY_LENGTH 120.0 //#define MAX_RAY_MARCHES_LO 30 //#define MAX_RAY_MARCHES_HI 70 #define NORM_OFF 0.005f // License: WTFPL, author: sam hocevar, found: https://stackoverflow.com/a/17897228/418488 __DEVICE__ float3 hsv2rgb(float3 c) { const float4 hsv2rgb_K = to_float4(1.0f, 2.0f / 3.0f, 1.0f / 3.0f, 3.0f); float3 p = abs_f3(fract(swi3(c,x,x,x) + swi3(hsv2rgb_K,x,y,z)) * 6.0f - swi3(hsv2rgb_K,w,w,w)); return c.z * _mix(swi3(hsv2rgb_K,x,x,x), clamp(p - swi3(hsv2rgb_K,x,x,x), 0.0f, 1.0f), c.y); } #define HSV2RGB(c) (c.z * _mix(swi3(hsv2rgb_K,x,x,x), clamp(abs_f3(fract_f3(swi3(c,x,x,x) + swi3(hsv2rgb_K,x,y,z)) * 6.0f - swi3(hsv2rgb_K,w,w,w)) - swi3(hsv2rgb_K,x,x,x), 0.0f, 1.0f), c.y)) // License: Unknown, author: Matt Taylor (https://github.com/64), found: https://64.github.io/tonemapping/ __DEVICE__ float3 aces_approx(float3 v) { v = _fmaxf(v, to_float3_s(0.0f)); v *= 0.6f; float a = 2.51f; float b = 0.03f; float c = 2.43f; float d = 0.59f; float e = 0.14f; return clamp((v*(a*v+b))/(v*(c*v+d)+e), 0.0f, 1.0f); } // License: Unknown, author: Unknown, found: don't remember __DEVICE__ float hash(float co) { return fract(_sinf(co*12.9898f) * 13758.5453f); } // License: Unknown, author: Unknown, found: don't remember __DEVICE__ float2 hash2(float2 p) { p = to_float2(dot (p, to_float2 (127.1f, 311.7f)), dot (p, to_float2 (269.5f, 183.3f))); return fract_f2(sin_f2(p)*43758.5453123f); } // License: CC BY-NC-SA 3.0f, author: Stephane Cuillerdier - Aiekick/2015 (twitter:@aiekick), found: https://www.shadertoy.com/view/Mt3GW2 __DEVICE__ float3 blackbody(float Temp) { float3 col = to_float3_s(255.0f); col.x = 56100000.0f * _powf(Temp,(-3.0f / 2.0f)) + 148.0f; col.y = 100.04f * _logf(Temp) - 623.6f; if (Temp > 6500.0f) col.y = 35200000.0f * _powf(Temp,(-3.0f / 2.0f)) + 184.0f; col.z = 194.18f * _logf(Temp) - 1448.6f; col = clamp(col, 0.0f, 255.0f)/255.0f; if (Temp < 1000.0f) col *= Temp/1000.0f; return col*col; } // License: Unknown, author: Unknown, found: don't remember __DEVICE__ float tanh_approx(float x) { // return _tanhf(x); float x2 = x*x; return clamp(x*(27.0f + x2)/(27.0f+9.0f*x2), -1.0f, 1.0f); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/smin __DEVICE__ float pmin(float a, float b, float k) { float h = clamp( 0.5f+0.5f*(b-a)/k, 0.0f, 1.0f ); return _mix( b, a, h ) - k*h*(1.0f-h); } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/smin __DEVICE__ float3 pmin_f3(float3 a, float3 b, float k) { float3 h = clamp( 0.5f+0.5f*(b-a)/k, 0.0f, 1.0f ); return mix_f3( b, a, h ) - k*h*(1.0f-h); } __DEVICE__ float pmax(float a, float b, float k) { return -pmin(-a, -b, k); } __DEVICE__ float3 pabs(float3 a, float k) { return -1.0f*pmin_f3(a, -a, k); } // License: MIT OR CC-BY-NC-4.0f, author: mercury, found: https://mercury.sexy/hg_sdf/ __DEVICE__ float mod1(inout float *p, float size) { float halfsize = size*0.5f; float c = _floor((*p + halfsize)/size); *p = mod_f(*p + halfsize, size) - halfsize; return c; } // License: MIT OR CC-BY-NC-4.0f, author: mercury, found: https://mercury.sexy/hg_sdf/ __DEVICE__ float2 mod2(inout float2 *p, float2 size) { float2 c = _floor((*p + size*0.5f)/size); *p = mod_f2f2(*p + size*0.5f,size) - size*0.5f; return c; } // License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/intersectors __DEVICE__ float rayPlane(float3 ro, float3 rd, float4 p) { return -(dot(ro,swi3(p,x,y,z))+p.w)/dot(rd,swi3(p,x,y,z)); } __DEVICE__ float circle(float2 p, float r) { return length(p) - r; } // License: MIT, author: Inigo Quilez, found: www.iquilezles.org/www/articles/distfunctions/distfunctions.htm __DEVICE__ float torus(float3 p, float2 t) { float2 q = to_float2(length(swi2(p,x,z))-t.x,p.y); return length(q)-t.y; } // License: MIT OR CC-BY-NC-4.0f, author: mercury, found: https://mercury.sexy/hg_sdf/ __DEVICE__ float3 mod3(inout float3 *p, float3 size) { float3 c = _floor((*p + size*0.5f)/size); *p = mod_f3f3(*p + size*0.5f,size) - size*0.5f; return c; } // License: MIT, author: Inigo Quilez, found: www.iquilezles.org/www/articles/distfunctions/distfunctions.htm __DEVICE__ float box(float3 p, float3 b) { float3 q = abs_f3(p) - b; return length(_fmaxf(q,to_float3_s(0.0f))) + _fminf(_fmaxf(q.x,_fmaxf(q.y,q.z)),0.0f); } // License: MIT, author: Inigo Quilez, found: www.iquilezles.org/www/articles/distfunctions/distfunctions.htm __DEVICE__ float boxf(float3 p, float3 b, float e) { p = abs_f3(p)-b; float3 q = abs_f3(p+e)-e; return _fminf(_fminf( length(_fmaxf(to_float3(p.x,q.y,q.z),to_float3_s(0.0f)))+_fminf(_fmaxf(p.x,_fmaxf(q.y,q.z)),0.0f), length(_fmaxf(to_float3(q.x,p.y,q.z),to_float3_s(0.0f)))+_fminf(_fmaxf(q.x,_fmaxf(p.y,q.z)),0.0f)), length(_fmaxf(to_float3(q.x,q.y,p.z),to_float3_s(0.0f)))+_fminf(_fmaxf(q.x,_fmaxf(q.y,p.z)),0.0f)); } // Intentionally bounded, not exact __DEVICE__ float bbox(float3 p, float3 b) { float3 q = abs_f3(p) - b; return (_fmaxf(q.x,_fmaxf(q.y,q.z))); } __DEVICE__ float segmentx(float2 p) { float d0 = _fabs(p.y); float d1 = length(p); return p.x > 0.0f ? d0 : d1; } __DEVICE__ float segmentx_l(float2 p, float l) { float hl = 0.5f*l; p.x = _fabs(p.x); float d0 = _fabs(p.y); float d1 = length(p-to_float2(hl, 0.0f)); return p.x > hl ? d1 : d0; } __DEVICE__ float sphere(float3 p, float r) { return length(p) - r; } __DEVICE__ float sphere4(float3 p, float r) { p *= p; return _powf(dot(p, p), 0.25f) - r; } __DEVICE__ float sphere8(float3 p, float r) { p *= p; p *= p; return _powf(dot(p, p), 0.125f) - r; } __DEVICE__ float3 toSpherical(float3 p) { float r = length(p); float t = _acosf(p.z/r); float ph = _atan2f(p.y, p.x); return to_float3(r, t, ph); } __DEVICE__ float sun(float2 p) { const float ch = 0.0125f; float2 sp = p; float d0 = circle(sp, 0.5f); float d = d0; return d; } __DEVICE__ float synth(float2 p, float aa, out float *h, out float *db, __TEXTURE2D__ iChannel0) { const float z = 75.0f; p.y -= -70.0f; const float st = 0.04f; p.x = _fabs(p.x); p.x -= 20.0f-3.5f; p.x += st*20.0f; p /= z; float par = p.x; float n = mod1(&par, st);//&(p.x), st); p.x = par; float dib = 1E6f; const int around = 0; for (int i = -around; i <=around ;++i) { float fft = texture(iChannel0, to_float2((n+(float)(i))*st, 0.25f)).x; fft *= fft; if (i == 0) *h = fft; float dibb = segmentx_l(swi2((p-to_float2(st*(float)(i), 0.0f)),y,x), fft+0.05f)-st*0.4f; dib = _fminf(dib, dibb); } float d = dib; *db = _fabs(p.y)*z; return smoothstep(aa, -aa, d*z); } __DEVICE__ float3 road(float3 ro, float3 rd, float3 nrd, float glare, out float *pt, float4 roadDim, float iTime, __TEXTURE2D__ iChannel0, float3 ColorsBKG[4]) { const float4 hsv2rgb_K = to_float4(1.0f, 2.0f / 3.0f, 1.0f / 3.0f, 3.0f); const float szoom = 0.5f; const float bsz = 25.0f; const float sm = 1.0f; float off = _fabs(roadDim.w); float t = rayPlane(ro, rd, roadDim); *pt = t; float3 p = ro+rd*t; float3 np = ro+nrd*t; float2 pp = swi2(p,x,z); float2 npp = swi2(np,x,z); float2 opp = pp; float aa = length(npp-pp)*_sqrtf(0.5f); pp.y += -60.0f*TIME; float3 gcol = to_float3_s(0.0f); float dr = _fabs(pp.x)-off; float2 cp = pp; float par = cp.y; mod1(&par, 6.0f*off);//&(cp.y), 6.0f*off); cp.y = par; float2 sp = pp; sp.x = _fabs(sp.x); par = sp.y; mod1(&par, off);//&(sp.y), off); sp.y = par; float dcl = segmentx_l(swi2(cp,y,x), 1.5f*off); float dsl = segmentx_l(swi2((sp-to_float2(0.95f*off, 0.0f)),y,x), off*0.5f); float2 mp = pp; mod2(&mp, to_float2_s(off*0.5f)); float2 dp = abs_f2(mp); float d = dp.x; d = pmin(d, dp.y, sm); d = _fmaxf(d, -dr); d = _fminf(d, dcl); d = _fminf(d, dsl); float2 s2 = sin_f2(TIME+2.0f*swi2(p,x,z)/off); float m = _mix(0.75f, 0.9f, tanh_approx(s2.x+s2.y)); m *= m; m *= m; m *= m; float3 hsv = to_float3(0.4f+_mix(0.5f, 0.0f, m), tanh_approx(0.15f*_mix(30.0f, 10.0f, m)*d), 1.0f) + ColorsBKG[2]; float fo = _expf(-0.04f*_fmaxf(_fabs(t)-off*2.0f, 0.0f)); float3 bcol = hsv2rgb(hsv); gcol += 2.0f*bcol*_expf(-0.1f*_mix(30.0f, 10.0f, m)*d)*fo; float sh; float sdb; float sd = synth(opp, 4.0f*aa, &sh, &sdb, iChannel0)*smoothstep(aa, -aa, -0.5f*dr); sh = tanh_approx(sh); sdb *= 0.075f; sdb *= sdb; sdb += 0.05f; float3 scol = sd*(sdb)*pow_f3(tanh_f3(to_float3_s(0.1f)+bcol), _mix(to_float3_s(1.0f), ColorsBKG[3], smoothstep(0.4f, 0.5f, sh))); //to_float3(1.5f, 0.5f, 0.5f) gcol += scol; gcol = t > 0.0f ? gcol : to_float3_s(0.0f); return gcol+scol; } __DEVICE__ float3 stars(float2 sp, float hh, float LAYERS, float iTime) { float3 col = to_float3_s(0.0f); const float m = LAYERS; hh = tanh_approx(20.0f*hh); for (float i = 0.0f; i < m; ++i) { float2 pp = sp+0.5f*i; float s = i/(m-1.0f); float2 dim = to_float2_s(_mix(0.05f, 0.003f, s)*PI); float2 np = mod2(&pp, dim); float2 h = hash2(np+127.0f+i); float2 o = -1.0f+2.0f*h; float y = _sinf(sp.x); pp += o*dim*0.5f; pp.y *= y; float l = length(pp); float h1 = fract(h.x*1667.0f); float h2 = fract(h.x*1887.0f); float h3 = fract(h.x*2997.0f); float3 scol = _mix(8.0f*h2, 0.25f*h2*h2, s)*blackbody(_mix(3000.0f, 20000.0f, h1*h1)); float3 ccol = col + _expf(-(_mix(6000.0f, 2000.0f, hh)/_mix(2.0f, 0.25f, s))*_fmaxf(l-0.001f, 0.0f))*scol; ccol *= _mix(0.125f, 1.0f, smoothstep(1.0f, 0.99f, _sinf(0.33f*TIME+TAU*h.y))); col = h3 < y ? ccol : col; } return col; } __DEVICE__ float3 meteorite(float2 sp, float iTime) { const float4 hsv2rgb_K = to_float4(1.0f, 2.0f / 3.0f, 1.0f / 3.0f, 3.0f); const float period = 3.0f; float mtime = mod_f(TIME, period); float ntime = _floor(TIME/period); float h0 = hash(ntime+123.4f); float h1 = fract(1667.0f*h0); float h2 = fract(9967.0f*h0); float2 mp = sp; mp.x += -1.0f; mp.y += -0.5f*h1; mp.y += PI*0.5f; mp = mul_f2_mat2(mp,ROT(PI+_mix(-PI/4.0f, PI/4.0f, h0))); float m = mtime/period; mp.x += _mix(-1.0f, 2.0f, m); float d0 = length(mp); float d1 = segmentx(mp); float3 col = to_float3_s(0.0f); col += 0.5f*_expf(-4.0f*_fmaxf(d0, 0.0f))*_expf(-1000.0f*_fmaxf(d1, 0.0f)); col *= 2.0f*HSV2RGB(to_float3(0.8f, 0.5f, 1.0f)); float fl = smoothstep(-0.5f, 0.5f, _sinf(12.0f*TTIME)); col += _mix(1.0f, 0.5f, fl)*_expf(-_mix(100.0f, 150.0f, fl)*_fmaxf(d0, 0.0f)); col = h2 > 0.8f ? col: to_float3_s(0.0f); return col; } __DEVICE__ float3 skyGrid(float2 sp, float2 iResolution) { const float m = 1.0f; const float2 dim = to_float2_s(1.0f/12.0f*PI); float y = _sinf(sp.x); float2 pp = sp; float2 np = mod2(&pp, dim*to_float2(1.0f/_floor(1.0f/y), 1.0f)); float3 col = to_float3_s(0.0f); float d = _fminf(_fabs(pp.x), _fabs(pp.y*y)); float aa = 2.0f/RESOLUTION.y; col += 0.25f*to_float3(0.5f, 0.5f, 1.0f)*_expf(-2000.0f*_fmaxf(d-0.00025f, 0.0f)); return col; } __DEVICE__ float3 sunset(float2 sp, float2 nsp) { const float szoom = 0.5f; float aa = length(nsp-sp)*_sqrtf(0.5f); sp -= (to_float2(0.5f, -0.5f)*PI); sp /= szoom; sp = swi2(sp,y,x); sp.y += 0.22f; sp.y = -sp.y; float ds = sun(sp)*szoom; float3 bscol = hsv2rgb(to_float3(fract(0.7f-0.25f*(sp.y)), 1.0f, 1.0f)); float3 gscol = 0.75f*sqrt_f3(bscol)*_expf(-50.0f*_fmaxf(ds, 0.0f)); float3 scol = _mix(gscol, bscol, smoothstep(aa, -aa, ds)); return scol; } __DEVICE__ float3 glow(float3 ro, float3 rd, float2 sp, float3 lp) { const float4 hsv2rgb_K = to_float4(1.0f, 2.0f / 3.0f, 1.0f / 3.0f, 3.0f); float ld = _fmaxf(dot(normalize(lp-ro), rd),0.0f); float y = -0.5f+sp.x/PI; y = _fmaxf(_fabs(y)-0.02f, 0.0f)+0.1f*smoothstep(0.5f, PI, _fabs(sp.y)); float ci = _powf(ld, 10.0f)*2.0f*_expf(-25.0f*y); float h = 0.65f; float3 col = hsv2rgb(to_float3(h, 0.75f, 0.35f*_expf(-15.0f*y)))+HSV2RGB(to_float3(0.8f, 0.75f, 0.5f))*ci; return col; } __DEVICE__ float3 neonSky(float3 ro, float3 rd, float3 nrd, out float *gl, float LAYERS, float iTime, float2 iResolution, float3 ColorsBKG[4]) { const float4 hsv2rgb_K = to_float4(1.0f, 2.0f / 3.0f, 1.0f / 3.0f, 3.0f); const float3 lp = 500.0f*ColorsBKG[0];//to_float3(0.0f, 0.25f, -1.0f); const float3 skyCol = HSV2RGB(ColorsBKG[1]);//to_float3(0.8f, 0.75f, 0.05f)); float glare = _powf(_fabs(dot(rd, normalize(lp))), 20.0f); float2 sp = swi2(toSpherical(swi3(rd,x,z,y)),y,z); float2 nsp = swi2(toSpherical(swi3(nrd,x,z,y)),y,z); float3 grd = rd; swi2S(grd,x,y, mul_f2_mat2(swi2(grd,x,y) , ROT(0.025f*TIME))); float2 spp = swi2(toSpherical(grd),y,z); float gm = 1.0f/_fabs(rd.y)*_mix(0.005f, 2.0f, glare); float3 col = skyCol*gm; float ig = 1.0f-glare; col += glow(ro, rd, sp, lp); if (rd.y > 0.0f) { col += sunset(sp, nsp); col += stars(sp, 0.0f, LAYERS, iTime)*ig; col += skyGrid(spp, iResolution)*ig; col += meteorite(sp, iTime)*ig; } *gl = glare; return col; } __DEVICE__ float3 render0(float3 ro, float3 rd, float3 nrd, float LAYERS, float4 roadDim, float iTime, float2 iResolution, __TEXTURE2D__ iChannel0, float3 ColorsBKG[4]) { float glare; float3 col = neonSky(ro, rd, nrd, &glare, LAYERS, iTime, iResolution, ColorsBKG); if (rd.y < 0.0f) { float t; col += road(ro, rd, nrd, glare, &t, roadDim, iTime, iChannel0, ColorsBKG); } return col; } //############################################################################################################## //#if defined(DF0) //#if !defined(BOXY) //#define BACKSTEP //#endif __DEVICE__ float dfeffect_DF0(float3 p, out float *ogd, bool BOXY, bool FLAIR) { const float sz = 20.0f; float d0=0.0f,d1=0.0f; if (BOXY) { d0 = box(p, to_float3_s(sz)); d1 = boxf(p, to_float3_s(sz+0.01f), 0.0f)-0.01f; } else d0 = sphere8(p, (sz)); float3 p2 = p; float bsz = 0.0f; if (FLAIR) bsz = 2.0f*sz/(3.0f-1.0f); else bsz = 2.0f*sz/(24.0f-1.0f); mod3(&p2, to_float3_s(bsz)); float d2 = box(p2, to_float3_s(0.80f*bsz*0.5f))-0.15f*bsz*0.5f; float d4 = sphere4(p, sz+-0.005f); float d = d2; d = _fmaxf(d, d0); if (BOXY) d = _fminf(d, d1); d = _fminf(d, d4); float gd = d4; if (BOXY) gd = _fminf(gd, d1); *ogd = gd; return d; } //#elif defined(DF1) //#if !defined(BOXY) //#define BACKSTEP //#endif //#define ZOOM (0.166f) #define FWD(x) exp2_f3((x)*ZOOM) #define REV(x) (_log2f(x)/ZOOM) __DEVICE__ float dfeffect_DF1(float3 p, out float *ogd, bool BOXY, bool FLAIR, float ZOOM) { const float sz = 20.0f; float d0=0.0f,d1=0.0f; if (BOXY) { d0 = box(p, to_float3_s(sz)); d1 = boxf(p, to_float3_s(sz+0.01f), 0.0f)-0.01f; } else d0 = sphere8(p, (sz)); float d3 = sphere4(p, sz); float d4 = _fminf(_fminf(_fabs(p.x), _fabs(p.y)), _fabs(p.z))-0.015f; //FLAIR float d5 = _fmaxf(d0, d4); float3 p2 = p; p2 = abs_f3(p2); p2 -= 20.0f; float3 fp2 = FWD(abs_f3(p2)); float n = _floor(_fmaxf(_fmaxf(fp2.x, fp2.y), fp2.z)); float x0 = REV(n); float x1 = REV(n+1.0f); float m = (x0+x1)*0.5f; float w = x1-x0; float d2 = _fabs(bbox(p2, to_float3_s(m)))-(w*0.5f)+0.125f; d0 = _fmaxf(d0, d2); float d = d0; d = _fminf(d, d3); if (FLAIR) d = _fminf(d, d5); if (BOXY) d = _fminf(d, d1); float gd = d3; if (FLAIR) gd = _fminf(gd, d5); if (BOXY) gd = _fminf(gd, d1); *ogd = gd; return d; } //#elif defined(DF2) //#define BACKSTEP //#define BOUNCE_ONCE __DEVICE__ float dfeffect_DF2(float3 p, out float *ogd, inout mat3 *g_rot) { const float sz = (20.0f); float3 p0 = p; float3 p1 = p; p1 = mul_f3_mat3(p1,(*g_rot)); p1 = pabs(p1, 10.0f); p1 -= 12.0f; p1 = mul_f3_mat3(p1,(*g_rot)); float d0 = sphere8(p0, 20.0f); float d1 = torus(p1, 10.0f*to_float2(1.0f, 0.0125f)); float d = d0; d = pmax(d, -(d1-2.0f), 5.0f); d = _fminf(d, d1); *ogd = d1; return d; } //#elif defined(DF3) //#define BACKSTEP //#define BOUNCE_ONCE __DEVICE__ float dfeffect_DF3(float3 p, out float *ogd, inout mat3 *g_rot) { const float sz = (20.0f); float3 p0 = p; float3 p1 = p; float d0 = sphere8(p0, 20.0f); float d1 = sphere(p1, 15.0f); float d = d0; d = pmax(d, -(d1-5.0f), 6.0f); d = _fminf(d, d1); *ogd = d1; return d; } //#elif defined(DF4) //#define BACKSTEP //#if !defined(FLAIR) //#define BOUNCE_ONCE //#endif __DEVICE__ void sphere_fold(inout float3 z, inout float dz, float min_radius2, float fixed_radius2) { float r2 = dot(z, z); if(r2 < min_radius2) { float temp = (fixed_radius2 / min_radius2); z *= temp; dz *= temp; } else if(r2 < fixed_radius2) { float temp = (fixed_radius2 / r2); z *= temp; dz *= temp; } } __DEVICE__ void box_fold(inout float3 *z, inout float dz, float folding_limit) { *z = clamp(*z, -folding_limit, folding_limit) * 2.0f - *z; } __DEVICE__ float mb(float3 z, out float *ddd, bool FLAIR, float folding_limit, float scale, float min_radius2, float fixed_radius2) { float3 offset = z; float dr = 1.0f; float d2 = 0.0f; if (FLAIR) d2 = 1E3; else d2 = ((sphere4(z,2.0f))); for(int n = 0; n < 5; ++n) { box_fold(&z, dr, folding_limit); sphere_fold(z, dr, min_radius2, fixed_radius2); z = scale * z + offset; dr = dr * _fabs(scale) + 1.5f; if (FLAIR) { if (n < 2) { float d = (length(z))/_fabs(dr)-0.06f; d2 = _fminf(d, d2); } } } float d = (length(z))/_fabs(dr)-0.04f; if (!FLAIR) d2 = pmax(d2, -d, 0.5f); d = _fminf(d, d2); *ddd = d2; return d; } __DEVICE__ float dfeffect_DF4(float3 p, out float *ogd, inout mat3 *g_rot, bool FLAIR, float folding_limit, float scale, float min_radius2, float fixed_radius2) { const float z = 10.0f; float3 p0 = p/z; float d2; float d0 = mb(p0, &d2, FLAIR, folding_limit, scale, min_radius2, fixed_radius2); d0 *= z; float d1 = d2*z; *ogd = d1; float d = d0; d = _fminf(d, d1); return d0; } //#elif defined(DF5) //#define BACKSTEP //#define BOUNCE_ONCE __DEVICE__ float dfeffect_DF5(float3 p, out float *ogd, inout mat3 *g_rot, bool BOXY) { const float sz = (22.0f); float d = 1E3f; *ogd = 1E3f; mat3 rot = *g_rot; float3 pp = p; const float zzz = 0.33f; float zz = 1.0f; const float MaxI = 5.0f; for (float i = 0.0f; i < MaxI; ++i) { pp = abs_f3(pp); float3 p0 = pp; float d0=0.0f,d1=0.0f; if (BOXY) { d0 = (sphere4(p0, sz)); d1 = torus(p0, sz*to_float2(1.1f, 0.0033f/(zz))); } else { d0 = (sphere(p0, sz)); d1 = torus(p0, sz*to_float2(1.01f, 0.0033f/(zz))); } float dd = d0; dd = pmax(dd, -(d1), 3.0f); dd = _fminf(dd, d1); *ogd = _fminf(*ogd, d1); dd *= zz; d = pmax(d, -(dd-2.0f*zz), 5.0f*zz); d = _fminf(d, dd); if (BOXY) pp -= sz*(14.0f/25.0f); else pp -= sz*(11.0f/25.0f); pp /= zzz; zz *= zzz; pp = mul_f3_mat3(pp,rot); rot = transpose(rot); } return d; } //#elif defined(DF6) //#define BACKSTEP //#define BOUNCE_ONCE __DEVICE__ float dfeffect_DF6(float3 p, out float *ogd, inout mat3 *g_rot) { float3 p0 = p; float d0 = sphere4(p0, 25.0f); float3 p2 = p; p2 = mul_f3_mat3(p2, transpose(*g_rot)); float d2 = sphere4(p2, 22.0f); d0 = pmax(d0, -d2, 4.0f); float d3 = pmax(d0, d2-2.0f, 0.5f); d0 = _fminf(d0, d2); float d = d0; *ogd = d3; return d; } __DEVICE__ float dfeffect(float3 p, out float *ogd, inout mat3 *g_rot) { const float sz = (20.0f); float3 p0 = p; float d0 = box(p0, to_float3_s(sz)); float3 p1 = p; float d1 = boxf(p1, to_float3_s(sz+0.01f), 0.0f)-0.01f; float d = d0; d = _fminf(d, d1); *ogd = d1; return d; } //############################################################################################################## __DEVICE__ float df(float3 p, float4 roadDim, inout float *g_gd, inout mat3 *g_rot, int DF, bool BOXY, bool FLAIR, float ZOOM, float folding_limit, float scale, float min_radius2, float fixed_radius2) { float d0 = dot(swi3(roadDim,x,y,z), p)+roadDim.w; p.y += -20.0f*1.30f; p.z += 66.0f; p = mul_f3_mat3(p,*g_rot); float gd1; float d1 = dfeffect(p, &gd1, g_rot); switch(DF) { case 0: d1 = dfeffect_DF0(p, &gd1, BOXY, FLAIR); break; case 1: d1 = dfeffect_DF1(p, &gd1, BOXY, FLAIR, ZOOM); break; case 2: d1 = dfeffect_DF2(p, &gd1, g_rot); break; case 3: d1 = dfeffect_DF3(p, &gd1, g_rot); break; case 4: d1 = dfeffect_DF4(p, &gd1, g_rot, FLAIR, folding_limit, scale, min_radius2, fixed_radius2); break; case 5: d1 = dfeffect_DF5(p, &gd1, g_rot, BOXY); break; case 6: d1 = dfeffect_DF6(p, &gd1, g_rot); break; default: d1 = dfeffect(p, &gd1, g_rot); } float d = _fmaxf(d1, -d0); float gd = gd1; *g_gd = _fminf(*g_gd, gd); return d; } __DEVICE__ float3 normal(float3 pos, float4 roadDim, inout float *g_gd, inout mat3 *g_rot, int DF, bool BOXY, bool FLAIR, float ZOOM, float folding_limit, float scale, float min_radius2, float fixed_radius2) { float2 eps = to_float2(NORM_OFF,0.0f); float3 nor; nor.x = df(pos+swi3(eps,x,y,y), roadDim, g_gd, g_rot, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2) - df(pos-swi3(eps,x,y,y), roadDim, g_gd, g_rot, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2); nor.y = df(pos+swi3(eps,y,x,y), roadDim, g_gd, g_rot, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2) - df(pos-swi3(eps,y,x,y), roadDim, g_gd, g_rot, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2); nor.z = df(pos+swi3(eps,y,y,x), roadDim, g_gd, g_rot, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2) - df(pos-swi3(eps,y,y,x), roadDim, g_gd, g_rot, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2); return normalize(nor); } __DEVICE__ float rayMarchLo(float3 ro, float3 rd, float tinit, out int *iter, float4 roadDim, inout float *g_gd, inout mat3 *g_rot, float TOLERANCE, float MAX_RAY_LENGTH, float MAX_RAY_MARCHES_LO, int DF, bool BOXY, bool FLAIR, float ZOOM, float folding_limit, float scale, float min_radius2, float fixed_radius2) { float t = tinit; const float tol = TOLERANCE; int i = 0; for (i = 0; i < MAX_RAY_MARCHES_LO; ++i) { float d = df(ro + rd*t, roadDim, g_gd, g_rot, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2); if (d < TOLERANCE || t > MAX_RAY_LENGTH) { break; } t += d; } *iter = i; return t; } __DEVICE__ float rayMarchHi(float3 ro, float3 rd, float tinit, out int *iter, float4 roadDim, inout float *g_gd, inout mat3 *g_rot, float TOLERANCE, float MAX_RAY_LENGTH, float MAX_RAY_MARCHES_HI, int DF, bool BOXY, bool FLAIR, float ZOOM, float folding_limit, float scale, float min_radius2, float fixed_radius2, bool BACKSTEP) { float t = tinit; const float tol = TOLERANCE; //(BACKSTEP) float2 dti = to_float2(1e10f,0.0f); int i = 0; for (i = 0; i < MAX_RAY_MARCHES_HI; ++i) { float d = df(ro + rd*t, roadDim, g_gd, g_rot, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2); if (BACKSTEP) if (d MAX_RAY_LENGTH) { break; } t += d; } if (BACKSTEP) if(i==MAX_RAY_MARCHES_HI) { t=dti.y; }; *iter = i; return t; } // License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets __DEVICE__ mat3 rotX(float a) { float c = _cosf(a); float s = _sinf(a); return to_mat3( 1.0f , 0.0f , 0.0 , 0.0f , +c , +s , 0.0f , -s , +c ); } // License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets __DEVICE__ mat3 rotY(float a) { float c = _cosf(a); float s = _sinf(a); return to_mat3( +c , 0.0f , +s , 0.0f , 1.0f , 0.0 , -s , 0.0f , +c ); } // License: CC0, author: Mårten Rånge, found: https://github.com/mrange/glsl-snippets __DEVICE__ mat3 rotZ(float a) { float c = _cosf(a); float s = _sinf(a); return to_mat3( +c , +s , 0.0 , -s , +c , 0.0 , 0.0f , 0.0f , 1.0 ); } __DEVICE__ float3 render1(float3 col, float3 m, float3 ro, float3 rd, float3 nrd, float4 roadDim, inout float *g_gd, inout mat3 *g_rot, float TOLERANCE, float MAX_RAY_LENGTH, float MAX_RAY_MARCHES_HI, float MAX_RAY_MARCHES_LO, float iTime, float2 iResolution, float3 glowCol1, float3 diffCol, float3 sunCol1, float3 sunDir1, float LAYERS, float3 Colors[4], __TEXTURE2D__ iChannel0, int DF, bool BOXY, bool FLAIR, float ZOOM, float folding_limit, float scale, float min_radius2, float fixed_radius2, bool BACKSTEP, bool BOUNCE_ONCE) { const float4 hsv2rgb_K = to_float4(1.0f, 2.0f / 3.0f, 1.0f / 3.0f, 3.0f); float tm = TIME*0.5f; *g_rot = mul_mat3_mat3(mul_mat3_mat3(rotX(0.333f*tm),rotZ(0.5f*tm)),rotY(0.23f*tm)); int iter; *g_gd = 1E3f; float t = rayMarchHi(ro, rd, 0.0f, &iter, roadDim, g_gd, g_rot, TOLERANCE, MAX_RAY_LENGTH, MAX_RAY_MARCHES_HI, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2, BACKSTEP); float gd = *g_gd; float3 ggcol = (glowCol1)*1.0f/_sqrtf(_fmaxf(gd, 0.00025f)); // Leuchtende Ringe if (t < MAX_RAY_LENGTH) { float3 p = ro+rd*t; float3 n = normal(p, roadDim, g_gd, g_rot, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2); float3 r = reflect(rd, n); float3 nr = reflect(nrd, n); float fre0 = 1.0f+dot(rd, n); float fre = fre0; fre *= fre; float ao = 1.0f-(float)(iter)/(float)(MAX_RAY_MARCHES_HI); float fo = _mix(0.2f, 1.0f, ao); float3 rf = m*_mix(0.33f, 1.0f, fre)*fo*0.75f; const float3 fre1 = HSV2RGB(to_float3(0.8f, 0.5f, 1.0f)); // Markierungen auf dem Objekt float3 rcol; if (BOUNCE_ONCE) { *g_gd = 1E3f; int riter; float rt = rayMarchLo(p, r, 1.0f, &riter, roadDim, g_gd, g_rot, TOLERANCE, MAX_RAY_LENGTH, MAX_RAY_MARCHES_LO, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2); float rgd = *g_gd; float3 rggcol = (glowCol1)*1.0f/_sqrtf(_fmaxf(rgd, 0.00025f)); rcol = clamp(rggcol, 0.0f, 4.0f); if (rt < MAX_RAY_LENGTH) { rcol += diffCol*0.2f; } else { rcol += render0(p, r, nr, LAYERS, roadDim, iTime, iResolution, iChannel0, Colors); } } else rcol = render0(p, r, nr, LAYERS, roadDim, iTime, iResolution, iChannel0, Colors); float dif = dot(sunDir1, n); col *= (1.0f-m); col += m*sunCol1*dif*dif*diffCol*fo; col += rf*rcol*fre1; } col += clamp(m*ggcol, 0.0f, 4.0f); return col; } __DEVICE__ float3 render2(float3 ro, float3 rd, float3 nrd, float4 roadDim, inout float *g_gd, inout mat3 *g_rot, float TOLERANCE, float MAX_RAY_LENGTH, float MAX_RAY_MARCHES_HI, float MAX_RAY_MARCHES_LO, float iTime, float2 iResolution, float3 glowCol1, float3 diffCol, float3 sunCol1, float3 sunDir1, float LAYERS, float3 Colors[4], __TEXTURE2D__ iChannel0, int DF, bool BOXY, bool FLAIR, float ZOOM, float folding_limit, float scale, float min_radius2, float fixed_radius2, bool BACKSTEP, bool BOUNCE_ONCE) { const float4 hsv2rgb_K = to_float4(1.0f, 2.0f / 3.0f, 1.0f / 3.0f, 3.0f); float3 col = render0(ro, rd, nrd, LAYERS, roadDim, iTime, iResolution, iChannel0, Colors); float t = rayPlane(ro, rd, roadDim); float3 p = ro+rd*t; float3 n = swi3(roadDim,x,y,z); float3 r = reflect(rd, n); float3 nr = reflect(nrd, n); float fre = 1.0f+dot(n, rd); fre *= fre; float3 ro0 = ro; float3 rd0 = rd; float3 nrd0= nrd; float3 m0 = to_float3_s(1.0f); if (rd.y < -0.12f) { ro0 = p; rd0 = r; nrd0 = nr; float3 fre0 = HSV2RGB(to_float3(0.8f, 0.9f, 0.1f)); //Colors[0]);// float3 fre1 = HSV2RGB(to_float3(0.8f, 0.3f, 0.9f)); //Colors[1]);// m0 = _mix(fre0, fre1, fre); } col = render1(col, m0, ro0, rd0, nrd0, roadDim, g_gd, g_rot, TOLERANCE, MAX_RAY_LENGTH, MAX_RAY_MARCHES_HI, MAX_RAY_MARCHES_LO, iTime, iResolution, glowCol1, diffCol, sunCol1, sunDir1, LAYERS, Colors, iChannel0, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2, BACKSTEP, BOUNCE_ONCE); return col; } __DEVICE__ float3 effect(float2 p, float2 pp, float4 roadDim, inout float *g_gd, inout mat3 *g_rot, float TOLERANCE, float MAX_RAY_LENGTH, float MAX_RAY_MARCHES_HI, float MAX_RAY_MARCHES_LO, float iTime, float2 iResolution, float4 iMouse, float3 glowCol1, float3 diffCol, float3 sunCol1, float3 sunDir1, float LAYERS, float3 View, float3 DView, float3 Colors[4], __TEXTURE2D__ iChannel0, int DF, bool BOXY, bool FLAIR, float ZOOM, float folding_limit, float scale, float min_radius2, float fixed_radius2, bool BACKSTEP, bool BOUNCE_ONCE) { float aa = 2.0f/RESOLUTION.y; float3 ro = to_float3(0.0f, 0.0f, 10.0f) + View; const float3 la = to_float3(0.0f, 2.0f, 0.0f); const float3 up = to_float3(0.0f, 1.0f, 0.0f); const float3 ww = normalize(la - ro); const float3 uu = normalize(cross(up, ww )); const float3 vv = (cross(ww,uu)); const float fov = _tanf(TAU/6.0f); float2 np = p + to_float2_s(aa); float3 rd = normalize( -p.x*uu + p.y*vv + fov*ww + DView); float3 nrd = normalize(-np.x*uu + np.y*vv + fov*ww); //############### 3D Mouse-Rotation des Objektes ############## float crz = (iMouse.x - iResolution.x / 2.0f) / iResolution.x * PI; float crx = (iMouse.y - iResolution.y / 2.0f) / iResolution.y * PI; mat3 m = mul_mat3_mat3(to_mat3(_cosf(crz), 0.0f, _sinf(crz), 0.0f, 1.0f, 0.0f, -_sinf(crz), 0.0f, _cosf(crz)) , to_mat3(1.0f, 0.0f, 0.0f, 0.0f, _cosf(crx), _sinf(crx), 0.0f, -_sinf(crx), _cosf(crx))); if(iMouse.z > 0.0f) { ro = mul_mat3_f3(m , ro); rd = mul_mat3_f3(m , rd); } //############################################################# float3 col = render2(ro, rd, nrd, roadDim, g_gd, g_rot, TOLERANCE, MAX_RAY_LENGTH, MAX_RAY_MARCHES_HI, MAX_RAY_MARCHES_LO, iTime, iResolution, glowCol1, diffCol, sunCol1, sunDir1, LAYERS, Colors, iChannel0, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2, BACKSTEP, BOUNCE_ONCE); col -= 0.0125f*to_float3(1.0f, 2.0f, 3.0f)*(length(pp)+0.25f); col *= smoothstep(1.75f, 0.5f, length(pp)); col = aces_approx(col); col = sqrt_f3(col); return col; } __KERNEL__ void MoreCubesForTheCubeLoversFuse(__CONSTANTREF__ Params* params, __TEXTURE2D__ iChannel0, __TEXTURE2D_WRITE__ destinationTexture) { DEFINE_KERNEL_ITERATORS_XY(fusion_x, fusion_y); if (fusion_x >= params->width || fusion_y >= params->height) return; float2 iResolution = to_float2(params->iResolution[0], params->iResolution[1]); float iTime = params->iTime; float4 iMouse = to_float4(params->iMouse[0],params->iMouse[1],params->iMouse[2],params->iMouse[3]); float4 fragColor = to_float4_s(0.0f); float2 fragCoord = to_float2(fusion_x,fusion_y); bool BACKSTEP = params->BACKSTEP; bool BOUNCE_ONCE = params->BOUNCE_ONCE; bool BOXY = params->BOXY; bool FLAIR = params->FLAIR; float4 GlowCol = to_float4(params->GlowCol[0], params->GlowCol[1], params->GlowCol[2], params->GlowCol[3]); float4 SunCol = to_float4(params->SunCol[0], params->SunCol[1], params->SunCol[2], params->SunCol[3]); float4 DiffCol = to_float4(params->DiffCol[0], params->DiffCol[1], params->DiffCol[2], params->DiffCol[3]); float4 BKG1 = to_float4(params->BKG1[0], params->BKG1[1], params->BKG1[2], params->BKG1[3]); float4 BKG2 = to_float4(params->BKG2[0], params->BKG2[1], params->BKG2[2], params->BKG2[3]); float4 BKG3 = to_float4(params->BKG3[0], params->BKG3[1], params->BKG3[2], params->BKG3[3]); float4 BKG4 = to_float4(params->BKG4[0], params->BKG4[1], params->BKG4[2], params->BKG4[3]); float2 ViewDXY = to_float2(params->ViewDXY[0], params->ViewDXY[1]); float ViewDZ = params->ViewDZ; float2 ViewXY = to_float2(params->ViewXY[0], params->ViewXY[1]); float ViewZ = params->ViewZ; float2 RoadXY = to_float2(params->RoadXY[0], params->RoadXY[1]); float RoadZ = params->RoadZ; float LAYERS = params->LAYERS; float TOLERANCE = params->TOLERANCE; float MAX_RAY_LENGTH = params->MAX_RAY_LENGTH; float hoff = params->hoff; float RoadDimW = params->RoadDimW; float ZOOM = params->ZOOM; float fixed_radius2 = params->fixed_radius2; float min_radius2 = params->min_radius2; float folding_limit = params->folding_limit; float scale = params->scale; int DF = params->DF; int MAX_RAY_MARCHES_LO = params->MAX_RAY_MARCHES_LO; int MAX_RAY_MARCHES_HI = params->MAX_RAY_MARCHES_HI; // -------- float3 Colors[4] = {swi3(BKG1,x,y,z), swi3(BKG2,x,y,z), swi3(BKG3,x,y,z), swi3(BKG4,x,y,z)}; float4 roadDim = to_float4_aw(normalize(to_float3(0.0f, 1.0f, 0.15f)+to_float3_aw(RoadXY, RoadZ)), RoadDimW); //20.0f const float4 hsv2rgb_K = to_float4(1.0f, 2.0f / 3.0f, 1.0f / 3.0f, 3.0f); //float hoff = -0.025f; float3 glowCol1 = HSV2RGB((to_float3(hoff,0.0f,0.0f)+swi3(GlowCol,x,y,z)));//to_float3(hoff+0.65f, 0.75f, 0.2f)); float3 sunCol1 = HSV2RGB((to_float3(hoff,0.0f,0.0f)+swi3(SunCol,x,y,z)));//to_float3(hoff+0.75f, 0.50f, 0.5f)); float3 diffCol = HSV2RGB((to_float3(hoff,0.0f,0.0f)+swi3(DiffCol,x,y,z)));//to_float3(hoff+0.40f, 0.75f, 0.125f)); float3 sunDir1 = normalize(to_float3(3.0f, 3.0f, -7.0f)); float g_gd = 0.0f; mat3 g_rot = to_mat3_n(1.0f); float2 q = fragCoord/RESOLUTION; float2 p = -1.0f + 2.0f*q; float2 pp = p; p.x *= RESOLUTION.x/RESOLUTION.y; float3 col = effect(p, pp, roadDim, &g_gd, &g_rot, TOLERANCE, MAX_RAY_LENGTH, MAX_RAY_MARCHES_HI, MAX_RAY_MARCHES_LO, iTime, iResolution, iMouse, glowCol1, diffCol, sunCol1, sunDir1, LAYERS, to_float3_aw(ViewXY, ViewZ), to_float3_aw(ViewDXY, ViewDZ), Colors, iChannel0, DF, BOXY, FLAIR, ZOOM, folding_limit, scale, min_radius2, fixed_radius2, BACKSTEP, BOUNCE_ONCE); fragColor = to_float4_aw(col, 1.0f); _tex2DVec4Write(destinationTexture, fusion_x, fusion_y, fragColor); } ]] -- /* -- // ------------------------------------------------------------------------ -- // Create -- // ------------------------------------------------------------------------ function Create() ShaderFuse.begin_create() ----- Inspector Panel Controls -- Speed Slider InFrequency = self:AddInput("Speedup", "speed", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_Default = 1.0, INP_MinScale = 0.0, INP_MaxScale = 5.0, SLCS_LowName = "stop", SLCS_HighName = "5x", }) -- iMouse Controls InMouseXY = self:AddInput("iMouse.xy", "iMouseXY", { LINKID_DataType = "Point", INPID_InputControl = "OffsetControl", INP_DoNotifyChanged = false, --INP_Passive = true, INPID_PreviewControl = "CrosshairControl", }) InMouseZW = self:AddInput("iMouse.zw", "iMouseZW", { LINKID_DataType = "Point", INPID_InputControl = "OffsetControl", INP_DoNotifyChanged = false, --INP_Passive = true, INPID_PreviewControl = "CrosshairControl", INP_Disabled = true, }) InMouseDrag = self:AddInput("Mouse Button Pressed", "iMouseClick", { LINKID_DataType = "Number", INPID_InputControl = "CheckboxControl", INP_DoNotifyChanged = false, --INP_Passive = true, INP_MinScale = 0, INP_MaxScale = 1, INP_Default = 0, }) InBACKSTEPCheckbox = self:AddInput("BACKSTEP", "BACKSTEP", { LINKID_DataType = "Number", INPID_InputControl = "CheckboxControl", INP_Integer = true, INP_Default = 0, }) InBOUNCE_ONCECheckbox = self:AddInput("BOUNCE_ONCE", "BOUNCE_ONCE", { LINKID_DataType = "Number", INPID_InputControl = "CheckboxControl", INP_Integer = true, INP_Default = 0, }) InBOXYCheckbox = self:AddInput("BOXY", "BOXY", { LINKID_DataType = "Number", INPID_InputControl = "CheckboxControl", INP_Integer = true, INP_Default = 0, }) InFLAIRCheckbox = self:AddInput("FLAIR", "FLAIR", { LINKID_DataType = "Number", INPID_InputControl = "CheckboxControl", INP_Integer = true, INP_Default = 1, }) self:BeginControlNest("Colors", "Colors", false, {}) self:BeginControlNest("GlowCol", "GlowCol", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "GlowCol", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InGlowColColorR = self:AddInput("Red", "GlowColRed", { INP_Default = 0.65, IC_ControlID = 0, attrs}) InGlowColColorG = self:AddInput("Green", "GlowColGreen", { INP_Default = 0.75, IC_ControlID = 1, attrs}) InGlowColColorB = self:AddInput("Blue", "GlowColBlue", { INP_Default = 0.2, IC_ControlID = 2, attrs}) InGlowColColorA = self:AddInput("Alpha", "GlowColAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("SunCol", "SunCol", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "SunCol", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InSunColColorR = self:AddInput("Red", "SunColRed", { INP_Default = 0.75, IC_ControlID = 0, attrs}) InSunColColorG = self:AddInput("Green", "SunColGreen", { INP_Default = 0.50, IC_ControlID = 1, attrs}) InSunColColorB = self:AddInput("Blue", "SunColBlue", { INP_Default = 0.5, IC_ControlID = 2, attrs}) InSunColColorA = self:AddInput("Alpha", "SunColAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("DiffCol", "DiffCol", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "DiffCol", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InDiffColColorR = self:AddInput("Red", "DiffColRed", { INP_Default = 0.40, IC_ControlID = 0, attrs}) InDiffColColorG = self:AddInput("Green", "DiffColGreen", { INP_Default = 0.75, IC_ControlID = 1, attrs}) InDiffColColorB = self:AddInput("Blue", "DiffColBlue", { INP_Default = 0.125, IC_ControlID = 2, attrs}) InDiffColColorA = self:AddInput("Alpha", "DiffColAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("BKG1", "BKG1", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "BKG1", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InBKG1ColorR = self:AddInput("Red", "BKG1Red", { INP_Default = 0.0, IC_ControlID = 0, attrs}) InBKG1ColorG = self:AddInput("Green", "BKG1Green", { INP_Default = 0.25, IC_ControlID = 1, attrs}) InBKG1ColorB = self:AddInput("Blue", "BKG1Blue", { INP_Default = -1.0, IC_ControlID = 2, attrs}) InBKG1ColorA = self:AddInput("Alpha", "BKG1Alpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("BKG2", "BKG2", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "BKG2", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InBKG2ColorR = self:AddInput("Red", "BKG2Red", { INP_Default = 0.8, IC_ControlID = 0, attrs}) InBKG2ColorG = self:AddInput("Green", "BKG2Green", { INP_Default = 0.75, IC_ControlID = 1, attrs}) InBKG2ColorB = self:AddInput("Blue", "BKG2Blue", { INP_Default = 0.05, IC_ControlID = 2, attrs}) InBKG2ColorA = self:AddInput("Alpha", "BKG2Alpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("BKG3", "BKG3", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "BKG3", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InBKG3ColorR = self:AddInput("Red", "BKG3Red", { INP_Default = 0.0, IC_ControlID = 0, attrs}) InBKG3ColorG = self:AddInput("Green", "BKG3Green", { INP_Default = 0.0, IC_ControlID = 1, attrs}) InBKG3ColorB = self:AddInput("Blue", "BKG3Blue", { INP_Default = 0.0, IC_ControlID = 2, attrs}) InBKG3ColorA = self:AddInput("Alpha", "BKG3Alpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("BKG4", "BKG4", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "BKG4", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InBKG4ColorR = self:AddInput("Red", "BKG4Red", { INP_Default = 1.5, IC_ControlID = 0, attrs}) InBKG4ColorG = self:AddInput("Green", "BKG4Green", { INP_Default = 0.5, IC_ControlID = 1, attrs}) InBKG4ColorB = self:AddInput("Blue", "BKG4Blue", { INP_Default = 0.5, IC_ControlID = 2, attrs}) InBKG4ColorA = self:AddInput("Alpha", "BKG4Alpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:EndControlNest() InViewDXYPoint = self:AddInput("ViewDXY", "ViewDXY", { LINKID_DataType = "Point", INPID_InputControl = "OffsetControl", INPID_PreviewControl = "CrosshairControl", INP_DefaultX = 0.0, INP_DefaultY = 0.0, }) InViewDZSlider = self:AddInput("ViewDZ", "ViewDZ", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -10.0, INP_MaxScale = 10.0, INP_Default = 0.0, }) InViewXYPoint = self:AddInput("ViewXY", "ViewXY", { LINKID_DataType = "Point", INPID_InputControl = "OffsetControl", INPID_PreviewControl = "CrosshairControl", INP_DefaultX = 0.0, INP_DefaultY = 0.0, }) InViewZSlider = self:AddInput("ViewZ", "ViewZ", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -10.0, INP_MaxScale = 10.0, INP_Default = 0.0, }) InRoadXYPoint = self:AddInput("RoadXY", "RoadXY", { LINKID_DataType = "Point", INPID_InputControl = "OffsetControl", INPID_PreviewControl = "CrosshairControl", INP_DefaultX = 0.0, INP_DefaultY = 0.0, }) InRoadZSlider = self:AddInput("RoadZ", "RoadZ", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -10.0, INP_MaxScale = 10.0, INP_Default = 0.0, }) InLAYERSSlider = self:AddInput("LAYERS", "LAYERS", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -1.0, INP_MaxScale = 10.0, INP_Default = 5.0, }) InTOLERANCESlider = self:AddInput("TOLERANCE", "TOLERANCE", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -0.01, INP_MaxScale = 0.01, INP_Default = 0.0001, }) InMAX_RAY_LENGTHSlider = self:AddInput("MAX_RAY_LENGTH", "MAX_RAY_LENGTH", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -1.0, INP_MaxScale = 200.0, INP_Default = 120.0, }) InhoffSlider = self:AddInput("hoff", "hoff", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -1.0, INP_MaxScale = 1.0, INP_Default = -0.025, }) InRoadDimWSlider = self:AddInput("RoadDimW", "RoadDimW", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -1.0, INP_MaxScale = 100.0, INP_Default = 20.0, }) InZOOMSlider = self:AddInput("ZOOM", "ZOOM", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -1.0, INP_MaxScale = 100.0, INP_Default = 20.0, }) Infixed_radius2Slider = self:AddInput("fixed_radius2", "fixed_radius2", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -1.0, INP_MaxScale = 5.0, INP_Default = 1.9, }) Inmin_radius2Slider = self:AddInput("min_radius2", "min_radius2", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -1.0, INP_MaxScale = 1.0, INP_Default = 0.1, }) Infolding_limitSlider = self:AddInput("folding_limit", "folding_limit", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -1.0, INP_MaxScale = 5.0, INP_Default = 1.0, }) InscaleSlider = self:AddInput("scale", "scale", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -5.0, INP_MaxScale = 2.0, INP_Default = -2.4, }) InDFSlider = self:AddInput("DF", "DF", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = 0, INP_MaxScale = 7, INP_Default = 2, INP_Integer = true, }) InMAX_RAY_MARCHES_LOSlider = self:AddInput("MAX_RAY_MARCHES_LO", "MAX_RAY_MARCHES_LO", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = 1, INP_MaxScale = 50, INP_Default = 30, INP_Integer = true, }) InMAX_RAY_MARCHES_HISlider = self:AddInput("MAX_RAY_MARCHES_HI", "MAX_RAY_MARCHES_HI", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = 1, INP_MaxScale = 100, INP_Default = 70, INP_Integer = true, }) Sep3 = self:AddInput(string.rep("_", 152), "Separator3", { LINKID_DataType = "Text", INPID_InputControl = "LabelControl", INP_External = false, INP_Passive = true, IC_Visible = true, INP_DoNotifyChanged = true, IC_NoLabel = true, }) InEdges = self:AddInput("Edges", "Edges", { LINKID_DataType = "Number", INPID_InputControl = "MultiButtonControl", INP_Default = 3.0, INP_Integer = true, INP_DoNotifyChanged = true, INP_External = false, MBTNC_ForceButtons = true, INP_MinScale = 0, INP_MaxScale = 3, INP_MinAllowed = 0, INP_MaxAllowed = 3, MBTNC_ShowBasicButton = true, MBTNC_StretchToFit = false, --true, MBTNC_ShowToolTip = true, { MBTNC_AddButton = "Canvas", MBTNCD_ButtonWidth = 4/16, }, { MBTNC_AddButton = "Wrap",MBTNCD_ButtonWidth = 3/16, }, { MBTNC_AddButton = "Duplicate", MBTNCD_ButtonWidth = 5/16, }, { MBTNC_AddButton = "Mirror", MBTNCD_ButtonWidth = 4/16, }, }) ----- Size & Depth InSize = self:AddInput("Size", "Size_Fuse", { LINKID_DataType = "Number", INPID_InputControl = "ComboControl", INP_DoNotifyChanged = true, INP_Default = 0, INP_Integer = true, ICD_Width = 1, { CCS_AddString = "Default", }, { CCS_AddString = "Manually", }, { CCS_AddString = "Image0", }, { CCS_AddString = "1920x1080", }, { CCS_AddString = "1200x675", }, { CCS_AddString = "800x450", }, { CCS_AddString = "640x360", }, CC_LabelPosition = "Horizontal", ICS_ControlPage = "Image", }) InWidth = self:AddInput("Width", "_Width", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_Default = 1920, INP_Integer = true, INP_MinScale = 0, INP_MaxScale = 4096, }) InHeight = self:AddInput("Height", "_Height", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_Default = 1080, INP_Integer = true, INP_MinScale = 0, INP_MaxScale = 4096, }) InDepth = self:AddInput("Depth_Fuse", "Depth_Fuse", { LINKID_DataType = "Number", INPID_InputControl = "ComboControl", INP_DoNotifyChanged = true, INP_Default = 0, INP_Integer = true, ICD_Width = 1, { CCS_AddString = "Default", }, { CCS_AddString = "int8", }, { CCS_AddString = "int16", }, { CCS_AddString = "float16", }, { CCS_AddString = "float32", }, CC_LabelPosition = "Horizontal", ICS_ControlPage = "Image", }) InMyWidth = self:FindInput("Width") InMyWidth:SetAttrs({ IC_Visible = false }) InMyHeight = self:FindInput("Height") InMyHeight:SetAttrs({ IC_Visible = false }) InMyDepth = self:FindInput("Depth") InMyDepth:SetAttrs({ IC_Visible = false }) ----- In/Out InChannel0 = self:AddInput( "iChannel0", "iChannel0", { LINKID_DataType = "Image", LINK_Main = 1, INP_Required = false }) OutImage = self:AddOutput("Output", "Output", { LINKID_DataType = "Image", LINK_Main = 1, }) ShaderFuse.end_create() end -- // ------------------------------------------------------------------------ -- // Process -- // ------------------------------------------------------------------------ function DefineEdges(edges, nodeX) --This gets the value of our input image for us to modify inside the kernel if edges == 0 then nodeX:AddSampler("RowSampler", TEX_FILTER_MODE_LINEAR,TEX_ADDRESS_MODE_BORDER, TEX_NORMALIZED_COORDS_TRUE) elseif edges == 1 then nodeX:AddSampler("RowSampler", TEX_FILTER_MODE_LINEAR,TEX_ADDRESS_MODE_WRAP, TEX_NORMALIZED_COORDS_TRUE) elseif edges == 2 then nodeX:AddSampler("RowSampler", TEX_FILTER_MODE_LINEAR,TEX_ADDRESS_MODE_DUPLICATE, TEX_NORMALIZED_COORDS_TRUE) elseif edges == 3 then nodeX:AddSampler("RowSampler", TEX_FILTER_MODE_LINEAR,TEX_ADDRESS_MODE_MIRROR, TEX_NORMALIZED_COORDS_TRUE) elseif edges == 4 then --print("Sampler 4") end end function Process(req) -- Imagesize and Depth if (InSize:GetValue(req).Value >= 1) then if (InSize:GetValue(req).Value == 2) then if (InChannel0:GetValue(req) ~= nil) then Width = InChannel0:GetValue(req).Width Height = InChannel0:GetValue(req).Height end else Width = InWidth:GetValue(req).Value Height = InHeight:GetValue(req).Value end end -- Alle ( int und float ) if (InDepth:GetValue(req).Value > 0) then if InDepth:GetValue(req).Value == 1 then SourceDepth = 5 else if InDepth:GetValue(req).Value == 2 then SourceDepth = 6 else if InDepth:GetValue(req).Value == 3 then SourceDepth = 7 else SourceDepth = 8 end end end end local imgattrs = { IMG_Document = self.Comp, { IMG_Channel = "Red", }, { IMG_Channel = "Green", }, { IMG_Channel = "Blue", }, { IMG_Channel = "Alpha", }, IMG_Width = Width, IMG_Height = Height, IMG_XScale = XAspect, IMG_YScale = YAspect, IMAT_OriginalWidth = realwidth, -- nil !?! IMAT_OriginalHeight = realheight, -- nil !?! IMG_Quality = not req:IsQuick(), IMG_MotionBlurQuality = not req:IsNoMotionBlur(), IMG_DeferAlloc = true, IMG_ProxyScale = ( (not req:IsStampOnly()) and 1 or nil), IMG_Depth = ( (SourceDepth~=0) and SourceDepth or nil ) } local dst = Image(imgattrs) local black = Pixel({R=0,G=0,B=0,A=0}) dst:Fill(black) if req:IsPreCalc() then local out = Image({IMG_Like = dst, IMG_NoData = true}) OutImage:Set(req, out) return end node = DVIPComputeNode(req, "MoreCubesForTheCubeLoversFuse", ShaderCompatibilityCode..ShaderKernelCode, "Params", ShaderParameters ) -- Extern texture or create a new one iChannel0 = InChannel0:GetValue(req) if iChannel0==nil then iChannel0 = Image(imgattrs) iChannel0:Fill(black) end -- DCTL parameters local framerate = self.Comp:GetPrefs("Comp.FrameFormat.Rate") local params = {} params = node:GetParamBlock(ShaderParameters) params.iResolution[0] = dst.Width params.iResolution[1] = dst.Height params.iTime = (req.Time / framerate) * InFrequency:GetValue(req).Value -- iMouse local mouse_xy = InMouseXY:GetValue(req) local mouse_zw = InMouseZW:GetValue(req) params.iMouse[0] = mouse_xy.X params.iMouse[1] = mouse_xy.Y params.iMouse[2] = mouse_zw.X params.iMouse[3] = mouse_zw.Y if InMouseDrag:GetValue(req).Value ~= 0 then if params.iMouse[2]==-1 and params.iMouse[3]==-1 then params.iMouse[2]=params.iMouse[0] params.iMouse[3]=params.iMouse[1] end else params.iMouse[2] = -1 params.iMouse[3] = -1 end if mouse_zw.X ~= params.iMouse[2] or mouse_zw.Y ~= params.iMouse[3] then InMouseZW:SetAttrs({INP_Disabled=false}) InMouseZW:SetSource(Point(params.iMouse[2],params.iMouse[3]),0,0) InMouseZW:SetAttrs({INP_Disabled=true}) end params.iMouse[0] = params.iMouse[0] * Width params.iMouse[1] = params.iMouse[1] * Height if params.iMouse[2] == -1 and params.iMouse[3] == -1 then params.iMouse[2] = 0 params.iMouse[3] = 0 else params.iMouse[2] = params.iMouse[2] * Width params.iMouse[3] = params.iMouse[3] * Height end params.BACKSTEP = InBACKSTEPCheckbox:GetValue(req).Value params.BOUNCE_ONCE = InBOUNCE_ONCECheckbox:GetValue(req).Value params.BOXY = InBOXYCheckbox:GetValue(req).Value params.FLAIR = InFLAIRCheckbox:GetValue(req).Value params.GlowCol = { InGlowColColorR:GetValue(req).Value, InGlowColColorG:GetValue(req).Value, InGlowColColorB:GetValue(req).Value,InGlowColColorA:GetValue(req).Value } params.SunCol = { InSunColColorR:GetValue(req).Value, InSunColColorG:GetValue(req).Value, InSunColColorB:GetValue(req).Value,InSunColColorA:GetValue(req).Value } params.DiffCol = { InDiffColColorR:GetValue(req).Value, InDiffColColorG:GetValue(req).Value, InDiffColColorB:GetValue(req).Value,InDiffColColorA:GetValue(req).Value } params.BKG1 = { InBKG1ColorR:GetValue(req).Value, InBKG1ColorG:GetValue(req).Value, InBKG1ColorB:GetValue(req).Value,InBKG1ColorA:GetValue(req).Value } params.BKG2 = { InBKG2ColorR:GetValue(req).Value, InBKG2ColorG:GetValue(req).Value, InBKG2ColorB:GetValue(req).Value,InBKG2ColorA:GetValue(req).Value } params.BKG3 = { InBKG3ColorR:GetValue(req).Value, InBKG3ColorG:GetValue(req).Value, InBKG3ColorB:GetValue(req).Value,InBKG3ColorA:GetValue(req).Value } params.BKG4 = { InBKG4ColorR:GetValue(req).Value, InBKG4ColorG:GetValue(req).Value, InBKG4ColorB:GetValue(req).Value,InBKG4ColorA:GetValue(req).Value } params.ViewDXY = {InViewDXYPoint:GetValue(req).X,InViewDXYPoint:GetValue(req).Y} params.ViewDZ = InViewDZSlider:GetValue(req).Value params.ViewXY = {InViewXYPoint:GetValue(req).X,InViewXYPoint:GetValue(req).Y} params.ViewZ = InViewZSlider:GetValue(req).Value params.RoadXY = {InRoadXYPoint:GetValue(req).X,InRoadXYPoint:GetValue(req).Y} params.RoadZ = InRoadZSlider:GetValue(req).Value params.LAYERS = InLAYERSSlider:GetValue(req).Value params.TOLERANCE = InTOLERANCESlider:GetValue(req).Value params.MAX_RAY_LENGTH = InMAX_RAY_LENGTHSlider:GetValue(req).Value params.hoff = InhoffSlider:GetValue(req).Value params.RoadDimW = InRoadDimWSlider:GetValue(req).Value params.ZOOM = InZOOMSlider:GetValue(req).Value params.fixed_radius2 = Infixed_radius2Slider:GetValue(req).Value params.min_radius2 = Inmin_radius2Slider:GetValue(req).Value params.folding_limit = Infolding_limitSlider:GetValue(req).Value params.scale = InscaleSlider:GetValue(req).Value params.DF = InDFSlider:GetValue(req).Value params.MAX_RAY_MARCHES_LO = InMAX_RAY_MARCHES_LOSlider:GetValue(req).Value params.MAX_RAY_MARCHES_HI = InMAX_RAY_MARCHES_HISlider:GetValue(req).Value -- Resolution params.width = dst.Width params.height = dst.Height -- Per channel time and resolution local edges = InEdges:GetValue(req).Value -- Set parameters and add I/O node:SetParamBlock(params) --node:AddSampler("RowSampler", TEX_FILTER_MODE_LINEAR,TEX_ADDRESS_MODE_MIRROR, TEX_NORMALIZED_COORDS_TRUE) DefineEdges(edges, node) node:AddInput("iChannel0",iChannel0) -- TODO: add a better channel name node:AddOutput("dst", dst) local ok = node:RunSession(req) if (not ok) then dst = nil dump(node:GetErrorLog()) end OutImage:Set(req,dst) collectgarbage(); end -- // ------------------------------------------------------------------------ -- // Callback -- // ------------------------------------------------------------------------ function NotifyChanged(inp, param, time) if (param ~= nil) then if inp == InSize then if param.Value == 1 then InWidth:SetAttrs({ IC_Visible = true }) InHeight:SetAttrs({ IC_Visible = true }) else InWidth:SetAttrs({ IC_Visible = false }) InHeight:SetAttrs({ IC_Visible = false }) end if param.Value == 3 then --1920x1080 InWidth:SetSource(Number(1920),0,0) InHeight:SetSource(Number(1080),0,0) end if param.Value == 4 then --1200x675 InWidth:SetSource(Number(1200),0,0) InHeight:SetSource(Number(675),0,0) end if param.Value == 5 then --800x450 InWidth:SetSource(Number(800),0,0) InHeight:SetSource(Number(450),0,0) end if param.Value == 6 then --640x360 InWidth:SetSource(Number(640),0,0) InHeight:SetSource(Number(360),0,0) end end end end -- */