Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

If you have any questions, reports, suggestions, or requests about Live2D, please send them to this forum.
※We cannot guarantee statements or answers from Live2D staff. Thank you for your understanding in advance.
 
Live2D Cubism
Cubism Products and Downloads
Cubism product manuals and tutorials
Cubism Editor Manual    Cubism Editor Tutorial    Cubism SDK Manual    Cubism SDK Tutorial
[About macOS Sequoia] (Updated October 22, 2024)
Live2D Cubism Editor 5.1.02 now supports macOS Sequoia.
Other Live2D Cubism products currently released are not guaranteed to work on macOS Sequoia.
Please refrain from upgrading macOS, as it may not operate properly.

Sometimes the live2d model shows darkness

edited February 2016 in Help

Comments

  • Hi, Yongjxu .

    Only this image information can't identify the cause .
    Please tell me the detailed information .
    ( Your OS, development environment , SDK Version or Program code etc...)

    I know the same thing will happen in the change of texture color in Unity .

    >> Transparency and texture color change of Live2D

  • IOS, use cocos2d-x3.5 with live2d 2.0.06_3.
    As the image shows, the live2dSprite.cpp and live2dSprite.h is my code.

    1.png 34.3K
  • Live2dSprite* Live2dSprite::createLive2dNode(const std::string& modelDir, const std::string& modelFileName, const cocos2d::Size &size)
    {
    Live2dSprite *sprite = new (std::nothrow) Live2dSprite(modelDir,modelFileName, size);
    if (sprite)
    {
    sprite->autorelease();
    return sprite;
    }
    CC_SAFE_DELETE(sprite);
    return nullptr;

    }

    Live2dSprite::Live2dSprite(const std::string& modelDir,
    const std::string& modelFileName,
    const Size &size):
    DrawNode(), touchMgr(nullptr),deviceToScreen(nullptr),
    viewMatrix(nullptr), l2d_model(nullptr),_eventListener(nullptr),
    l2d_size(size),_shadow(1.0),_isRenderShadow(false)
    {
    l2d_model = new LAppModel();
    l2d_model->load(modelDir.c_str(), modelFileName.c_str());
    model_width = l2d_model->getCanvasWidth();
    model_height = l2d_model->getCanvasHeight();

    touchMgr=new TouchManager();

    deviceToScreen = new L2DMatrix44();

    viewMatrix = new L2DViewMatrix();

    //Size size=Director::getInstance()->getWinSize();

    float width= l2d_size.width;
    float height= l2d_size.height;
    float ratio=(float)height/width;
    float left = VIEW_LOGICAL_LEFT;
    float right = VIEW_LOGICAL_RIGHT;
    float bottom = -ratio;
    float top = ratio;
    _scale = _scaleX = 1.0f;

    viewMatrix->setScreenRect(left,right,bottom,top);

    float screenW=abs(left-right);
    deviceToScreen->multTranslate(-width/2.0f,-height/2.0f );
    deviceToScreen->multScale( screenW/width , -screenW/width );

    viewMatrix->setMaxScale( VIEW_MAX_SCALE );
    viewMatrix->setMinScale( VIEW_MIN_SCALE );


    viewMatrix->setMaxScreenRect(
    VIEW_LOGICAL_MAX_LEFT,
    VIEW_LOGICAL_MAX_RIGHT,
    VIEW_LOGICAL_MAX_BOTTOM,
    VIEW_LOGICAL_MAX_TOP
    );

    }

    void Live2dSprite::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags)
    {
    DrawNode::draw(renderer, transform, flags);

    _customCommand.init(_globalZOrder);
    _customCommand.func = CC_CALLBACK_0(Live2dSprite::onDraw, this, transform, flags);
    renderer->addCommand(&_customCommand);
    }


    void Live2dSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
    {
    this->updatePosition(ccpAdd( getParent()->getPosition(), getPosition()));
    kmGLPushMatrix();
    kmGLLoadMatrix(&transform);

    if(_isRenderShadow)
    {
    int size = l2d_model->getModelSetting()->getTextureNum();
    auto model = ((Live2DModelOpenGL*)l2d_model->getLive2DModel());
    for(int i = 0;isetTextureColor(i, 0.0, 0.0, 0.0, 0);
    }
    }

    // colors
    glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
    modelUpdate();

    if(_isRenderShadow)
    {
    int size = l2d_model->getModelSetting()->getTextureNum();
    auto model = ((Live2DModelOpenGL*)l2d_model->getLive2DModel());
    for(int i = 0;isetTextureColor(i, _shadow, _shadow, _shadow, 0);
    }
    }

    kmGLPopMatrix();
    glFrontFace(GL_CCW);
    }


    void Live2dSprite::modelUpdate()
    {
    live2d::DrawProfileCocos2D::preDraw();

    L2DMatrix44 projection;

    Director* director=Director::getInstance();
    Size window=director->getWinSize();

    projection.scale(1, window.width/window.height);
    //float scale = model_width/window.width;
    //projection.scale(scale, window.width/window.height * scale);
    if (viewMatrix != NULL) {
    projection.append(viewMatrix);
    }


    if(l2d_model != NULL)
    {
    l2d_model->update();
    l2d_model->draw(projection);
    }

    live2d::DrawProfileCocos2D::postDraw();
    }
  • Are you using the setBaseColor to the texture color change ?

    Live2D API Reference - DrawParam->setBaseColor()

    What is isetTextureColor?
    I think that perhaps _shadow becomes 0.0 .
    isetTextureColor(i, _shadow, _shadow, _shadow, 0)
    I think it is draw correctly if you use the following .
    DrawParam->setBaseColor(1.0, 1.0, 1.0, 1.0)
  • I have removed the code setTextureColor. And it still happens.
    void Live2dSprite::setShadowOnModel(float shadow)
    {
    if(shadow>1.0 || shadow<0.0)
    {
    shadow = 1.0;
    }
    _shadow = shadow;
    /*
    if(l2d_model)
    {
    int size = l2d_model->getModelSetting()->getTextureNum();
    auto model = ((Live2DModelOpenGL*)l2d_model->getLive2DModel());
    for(int i = 0;isetTextureColor(i, _shadow, _shadow, _shadow, 0);
    }
    }
    */
    }

    void Live2dSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
    {
    this->updatePosition(ccpAdd( getParent()->getPosition(), getPosition()));
    kmGLPushMatrix();
    kmGLLoadMatrix(&transform);
    /*
    if(_isRenderShadow)
    {
    int size = l2d_model->getModelSetting()->getTextureNum();
    auto model = ((Live2DModelOpenGL*)l2d_model->getLive2DModel());
    for(int i = 0;isetTextureColor(i, 0.0, 0.0, 0.0, 0);
    }
    }
    */
    // colors
    glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
    modelUpdate();
    /*
    if(_isRenderShadow)
    {
    int size = l2d_model->getModelSetting()->getTextureNum();
    auto model = ((Live2DModelOpenGL*)l2d_model->getLive2DModel());
    for(int i = 0;isetTextureColor(i, _shadow, _shadow, _shadow, 0);
    }
    }
    */
    kmGLPopMatrix();
    glFrontFace(GL_CCW);
    }
  • So I said, use the following API !
    DrawParam->setBaseColor(1.0, 1.0, 1.0, 1.0)
  • I have using the API you said, the bugs still shows after I load and release the live2d model for dozens of times.
    As you can see, left image the bug shows and right image shows when I set the texture color to black.

    Code:

    void Live2dSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
    {
    this->updatePosition(ccpAdd( getParent()->getPosition(), getPosition()));
    kmGLPushMatrix();
    kmGLLoadMatrix(&transform);

    l2d_model->getLive2DModel()->getDrawParam()->setBaseColor(1.0, 1.0, 1.0, 1.0);

    // colors
    glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
    modelUpdate();
    kmGLPopMatrix();
    glFrontFace(GL_CCW);
    }
  • edited December 2015
    I See . Please ignore the contents of which I have commented in the past .
    In code that you have posted the first time in this discussion , What happens if you have modified as follows ?
    isetTextureColor(i, _shadow, _shadow, _shadow, 0);
                ↓
    isetTextureColor(i, 1.0, 1.0, 1.0, 0);
    In the case of Simple project of cocos2d-X Live2D SDK, I was able to change the texture color in setBaseColor().

    [SampleLive2DSprite.cpp]

    void SampleLive2DSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
    {
    	kmGLPushMatrix();
        kmGLLoadMatrix(&transform);
    	 
    	double t = (UtSystem::getUserTimeMSec()/1000.0) * 2 * M_PI;
    	double cycle=3.0;
    	double value=sin( t/cycle );
    	live2DModel->setParamFloat( "PARAM_ANGLE_X" , (float) (30 * value) ) ;
    	live2d::DrawProfileCocos2D::preDraw();    
        // << add Code >> Texture Color = Black
        // live2DModel->getDrawParam()->setBaseColor(1.0, 0.0, 0.0, 0.0);
        // << add Code >> Texture Color = Default
       live2DModel->getDrawParam()->setBaseColor(1.0, 1.0, 1.0, 1.0);
        
    	live2DModel->update() ;
    	live2DModel->draw() ;
    	
    	live2d::DrawProfileCocos2D::postDraw() ;
    	kmGLPopMatrix();
    }
    



    In your program , I think that it probably has been changed texture color in isetTextureColor .
    In a program that has been posted on here , I don't know detailed processing of isetTextureColor.
    Probably you don't have the same process as setBaseColor?

    Or it might be a problem of the model .
    How do you Test in Live2D of sample models ?

    Live2D Manual - Live2D Sample Model


    And I'm sorry if the cause is completely different .
    I know it is only this . thanks !
  • Thanks for your support. I have found the root cause for the problem.

    I have made the flowing change in file LAppTextureDesc.cpp.

    LAppTextureDesc::LAppTextureDesc(cocos2d::Texture2D* tex,std::string fileName)
    {
    data=tex;
    tex->retain();
    textureFileName=fileName;
    }

    LAppTextureDesc::~LAppTextureDesc()
    {
    data->release();
    if(data->getReferenceCount() == 1)
    Director::getInstance()->getTextureCache()->removeTextureForKey(textureFileName);

    }
Sign In or Register to comment.