Entradas

Mostrando las entradas etiquetadas como osl

Blender Cycles OSL: Mandelbrot Fractal

Imagen
Hi. Today I'm going to show you an OSL code to get a Mandelbrot Fractal , like this: This fractal uses the following complex numbers formula: Z(n+1) = Z(n) ^ 2  + C I have parameterized the exponent of the formula and the bailout value, that is, the value to stop the iterations. So the code is this : shader mandelbrot_fractal_zn_zoom( float Scale = 1.0, float Zoom = 3.5, vector Vector = (vector)P, float CenterX = 0.0, float CenterY = 0.0, int MaxIterations = 64, int Exponent = 2, float Bailout = 2.0, output float Fac = 0.0) { point p = (point)Vector*Scale/(2*Zoom); int i = 0; int j = 0; int prevIteration = MaxIterations; float factor = 0.0; float foo = 0.0; // Starting point p[0] += CenterX; p[1] += CenterY; // Initialize point pa = point(0.0); point pb = point(0.0); point pc = point(0.0); // Mandelbrot algorithm do { // z^j for(j = 1; j B...

Blender Cycles OSL: Copper Material

Imagen
Hi everybody. Today I'm going to show you a migration to OSL of my Copper Material : This is the Cycles version: As I did with my OSL Gold Material , I have migrated all the nodes information included in that material to the code, trying to minimize the overhead of the node system. This time the facing value is an input parameter in the script. So the OSL code is as follows: /* * Migrated from "http://elbrujodelatribu.blogspot.com/2013/07/cooper-material.html" * By: elbrujodelatribu */ shader node_metal_copper( color ForeColor = 0.8, color MiddleColor = 0.4, float Facing = 0.665, float ForeRoughness = 0.01, color BackColor = 0.1, float BackRoughness = 0.04, normal Normal = N, output closure color Metal = 0.0) { closure color ForeClosure = background(); closure color BackClosure = background(); // Facing colors - formula and code from Blender OSL code float aux = fabs(dot(I,(vector)Normal)); float...

Blender Cycles OSL: Gold Material

Imagen
Hi everybody. Today I'm going to show you a migration to OSL of my Gold Material : In that article I used a mix of colors I called Colombia Gold . Here I have called this mix as Egypt Gold . This is the same node setup in cycles without OSL: In most of the posts you can find in Blender Artist , the OSL code is used to get a pattern or a texture. This time I have migrated all the nodes information included in that material to the code, trying to minimize the overhead of the node system. So the OSL code is as follows: /* * Migrated from "http://elbrujodelatribu.blogspot.com.es/2013/01/gold-material.html" * By: elbrujodelatribu */ shader node_metal_gold( color ForeColor = 0.8, color MiddleColor = 0.4, color BackColor = 0.1, vector Normal = N, float ForeRoughness = 0.01, float BackRoughness = 0.04, output closure color Metal = 0.0) { closure color ForeClosure = background(); closure color BackClosure = background(); /...

Blender Cycles OSL: Color Turbulence

Imagen
Hi every body. Today I'm going to show you a color turbulence material: This is the OSL code: /* * Migrated from "http://glsl.heroku.com/e#8664.0" * By: elbrujodelatribu */ shader node_color_turbulence( vector Vector = P, float Scale = 0.2, float Time = 1.0, int MaxIterations = 64, output color Color = 0.8) { vector p = Vector * Scale;//surfacePosition; for(int i=1; i < MaxIterations; i++) { vector newp = p; newp[0]+=0.6/float(i)*sin(float(i)*p[1]+Time/20.0+0.3*float(i))+20.0; newp[1]+=0.6/float(i)*sin(float(i)*p[0]+Time/20.0+0.3*float(i+10))-5.0; p=newp; } Color = color(sin(Time+p[1]+p[0]-M_PI*color(0,2,4)/(4.0+sin(Time)))*0.3+0.5); } And here there is the node setup. I have used a HSV Color node to increase the color saturation and provide a result more vivid: And this another example scene ( hires version here ). I hope you like it. Bye

Blender Cycles OSL: Sierpinski Squares

Imagen
Hi everybody. Today I'm going to show you a Sierpinski Squares material using OSL and blender. The code for the sierpinski squares pattern is as follows: /* *   Migrated from "http://glsl.heroku.com/e#1891.0" *   By: elbrujodelatribu */ float genCheck(vector p, float res) {     return (mod(res * p[0], 1.0) < 0.5 ^ mod(res * p[1], 1.0) < 0.5) ?         0.0 : 1.0; } shader node_sierpinski_squares(     float Scale = 1.0,     float Zoom = 1.0,     vector Vector = P,     float MaxIterations = 10.0,     output float Fac = 1.0,     output color ColorOut = 0.8)    {     vector p = Vector*Scale/(2.0*Zoom);     float diExp = 1.0;     float result = genCheck(p,1.0);     for(float i = 0.7; i <= MaxIterations; i++)     {   ...

Blender Cycles OSL: Color Squares

Imagen
Hi everybody. Today I'm going to show you a color squares pattern material, similar to present papers. The materials looks like this: Here the code is: /* * Migrated from "http://glsl.heroku.com/e#5335.0" * Author: elbrujodelatribu */ // Returns fractional part float fract(float x) { return (x - floor(x)); } // Returns fractional part, by coordenates point fract(point x) { return point(fract(x[0]),fract(x[1]),fract(x[2])); } // Colorize squares point tri(point p, float r) { point pos = p; pos *= r; point x = fract(pos); point i = pos - x; point c = point(sin(i[0]*2.0), sin(i[1]*2.0), 0.0)*0.2+0.2; return (((x[0] < x[1]) == (x[0] < 1.0 - x[1])) ? 1.0 : 0.0) * c; } shader color_squares( float Scale = 1.0, vector Vector = P, output color ColorOut = 0.8) { vector pos = Vector*Scale; float r = 20.0; point x = fract(pos*r); point i = pos*r - x; float w = 50.0; float l = clamp(0.0, 1.0, (0.5 - ab...

Blender Cycles OSL: Voronoi Tiles Material

Imagen
Hi everybody. This code is ported to OSL from a GLSL version . The material looks like this: The OSL code is as follows: #include <stdosl.h> #define TILE_MAX_HEIGHT 0.12 #define TILE_MIN_HEIGHT 0.05 // GLSL function float fract(float x) { return (x - floor(x)); } // GLSL function vector fract(vector v) { return vector(v[0] - floor(v[0]),v[1] - floor(v[1]),v[2] - floor(v[2])); } float rand(vector co){ return fract(sin(dot(co ,vector(12.9898,78.233,0.0))) * 43758.5453); } vector random2f( vector seed ) { float rnd1 = mod(rand(seed), 1.0); float rnd2 = mod(rnd1*2.0,1.0); return vector(rnd1, rnd2, 0.0); } float hash(float n) { return fract(pow(sin(n), 1.1)*1e6); } float noise(vector x) { vector p = vector(x[0],x[1],x[1]); vector d = vector(1.0,30.0,30.0*30.0); vector f = fract(p), p0 = floor(p)*d, p1 = p0 + d; f[0] = f[0] * f[0] * (3.0 - 2.0 * f[0]); f[1] = f[1] * f[1] * (3.0 - 2.0 * f[1]); float t = mix(mix(m...

Blender Cycles OSL: Mandelbrot Fractal (Interior Colors)

Imagen
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, ...