Ok. Done. Fixed it a bit. Needs a bit of clean up... and maybe a few more colors. I'm going to look at other palette editing code for a more generalized palette generation scheme.
Add this code to your raytracer, replacing the existing getcolor() function, and adding the "palette" tab. Maybe remove the old coloring scheme, since it... well. I don't know. Keep it if you want. I only put a couple colors in for now. You can see how to add and balance them from the following. It took me a while to figure out the extremely simple math to blend the colors.. for whatever reason I had problems with it.
I'm thinking about adding in a sharp color option, so the color change is discrete, instead of smooth. Ok.. did it...
UPDATED Frags have "sharp" option added, and so does the code below.
ummm updated again... wanted to specify Sharp0to1, so people understand the range.... and changed the default preset in Mandelbulb.frag, and pine tree's lolcolors preset.
#group Palette
uniform bool paletteColoring; checkbox[true]
uniform vec3 pBaseColor;color[0,0,0]
uniform float BaseStrength;slider[0,.3,1]
//speed of palette cycling
uniform float cSpeed; slider[0,10.,50.00]
//palette offset... rotates pallete so you can put colors where you want 'em
uniform float pOffset; slider[0,0,100]
uniform vec3 color0;color[0.95,0.83,0.42]
uniform bool Sharp0to1;checkbox[false]
uniform float Dist0to1;slider[0,1,3]
uniform vec3 color1;color[1.,0.,0.07]
uniform bool Sharp1to2;checkbox[false]
uniform float Dist1to2;slider[0,1,3]
uniform vec3 color2;color[.7,.7,0.42]
uniform bool Sharp2to3;checkbox[false]
uniform float Dist2to3;slider[0,1,3]
uniform vec3 color3;color[1.,0.37,0.]
uniform bool Sharp3to0;checkbox[false]
uniform float Dist3to0;slider[0,1,3]
//uniform bool Orbit; checkbox[False]
uniform vec4 orbitStrengthXYZR;slider[(-3,-3,-3,-3),(1,1,1,1),(3,3,3,3)]
float PaletteCycleDistance=
(Dist0to1+Dist1to2+Dist2to3+Dist3to0);
float dist01=Dist0to1/PaletteCycleDistance;
float dist12=Dist1to2/PaletteCycleDistance;
float dist23=Dist2to3/PaletteCycleDistance;
float dist30=Dist3to0/PaletteCycleDistance;
float cyclespeedadjusted=cSpeed*.1;
float poffset=pOffset/100.;
vec3 palette(vec4 p) {
float orbittotal=orbitStrengthXYZR.x*orbitTrap.x+
orbitStrengthXYZR.y*orbitTrap.y+
orbitStrengthXYZR.z*orbitTrap.z+
orbitStrengthXYZR.w*orbitTrap.w;
orbittotal=mod(abs(orbittotal)*cyclespeedadjusted,1.);
orbittotal=mod(orbittotal+poffset,1.);
vec3 colormix;
if (orbittotal<=dist01) {
if (Sharp0to1) {
colormix=mix(color0,pBaseColor,BaseStrength);
} else {
colormix=mix(color0,color1,abs(orbittotal)/(dist01));
colormix=mix(colormix,pBaseColor,BaseStrength);
}
} else if (orbittotal<=dist01+dist12) {
if (Sharp1to2) {
colormix=mix(color1,pBaseColor,BaseStrength);
} else {
colormix=mix(color1,color2,abs(orbittotal-dist01)/abs(dist12));
colormix=mix(colormix,pBaseColor,BaseStrength);
}
} else if (orbittotal<=dist01+dist12+dist23) {
if (Sharp2to3) {
colormix=mix(color2,pBaseColor,BaseStrength);
} else {
colormix=mix(color2,color3,abs(orbittotal-dist01-dist12)/abs(dist23));
colormix=mix(colormix,pBaseColor,BaseStrength);
}
} else {
if (Sharp3to0) {
colormix=mix(color3,pBaseColor,BaseStrength);
} else {
colormix=mix(color3,color0,abs(orbittotal-dist01-dist12-dist23)/abs(dist30));
colormix=mix(colormix,pBaseColor,BaseStrength);
}
}
return colormix;
}
vec3 getColor() {
vec3 orbitColor;
vec3 color;
if (paletteColoring) {
color = palette(orbitTrap);
} else {
if (CycleColors) {
orbitColor = cycle(X.xyz,orbitTrap.x)*X.w*orbitTrap.x +
cycle(Y.xyz,orbitTrap.y)*Y.w*orbitTrap.y +
cycle(Z.xyz,orbitTrap.z)*Z.w*orbitTrap.z +
cycle(R.xyz,orbitTrap.w)*R.w*orbitTrap.w;
} else {
orbitColor = X.xyz*X.w*orbitTrap.x +
Y.xyz*Y.w*orbitTrap.y +
Z.xyz*Z.w*orbitTrap.z +
R.xyz*R.w*orbitTrap.w;
}
color = mix(BaseColor, 3.0*orbitColor, OrbitStrength);
}
return color;
}
lol... colors: