Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Color Blending Options

    SDK Help
    0
    4
    388
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 13/11/2014 at 10:31, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   13 
      Platform:   Windows  ;   
      Language(s) :     C++  ;

      ---------
      Hi,
      I'm making a material plugin that has a color channel and a color picker in it.
      I've got it all set up and working. And now I'm trying to set up the color blending options in it like it is in the standard materials.

      I think I have the Multiply & Add math options working correctly in my InitGLImage() and CalcSurface() methods.
      But what is the math used for the "Normal" option that Maxon uses to blend two colors in the standard material?

      The result I'm looking for is:
      -When the slider is at zero. The output color should be only from the color picker.
      -When the slider is between 0-100%. The output color should be a mixture of the color picker & the sampled shader.
      -When the slider is at 100%. The output color should be only from the sampled shader.

      -ScottA

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 14/11/2014 at 00:41, xxxxxxxx wrote:

        You want this function, from the SDK:

          
        LVector Mix(const LVector& v1, const LVector& v2, LReal t)   
        Mixes the two vectors together, such as mixing two colours.   
        Return   
            LVector   
                The resulting mixed vector.   
        Parameters   
            const LVector& v1   
                Vector to mix.   
            const LVector& v2   
                Vector to mix.   
            LReal t   
                Mix amount, with 0 <= t <= 1.0.   
        

        Steve

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 14/11/2014 at 01:10, xxxxxxxx wrote:

          Hello,

          for new projects please use the current API[URL-REMOVED] with Vector64[URL-REMOVED] and the Blend function[URL-REMOVED]. You find a use case in the gradient shader example.

          Best wishes,
          Sebastian


          [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 14/11/2014 at 08:04, xxxxxxxx wrote:

            Thanks guys.
            I think I'm probably doing it wrong.

            In order to use the Mix() function I need to feed it the sampled shader's color value in one of the params.
            But the place where I'm getting the Add & Multiply results from is before I'm using my shader sampling For() loops.
            I'm getting the Add & Multiply options by controlling the color picker's overall amount. Using the value of a slider to get that. And they seem to be looking correct. But maybe this is wrong?

                //Get the mix mode option from the ComboButton  
              //Then blend the color picker with the shader's sampled colors accordingly  
              LONG mixItem = data->GetLong(COLOR_MIX_MODE);  
              switch (mixItem)  
                {  
                case MATERIAL_COLOR_NORMAL:  
                    {   
                      //?? <--- Can't use Mix() here because I need the sampled color value. And I haven't done that yet!!  
                    }break;  
              
                case MATERIAL_COLOR_ADD:  
                    {   
                        mixedCol = colpicker + data->GetReal(COLOR_MIX_SLIDER);  
                    }break;  
              
                case MATERIAL_COLOR_MULTIPLY:  
                    {  
                        mixedCol = colpicker * data->GetReal(COLOR_MIX_SLIDER);  
                    }break;  
              }  
              
              //Loop through the object's UV's and sample the colors  
              const LONG w = bmp->GetBw();  
              const LONG h = bmp->GetBh();  
              if( w == 0 || h == 0) return false;  
              for(LONG y = 0; y < h; y++)  
              {  
                  for(LONG x = 0; x < w; x++)  
                  {  
                      //...The rest of the code that loops through the UV's and samples the colors  
              
                      //Set the final color value by mixing the color picker with the shader's color values  
                      bmp->SetPixel(x, y, finalR*mixedCol.x, finalG*mixedCol.y, finalB*mixedCol.z);  
                  }  
              }
            

            I don't want to put my switch code block inside of the for loops. That would be crazy.
            So I need to figure out how this is done.

            -ScottA

            1 Reply Last reply Reply Quote 0
            • First post
              Last post