Sampling some object's material color channel



  • 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
    }
    


  • 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



  • @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?



  • 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



  • @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;



  • @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.



  • @r_gigante Nice one, thanks!


Log in to reply