machinainfinitum Posted October 22, 2020 Share Posted October 22, 2020 I’m looking for someone who can convert some OSL code to VEX code. I have a fractal formula written in OSL that needs to be volume density output VEX. For now the simple mandelbulb fractal conversion is enough but I'm looking for someone that could convert many other complex formulas.(200-300 lines of code). New to Houdini, and can't find a way to get this working...after days of looking around, this forum is my last option. OSL CODE TO CONVERT: shader OslGeometry( int Iterations = 10, float Power = 2.0, float Bailout = 20, output _sdf c = _SDFDEF) { vector pos = P; vector z = P; float dr = 1.0; float r = 0.0; for (int i = 0; i < Iterations ; i++) { r = length(z); if (r>Bailout) break; // convert to polar coordinates float theta = acos(z[2]/r); float phi = atan2(z[1],z[0]); dr = pow( r, Power-1.0)*Power*dr + 1.0; // scale and rotate the point float zr = pow( r,Power); theta = theta*Power; phi = phi*Power; // convert back to cartesian coordinates z = zr*vector(sin(theta)*cos(phi), sin(phi)*sin(theta), cos(theta)); z+=pos; } c.dist = 0.5*log(r)*r/dr; } OSL CODE THAT WORKS BUT NEED IT TO BE LIKE THE OSL: function int Mandel(float x0, y0, z0; int Iterations){ float x, y, z, xnew, ynew, znew, n=ch('n'), r, theta, phi; int i; x = x0; y = y0; z = z0; for(i=0; i < Iterations; i++){ r = sqrt(x*x + y*y + z*z); theta = atan2(sqrt(x*x + y*y) , z); phi = atan2(y,x); xnew = pow(r, n) * sin(theta*n) * cos(phi*n) + x0; ynew = pow(r, n) * sin(theta*n) * sin(phi*n) + y0; znew = pow(r, n) * cos(theta*n) + z0; if(xnew*xnew + ynew*ynew + znew*znew > 8){ return(i); } x = xnew; y = ynew; z = znew; } return(Iterations); } //--- Main --- int maxiter = 8; if(Mandel(@P.x, @P.y, @P.z, maxiter) < maxiter){ @density = 0.0; } else { @density = 1.0; } AAND MY CONVERSION THAT DOES NOT WORK function int Fractal(int Iterations, float Power, float Bailout, vector pos, vector z, float dr, float r){ for (int i = 0; i < Iterations ; i++) { r = length(z); if (r>Bailout) break; // convert to polar coordinates float theta = acos(z.z/r); float phi = atan2(z.y,z.x); dr = pow( r, Power-1.0)*Power*dr + 1.0; // scale and rotate the point float zr = pow( r,Power); theta = theta*Power; phi = phi*Power; // convert back to cartesian coordinates z = zr*vector(sin(theta)*cos(phi), sin(phi)*sin(theta), cos(theta)); z+=pos; } return 0.5*log(r)*r/dr; } int Iterations = 10; float Power = 2.0; float Bailout = 20; vector pos = @P; vector z = @P; float dr = 1.0; float r = 0.0; if(Fractal(Iterations,Power,Bailout,@P,@P,dr,r) < Iterations){ @density = 0.0; } else { @density = 1.0; } Thanks in advance. Cheers, Scappin Matteo www.machina-infinitum.com Quote Link to comment Share on other sites More sharing options...
Librarian Posted October 22, 2020 Share Posted October 22, 2020 (edited) Nice Stuff -- https://www.machina-infinitum.com/vectron-formulas?fbclid=IwAR1Aihbcn5T2ngX5yAHUNDyJsO7peZYsOGW64g8exTq8YA5X5Rsq0A3sco0 why in vex? @machinainfinitum This can HELP maybe https://github.com/thi-ng/vexed-generation https://github.com/jtomori/vft https://www.sidefx.com/tutorials/vex-in-houdini-mandelbrot-and-mandelbulb/ https://vimeo.com/215581282 Edited October 22, 2020 by Librarian Quote Link to comment Share on other sites More sharing options...
machinainfinitum Posted October 22, 2020 Author Share Posted October 22, 2020 Thanks I need to convert all my existing OSL fractals code to VEX. Than I can mesh the VEX fractal and use it as dummy obj on top of Octane Vectron fractals Quote Link to comment Share on other sites More sharing options...
varomix Posted March 22, 2021 Share Posted March 22, 2021 On 10/22/2020 at 10:28 AM, machinainfinitum said: Thanks I need to convert all my existing OSL fractals code to VEX. Than I can mesh the VEX fractal and use it as dummy obj on top of Octane Vectron fractals Hi not sure if you still care about this but I fixed your code float fractal(int iterations; float power; float bailout; vector pos){ float r = 0.0; float dr = 0.0; vector z = pos; for (int i = 0; i < iterations ; i++) { r = length(z); if (r>bailout) break; // convert to polar coordinates float theta = acos(z.z/r); float phi = atan2(z.y,z.x); dr = pow( r, power-1.0)*power*dr + 1.0; // scale and rotate the point float zr = pow( r,power); theta = theta*power; phi = phi*power; // convert back to cartesian coordinates z = zr*set(sin(theta)*cos(phi), sin(phi)*sin(theta), cos(theta)); z+=pos; } return 0.5*log(r)*r/dr; } int iterations = 5; float power = 5.0; float bailout = 20.0; vector pos = @P; float map = 0.0; map = fractal(iterations, power, bailout, pos); @surface = map; Quote Link to comment Share on other sites More sharing options...
machinainfinitum Posted March 22, 2021 Author Share Posted March 22, 2021 14 minutes ago, varomix said: Hi not sure if you still care about this but I fixed your code float fractal(int iterations; float power; float bailout; vector pos){ float r = 0.0; float dr = 0.0; vector z = pos; for (int i = 0; i < iterations ; i++) { r = length(z); if (r>bailout) break; // convert to polar coordinates float theta = acos(z.z/r); float phi = atan2(z.y,z.x); dr = pow( r, power-1.0)*power*dr + 1.0; // scale and rotate the point float zr = pow( r,power); theta = theta*power; phi = phi*power; // convert back to cartesian coordinates z = zr*set(sin(theta)*cos(phi), sin(phi)*sin(theta), cos(theta)); z+=pos; } return 0.5*log(r)*r/dr; } int iterations = 5; float power = 5.0; float bailout = 20.0; vector pos = @P; float map = 0.0; map = fractal(iterations, power, bailout, pos); @surface = map; This works perfectly ! Thanks so much! Now I'll try to convert all the formulas I have Quote Link to comment Share on other sites More sharing options...
varomix Posted March 22, 2021 Share Posted March 22, 2021 let me know if you need any help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.