- /
-
Energy
on 2 Dec 2023
- 24
- 333
- 0
- 3
- 873
drawframe(1);
Write your drawframe function below
function drawframe(f)
% This is Xor's AMAZING shader
% https://www.shadertoy.com/view/cltfRf
% Here is my translation to MATLAB
iRes = [800 450];
iTime = f/16;
persistent fragCoord
if isempty(fragCoord)
[x,y]=meshgrid(1:iRes(1),iRes(2):-1:1);
fragCoord = cat(3,x',y');
end
im4 = mainImage(fragCoord);
imr = imresize(im4, flip(iRes).*2, 'method', 'bilinear');
im = imshow(imr);
function finalColor=mainImage( fragCoord )
finalColor = zeros(iRes(1), iRes(2), 3);
r = cat(3,iRes(1),iRes(2));
for i = 0:0.01:1
% Center and scale outward
p = (fragCoord.* 2 - r)./iRes(2).*i;
% Compute z
z = max(1 - vecnorm(p,2,3).^2, 0);
% Sphere distortion
p = p./(0.2 + sqrt(z).*0.3);
% Offset for hex pattern
p(:,:,1) = p(:,:,1)./0.9 + iTime;
p(:,:,2) = p(:,:,2) + mod(ceil(p(:,:,1))*0.5, 1) + iTime * 0.1625;
% Mirror quadrants
v = abs((mod(p, 1))-0.5);
% Add color
c = [2, 3, 5]./2e3;
d1 =max(v(:,:,1).*1.5+ v(:,:,1), v(:,:,1).*2);
d2 =max(v(:,:,1).*1.5+ v(:,:,2), v(:,:,2).*2);
d3 =cat(3,d1,d2);
for j = 1:3
finalColor(:,:,j) = finalColor(:,:,j) + c(j).*z./(abs(d3(:,:,2) - 1) + 0.1 - i * 0.09);
end
end
finalColor = tanh(finalColor.^2);
finalColor = permute(finalColor,[2 1 3]);
end
end