Davinci Resolve Page Curl Transition

This can be used to generate a page curl transition in Davinci Resolve. This is based off the shadertoy code from Eduardo Casineyra here

To create this effect you first need to ensure you have the latest version of my fragment shader 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.

__DEVICE__ float2 curlFun(float t, float maxt, float3 cyl) {
	float2 ret = to_float2(t, 1.0f);   
	if (t < cyl.z - 0.1f)
		return ret;
	if (t > cyl.z + 0.1f)
		return to_float2_s(-1.0f);
	float a = _asinf((t - cyl.z) / 0.1f);
	float ca = -a + M_PI;
	ret.x = cyl.z + ca * 0.1f;
	ret.y = _cosf(ca);
	if (ret.x < maxt)
		return ret;
	if (t < cyl.z)
		return to_float2(t, 1.0f);
	ret.y = _cosf(a);
	ret.x = cyl.z + a * 0.1f;
	return ret.x < maxt ? ret : to_float2_s(-1.0f);
}

__KERNEL__ void ShaderToyKernel(__CONSTANTREF__ ShaderToyParams *params, __TEXTURE2D__ iChannel0, __TEXTURE2D__ iChannel1, __TEXTURE2D__ iChannel2, __TEXTURE2D__ iChannel3, __TEXTURE2D_WRITE__ dst) {
	DEFINE_KERNEL_ITERATORS_XY(x, y);
	float3 cyl = to_float3_s(0.0f);
	float ox = x;
	float oy = y;
	if (x > params->width - 2) { ox = params->width - 1; } // Fix iterator bug for last column

	float2 uv = to_float2(ox,oy) / to_float2(iResolution.x,iResolution.x);
	float2 ur = to_float2(1.0, iResolution.y/iResolution.x);

	float2 mouse = to_float2_s(_fmaxf(0.0001f,_fabs(1-p_Float1)));
	float d = length(mouse * (1.0f + 4.0f *0.1f)) - 2.0f *0.1f;
	cyl = to_float3_aw(normalize(mouse),d);

	d = dot(uv, to_float2(cyl.x,cyl.y));
	float2 end;
	float2 urluv = ur - uv;
	end.x = _fabs(urluv.x/cyl.x);
	end.y = _fabs(urluv.y/cyl.y);
	float maxt = d + _fminf(end.x, end.y);
	float2 cf = curlFun(d, maxt,cyl);
	float2 tuv = uv + to_float2(cyl.x,cyl.y) * (cf.x - d);

	float shadow = 1.0 - smoothstep (0.0f, (float)(0.1f * 2.0), (float)-(d - cyl.z));
	float shadow2 = smoothstep (0.0f, (float)(0.1f * 2.0), (float)(d - cyl.z));
	shadow *= (smoothstep((float)-0.1f,(float) 0.1f, (float)(maxt - (cf.x + 1.5 * M_PI * 0.1f +  0.1f))));
	float2 pos = tuv;
	pos.x = pos.x * iResolution.x;
	pos.y = pos.y * iResolution.x;
	float4 curr = _tex2DVecN(iChannel0, pos.x,pos.y, 0);
	curr = cf.y > 0.0 ? curr * cf.y  * (1.0f - shadow): (curr * 0.25f + 0.75f) * (-cf.y);

	pos = uv;
	pos.x = pos.x * iResolution.x;
	pos.y = pos.y * iResolution.x;
	float4 next = _tex2DVecN(iChannel1, pos.x,pos.y, 0.0f)*shadow ;
	next = next * shadow;

	float4 fragColor = cf.x > 0.0 ? curr : next;

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

Leave a Reply