--[[--/* Gastly.fuse Based on https://www.shadertoy.com/view/N3l3RN 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]; bool REFRACT; bool REFLECT; float BGMult[4]; float VolGasCol[4]; float Mat1Color[4]; float Mat2Color[4]; float Mat3Color[4]; float Mat4Color[4]; float Mat5Color[4]; float RimColor[4]; float ViewXY[2]; float ViewZ; float CamAngle; float CamDist; float GasAura; 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 abs_f3(a) _fabs(a) #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 abs_f3(a) fabs(a) #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 abs_f3(a) to_float3(_fabs((a).x), _fabs((a).y),_fabs((a).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 = [[ // ---------------------------------------------------------------------------------- // - Image - // ---------------------------------------------------------------------------------- #define pi 3.1415926535897f // 3D Gastly Shader // By Noztol #define MAX_STEPS 300 #define MAX_DIST 20.0f #define SURF_DIST 0.001f __DEVICE__ mat2 rot(float a) { float s = _sinf(a), c = _cosf(a); return to_mat2(c, -s, s, c); } // --- Primitive SDFs --- __DEVICE__ float sdSphere(float3 p, float s) { return length(p) - s; } __DEVICE__ float sdBox(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); } __DEVICE__ float sdCone(float3 p, float r, float h) { float2 q = to_float2(length(swi2(p,x,z)), p.y); float d = _fmaxf(q.y - h, -q.y); float rad = r * (1.0f - clamp(q.y / h, 0.0f, 1.0f)); return _fmaxf(d, q.x - rad); } __DEVICE__ float sdEllipsoid(float3 p, float3 r) { float k0 = length(p/r); float k1 = length(p/(r*r)); return k0*(k0-1.0f)/k1; } // --- Boolean Operations --- __DEVICE__ float2 opU(float2 d1, float2 d2) { return (d1.x < d2.x) ? d1 : d2; } __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); } // --- Scene Map --- __DEVICE__ float2 map(float3 p, float iTime) { // 0.0f Global Hover Animation float hover = _sinf(iTime * 2.5f) * 0.15f + 0.4f; float3 pModel = p; pModel.y -= hover; // 1.0f The Main Body float3 pBody = pModel - to_float3(0.0f, 0.35f, 0.0f); float bodyDist = sdSphere(pBody, 1.0f); float mouthAnim = _sinf(iTime * 3.5f) * 0.5f + 0.5f; float openAmt = _mix(0.02f, 0.15f, mouthAnim); // 2.0f The Mouth Cavity float3 pMouth = pModel - to_float3(0.0f, 0.2f, -0.85f); pMouth.y -= pMouth.x * pMouth.x * 0.8f; float mouthCavity = sdEllipsoid(pMouth, to_float3(0.65f, 0.2f, 0.3f)); mouthCavity = _fmaxf(mouthCavity, _fabs(pMouth.y) - openAmt); float bodyWithMouth = smax(bodyDist, -mouthCavity, 0.03f); float matID = 1.0f; if (-mouthCavity > bodyDist - 0.025f) { matID = 4.0f; } float2 res = to_float2(bodyWithMouth, matID); float3 pLeft = pModel; pLeft.x = _fabs(pLeft.x); // 3.0f Eye Whites float3 pEye = pLeft - to_float3(0.35f, 0.85f, -0.75f); swi2S(pEye,x,y, mul_f2_mat2(swi2(pEye,x,y) , rot(-0.35f))); swi2S(pEye,y,z, mul_f2_mat2(swi2(pEye,y,z) , rot(0.05f))); float eyeSphere = sdSphere(pEye, 0.45f); float eyeW = _fmaxf(eyeSphere, pEye.y); res = opU(res, to_float2(eyeW, 2.0f)); // 4.0f Eyebrows float browThick = 0.06f; float3 pBrow = pEye - to_float3(0.0f, browThick, 0.0f); float brow = sdBox(pBrow, to_float3(0.55f, browThick, 0.45f)); res = opU(res, to_float2(brow, 3.0f)); // 5.0f Pupils float3 pPupil = pEye - to_float3(0.0f, -0.15f, -0.42f); float pupil = sdSphere(pPupil, 0.06f); res = opU(res, to_float2(pupil, 3.0f)); // 6.0f Fangs (Pushed much higher on the Y-axis to bury the base into the roof of the mouth) float3 pFang = pLeft - to_float3(0.3f, 0.28f + openAmt, -0.78f); pFang.y = -pFang.y; swi2S(pFang,x,y, mul_f2_mat2(swi2(pFang,x,y) , rot(-0.1f))); swi2S(pFang,y,z, mul_f2_mat2(swi2(pFang,y,z) , rot(0.15f))); // Made slightly longer (0.22f) and thicker (0.06f) so they still protrude after being buried deeper float fangs = sdCone(pFang, 0.06f, 0.22f); res = opU(res, to_float2(fangs, 2.0f)); // 7.0f Floor float floorDist = p.y + 0.65f; res = opU(res, to_float2(floorDist, 5.0f)); return res; } __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), iTime).x - map(p - swi3(e,x,y,y), iTime).x, map(p + swi3(e,y,x,y), iTime).x - map(p - swi3(e,y,x,y), iTime).x, map(p + swi3(e,y,y,x), iTime).x - map(p - swi3(e,y,y,x), iTime).x )); } __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, iTime).x; if(h < 0.001f) return 0.0f; res = _fminf(res, 8.0f * h / t); t += h; if(t > 6.0f) break; } return clamp(res, 0.0f, 1.0f); } __KERNEL__ void GastlyFuse(__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); bool REFRACT = params->REFRACT; bool REFLECT = params->REFLECT; float4 BGMult = to_float4(params->BGMult[0], params->BGMult[1], params->BGMult[2], params->BGMult[3]); float4 VolGasCol = to_float4(params->VolGasCol[0], params->VolGasCol[1], params->VolGasCol[2], params->VolGasCol[3]); 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 Mat4Color = to_float4(params->Mat4Color[0], params->Mat4Color[1], params->Mat4Color[2], params->Mat4Color[3]); float4 Mat5Color = to_float4(params->Mat5Color[0], params->Mat5Color[1], params->Mat5Color[2], params->Mat5Color[3]); float4 RimColor = to_float4(params->RimColor[0], params->RimColor[1], params->RimColor[2], params->RimColor[3]); float2 ViewXY = to_float2(params->ViewXY[0], params->ViewXY[1]); float ViewZ = params->ViewZ; float CamAngle = params->CamAngle; float CamDist = params->CamDist; float GasAura = params->GasAura; // -------- float Alpha = Mat4Color.w; float2 uv = (fragCoord - 0.5f * iResolution) / iResolution.y; // 90 Degree Camera Swivel (785398 rad == 45 degrees) float camAngle = _sinf(iTime * 0.546f) * CamAngle;//0.785398f; float camDist = CamDist;//4.5f; float3 ro = to_float3(_sinf(camAngle) * camDist, 1.5f, -_cosf(camAngle) * camDist); 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.0f, 1.0f, 0.0f), 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); } //############################################################# float dO = 0.0f; float matID = 0.0f; float gasAura = 0.0f; float hover = _sinf(iTime * 2.5f) * 0.15f + 0.4f; float3 centerPos = to_float3(0.0f, 0.35f + hover, 0.0f); for(int i=0; i MAX_DIST) break; dO += stepSize; matID = dS.y; } float3 col = swi3(BGMult,x,y,z); //to_float3(0.05f, 0.02f, 0.1f); if(dO < MAX_DIST) { float3 p = ro + rd * dO; float3 n = calcNormal(p, iTime); float3 lightPos = to_float3(2.0f, 4.0f, -3.5f); 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.5f + 0.5f * n.y; float spec = _powf(clamp(dot(view, ref), 0.0f, 1.0f), 32.0f); float shadow = getShadow(p + n * 0.01f, l, iTime); float3 albedo = to_float3_s(0.0f); if(matID == 1.0f) albedo = swi3(Mat1Color,x,y,z), Alpha = 1.0f;//to_float3(0.08f, 0.01f, 0.15f); if(matID == 2.0f) albedo = swi3(Mat2Color,x,y,z), Alpha = 1.0f;//to_float3_s(0.95f); if(matID == 3.0f) albedo = swi3(Mat3Color,x,y,z), Alpha = 1.0f;//to_float3_s(0.02f); if(matID == 4.0f) { albedo = swi3(Mat4Color,x,y,z);//to_float3(0.6f, 0.15f, 0.3f); spec = 0.0f; amb *= 0.3f; } if(matID == 5.0f) albedo = swi3(Mat5Color,x,y,z);//to_float3_s(0.15f); col = albedo * (dif * shadow + amb * 0.15f) + spec * 0.5f * (1.0f - albedo.x); 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.5f), Alpha = 1.0f;//to_float3(0.8f, 0.1f, 1.0f) * _powf(rim, 3.5f); } } // Add Volumetric Gas col += swi3(VolGasCol,x,y,z) * gasAura;//to_float3(0.7f, 0.1f, 1.0f) * gasAura; 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, }) InREFRACTCheckbox = self:AddInput("REFRACT", "REFRACT", { LINKID_DataType = "Number", INPID_InputControl = "CheckboxControl", INP_Integer = true, INP_Default = 1, }) InREFLECTCheckbox = self:AddInput("REFLECT", "REFLECT", { LINKID_DataType = "Number", INPID_InputControl = "CheckboxControl", INP_Integer = true, INP_Default = 1, }) self:BeginControlNest("Colors", "Colors", false, {}) self:BeginControlNest("BGMult", "BGMult", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "BGMult", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InBGMultColorR = self:AddInput("Red", "BGMultRed", { INP_Default = 0.05, IC_ControlID = 0, attrs}) InBGMultColorG = self:AddInput("Green", "BGMultGreen", { INP_Default = 0.02, IC_ControlID = 1, attrs}) InBGMultColorB = self:AddInput("Blue", "BGMultBlue", { INP_Default = 0.1, IC_ControlID = 2, attrs}) InBGMultColorA = self:AddInput("Alpha", "BGMultAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("VolGasCol", "VolGasCol", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "VolGasCol", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InVolGasColColorR = self:AddInput("Red", "VolGasColRed", { INP_Default = 0.7, IC_ControlID = 0, attrs}) InVolGasColColorG = self:AddInput("Green", "VolGasColGreen", { INP_Default = 0.1, IC_ControlID = 1, attrs}) InVolGasColColorB = self:AddInput("Blue", "VolGasColBlue", { INP_Default = 1.0, IC_ControlID = 2, attrs}) InVolGasColColorA = self:AddInput("Alpha", "VolGasColAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() 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.08, IC_ControlID = 0, attrs}) InMat1ColorColorG = self:AddInput("Green", "Mat1ColorGreen", { INP_Default = 0.01, IC_ControlID = 1, attrs}) InMat1ColorColorB = self:AddInput("Blue", "Mat1ColorBlue", { INP_Default = 0.15, 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.95, IC_ControlID = 0, attrs}) InMat2ColorColorG = self:AddInput("Green", "Mat2ColorGreen", { INP_Default = 0.95, IC_ControlID = 1, attrs}) InMat2ColorColorB = self:AddInput("Blue", "Mat2ColorBlue", { INP_Default = 0.95, 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.02, IC_ControlID = 0, attrs}) InMat3ColorColorG = self:AddInput("Green", "Mat3ColorGreen", { INP_Default = 0.02, IC_ControlID = 1, attrs}) InMat3ColorColorB = self:AddInput("Blue", "Mat3ColorBlue", { INP_Default = 0.02, IC_ControlID = 2, attrs}) InMat3ColorColorA = self:AddInput("Alpha", "Mat3ColorAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Mat4Color", "Mat4Color", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Mat4Color", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InMat4ColorColorR = self:AddInput("Red", "Mat4ColorRed", { INP_Default = 0.6, IC_ControlID = 0, attrs}) InMat4ColorColorG = self:AddInput("Green", "Mat4ColorGreen", { INP_Default = 0.15, IC_ControlID = 1, attrs}) InMat4ColorColorB = self:AddInput("Blue", "Mat4ColorBlue", { INP_Default = 0.3, IC_ControlID = 2, attrs}) InMat4ColorColorA = self:AddInput("Alpha", "Mat4ColorAlpha", { INP_Default = 1.0, IC_ControlID = 3, attrs}) self:EndControlNest() self:BeginControlNest("Mat5Color", "Mat5Color", true, {}) ctrl_grp_cnt = (ctrl_grp_cnt==nil) and 1 or (ctrl_grp_cnt+1) attrs = { ICS_Name = "Mat5Color", LINKID_DataType = "Number", INPID_InputControl = "ColorControl", INP_MinScale = 0.0, INP_MaxScale = 1.0, IC_ControlGroup = ctrl_grp_cnt, } InMat5ColorColorR = self:AddInput("Red", "Mat5ColorRed", { INP_Default = 0.15, IC_ControlID = 0, attrs}) InMat5ColorColorG = self:AddInput("Green", "Mat5ColorGreen", { INP_Default = 0.15, IC_ControlID = 1, attrs}) InMat5ColorColorB = self:AddInput("Blue", "Mat5ColorBlue", { INP_Default = 0.15, IC_ControlID = 2, attrs}) InMat5ColorColorA = self:AddInput("Alpha", "Mat5ColorAlpha", { 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.1, IC_ControlID = 1, attrs}) InRimColorColorB = self:AddInput("Blue", "RimColorBlue", { INP_Default = 1.0, IC_ControlID = 2, attrs}) InRimColorColorA = self:AddInput("Alpha", "RimColorAlpha", { 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, }) InCamAngleSlider = self:AddInput("CamAngle", "CamAngle", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -2.0, INP_MaxScale = 2.0, INP_Default = 0.785398, }) InCamDistSlider = self:AddInput("CamDist", "CamDist", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -2.0, INP_MaxScale = 10.0, INP_Default = 4.5, }) InGasAuraSlider = self:AddInput("GasAura", "GasAura", { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = -2.0, INP_MaxScale = 2.0, INP_Default = 0.35, }) 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, "GastlyFuse", 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.REFRACT = InREFRACTCheckbox:GetValue(req).Value params.REFLECT = InREFLECTCheckbox:GetValue(req).Value params.BGMult = { InBGMultColorR:GetValue(req).Value, InBGMultColorG:GetValue(req).Value, InBGMultColorB:GetValue(req).Value,InBGMultColorA:GetValue(req).Value } params.VolGasCol = { InVolGasColColorR:GetValue(req).Value, InVolGasColColorG:GetValue(req).Value, InVolGasColColorB:GetValue(req).Value,InVolGasColColorA:GetValue(req).Value } 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.Mat4Color = { InMat4ColorColorR:GetValue(req).Value, InMat4ColorColorG:GetValue(req).Value, InMat4ColorColorB:GetValue(req).Value,InMat4ColorColorA:GetValue(req).Value } params.Mat5Color = { InMat5ColorColorR:GetValue(req).Value, InMat5ColorColorG:GetValue(req).Value, InMat5ColorColorB:GetValue(req).Value,InMat5ColorColorA:GetValue(req).Value } params.RimColor = { InRimColorColorR:GetValue(req).Value, InRimColorColorG:GetValue(req).Value, InRimColorColorB:GetValue(req).Value,InRimColorColorA:GetValue(req).Value } params.ViewXY = {InViewXYPoint:GetValue(req).X,InViewXYPoint:GetValue(req).Y} params.ViewZ = InViewZSlider:GetValue(req).Value params.CamAngle = InCamAngleSlider:GetValue(req).Value params.CamDist = InCamDistSlider:GetValue(req).Value params.GasAura = InGasAuraSlider: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 -- */