Method for introducing new vec3 color options

  • 1 Replies

0 Members and 1 Guest are viewing this topic.

Offline mclarekin

  • *
  • Moderator
  • ******
  • Posts: 660
« on: March 22, 2019, 12:55:23 AM »
Method for adding new vec3 color (sabine62 baseColor hack)

//tell FragM to use custom colours
#define providesColor 

 //add required uniforms to the Coloring-tab
#group Coloring

Code: [Select]
#group Coloring                                         
//multiplier for the division
uniform vec3 LVI; slider[(-1,-1,-1),(0,0,0),(1,1,1)]       
//added to LLI to give more possibilities
uniform vec3 LVI2; slider[(-1,-1,-1),(0,0,0),(1,1,1)]     
//determines for how many iterations the difference between the vectors should be calculated
uniform int LightIter; slider[0,1,100]                     
//choose between lightold/lightnew or lightnew/lightold
uniform bool RevertDiv; checkbox[false]                     
//in some cases/formulas I found it beneficial to add this
uniform bool AddOrbitStrength; checkbox[false]
//previous vector         
vec3 lightold;
 //current vector                                             
vec3 lightnew;

// add in code to extract values required to generate color
Code: [Select]
vec3 pos = z;
lightold=z;                                 //initialize lightold, necessary in some formulas
float DF = 1.0;

for (int i = 0; i < Box_Iterations ; i++)
if (i<LightIter) {lightold=z;} else {lightold=lightold;};        //get old vector, stop at LightIter-value = clamp(, -fold, fold)*2. -;
float r =dot2(z);
if (r< 0.001 || r> 1000.) break;
DF/= r;
z+=(Julia ? JuliaC : pos);
if (i<LightIter) {lightnew=z;} else {lightnew=lightnew;};            //get new vector, stop at LightIter-value
// Use vec3 baseColor to introduce the new color   

Code: [Select]
vec3 baseColor(vec3 p, vec3 q){
  if (RevertDiv) {q=abs(lightnew/lightold);} else {q=abs(lightold/lightnew);};
if (AddOrbitStrength) q+=OrbitStrength;
   return q;


Offline mclarekin

  • *
  • Moderator
  • ******
  • Posts: 660
« Reply #1 on: March 26, 2019, 12:53:06 AM »
How does it All WORK? I am going to find out by looking at the code

#ifdef  providesColor


      #ifdef  providesColor
      hitColor = mix(BaseColor,  baseColor(hit,hitNormal),  OrbitStrength);
      hitColor = getColor();

This means that the orbitTrap code is disconnected, instead the points color will come from mixing the BaseColor (chosen with the BaseColor color-picker) with a vec3(R,G,B) generated in the fractal.frag
The two components are mixed with the slider scale called OrbitStrength (but in the hack it is just the mixing scale)
The lefthand side of the mix "BaseColor", is a vec3 containing numbers between 0.0 and 1.0
 BaseColor is the pure color of object (in white light)
 (1,1,1) is white, bright

 (0,0,0) is black, dark
 (1,0,0) is fully saturated bright red
The righthand side of the mix "baseColor(vec3,vec3); is the function that is used for coding in other types of color functions, without having to edit a DE-raymarching.frag.
Thinking about the size of the values that will be generated can be important!!   We really want the RGBs  to be between 0 and 1.


 A standard Menger Sponge is contained within a cubic space from -1 to +1. If we use data from a color function using original point values then the data numbers will be inside that range. If we abs() the data it will then  be between 0 and +1

 Summary. We are mixing whatever color setting we pick for BaseColor with the return from a function called baseColor (confusing naming:))

Mandelbulb frag with some options

Started by mclarekin on Fragmentarium

1 Replies
Last post October 07, 2018, 07:56:54 AM
by Sabine62
Groupbox options appear in Preferences > OpenCL settings

Started by Tas_mania on Mandelbulber

2 Replies
Last post May 21, 2019, 01:41:54 AM
by Tas_mania
ffmpeg: best mandelbrot video creation options for youtube

Started by CFJH on Fractal Programs Discussion, Help, & Support

2 Replies
Last post April 03, 2018, 11:13:27 PM
Introducing prefixes for advanced sorting

Started by Fraktalist on Fractal Image Gallery

14 Replies
Last post October 03, 2017, 01:16:23 PM
by Fraktalist
Introducing the Mandelbrot Butterfly Safari

Started by JonathanD on Meet & Greet

0 Replies
Last post February 01, 2020, 02:47:24 AM
by JonathanD