Blender Cycles OSL: Mandelbrot Fractal (Interior Colors)

Hi. Today I'm going to show you an OSL code to get a Mandelbrot Fractal with its interior colorized, like this:




You can see a HiRes version in this link.

This is the code:

#include <stdosl.h>

shader node_fractal(
    float CenterX = 0.0,
    float CenterY = 0.0,
    point Vector = P,
    float Zoom = 1.0,
    int MaxIterations = 50,
    color Foreground = color(1.0),
    color Background = color(0.0),
    output float Fac = 0.0,
    output color Color = 0.0)
{
    point p = Vector / (2* Zoom);
    float auxiliar = 0.0;
		
	p[0] += CenterX;	
	p[1] += CenterY;	
	
    point pa = p;
    point pb = point(0.0);
    int i = 0;
    for(i=1; i<MaxIterations; i++)
    {
        pb[0] = pa[0]*pa[0] - pa[1]*pa[1];
        pb[1] = pa[0]*pa[1] + pa[1]*pa[0];
        pa = pb + p;
    }
	
    auxiliar = sqrt((pa[0]*pa[0]) + (pa[1]*pa[1]));

    Fac = clamp(auxiliar,0.0,1.0);

    if (Fac == 0.0)
        Color = Background;
    else
        Color = mix(Foreground, Background, Fac);       
}

And this is the node setup to get the image before:





Finally, the osl code is prepared to get a colorized image without using a color ramp node. If you connect the "Color" output socket with the diffuse node, you get this:






Bye

Comentarios

Javi ha dicho que…
Got this error:
"/home/javi/Documentos/blend files/mandelbrot.osl:1:9: error: #include espera "NOMBRE_ARCHIVO" ó
Error: OSL script compilation failed, see console for errors"
Javi ha dicho que…
Solved. After that problem I got another one of sintax.
The code that worked for me:

#include "stdosl.h"

shader node_mandelbrot_interior(
float CenterX = 0.0,
float CenterY = 0.0,
point Vector = P,
float Zoom = 1.0,
int Iterations = 50,
color Foreground = color(1.0),
color Background = color(0.0),
output float Fac = 0.0,
output color Color = 0.0)
{
// Scale position
point p = Vector / (2* Zoom);
float s = 0.0;
float auxiliar = 0.0;
float factor = 0.0;

// Move center of the image
p[0] += CenterX;
p[1] += CenterY;

point pa = p;
point pb = point(0.0);
int i = 0;
for(i=1; i < 100; i++)
{
pb[0] = pa[0]*pa[0] - pa[1]*pa[1];
pb[1] = pa[0]*pa[1] + pa[1]*pa[0];
pa = pb + p;
}

auxiliar = sqrt((pa[0]*pa[0]) + (pa[1]*pa[1]));

// Colorize
Fac = clamp(auxiliar,0.0,1.0);

// Return variables
if (Fac == 0.0)
Color = Background;
else
Color = mix(Foreground, Background, Fac);
}
Eduardo Maldonado Malo ha dicho que…
Thank you for your comment Javi, probably a copy / paste error while formatting the article.
Achtransferconsultant ha dicho que…
I have authenticate western union transfer bug software which is capable of running multiple western union transfer
All job are done smoothly
Message
Whatsapp : +1 724 672 3074
Achtransferconsultant ha dicho que…
Hello Customers..

Achtransferconsultant service with years of experience is now trading Bitcoin for sale of Hacked PayPal, Bank wire logins, Wu transfer, cc top-up, fullz, atm skimmer, cvv, smtp, rdp, inbox mailer, email leads, dumps, warez..

I am selling Hacked WU Bug and MTCN, Verizon, AT&T account, Transferwise, Hacked PayPal accounts, Bank wire logins, Money Booker, Skrill account, cc top-up, fullz, dumps+pin leads, rdp, smtp, email leads..

Contact: achtransferconsultant

Whatsapp : +1 724 672 3074

Email : consultantachtransfer@gmail.com

Phone number : +1 724 672 3074

All transactions are carried out offshore and has no trace backs or charge-backs here are the Rates List with Explanation :-

Western Union Transfer :-Transferring Western Union all over the world and it takes 10 - 30 minutes maximum to receive MTCN and senders info then you can pick up funds from Western union Store. (transferring all over the world)
Necessary Info needed for WU transfers :-
1: Full name
2: Cell number (Not Necessary)
3: City
4:Country

Western Union Transfer Rates :
$1500 Transfer = $200
$3000 Transfer = $300
$4500 Transfer = $400
$7000 Transfer = $500
$10000 Transfer = $700

Bank Transfers :- My responsibility is to transfer the required amount into your account after your payment from my spammed logins, we have method for making clear payment so no dispute no charge-back chances. (transferring all over the world)
Info needed for Bank transfers :-
1: Bank name
2: Bank address
3: Zip code
4: Account Holder Name
5: Account number
6: Account Type
7: Routing number
Bank transfer will take maximum 6 hours for reflection of money in bank account.

Transfer Rates :
$3000 Transfer = $250 Charges
$5000 Transfer = $400 Charges
$9000 Transfer = $700 Charges
$12000 Transfer = $1000 Charges
$15000 Transfer = $1200 Charges

PayPal Transfer :- Using hacked and verified PayPal accounts to transfer PayPal account to account transfer. This is the most safest way to earn money. (transferring all over the world except banned/blacklisted countries)

PayPal Transfer Rates :
$3000 Transfer = $250 Charges
$5000 Transfer = $400 Charges
$9000 Transfer = $700 Charges
$15,000 Transfer = $1200 Charges


Credit-card Top Up Rates:-
$3000 Transfer = $300 Charges
$5000 Transfer = $400 Charges
$10,000 Transfer = $700 Charges

***Also selling RDP, SMTP SERVERS, WEB-MAILS, MAILERS, BULK MAILS (US/UK based) DATING ACCOUNTS, cPanel HOSTING, Hacked Panels, CC dumps, Fullz, Bin leads...

***TERMS AND CONDITIONS
A person can receive transfer as much as you desire in a week as long as you can handle your end. If anyone want to do regular business with me then you must have more than one bank account, PayPal, Money Booker and fake ids for western union. You are advised to have a safe account to transfer funds to and also withdraw for cash or make purchases online.

PAYMENT METHODS INCLUDE: [ BITCOIN, ETHEREUM, PERFECT MONEY, ITUNES GIFT CARD, WESTERN UNION TRF, MONEY GRAM ]

Contact : achtransferconsultant

Whatsapp : +1 724 672 3074

Gmail : consultantachtransfer@gmail.com

Phone number: +1 724 672 3074

Fixit ha dicho que…
Hello all
am looking few years that some guys comes into the market
they called themselves hacker, carder or spammer they rip the
peoples with different ways and it’s a badly impact to real hacker
now situation is that peoples doesn’t believe that real hackers and carder scammer exists.
Anyone want to make deal with me any type am available but first
I‘ll show the proof that am real then make a deal like

Available Services

..Wire Bank Transfer all over the world

..Western Union Transfer all over the world

..Credit Cards (USA, UK, AUS, CAN, NZ)

..School Grade upgrade / remove Records

..Spamming Tool

..keyloggers / rats

..Social Media recovery

.. Teaching Hacking / spamming / carding (1/2 hours course)

discount for re-seller

Contact: 24/7

fixitrogers@gmail.com

Entradas populares de este blog

Santa Alejandra

Stucco Material III

Blender Cycles: Vector Transform for Texturing (New Feature in Blender 2.69)