Пример #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
    DiShaderProgram* DiShaderManager::LoadShader(const DiString& filename, uint64 flag)
    {
        DiShaderProgram* shader = NULL;

        ShaderLibsIt it = mShaderLibs.find(filename);
        if(it != mShaderLibs.end())
        {
            DiMap<uint64,DiShaderProgram*>::iterator flagIt =
                it->second.find(flag);

            if(flagIt != it->second.end())
                return flagIt->second;
        }

        shader = DI_NEW DiShaderProgram(filename);
        BOOL ret = shader->Load();

        if(!ret)
        {
            DI_WARNING("Failed to load the shader : %s", filename.c_str());
            DI_DELETE shader;
            return NULL;
        }

        DiShaderType type = shader->GetShaderType();
        
        DiCompileDesc desc;
        desc.entryName = type == SHADER_VERTEX?"vs_main":"ps_main";
        desc.profile = DiShaderProgram::GetDefaultProfile(type);

        ModifyMarcosByFlag(flag,desc);

        shader->Compile(desc);

        mShaderLibs[filename].insert(DiMap<uint64,DiShaderProgram*>::iterator::value_type(flag,shader));

        return shader;
    }
Пример #3
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);
    }