Rainy Window Effect In Davinci Resolve Fusion (All GPUs)

This creates a cool Rainy Window effect with fog in Davinci Resolve/Fusion.

To create this effect you first need to ensure you have the latest version of my experimental Shader Toy Tool.

Download the file: here

In Windows it’s easiest to right click, save as and download and save the file to:

C:\ProgramData\Blackmagic Design\DaVinci Resolve\Fusion\Fuses

On a Mac you should find the Fuses folder under:

Library\Application Support\Blackmagic Design\DaVinci Resolve\Fusion\Fuses

After downloading the file and saving it in the folder, you will need to restart Davinci Resolve if you already have it open. Otherwise it won’t show.

Now you have that, you need the following code. Copy and paste it into the box in the third tab in the tool. Afterwards on the second tab set p_Float1 to 4 and p_Float2 to -5.

// Rainy Window Shader for Resolve Fusion
// Based on this awesome tutorial for Unity https://www.youtube.com/watch?v=EBrAdahFtuo

__DEVICE__ float3 Layer(float2 uv, __GLOBAL__ ShaderToyParams *params) {
	float size = p_Float1;
	float2 aspect = { 3,1 };
	uv = uv *size * aspect;
	float t = _fmod(iTime,7200);
	uv.y += t * .25;

	float2 gv;
	gv.x = _fract(uv.x) -0.5;
	gv.y = _fract(uv.y) - 0.5;

	float2 id = _floor(uv);
	
	float n = _srand(id.x*id.y);
	t += n*6.2831;
	float w = uv.y * 10;
	float dx = (n-.5) * .8;
	dx += (0.4 - _fabs(dx)) *  _sinf(3*w) * _sinf(w)  * _sinf(w) * _sinf(w) * _sinf(w) * _sinf(w) * _sinf(w) *.25;
	float dy = _sinf(t+_sinf(t+_sinf(t)*.5))*-0.45;
	dy -= (gv.x-dx)/3 * (gv.x-dx)/3;

	float2 dp = { dx, dy };
	float2 dropPos = (gv-dp)/aspect;
	float drop=_smoothstep(.05, .03, _length_v(dropPos));

	dp.y = t * .25;
	float2 trailPos = (gv-dp)/aspect;
	trailPos.y =(_fract(trailPos.y * 8)-.5)/8;
	float trail=_smoothstep(.02, .01, _length_v(trailPos));
	float fogTrail = _smoothstep(-.05,.05,dropPos.y);
	fogTrail *= _smoothstep(.5, dy,gv.y);
	trail *= fogTrail;
	fogTrail *= _smoothstep(0.05,0.04, _fabs(dropPos.x));

	float2 offs = drop * dropPos + trail * trailPos;

	float3 data;
	data.x = offs.x;
	data.y = offs.y;
	data.z = fogTrail;

	return data;
}

__KERNEL__ void ShaderToyKernel(__GLOBAL__ ShaderToyParams *params, __TEXTURE2D__ iChannel0, __TEXTURE2D__ iChannel1, __TEXTURE2D__ iChannel2, __TEXTURE2D__ iChannel3, __TEXTURE2D_WRITE__ dst) {
	DEFINE_KERNEL_ITERATORS_XY(x, y);
	float ox = x;
	float oy = y;
	if (x > params->width - 2) { ox = params->width - 1; } // Fix iterator bug for last column
	float2 uv = { ox / iResolution.x, oy / iResolution.y };

	float3 drops = Layer(uv, params);
	float2 uvoffs = uv;
	uvoffs.x *= (float)1.23;
	uvoffs.y *= (float)1.23;	
	drops += Layer(uvoffs+(float)7.54,params);
	uvoffs = uv;
	uvoffs.x *= (float)1.353;
	uvoffs.y *= (float)1.35;	
	drops += Layer(uvoffs+(float)1.54,params);
	uvoffs = uv;
	uvoffs.x *= (float)1.57;
	uvoffs.y *= (float)1.57;	
	drops += Layer(uvoffs-(float)7.54,params);

	float4 clear = _tex2DVecN(iChannel0, (uv.x + (drops.x * p_Float2))  * iResolution.x, (uv.y+(drops.y * p_Float2))  * iResolution.y, 0);
	float4 blurred = _tex2DVecN(iChannel1, (uv.x + (drops.x * p_Float2)) * iResolution.x, (uv.y + (drops.y * p_Float2))  * iResolution.y, 0);

	float4 fragColor = _mix(blurred,clear,drops.z);

	_tex2DVec4Write(dst, ox, oy, fragColor);
}

Leave a Reply