Scratch fisheye effect

Acts just like the fisheye effect from Scratch

NOTICE: This shader uses edited code from another source (Under BSD-3-Clause license)
Source: https://github.com/scratchfoundation/scratch-render/blob/develop/src/shaders/sprite.frag

Copyright (c) 2016, Massachusetts Institute of Technology

All rights reserved.

 

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

 

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

 

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

 

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 

 

Shader code
shader_type canvas_item;

uniform float amount = 0.0;

void fragment() {
	float newAmount = (amount / 100.0) + 1.0;
	
	vec2 texcoord0 = UV;
	vec2 kCenter = vec2(0.5);
	
	vec2 vec = (texcoord0 - kCenter) / kCenter;
	float vecLength = length(vec);
	float r = pow(min(vecLength, 1.0), newAmount) * max(1.0, vecLength);
	vec2 unit = vec / vecLength;

	texcoord0 = kCenter + r * unit * kCenter;
	
	COLOR = texture(TEXTURE, texcoord0);
}
Tags
Scratch
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from The2AndOnly

Scratch mosaic effect

Fnaf / Clickteam perspective (displacement) – Godot 4.2

Scratch whirl effect

Related shaders

Fisheye & Anti fisheye Camera Effect

Scratch brightness effect

Scratch pixelate effect

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments