diff --git a/Shaders/README.md b/Shaders/README.md index 21a46abc..29316539 100644 --- a/Shaders/README.md +++ b/Shaders/README.md @@ -13,13 +13,13 @@ Furthermore must be mentioned that this repository is only an incubator to devel See [Shaders](Shaders.md) for a list of all shaders implemented so far - resp. the [Overview](Overview.md) to have with thumbnails a more 'visual experience'. Find what's new with the [latest conversions](Latest Conversions.md), or have a look at the [Shader of the Week](Shader of the Week.md) list. -Current Shader of the Week (17th of July 2024): +Current Shader of the Week (10th of September 2024):
-[![AlienTunnel](https://github.com/user-attachments/assets/7db038b1-170f-4978-9e69-6f67424991f9) -](ShaderOfTheWeek/AlienTunnel.md) +[![StarryPlanes](https://github.com/user-attachments/assets/bb5f6226-ca3c-4fb3-94c8-4e2d72450020) +](ShaderOfTheWeek/StarryPlanes.md) -[Alien Tunnel](ShaderOfTheWeek/AlienTunnel.md) by [lz](https://www.shadertoy.com/user/lz) +[StarryPlanes](ShaderOfTheWeek/StarryPlanes.md) by [mrange](https://www.shadertoy.com/user/mrange)
diff --git a/Shaders/ShaderOfTheWeek/StarryPlanes.fuse b/Shaders/ShaderOfTheWeek/StarryPlanes.fuse new file mode 100644 index 00000000..85753483 --- /dev/null +++ b/Shaders/ShaderOfTheWeek/StarryPlanes.fuse @@ -0,0 +1,826 @@ +--[[--/* + + StarryPlanes.fuse + + Based on https://www.shadertoy.com/view/MfjyWK 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]; + float PathA[2]; + float PathB[2]; + float planeDist; + float furthest; + float fadeFrom; + + 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 swi3S(a,b,c,d,e) a.b##c##d = e + + #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 swi3S(a,b,c,d,e) {float3 tmp = e; (a).b = tmp.x; (a).c = tmp.y; (a).d = tmp.z;} + #define swi4S(a,b,c,d,e,f) {float4 tmp = f; (a).b = tmp.x; (a).c = tmp.y; (a).d = tmp.z; (a).e = tmp.w;} + + #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 + + +#if defined(USE_NATIVE_METAL_IMPL) + + #define sin_f2(i) sin(i) + #define sin_f3(i) sin(i) + #define cos_f2(i) cos(i) + #define sqrt_f3(a) _sqrtf(a) + #define sign_f(a) sign(a) + #define distance_f2(pt1,pt2) _sqrtf(dot(pt2 - pt1,pt2 - pt1)) + +#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 sin_f2(i) sin(i) + #define sin_f3(i) sin(i) + #define cos_f2(i) cos(i) + #define sqrt_f3(a) _sqrtf(a) + #define sign_f(a) sign(a) + #define distance_f2( p1, p2) distance(p1, p2) + + #else // Generic + + #define fract(a) ((a)-_floor(a)) + + #define sin_f2(i) to_float2( _sinf((i).x), _sinf((i).y)) + #define sin_f3(i) to_float3( _sinf((i).x), _sinf((i).y), _sinf((i).z)) + #define cos_f2(i) to_float2( _cosf((i).x), _cosf((i).y)) + #define sqrt_f3(a) to_float3(_sqrtf((a).x),_sqrtf((a).y),_sqrtf((a).z)) + #define sign_f(a) (a==0.0f?0.0f:a>0.0f?1.0f:-1.0f) + #define distance_f2(pt1,pt2) _sqrtf(dot(pt2 - pt1,pt2 - pt1)) + + #endif + +#endif + + +]] +-- /* + + + +-- // ------------------------------------------------------------------------ +-- DCTL kernel implementation +-- // ------------------------------------------------------------------------ + +-- */ +ShaderKernelCode = +[[ + +// ---------------------------------------------------------------------------------- +// - Image - +// ---------------------------------------------------------------------------------- + + +// CC0: Starry planes +// Revisited the ye olde "plane-marcher". +// A simple result that I think turned out pretty nice + +#define TIME iTime +#define RESOLUTION iResolution + +#define ROT(a) to_mat2(_cosf(a), _sinf(a), -_sinf(a), _cosf(a)) + + + #define pi (_acosf(-1.0f)) + #define tau (2.0f*pi) + + + + +const float4 U = {0, 1, 2, 3}; + +// 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); +} + +__DEVICE__ float3 offset(float z, float2 pathA, float2 pathB) { + return to_float3_aw(pathB*sin_f2(pathA*z), z); +} + +__DEVICE__ float3 doffset(float z, float2 pathA, float2 pathB) { + return to_float3_aw(pathA*pathB*cos_f2(pathA*z), 1.0f); +} + +__DEVICE__ float3 ddoffset(float z, float2 pathA, float2 pathB) { + return to_float3_aw(-1.0f*pathA*pathA*pathB*sin_f2(pathA*z), 0.0f); +} + +__DEVICE__ float4 alphaBlend(float4 back, float4 front) { + // Based on: https://en.wikipedia.org/wiki/Alpha_compositing + float w = front.w + back.w*(1.0f-front.w); + float3 xyz = (swi3(front,x,y,z)*front.w + swi3(back,x,y,z)*back.w*(1.0f-front.w))/w; + return w > 0.0f ? to_float4_aw(xyz, w) : to_float4_s(0.0f); +} + +// License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/smin/smin.htm +__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); +} + +__DEVICE__ float pmax(float a, float b, float k) { + return -pmin(-a, -b, k); +} + +__DEVICE__ float pabs(float a, float k) { + return -pmin(a, -a, k); +} + +// License: MIT, author: Inigo Quilez, found: https://iquilezles.org/articles/distfunctions2d/ +// Slightly tweaked to round the inner corners +__DEVICE__ float star5(float2 p, float r, float rf, float sm) { + p = -p; + const float2 k1 = to_float2(0.809016994375f, -0.587785252292f); + const float2 k2 = to_float2(-k1.x,k1.y); + p.x = _fabs(p.x); + p -= 2.0f*_fmaxf(dot(k1,p),0.0f)*k1; + p -= 2.0f*_fmaxf(dot(k2,p),0.0f)*k2; + p.x = pabs(p.x, sm); + p.y -= r; + float2 ba = rf*to_float2(-k1.y,k1.x) - to_float2(0,1); + float h = clamp( dot(p,ba)/dot(ba,ba), 0.0f, r ); + return length(p-ba*h) * sign_f(p.y*ba.x-p.x*ba.y); +} + +__DEVICE__ float3 palette(float n) { + + return 0.5f+0.5f*sin_f3(to_float3(0.0f,1.0f,2.0f)+n); +} + +__DEVICE__ float4 plane(float3 ro, float3 rd, float3 pp, float3 npp, float pd, float3 cp, float3 off, float n, float2 pathA, float2 pathB) { + + float aa = 3.0f*pd*distance_f2(swi2(pp,x,y), swi2(npp,x,y)); + float4 col = to_float4_s(0.0f); + float2 p2 = swi2(pp,x,y); + p2 -= swi2(offset(pp.z, pathA, pathB),x,y); + float2 doff = swi2(ddoffset(pp.z, pathA, pathB),x,z); + float2 ddoff = swi2(doffset(pp.z, pathA, pathB),x,z); + float dd = dot(doff, ddoff); + p2 = mul_f2_mat2(p2,ROT(dd*pi*5.0f)); + + float d0 = star5(p2, 0.45f, 1.6f,0.2f)-0.02f; + float d1 = d0-0.01f; + float d2 = length(p2); + const float colp = pi*100.0f; + float colaa = aa*200.0f; + + swi3S(col,x,y,z, palette(0.5f*n+2.0f*d2)*_mix(0.5f/(d2*d2), 1.0f, smoothstep(-0.5f+colaa, 0.5f+colaa, _sinf(d2*colp)))/_fmaxf(3.0f*d2*d2, 1E-1f)); + swi3S(col,x,y,z, _mix(swi3(col,x,y,z), to_float3_s(2.0f), smoothstep(aa, -aa, d1))); + col.w = smoothstep(aa, -aa, -d0); + return col; +} + +__DEVICE__ float3 color(float3 ww, float3 uu, float3 vv, float3 ro, float2 p, float2 iResolution, float2 pathA, float2 pathB, float planeDist, float furthest, float fadeFrom) { + float lp = length(p); + float2 np = p + 1.0f/RESOLUTION; + float rdd = 2.0f-0.25f; + + float3 rd = normalize(p.x*uu + p.y*vv + rdd*ww); + float3 nrd = normalize(np.x*uu + np.y*vv + rdd*ww); + + float nz = _floor(ro.z / planeDist); + + float4 acol = to_float4_s(0.0f); + + float3 aro = ro; + float apd = 0.0f; + + for (float i = 1.0f; i <= furthest; ++i) { + if ( acol.w > 0.95f) { + // Debug col to see when exiting + // swi3(acol,x,y,z) = palette(i); + break; + } + float pz = planeDist*nz + planeDist*i; + + float lpd = (pz - aro.z)/rd.z; + float npd = (pz - aro.z)/nrd.z; + float cpd = (pz - aro.z)/ww.z; + + { + float3 pp = aro + rd*lpd; + float3 npp= aro + nrd*npd; + float3 cp = aro+ww*cpd; + + apd += lpd; + + float3 off = offset(pp.z, pathA, pathB); + + float dz = pp.z-ro.z; + float fadeIn = smoothstep(planeDist*furthest, planeDist*fadeFrom, dz); + float fadeOut = smoothstep(0.0f, planeDist*0.1f, dz); + float fadeOutRI = smoothstep(0.0f, planeDist*1.0f, dz); + + float ri = _mix(1.0f, 0.9f, fadeOutRI*fadeIn); + + float4 pcol = plane(ro, rd, pp, npp, apd, cp, off, nz+i, pathA, pathB); + + pcol.w *= fadeOut*fadeIn; + acol = alphaBlend(pcol, acol); + aro = pp; + } + } + + return swi3(acol,x,y,z)*acol.w; + +} + +__KERNEL__ void StarryPlanesFuse(__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); + + + float2 PathA = to_float2(params->PathA[0], params->PathA[1]); + float2 PathB = to_float2(params->PathB[0], params->PathB[1]); + float planeDist = params->planeDist; + float furthest = params->furthest; + float fadeFrom = params->fadeFrom; + + // -------- + + //const float planeDist = 0.5f, + // furthest = 16.0f, + // fadeFrom = 8.0f; + + const float2 + pathA = to_float2(0.31f, 0.41f)+PathA, + pathB = to_float2(1.0f,_sqrtf(0.5f))+PathB; + + float2 r = RESOLUTION, q = fragCoord/r, pp = -1.0f+2.0f*q, p = pp; + p.x *= r.x/r.y; + + float tm = planeDist*TIME; + + float3 ro = offset(tm, pathA, pathB); + float3 dro = doffset(tm, pathA, pathB); + float3 ddro = ddoffset(tm, pathA, pathB); + + float3 ww = normalize(dro);//+swi2(iMouse,x,y)/iResolution-0.5f); + float3 uu = normalize(cross(swi3(U,x,y,x)+ddro, ww)); + float3 vv = cross(ww, uu); + + float3 col = color(ww, uu, vv, ro, p, iResolution, pathA, pathB, planeDist, furthest, fadeFrom); + col = aces_approx(col); + col = sqrt_f3(col); + fragColor = to_float4_aw(col, 1); + + _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, + INPID_PreviewControl = "CrosshairControl", + }) + + InMouseZW = self:AddInput("iMouse.zw", "iMouseZW", { + LINKID_DataType = "Point", + INPID_InputControl = "OffsetControl", + INP_DoNotifyChanged = false, + INPID_PreviewControl = "CrosshairControl", + INP_Disabled = true, + }) + + InMouseDrag = self:AddInput("Mouse Button Pressed", "iMouseClick", { + LINKID_DataType = "Number", + INPID_InputControl = "CheckboxControl", + INP_DoNotifyChanged = false, + INP_MinScale = 0, + INP_MaxScale = 1, + INP_Default = 0, + }) + InPathAPoint = self:AddInput("PathA", "PathA", { + LINKID_DataType = "Point", + INPID_InputControl = "OffsetControl", + INPID_PreviewControl = "CrosshairControl", + INP_DefaultX = 0.0, + INP_DefaultY = 0.0, + }) + + InPathBPoint = self:AddInput("PathB", "PathB", { + LINKID_DataType = "Point", + INPID_InputControl = "OffsetControl", + INPID_PreviewControl = "CrosshairControl", + INP_DefaultX = 0.0, + INP_DefaultY = 0.0, + }) + + InplaneDistSlider = self:AddInput("planeDist", "planeDist", { + LINKID_DataType = "Number", + INPID_InputControl = "SliderControl", + INP_MinScale = -1.0, + INP_MaxScale = 5.0, + INP_Default = 0.5, + }) + + InfurthestSlider = self:AddInput("furthest", "furthest", { + LINKID_DataType = "Number", + INPID_InputControl = "SliderControl", + INP_MinScale = -1.0, + INP_MaxScale = 30.0, + INP_Default = 16.0, + }) + + InfadeFromSlider = self:AddInput("fadeFrom", "fadeFrom", { + LINKID_DataType = "Number", + INPID_InputControl = "SliderControl", + INP_MinScale = -1.0, + INP_MaxScale = 20.0, + INP_Default = 8.0, + }) + + + + Sep3 = self:AddInput(string.rep("_", 252), "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 + + + 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, + "StarryPlanesFuse", 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.PathA = {InPathAPoint:GetValue(req).X,InPathAPoint:GetValue(req).Y} + params.PathB = {InPathBPoint:GetValue(req).X,InPathBPoint:GetValue(req).Y} + params.planeDist = InplaneDistSlider:GetValue(req).Value + params.furthest = InfurthestSlider:GetValue(req).Value + params.fadeFrom = InfadeFromSlider: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: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 + +-- */ diff --git a/Shaders/ShaderOfTheWeek/StarryPlanes.md b/Shaders/ShaderOfTheWeek/StarryPlanes.md new file mode 100644 index 00000000..8d20af93 --- /dev/null +++ b/Shaders/ShaderOfTheWeek/StarryPlanes.md @@ -0,0 +1,10 @@ +# Here insert a description of the shader! And maybe a gif + +# Description of the Shader in Shadertoy: +CC0: Starry planes + Revisited ye olde "plane-marcher". + A simple result that I think turned out pretty nice + + +[![Thumbnail](StarryPlanes_screenshoot.png)](StarryPlanes.fuse) + diff --git a/Shaders/ShaderOfTheWeek/StarryPlanes.png b/Shaders/ShaderOfTheWeek/StarryPlanes.png new file mode 100644 index 00000000..2ac15232 Binary files /dev/null and b/Shaders/ShaderOfTheWeek/StarryPlanes.png differ diff --git a/Shaders/ShaderOfTheWeek/StarryPlanes.sfi b/Shaders/ShaderOfTheWeek/StarryPlanes.sfi new file mode 100644 index 00000000..d7c67354 --- /dev/null +++ b/Shaders/ShaderOfTheWeek/StarryPlanes.sfi @@ -0,0 +1,22 @@ +info = { + + -- https://www.shadertoy.com/view/MfjyWK + + Shadertoy = { + Name = "Starry planes", + Author = "mrange", + ID = "MfjyWK", + }, + + Fuse = { + Author = "JiPi", + Date = "2024-09-13", + }, + + Compatibility = { + macOS_Metal = false, + macOS_OpenCL = false, + Windows_CUDA = true, + Windows_OpenCL = true, + }, +} \ No newline at end of file diff --git a/Shaders/ShaderOfTheWeek/StarryPlanes_screenshot.png b/Shaders/ShaderOfTheWeek/StarryPlanes_screenshot.png new file mode 100644 index 00000000..f63e13aa Binary files /dev/null and b/Shaders/ShaderOfTheWeek/StarryPlanes_screenshot.png differ