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

    Sampling some object's material color channel

    Cinema 4D SDK
    c++ r19 r20
    3
    7
    1.0k
    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.
    • rsodreR
      rsodre
      last edited by

      Hey!

      I'm trying to sample some object's current material color channel, I want to achieve something like the Hair shader Surface option.
      It's enough for me to get the COLOR channel from the material, but the result I'm having is not really the computed color (mixed color + texture), but ONLY the shader color.
      The Hair Shader Surface mode even mixes different texture tags. Is there anything available to do that or it has to read and mix every channel?

      Here's some of my code:

      const auto channel = material->GetChannel( CHANNEL_COLOR );
      CHECK_RETURN( channel != nullptr )
      
      InitRenderStruct irs( doc );
      
      CHECK_RETURN( channel->InitTexture( irs ) == INITRENDERRESULT_OK )
      
      auto normal = Vector( 0, 1, 0 );
      auto delta = Vector( 1, 1, 1 );
      
      for( int strandIndex = 0 ; strandIndex < strandCount ; ++strandIndex )
      {
      	auto uv = textureCoordinates[strandIndex];
      	auto color = channel->Sample( nullptr, &uv, &delta, &normal, doc->GetTime().Get(), TEX_TILE, 0, 0 );
      	// use color
      }
      
      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by

        Hello,

        I'm not aware of a way so sample really a single channel. But you can sample the whole material using the BaseMaterial class.

        You find example code on how to use BaseMaterial in the BaseMaterial Manual.

        best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        rsodreR 1 Reply Last reply Reply Quote 1
        • rsodreR
          rsodre @s_bach
          last edited by

          @s_bach Ok, but this is all based on VolumeData, only available at VideoPost, I need to sample outside a VP.

          So you mean each of the material BaseChannel is not really the computed channel color, but only the Texture?

          1 Reply Last reply Reply Quote 0
          • r_giganteR
            r_gigante
            last edited by

            Hi Roger, thanks for reaching out us.

            With regard to your request, the blending between color and shader in the hair material is actually delivered via a very basic approach which simply consists in two steps:

            1. calculate the color at the given strand length (it's a gradient)
            2. blend the color obtained at 1 with the (eventual) color obtained by sampling the BaseShader found in the Texture slot using BaseShader::Sample().

            Hope this can help.
            Riccardo

            rsodreR 1 Reply Last reply Reply Quote 0
            • rsodreR
              rsodre @r_gigante
              last edited by

              @r_gigante But only sampling the texture shader does not mix it with the color slot.

              I achieved what I wanted by sampling MATERIAL_COLOR_SHADER and mixing it with MATERIAL_COLOR_SHADER using MATERIAL_COLOR_TEXTUREMIXING and MATERIAL_COLOR_TEXTURESTRENGTH;

              1 Reply Last reply Reply Quote 0
              • r_giganteR
                r_gigante
                last edited by r_gigante

                @rsodre exactly! You have to properly use the strength and the mixing mode to get the right blended value between the constant color and the uv-dependent one. Some details on mixing modes are here

                last but not least with regard to normal, add, subtract and multiply you can consider this static function

                static Vector MixColors(const Vector &constCol, const Vector &shaderCol, Int32 mixingMode, Float mixingStrength)
                {
                	switch (mixingMode)
                	{
                	case 0: // normal mode
                		return (constCol + (shaderCol - constCol) * mixingStrength);
                	case 1: // add mode
                		return (constCol + shaderCol * mixingStrength);
                	case 2: // subtract mode
                	{	
                		Vector temp = (shaderCol - constCol * mixingStrength);
                		temp.ClampMin();
                		return temp;
                	}
                	case 3: // multiply mode
                		return (constCol * (shaderCol * mixingStrength));
                	default: // return the non-blended constant color - for debug purposes
                		return constCol;
                	}
                }
                
                

                Cheers, R.

                rsodreR 1 Reply Last reply Reply Quote 1
                • rsodreR
                  rsodre @r_gigante
                  last edited by

                  @r_gigante Nice one, thanks!

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