--[[--/* Ditto.fuse Based on https://www.shadertoy.com/view/fXl3z4 a WebGL shader created by noztol. 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]; float Mat1Color[4]; float Mat2Color[4]; float Mat3Color[4]; float RimColor[4]; float Sky1Color[4]; float Sky2Color[4]; float Floor1Color[4]; float Floor2Color[4]; float ViewXY[2]; float ViewZ; 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 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__ 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 mod_f(a,b) fmod((a),(b)) #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 mod_f(a,b) _fmod(a,b) #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 mod_f(a,b) ((a)-(b)*_floor((a)/(b))) #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 = [[ // ---------------------------------------------------------------------------------- // - Image - // ---------------------------------------------------------------------------------- #define pi 3.1415926535897f // 3D Ditto // By Noztol #define MAX_STEPS 300 #define MAX_DIST 20.0f #define SURF_DIST 0.001f // Rotation matrix __DEVICE__ mat2 rot(float a) { float s = _sinf(a), c = _cosf(a); return to_mat2(c, -s, s, c); } // Smooth _fminf (union) __DEVICE__ float smin(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); } // Smooth _fmaxf (subtraction) __DEVICE__ float smax(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); } // Primitives __DEVICE__ float sdSphere(float3 p, float s) { return length(p) - s; } __DEVICE__ float sdEllipsoid(float3 p, float3 r) { float k0 = length(p/r); float k1 = length(p/(r*r)); return k0*(k0-1.0f)/k1; } // Union combining distance and material ID __DEVICE__ float2 opU(float2 d1, float2 d2) { return (d1.x < d2.x) ? d1 : d2; } // Scene Map __DEVICE__ float2 map(float3 p, bool isShadow, float iTime) { // jiggle float jt = iTime * 3.0f; float jiggleX = _sinf(jt) * 0.03f; float jiggleY = _cosf(jt) * 0.04f; float jiggleZ = _sinf(jt + 1.0f) * 0.03f; // body float body = sdEllipsoid(p, to_float3(0.9f + jiggleX, 0.75f + jiggleY, 0.8f + jiggleZ)); // Right arm raised float3 pArm1 = p - to_float3(0.75f, 0.35f + jiggleY, 0.0f); swi2S(pArm1,x,y, mul_f2_mat2(swi2(pArm1,x,y) , rot(-0.6f))); float arm1 = sdEllipsoid(pArm1, to_float3(0.55f, 0.16f, 0.16f)); // Left arm raised float3 pArm2 = p - to_float3(-0.75f, 0.35f + jiggleY, 0.0f); swi2S(pArm2,x,y, mul_f2_mat2(swi2(pArm2,x,y) , rot(0.6f))); float arm2 = sdEllipsoid(pArm2, to_float3(0.55f, 0.16f, 0.16f)); float hump1 = sdSphere(p - to_float3(0.4f, 0.6f + jiggleY, 0.0f), 0.35f); float hump2 = sdSphere(p - to_float3(-0.4f, 0.6f + jiggleY, 0.0f), 0.35f); body = smin(body, arm1, 0.2f); body = smin(body, arm2, 0.2f); body = smin(body, hump1, 0.3f); body = smin(body, hump2, 0.3f); body = smax(body, -(p.y + 0.65f), 0.1f); // mouth float3 pMouth = p - to_float3(0.0f, 0.15f + jiggleY, -0.78f); // Curve the mouth space horizontally to create the smile pMouth.y -= pMouth.x * pMouth.x * 0.5f; // Animation: Ranges from closed (0.0f) to fully open (0.15f) float mouthAnim = _sinf(iTime * 3.5f) * 0.5f + 0.5f; float openAmt = _mix(0.0f, 0.15f, mouthAnim); // The cutting shape for the hole float mouthCavity = sdEllipsoid(pMouth, to_float3(0.45f, 0.15f, 0.25f)); mouthCavity = _fmaxf(mouthCavity, _fabs(pMouth.y) - openAmt); // Slices it shut dynamically // Carve the cavity hole into the body float bodyWithMouth = smax(body, -mouthCavity, 0.025f); // If the inverted mouth cavity is closer to the surface than the un-cut body, // it means the ray is hitting the inside wall of the mouth hole. float matID = 1.0f; // Default to pink body if (-mouthCavity > body - 0.015f) { // The 0.015f offset ensures the outer edge (lips) stays pink before transitioning matID = 3.0f; // Dark red cavity } float2 res = to_float2(bodyWithMouth, matID); // eyes if (!isShadow) { // Hide from shadow rays to keep body clean float3 pEyeLeft = p - to_float3(-0.32f, 0.68f + jiggleY, -0.66f); float3 pEyeRight = p - to_float3(0.32f, 0.68f + jiggleY, -0.66f); float eyeL = sdSphere(pEyeLeft, 0.045f); float eyeR = sdSphere(pEyeRight, 0.045f); res = opU(res, to_float2(_fminf(eyeL, eyeR), 2.0f)); } // floor float floor = p.y + 0.65f; res = opU(res, to_float2(floor, 5.0f)); return res; } // Calculate normal vector __DEVICE__ float3 calcNormal(float3 p, float iTime) { float2 e = to_float2(0.001f, 0.0f); return normalize(to_float3( map(p + swi3(e,x,y,y), false, iTime).x - map(p - swi3(e,x,y,y), false, iTime).x, map(p + swi3(e,y,x,y), false, iTime).x - map(p - swi3(e,y,x,y), false, iTime).x, map(p + swi3(e,y,y,x), false, iTime).x - map(p - swi3(e,y,y,x), false, iTime).x )); } // Raymarching loop __DEVICE__ float2 rayMarch(float3 ro, float3 rd, float iTime) { float dO = 0.0f; float mat = 0.0f; for(int i=0; i MAX_DIST || _fabs(dS.x) < SURF_DIST) break; } return to_float2(dO, mat); } // Soft shadows __DEVICE__ float getShadow(float3 ro, float3 rd, float iTime) { float res = 1.0f; float t = 0.05f; for(int i = 0; i < 40; i++) { float h = map(ro + rd * t, true, iTime).x; if(h < 0.001f) return 0.0f; res = _fminf(res, 10.0f * h / t); t += h * 0.5f; } return res; } __KERNEL__ void DittoFuse(__CONSTANTREF__ Params* params, __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); float4 Mat1Color = to_float4(params->Mat1Color[0], params->Mat1Color[1], params->Mat1Color[2], params->Mat1Color[3]); float4 Mat2Color = to_float4(params->Mat2Color[0], params->Mat2Color[1], params->Mat2Color[2], params->Mat2Color[3]); float4 Mat3Color = to_float4(params->Mat3Color[0], params->Mat3Color[1], params->Mat3Color[2], params->Mat3Color[3]); float4 RimColor = to_float4(params->RimColor[0], params->RimColor[1], params->RimColor[2], params->RimColor[3]); float4 Sky1Color = to_float4(params->Sky1Color[0], params->Sky1Color[1], params->Sky1Color[2], params->Sky1Color[3]); float4 Sky2Color = to_float4(params->Sky2Color[0], params->Sky2Color[1], params->Sky2Color[2], params->Sky2Color[3]); float4 Floor1Color = to_float4(params->Floor1Color[0], params->Floor1Color[1], params->Floor1Color[2], params->Floor1Color[3]); float4 Floor2Color = to_float4(params->Floor2Color[0], params->Floor2Color[1], params->Floor2Color[2], params->Floor2Color[3]); float2 ViewXY = to_float2(params->ViewXY[0], params->ViewXY[1]); float ViewZ = params->ViewZ; // -------- float Alpha = Mat3Color.w; float2 uv = (fragCoord - 0.5f * iResolution) / iResolution.y; // Camera setup float3 ro = to_float3(0.0f, 1.5f, -3.5f); float3 target = to_float3(0.0f, 0.3f, 0.0f) + to_float3_aw(ViewXY, ViewZ); float3 f = normalize(target - ro); float3 r = normalize(cross(to_float3(0,1,0), f)); float3 u = cross(f, r); float3 rd = normalize(f + uv.x * r + uv.y * u); //############### 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); } //############################################################# // Cast Ray float2 rm = rayMarch(ro, rd, iTime); float d = rm.x; float matID = rm.y; float3 col = to_float3_s(0.0f); if(d < MAX_DIST) { float3 p = ro + rd * d; float3 n = calcNormal(p, iTime); // Lighting Setup float3 lightPos = to_float3(2.0f, 4.0f, -3.0f); float3 l = normalize(lightPos - p); float3 view = normalize(ro - p); float3 ref = reflect(-l, n); float dif = clamp(dot(n, l), 0.0f, 1.0f); float amb = 0.4f + 0.6f * clamp(0.5f + 0.5f * n.y, 0.0f, 1.0f); float spec = _powf(clamp(dot(view, ref), 0.0f, 1.0f), 32.0f); float shadow = getShadow(p + n * 0.01f, l, iTime); dif *= shadow; // Apply Material Properties float3 albedo = to_float3_s(1.0f); float roughness = 0.5f; if(matID == 1.0f) { // Ditto Body albedo = swi3(Mat1Color,x,y,z);//to_float3(0.85f, 0.4f, 0.6f); // Pink roughness = 0.2f; Alpha = 1.0f; } else if(matID == 2.0f) { // Eyes albedo = swi3(Mat2Color,x,y,z);//to_float3_s(0.02f); // Black roughness = 0.05f; spec *= 2.0f; Alpha = 1.0f; } else if(matID == 3.0f) { // Mouth Interior (Deep Cavity) albedo = swi3(Mat3Color,x,y,z);//to_float3(0.05f, 0.0f, 0.0f); // Very dark, almost black roughness = 1.0f; spec = 0.0f; // No reflections inside the hole amb *= 0.1f; // Darken ambient light to force the deep shadow illusion Alpha = 1.0f; } else if(matID == 5.0f) { // Floor float checker = mod_f(_floor(p.x * 2.0f) + _floor(p.z * 2.0f), 2.0f); //albedo = _mix(to_float3_s(0.2f), to_float3_s(0.3f), checker); albedo = _mix(swi3(Floor1Color,x,y,z), swi3(Floor2Color,x,y,z), checker); roughness = 0.8f; spec = 0.0f; } // Final color mix col = albedo * (dif * 0.8f + amb * 0.3f) + spec * (1.0f - roughness); // Fake subsurface scattering / rim light if(matID == 1.0f) { float rim = 1.0f - clamp(dot(view, n), 0.0f, 1.0f); col += swi3(RimColor,x,y,z) * _powf(rim, 3.0f) * 0.5f;//to_float3(0.8f, 0.3f, 0.5f) * _powf(rim, 3.0f) * 0.5f; Alpha = 1.0f; } } else { // Sky gradient background //col = _mix(to_float3(0.7f, 0.8f, 0.9f), to_float3(0.2f, 0.4f, 0.8f), rd.y * 0.5f + 0.5f); col = _mix(swi3(Sky1Color,x,y,z), swi3(Sky2Color,x,y,z), rd.y * 0.5f + 0.5f); } // Gamma correction col = pow_f3(col, to_float3_s(0.4545f)); fragColor = to_float4_aw(col, Alpha); _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, }) self:BeginControlNest("Colors", "Colors", false, {}) self:BeginControlNest("Mat1Color", "Mat1Color", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Mat1Color", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InMat1ColorColorR = self:AddInput("Red", "Mat1ColorRed", { INP_Default = 0.85, IC_ControlID = 0, attrs}) InMat1ColorColorG = self:AddInput("Green", "Mat1ColorGreen", { INP_Default = 0.4, IC_ControlID = 1, attrs}) InMat1ColorColorB = self:AddInput("Blue", "Mat1ColorBlue", { INP_Default = 0.6, IC_ControlID = 2, attrs}) InMat1ColorColorA = self:AddInput("Alpha", "Mat1ColorAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Mat2Color", "Mat2Color", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Mat2Color", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InMat2ColorColorR = self:AddInput("Red", "Mat2ColorRed", { INP_Default = 0.02, IC_ControlID = 0, attrs}) InMat2ColorColorG = self:AddInput("Green", "Mat2ColorGreen", { INP_Default = 0.02, IC_ControlID = 1, attrs}) InMat2ColorColorB = self:AddInput("Blue", "Mat2ColorBlue", { INP_Default = 0.02, IC_ControlID = 2, attrs}) InMat2ColorColorA = self:AddInput("Alpha", "Mat2ColorAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Mat3Color", "Mat3Color", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Mat3Color", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InMat3ColorColorR = self:AddInput("Red", "Mat3ColorRed", { INP_Default = 0.05, IC_ControlID = 0, attrs}) InMat3ColorColorG = self:AddInput("Green", "Mat3ColorGreen", { INP_Default = 0.0, IC_ControlID = 1, attrs}) InMat3ColorColorB = self:AddInput("Blue", "Mat3ColorBlue", { INP_Default = 0.0, IC_ControlID = 2, attrs}) InMat3ColorColorA = self:AddInput("Alpha", "Mat3ColorAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("RimColor", "RimColor", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "RimColor", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InRimColorColorR = self:AddInput("Red", "RimColorRed", { INP_Default = 0.8, IC_ControlID = 0, attrs}) InRimColorColorG = self:AddInput("Green", "RimColorGreen", { INP_Default = 0.3, IC_ControlID = 1, attrs}) InRimColorColorB = self:AddInput("Blue", "RimColorBlue", { INP_Default = 0.5, IC_ControlID = 2, attrs}) InRimColorColorA = self:AddInput("Alpha", "RimColorAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Sky1Color", "Sky1Color", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Sky1Color", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InSky1ColorColorR = self:AddInput("Red", "Sky1ColorRed", { INP_Default = 0.7, IC_ControlID = 0, attrs}) InSky1ColorColorG = self:AddInput("Green", "Sky1ColorGreen", { INP_Default = 0.8, IC_ControlID = 1, attrs}) InSky1ColorColorB = self:AddInput("Blue", "Sky1ColorBlue", { INP_Default = 0.9, IC_ControlID = 2, attrs}) InSky1ColorColorA = self:AddInput("Alpha", "Sky1ColorAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Sky2Color", "Sky2Color", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Sky2Color", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InSky2ColorColorR = self:AddInput("Red", "Sky2ColorRed", { INP_Default = 0.2, IC_ControlID = 0, attrs}) InSky2ColorColorG = self:AddInput("Green", "Sky2ColorGreen", { INP_Default = 0.4, IC_ControlID = 1, attrs}) InSky2ColorColorB = self:AddInput("Blue", "Sky2ColorBlue", { INP_Default = 0.8, IC_ControlID = 2, attrs}) InSky2ColorColorA = self:AddInput("Alpha", "Sky2ColorAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Floor1Color", "Floor1Color", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Floor1Color", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InFloor1ColorColorR = self:AddInput("Red", "Floor1ColorRed", { INP_Default = 0.3, IC_ControlID = 0, attrs}) InFloor1ColorColorG = self:AddInput("Green", "Floor1ColorGreen", { INP_Default = 0.3, IC_ControlID = 1, attrs}) InFloor1ColorColorB = self:AddInput("Blue", "Floor1ColorBlue", { INP_Default = 0.3, IC_ControlID = 2, attrs}) InFloor1ColorColorA = self:AddInput("Alpha", "Floor1ColorAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Floor2Color", "Floor2Color", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Floor2Color", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InFloor2ColorColorR = self:AddInput("Red", "Floor2ColorRed", { INP_Default = 0.2, IC_ControlID = 0, attrs}) InFloor2ColorColorG = self:AddInput("Green", "Floor2ColorGreen", { INP_Default = 0.2, IC_ControlID = 1, attrs}) InFloor2ColorColorB = self:AddInput("Blue", "Floor2ColorBlue", { INP_Default = 0.2, IC_ControlID = 2, attrs}) InFloor2ColorColorA = self:AddInput("Alpha", "Floor2ColorAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:EndControlNest() 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, }) 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 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, "DittoFuse", ShaderCompatibilityCode..ShaderKernelCode, "Params", ShaderParameters ) -- Extern texture or create a new one -- 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.Mat1Color = { InMat1ColorColorR:GetValue(req).Value, InMat1ColorColorG:GetValue(req).Value, InMat1ColorColorB:GetValue(req).Value,InMat1ColorColorA:GetValue(req).Value } params.Mat2Color = { InMat2ColorColorR:GetValue(req).Value, InMat2ColorColorG:GetValue(req).Value, InMat2ColorColorB:GetValue(req).Value,InMat2ColorColorA:GetValue(req).Value } params.Mat3Color = { InMat3ColorColorR:GetValue(req).Value, InMat3ColorColorG:GetValue(req).Value, InMat3ColorColorB:GetValue(req).Value,InMat3ColorColorA:GetValue(req).Value } params.RimColor = { InRimColorColorR:GetValue(req).Value, InRimColorColorG:GetValue(req).Value, InRimColorColorB:GetValue(req).Value,InRimColorColorA:GetValue(req).Value } params.Sky1Color = { InSky1ColorColorR:GetValue(req).Value, InSky1ColorColorG:GetValue(req).Value, InSky1ColorColorB:GetValue(req).Value,InSky1ColorColorA:GetValue(req).Value } params.Sky2Color = { InSky2ColorColorR:GetValue(req).Value, InSky2ColorColorG:GetValue(req).Value, InSky2ColorColorB:GetValue(req).Value,InSky2ColorColorA:GetValue(req).Value } params.Floor1Color = { InFloor1ColorColorR:GetValue(req).Value, InFloor1ColorColorG:GetValue(req).Value, InFloor1ColorColorB:GetValue(req).Value,InFloor1ColorColorA:GetValue(req).Value } params.Floor2Color = { InFloor2ColorColorR:GetValue(req).Value, InFloor2ColorColorG:GetValue(req).Value, InFloor2ColorColorB:GetValue(req).Value,InFloor2ColorColorA:GetValue(req).Value } params.ViewXY = {InViewXYPoint:GetValue(req).X,InViewXYPoint:GetValue(req).Y} params.ViewZ = InViewZSlider:GetValue(req).Value -- Resolution params.width = dst.Width params.height = dst.Height -- Per channel time and resolution -- Set parameters and add I/O node:SetParamBlock(params) node:AddSampler("RowSampler", TEX_FILTER_MODE_LINEAR,TEX_ADDRESS_MODE_MIRROR, TEX_NORMALIZED_COORDS_TRUE) 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 -- */