--[[--/* TheTetrisDimension.fuse Based on https://www.shadertoy.com/view/NtByzD a WebGL shader created by Hyeve. 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 Reset; float Color1[4]; float Color2[4]; float Color3[4]; float Color4[4]; float Color5[4]; float ViewDXY[2]; float ViewDZ; float ViewXY[2]; float ViewZ; float refmul; float refoff; 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 mat3 to_mat3_f3( float3 a, float3 b, float3 c ) { return mat3(a,b,c); } __DEVICE__ inline float3 mul_mat3_f3( mat3 B, float3 A) { return (B*A); } __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 mat3 to_mat3_f3( float3 A, float3 B, float3 C) { mat3 D; D.r0 = A; D.r1 = B; D.r2 = C; return D; } __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__ 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 mod_f(a,b) fmod((a),(b)) #define mod_f2(value,divisor) fmod(value,divisor) #define cos_f2(i) cos(i) #define abs_f2(a) _fabs(a) #define abs_f3(a) _fabs(a) #define sign_f(a) sign(a) #define pow_f3(a,b) pow(a,b) #define pow_f4(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 mod_f(a,b) _fmod(a,b) #define mod_f2(value,divisor) _fmod(value,divisor) #define cos_f2(i) cos(i) #define abs_f2(a) fabs(a) #define abs_f3(a) fabs(a) #define sign_f(a) sign(a) #define pow_f3(a,b) pow(a,b) #define pow_f4(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 mod_f(a,b) ((a)-(b)*_floor((a)/(b))) #define mod_f2(value,divisor) to_float2(mod_f((value).x, (divisor)),mod_f((value).y, (divisor))) #define cos_f2(i) to_float2( _cosf((i).x), _cosf((i).y)) #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 sign_f(a) (a==0.0f?0.0f:a>0.0f?1.0f:-1.0f) #define pow_f3(a,b) to_float3(_powf((a).x,(b).x),_powf((a).y,(b).y),_powf((a).z,(b).z)) #define pow_f4(a,b) to_float4(_powf((a).x,(b).x),_powf((a).y,(b).y),_powf((a).z,(b).z),_powf((a).w,(b).w)) #endif #endif ]] -- /* -- // ------------------------------------------------------------------------ -- DCTL kernel implementation -- // ------------------------------------------------------------------------ -- */ ShaderKernelCode = [[ // ---------------------------------------------------------------------------------- // - Common - // ---------------------------------------------------------------------------------- #define texture(ch,uv) _tex2DVecN(ch, (uv).x, (uv).y, 15) #define pi 3.1415926535897f __DEVICE__ inline mat3 mat3_sub_mat3( mat3 A, mat3 B) { mat3 C; C.r0 = to_float3(A.r0.x - B.r0.x, A.r0.y - B.r0.y,A.r0.z - B.r0.z); C.r1 = to_float3(A.r1.x - B.r1.x, A.r1.y - B.r1.y,A.r1.z - B.r1.z); C.r2 = to_float3(A.r2.x - B.r2.x, A.r2.y - B.r2.y,A.r2.z - B.r2.z); return C; } #define tan_f2(i) to_float2(_tanf((i).x), _tanf((i).y)) //to_float2(_sinf((i).x), _sinf((i).y)) // __DEVICE__ float _powcf(float x, float y) { float ret = _powf(x,y); if (isnan(ret)) { ret = 0.0001f; } return ret; } __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; } __DEVICE__ float3 _refract_f3(float3 I, float3 N, float eta, float refmul, float refoff) { float dotNI = dot(N, I); float k = 1.0f - eta * eta * (1.0f - dotNI * dotNI); if (k < 0.0f) { return to_float3_s(0.0); } return eta * I - (eta * dotNI * _sqrtf(k)) * N * refmul + refoff; //+0.5f; * -01.50f;(MarchingCubes) - 0.15f; (GlassDuck) } // ---------------------------------------------------------------------------------- // - Image - // ---------------------------------------------------------------------------------- // Connect Image 'Texture: Picture' to iChannel0 #define rot(a) to_mat2(_cosf(a),_sinf(a),-_sinf(a),_cosf(a)) //float2 uv; //float3 cp,cn,cr,ro,rd,ss,oc,cc,gl,vb; //float4 fc; //float tt,cd,sd,io,oa,td,tc; //int es=0,ec; __DEVICE__ float bx(float3 p,float3 s){ float3 q=abs_f3(p)-s;return _fminf(_fmaxf(q.x,_fmaxf(q.y,q.z)),0.0f)+length(_fmaxf(q,to_float3_s(0.0f)));} __DEVICE__ float3 minoc(int num) { num=(int)(mod_f((float)(num),7.0f)); float3 c=to_float3_s(0.0);switch(num){ case 0:c=to_float3(0.7f,0,0);break; case 1:c=to_float3(0,0.7f,0);break; case 2:c=to_float3(0.8f,0.7f,0.1f);break; case 3:c=to_float3(0.5f,0.2f,0.8f);break; case 4:c=to_float3(0.1f,0.7f,0.8f);break; case 5:c=to_float3(0,0.2f,0.7f);break; case 6:c=to_float3(0.9f,0.5f,0);break;} return c; } __DEVICE__ float mino(int num, float3 p, float s) { int n = num % 7; if (n < 0) n += 7; float2 o2=to_float2_s(0.0f);float2 o3=to_float2_s(0.0f);float2 o4=to_float2_s(0.0f); if (n == 2) { o2 = to_float2(1.0f,-1.0f); o4 = to_float2(-0.5f,0.5f); } else if (n == 3) { o4 = to_float2(0.0f, 0.5f); } else if (n == 4) { o3 = to_float2(-2.0f, 0.0f); o4 = to_float2(0.5f, 0.0f); } if (n>2)o2=to_float2(-1.0f,0.0f); if (n<4)o3=to_float2(0.0f,1.0f-sign_f((float)(n))*2.0f); if (n>4){o3=to_float2(sign_f((float)(n)-5.5f),-1.0f);o4=to_float2(0.0f,0.5f);} if (n<2){o2 = to_float2(-1.0f,-sign_f((float)(n)-0.5f));o4 = to_float2(0.0f,sign_f((float)(n)-0.5f)*0.5f);} swi2S(p,x,y, swi2(p,x,y)+o4*s); float3 dp=p;float hs=s*0.5f;float d=bx(dp,to_float3_s(hs)); swi2S(dp,x,y, swi2(dp,x,y)+to_float2(1.0f,0.0f)*s);d=_fminf(d,bx(dp,to_float3_s(hs)));dp=p; swi2S(dp,x,y, swi2(dp,x,y)+o2*s);d=_fminf(d,bx(dp,to_float3_s(hs)));dp=p; swi2S(dp,x,y, swi2(dp,x,y)+o3*s);d=_fminf(d,bx(dp,to_float3_s(hs)));dp=p; return d; } __DEVICE__ float hash(float2 p) { p=fract_f2(p)-cos_f2(p); float2 q=tan_f2(abs_f2(p*37482.34f)+swi2(p,y,x)*678324.0f); return fract(q.x+p.x*q.y-p.y); } __DEVICE__ float mp(float3 p, float tt, inout float3 *gl, inout float *sd, inout float *io, inout float3 *oc, inout float *oa, inout float3 *ss, inout float3 *vb, inout int *ec) { float3 pp=p; p.y+=tt; p.z-=20.0f;float yid=_truncf(p.y/16.0f+8.0f); p.y=mod_f(p.y,16.0f)-8.0f; swi2S(p,x,z, mul_f2_mat2(swi2(p,x,z) , rot(tt*0.3f+yid))); swi2S(p,x,y, mul_f2_mat2(swi2(p,x,y) , rot(tt*0.1f))); int mn=(int)(tt+yid*2.0f); float mm=_powcf(mod_f(tt,1.0f),5.0f); float ms=3.0f; float mno=mino(mn,p,ms)-0.05f; mno=_mix(mno,mino(mn+1,p,ms)-0.05f,mm); float3 mc=_mix(minoc(mn),minoc(mn+1),mm); if(mno>0.03f) *gl += _expf(-mno)*mc*1.4f; p=pp;p.z+=tt*1.5f; float3 cellID = to_float3(_truncf(p.x/2.0f+0.5f),_truncf(p.y/2.0f+0.5f),_truncf(p.z/2.0f+0.5f)); float3 id=to_float3(hash(swi2(cellID,x,x)+swi2(cellID,y,z)),hash(swi2(cellID,y,z)),hash(swi2(cellID,z,y)))*to_float3(1,0.6f,1); if(length(id) < 1.15f) id = to_float3_s(0.0f); else id = normalize(id); if(isnan(id.x))id=to_float3_s(0); //this is a stupid fix but whatever swi2S(p,y,z, mod_f2(swi2(p,y,z)-1.0f,2.0f)-1.0f); p.x=_fabs(p.x)-28.0f; float wls = bx(p,to_float3_s(0.7f))-0.05f; if(*sd>0.01f) *gl += _expf(-wls*0.1f) * id*0.5f; *sd=_fminf(mno,wls); *sd=_fabs(*sd)-0.001f; if(*sd<0.001f) { *io=mno80.0f)break;}} __DEVICE__ void nm(float3 cp, inout float3 *cn, float tt, inout float3 *gl, inout float *sd, inout float *io, inout float3 *oc, inout float *oa, inout float3 *ss, inout float3 *vb, inout int *ec ){mat3 k=mat3_sub_mat3(to_mat3_f3(cp,cp,cp),to_mat3_n(0.001f)); *cn=normalize(mp(cp, tt, gl, sd, io, oc, oa, ss, vb, ec)-to_float3(mp(k.r0, tt, gl, sd, io, oc, oa, ss, vb, ec),mp(k.r1, tt, gl, sd, io, oc, oa, ss, vb, ec),mp(k.r2, tt, gl, sd, io, oc, oa, ss, vb, ec)));} __DEVICE__ void px(inout float3 *cc, float3 rd, float tc, float cd, float3 cn, float3 cr, float3 cp, float tt, inout float3 *gl, inout float *sd, inout float *io, inout float3 *oc, inout float *oa, inout float3 *ss, inout float3 *vb, inout int *ec, float3 Colors[5]) { *cc=to_float3(0.0f,0.0f,0.0f)+length(pow_f3(abs_f3(rd+to_float3(0,0.5f,0)),to_float3_s(3))) * Colors[0] + *gl / tc; //to_float3(0.1f,0.0f,0.2f) float3 l = Colors[1]; //to_float3(0.5f,0.5f,0.8f); if(cd>80.0f){*oa=1.0f; return;} float df=clamp(length(cn*l),0.0f,1.0f); float3 fr = Colors[3];//_powcf(1.0f-df,3.0f) * _mix(*cc,Colors[3],0.5f); //to_float3_s(0.4f) float sp=(1.0f-length(cross(cr,cn*l)))*0.2f; float ao=_fminf(mp(cp+cn*0.3f, tt, gl, sd, io, oc, oa, ss, vb, ec)-0.3f,0.3f)*0.5f; *cc=_mix((*oc*(df+fr+ *ss)+fr+sp+ao+ *gl/tc), *oc, (*vb).x); } __DEVICE__ void render(float2 frag, float2 res, float time, out float4 *col, inout float2 *uv, inout float3 *rd, inout float3 *ro, inout float *tt, inout float *cd, inout float *td, inout float *tc, inout float3 *gl, inout float *sd, inout float *io, inout float3 *oc, inout float *oa, inout float3 *ss, inout float3 *vb, inout int *ec, inout float3 *cp, inout float3 *cr, inout int *es, inout float4 *fc, inout float3 *cn, inout float3 *cc, float refmul, float refoff, float4 iMouse, float2 iResolution, float3 View[2], float3 Colors[5] ) { *uv=to_float2(frag.x/res.x,frag.y/res.y); *uv-=0.5f;*uv/=to_float2(res.y/res.x,1); *ro=to_float3(0,0,-15)+View[0];*rd=normalize(to_float3_aw(*uv,1)+View[1]); *tt=mod_f(time, 100.0f); //############### 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); } //############################################################# for(int i=0;i<25;i++) { tr(*rd, *ro, cd, td, tc, *tt, gl, sd, io, oc, oa, ss, vb, ec); *cp=*ro+ *rd* *cd; nm(*cp, cn, *tt, gl, sd, io, oc, oa, ss, vb, ec); *ro = *cp - *cn * (*io<0.0f?-0.01f:0.01f); *cr = _refract_f3(*rd, *cn,i%2==0?1.0f/ *io:*io, refmul, refoff);i=*io<0.0f?i+1:i; if((length(*cr) == 0.0f && *es<=0)|| *io<0.0f){ *cr=reflect(*rd, *cn); *es=( *io<0.0f?*es:*ec);} if(max(*es,0)%3==0 && *cd<128.0f) *rd = *cr; *es-=1; if((*vb).x>0.0f&&i%2==1) *oa = _powcf(clamp(*cd/(*vb).y,0.0f,1.0f),(*vb).z); px(cc, *rd, *tc, *cd, *cn, *cr, *cp, *tt, gl, sd, io, oc, oa, ss, vb, ec, Colors); *fc = *fc+to_float4_aw(*cc* *oa,*oa)*(1.0f-(*fc).w); if(((*fc).w>=1.0f || *cd>80.0f)) break; } *col = pow_f4(*fc/(*fc).w, to_float4_s(0.8f)); } __KERNEL__ void TheTetrisDimensionFuse(__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 Reset = params->Reset; float4 Color1 = to_float4(params->Color1[0], params->Color1[1], params->Color1[2], params->Color1[3]); float4 Color2 = to_float4(params->Color2[0], params->Color2[1], params->Color2[2], params->Color2[3]); float4 Color3 = to_float4(params->Color3[0], params->Color3[1], params->Color3[2], params->Color3[3]); float4 Color4 = to_float4(params->Color4[0], params->Color4[1], params->Color4[2], params->Color4[3]); float4 Color5 = to_float4(params->Color5[0], params->Color5[1], params->Color5[2], params->Color5[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; float refmul = params->refmul; float refoff = params->refoff; // -------- float3 View[2] = {to_float3_aw(ViewXY,ViewZ),to_float3_aw(ViewDXY,ViewDZ)}; float3 Colors[5] = {swi3(Color1,x,y,z),swi3(Color2,x,y,z),swi3(Color3,x,y,z),swi3(Color4,x,y,z),swi3(Color5,x,y,z)}; float2 uv=to_float2_s(0.0); float3 cp=to_float3_s(0.0),cn=to_float3_s(0.0),cr=to_float3_s(0.0),ro=to_float3_s(0.0),rd=to_float3_s(0.0),ss=to_float3_s(0.0),oc=to_float3_s(0.0),cc=to_float3_s(0.0),gl=to_float3_s(0.0),vb=to_float3_s(0.0); float4 fc=to_float4_s(0.0); float tt=0.0f,cd=0.0f,sd=0.0f,io=0.0f,oa=0.0f,td=0.0f,tc=0.0f; int es=0,ec=0; render(fragCoord,iResolution,iTime, &fragColor, &uv, &rd, &ro, &tt, &cd, &td, &tc, &gl, &sd, &io, &oc, &oa, &ss, &vb, &ec, &cp, &cr, &es, &fc, &cn, &cc, refmul, refoff, iMouse, iResolution, View, Colors); _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, }) InResetCheckbox = self:AddInput("Reset", "Reset", { LINKID_DataType = "Number", INPID_InputControl = "CheckboxControl", INP_Integer = true, INP_Default = 0, }) self:BeginControlNest("Color1", "Colors", false, {}) self:BeginControlNest("Color1", "Color1", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Color1", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InColor1ColorR = self:AddInput("Red", "Color1Red", { INP_Default = 0.1, IC_ControlID = 0, attrs}) InColor1ColorG = self:AddInput("Green", "Color1Green", { INP_Default = 0.0, IC_ControlID = 1, attrs}) InColor1ColorB = self:AddInput("Blue", "Color1Blue", { INP_Default = 0.2, IC_ControlID = 2, attrs}) InColor1ColorA = self:AddInput("Alpha", "Color1Alpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Color2", "Color2", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Color2", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InColor2ColorR = self:AddInput("Red", "Color2Red", { INP_Default = 0.5, IC_ControlID = 0, attrs}) InColor2ColorG = self:AddInput("Green", "Color2Green", { INP_Default = 0.5, IC_ControlID = 1, attrs}) InColor2ColorB = self:AddInput("Blue", "Color2Blue", { INP_Default = 0.8, IC_ControlID = 2, attrs}) InColor2ColorA = self:AddInput("Alpha", "Color2Alpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Color3", "Color3", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Color3", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InColor3ColorR = self:AddInput("Red", "Color3Red", { INP_Default = 0.4, IC_ControlID = 0, attrs}) InColor3ColorG = self:AddInput("Green", "Color3Green", { INP_Default = 0.4, IC_ControlID = 1, attrs}) InColor3ColorB = self:AddInput("Blue", "Color3Blue", { INP_Default = 0.4, IC_ControlID = 2, attrs}) InColor3ColorA = self:AddInput("Alpha", "Color3Alpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Color4", "Color4", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Color4", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InColor4ColorR = self:AddInput("Red", "Color4Red", { INP_Default = 0.0, IC_ControlID = 0, attrs}) InColor4ColorG = self:AddInput("Green", "Color4Green", { INP_Default = 0.0, IC_ControlID = 1, attrs}) InColor4ColorB = self:AddInput("Blue", "Color4Blue", { INP_Default = 0.0, IC_ControlID = 2, attrs}) InColor4ColorA = self:AddInput("Alpha", "Color4Alpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Color5", "Color5", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Color5", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InColor5ColorR = self:AddInput("Red", "Color5Red", { INP_Default = 0.0, IC_ControlID = 0, attrs}) InColor5ColorG = self:AddInput("Green", "Color5Green", { INP_Default = 0.0, IC_ControlID = 1, attrs}) InColor5ColorB = self:AddInput("Blue", "Color5Blue", { INP_Default = 0.0, IC_ControlID = 2, attrs}) InColor5ColorA = self:AddInput("Alpha", "Color5Alpha", { 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, }) InrefmulSlider = self:AddInput("refmul", "refmul", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -1.0, INP_MaxScale = 10.0, INP_Default = 0.04, }) InrefoffSlider = self:AddInput("refoff", "refoff", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -1.0, INP_MaxScale = 10.0, INP_Default = 0.0, }) 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, }) ----- 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, LINK_Visible = false, INP_Required = false }) OutImage = self:AddOutput("Output", "Output", { LINKID_DataType = "Image", LINK_Main = 1, }) ShaderFuse.end_create() end -- // ------------------------------------------------------------------------ -- // Process -- // ------------------------------------------------------------------------ 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, "TheTetrisDimensionFuse", 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.Reset = InResetCheckbox:GetValue(req).Value params.Color1 = { InColor1ColorR:GetValue(req).Value, InColor1ColorG:GetValue(req).Value, InColor1ColorB:GetValue(req).Value,InColor1ColorA:GetValue(req).Value } params.Color2 = { InColor2ColorR:GetValue(req).Value, InColor2ColorG:GetValue(req).Value, InColor2ColorB:GetValue(req).Value,InColor2ColorA:GetValue(req).Value } params.Color3 = { InColor3ColorR:GetValue(req).Value, InColor3ColorG:GetValue(req).Value, InColor3ColorB:GetValue(req).Value,InColor3ColorA:GetValue(req).Value } params.Color4 = { InColor4ColorR:GetValue(req).Value, InColor4ColorG:GetValue(req).Value, InColor4ColorB:GetValue(req).Value,InColor4ColorA:GetValue(req).Value } params.Color5 = { InColor5ColorR:GetValue(req).Value, InColor5ColorG:GetValue(req).Value, InColor5ColorB:GetValue(req).Value,InColor5ColorA: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.refmul = InrefmulSlider:GetValue(req).Value params.refoff = InrefoffSlider:GetValue(req).Value -- Resolution params.width = dst.Width params.height = dst.Height -- Per channel time and resolution node:SetParamBlock(params) node:AddSampler("RowSampler", TEX_FILTER_MODE_LINEAR,TEX_ADDRESS_MODE_MIRROR, TEX_NORMALIZED_COORDS_TRUE) 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 -- */