// Created by Jerome Stephan (@jstephan828) 22/08/2021 for Redshift3D
// Modified by Saul Espinosa 09/23/2021 to add OCIO Color Management & Page Meta Data
// Using colors based on https://github.com/redshift3d/RedshiftOSLShaders/blob/main/NoiseColor.osl
#include <vector2.h>
#define vec2 vector2
#define vec3 vector
#include <vector4.h>
#define vec4 vector4
float fract(float x){return mod(x, 1.0);}
vec3 fract(point x){return vec3(mod(x.x, 1.0),mod(x.y, 1.0),mod(x.z, 1.0)) ;}
point matrix_mul(point matx, point maty, point matz, point px){
point result;
result.x = matx[0]*px.x+matx[1]*px.y+matx[2]*px.z;
result.y = maty[0]*px.x+maty[1]*px.y+maty[2]*px.z;
result.z = matz[0]*px.x+matz[1]*px.y+matz[2]*px.z;
return result;
}
float def_turbulence(point x){
point px = x;
point mx = point( 1.6, 1.2, -1.2);
point my = point( -1.6, 1.5, 1.2);
point mz = point( 1.6, -1.2, 1.8);
float f = 0.0;
f = 0.5000*noise( px ); px = matrix_mul(mx, my, mz, px);
f += 0.2500*noise( px ); px = matrix_mul(mx, my, mz, px);
f += 0.1250*noise( px ); px = matrix_mul(mx, my, mz, px);
f += 0.0625*noise( px ); px = matrix_mul(mx, my, mz, px);
f += 0.0313*noise( px ); px = matrix_mul(mx, my, mz, px);
//f = 0.5 + 0.5*f;
return f;
}
shader JawbreakerNoise
[[ string help = "Jawbreaker-like color layer Noise",
string label = "Jawbreaker Noise" ]]
(
point Po = P
[[ string label = "Position", string page = "Position" ]],
point Pcent = vec3(0)
[[string label = "Center", string page = "Position"]],
float Scale = 1.0
[[ string label = "Overall Scale", float min = 0.0, float max = 20.0, string page = "Noise Color"]],
float Time = 1.0
[[ string label = "Color Time", float min = 0.0, float max = 1000.0, string page = "Noise Color"]],
float ColIntens = 0.5
[[ string label = "Color Brightness", float min = 0.0, float max = 10.0, string page = "Noise Color"]],
float ColComplex = 1.0
[[ string label = "Color Complexity", float min = 0.0, float max = 5.0, string page = "Noise Color"]],
float NoiseTime = 0.0
[[ string label = "Noise Time", float min = 0.0, float max = 10.0, string page = "Noise Shape"]],
float NoiseAmount = 8.0
[[ string label = "Noise Amount", float min = 0.0, float max = 80.0, string page = "Noise Shape"]],
float Layers = 15.0
[[ string label = "Layers", float min = 1.0, float max = 150.0, string page = "Noise Shape"]],
string toSpace = ""
[[ string label = "Output Color Space", string widget = "colorspace", string page = "OCIO Colorspace"]],
output color outColor = 0
)
{
float Pi = 10.;
int complexity = 10; // More points of color.
float fluid_speed = 600.0; // Drives speed, higher number will make it slower.
float color_intensity = ColIntens;
point puv = Po*Scale;
point p = Po*Scale;
p.x += (def_turbulence(p*0.1+NoiseTime)-0.5)*NoiseAmount;
p.y += (def_turbulence(p*0.1+NoiseTime+0.5)-0.5)*NoiseAmount;
p.z += (def_turbulence(p*0.1+NoiseTime+1.5)-0.5)*NoiseAmount;
float layers_adj = Layers/10.0;
float steps = floor(layers_adj*distance(Pcent, p));
steps = mix(steps, layers_adj*distance(Pcent, p), 0.2);
p = vec3(steps);
p+=noise(puv*0.005);
for(int i=1;i<complexity;i++){
point newp=p + Time*0.001;
newp[0]+=ColComplex*(0.6/float(i)*sin(float(i)*p[1]+Time/fluid_speed+2.3*float(i)) + 0.5);
newp[1]+=ColComplex*(0.6/float(i)*sin(float(i)*p[0]+Time/fluid_speed+0.3*float(i)) - 0.5);
p=newp;
}
color Out= color(color_intensity*sin(5.0*p[0])+color_intensity,color_intensity*sin(3.0*p[1])+color_intensity,color_intensity*sin((p[0]+p[1]))+color_intensity);
{
outColor = linearstep (0, 2, (transformc( toSpace, Out)));
}
}