Пример #1
0
    void DiMaterial::RecompileShader( DiShaderType type, const DiPair<DiString,DiString>& marco )
    {
        DiShaderProgram* shader = nullptr;

        if (type == SHADER_VERTEX)
            shader = mVertexShader;
        else if (type == SHADER_PIXEL)
            shader = mPixelShader;

        if (shader)
        {
            DiShaderInstance* si = shader->GetShader();
            si->mCompileDesc.AddMarco(marco.first,marco.second);
            si->Compile(shader->GetCode());
            mShaderParameter->LoadParameters();
        }
    }
Пример #2
0
    void DiFoliageLayer::UpdateMaterial()
    {
        if (!mNeedUpdateMaterial)
            return;

        mNeedUpdateMaterial = false;

        DI_ASSERT(mMaterial);

        DiCompileDesc desc;
        desc.entryName = "vs_main";
        desc.profile = DiShaderProgram::GetDefaultVsProfile();

        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_FADE_ALPHA"        ,"0"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_FADE_GROW"        ,"1"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_FADE_ALPHA_GROW","2"));

        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_RENDER_QUAD"    ,"0"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_RENDER_SPRITE"    ,"1"));

        DiString fadeMarco;
//         if (m_pkDesc->m_eFadeTechnique == FADETECH_ALPHA)
//         {
             fadeMarco = "0";
//         }
//         else if (m_pkDesc->m_eFadeTechnique == FADETECH_GROW)
//         {
//            fadeMarco = "1";
//         }
//         else if (m_pkDesc->m_eFadeTechnique == FADETECH_ALPHAGROW)
//         {
//             fadeMarco = "2";
//         }

        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_LIGHTING"    ,mDesc->mLighting?    "1":"0"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_ANIMATE"    ,mDesc->mAnimate?    "1":"0"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_BLEND"        ,/*m_pkDesc->m_bBlend?    "1":"0"*/"1"));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_FADE_TECH"    ,fadeMarco));
        desc.marcos.push_back(DiPair<DiString,DiString>("_GRASS_RENDER_TECH",mDesc->mRenderTechnique == GRASSTECH_SPRITE ? "1" : "0"));

        DiShaderParameter* msp = mMaterial->GetShaderParameter();

        DiShaderProgram* vp = mMaterial->GetVertexShader();

        if (vp)
        {
            DiShaderInstance* si = vp->GetShader();
            if (si)
            {
                si->mCompileDesc = desc;
                si->Compile(vp->GetCode());
                msp->LoadVariables(vp,SHADER_VERTEX);
            }
        }

        // д²ÎÊý
//        if (m_pkDesc->m_bBlend)
        {
            msp->WriteFloat("fadeRange", 100);
        }

        //if (m_pkDesc->m_eFadeTechnique == FADETECH_GROW ||
        //    m_pkDesc->m_eFadeTechnique == FADETECH_ALPHAGROW)
        {
            //msp->WriteFloat("grassHeight", m_pkDesc->m_fMaxHeight * 1.05f);
        }

        msp->WriteTexture2D("diffuseTexture",mDesc->DemiureName);
    }