void DiK2World::ProcessCliff(DiK2RenderObject* renderObj) { DiK2ModelPtr model = renderObj->GetModel(); model->SetBatchGroup(BATCH_TERRAIN); DiCullNode* node = renderObj->GetNode(); DiVec3 pos = node->GetPosition(); DiQuat rot = node->GetOrientation(); DiTerrainDescPtr terDesc = mTerrain->GetDesc(); float cliffsize = terDesc->mCliffSize * terDesc->mGridSize / 2.0f; DiVec3 transl(-cliffsize, 0, cliffsize); pos += rot * transl; DiTerrainDescPtr desc = mTerrain->GetDesc(); int gridx = pos.x / CHUNK_GRID_SIZE; int gridy = pos.z / CHUNK_GRID_SIZE; int gridSizeX = (CHUNK_GRID_SIZE * desc->mSizeX); int gridSizeY = (CHUNK_GRID_SIZE * desc->mSizeY); int realGrid = gridx + gridy * gridSizeX; realGrid = DiMath::Clamp(realGrid, 0, gridSizeX*gridSizeY - 1); uint16 diftexid = desc->mTextureIDMap->GetBuffer(0)[realGrid].diffuseID; uint16 normtexid = desc->mTextureIDMap->GetBuffer(0)[realGrid].normalID; DiString diffuse = desc->mTextureTable[diftexid]; DiString normal = desc->mTextureTable[normtexid]; DiTexturePtr textureDif = DiAssetManager::GetInstance().ManualLoadAsset<DiTexture>(diffuse); #if DEMI_PLATFORM == DEMI_PLATFORM_IOS DiTexturePtr textureNor = DiAssetManager::GetInstance().ManualLoadAsset<DiTexture>(normal); #else DiTexturePtr textureNor = DiAssetManager::GetInstance().ManualLoadAsset<DiTexture>(normal + "_rxgb"); DiTexturePtr textureSpe = DiAssetManager::GetInstance().ManualLoadAsset<DiTexture>(normal + "_s"); #endif uint32 submodels = model->GetNumSubModels(); for (uint32 i = 0; i < submodels; ++i) { DiSubModel* sm = model->GetSubModel(i); auto material = sm->GetMaterial(); auto newMat = material->Clone(); sm->SetMaterial(newMat); DiShaderParameter* shaderparam = newMat->GetShaderParameter(); shaderparam->WriteTexture2D("terrainMap", textureDif); shaderparam->WriteTexture2D("terrainNormalMap", textureNor); #if DEMI_PLATFORM != DEMI_PLATFORM_IOS shaderparam->WriteTexture2D("terrainSpecularMap", textureSpe); #endif shaderparam->WriteFloat("cliffUVScale", 1.0f / (terDesc->mTextureScale * terDesc->mGridSize)); } }
void DiWaterMap::CreateMaterial() { UpdateWaterTexture(); mWaterMaterial = DiAssetManager::GetInstance().GetAsset<DiMaterial>("water_well.mtl"); DiShaderParameter* pm = mWaterMaterial->GetShaderParameter(); pm->WriteTexture2D("maskTexture","_global_wt_tex"); // if (mTerrainMap) // { // DiString waterMaterial = "todo"; // DiMaterialSerializer mss; // mss.ParseMaterial(waterMaterial, mWaterMaterial.get()); // } }
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); }