void AddMeshes() { DiSceneManager* sm = DiBase::Driver->GetSceneManager(); DiCullNode* cullnode = sm->GetRootNode()->CreateChild(); DiModelPtr model = make_shared<DiModel>("sponza_model","sponza.model"); cullnode->AttachObject(model); cullnode->SetScale(6,6,6); //sm->GetCamera()->SetFarClipDistance(200); }
void SetupWater(DiSceneManager* sm) { // Render targets auto reflectMap = DiAssetManager::GetInstance().CreateOrReplaceAsset<DiTexture>("reflect_rt"); reflectMap->SetDimensions(512, 512); reflectMap->SetFormat(PF_A8R8G8B8); reflectMap->SetUsage(TU_RENDER_TARGET); reflectMap->SetAutoMipmap(false); reflectMap->SetAddressing(AM_CLAMP); reflectMap->CreateTexture(); auto reflectRT = reflectMap->GetRenderTarget(); auto refractMap = DiAssetManager::GetInstance().CreateOrReplaceAsset<DiTexture>("refract_rt"); refractMap->SetDimensions(512, 512); refractMap->SetFormat(PF_A8R8G8B8); refractMap->SetUsage(TU_RENDER_TARGET); refractMap->SetAutoMipmap(false); refractMap->SetAddressing(AM_CLAMP); refractMap->CreateTexture(); auto refractRT = refractMap->GetRenderTarget(); // Water plane DiCullNode* nodePlane = sm->GetRootNode()->CreateChild(); DiSimpleShapePtr model = make_shared<DiSimpleShape>(); model->CreatePlane(100); auto waterMat = DiMaterial::QuickCreate("pool_fresnel_v", "pool_fresnel_p"); auto shaderParam = waterMat->GetShaderParameter(); shaderParam->WriteFloat("scale", 1.0f); shaderParam->WriteFloat("scroll", 0.05f); shaderParam->WriteFloat("fresnelBias", -0.1f); shaderParam->WriteFloat("fresnelScale", 1.8f); shaderParam->WriteFloat("fresnelPower", 8.0f); shaderParam->WriteFloat("noiseScale", 0.05f); shaderParam->WriteFloat4("tintColour", DiVec4(0, 0.05f, 0.05f, 1)); shaderParam->WriteTexture2D("noiseMap", "waves2.dds"); shaderParam->WriteTexture2D("reflectMap", "reflect_rt"); shaderParam->WriteTexture2D("refractMap", "refract_rt"); model->SetMaterial(waterMat); nodePlane->AttachObject(model); nodePlane->SetScale(7, 1, 13); // Add to scene manager with the callbacks DiCamera* cam = sm->GetCamera(); cam->MoveRelative(DiVec3(0, 0, 700)); sm->AddExtraRenderTarget(refractRT, cam, [nodePlane](DiRenderTarget*) { nodePlane->SetVisible(false); }, [nodePlane](DiRenderTarget*) { nodePlane->SetVisible(true); } ); sm->AddExtraRenderTarget(reflectRT, cam, [nodePlane, cam](DiRenderTarget*) { nodePlane->SetVisible(false); cam->EnableReflection(DiPlane(DiVec3::UNIT_Y, 0)); }, [nodePlane, cam](DiRenderTarget*) { nodePlane->SetVisible(true); cam->DisableReflection(); } ); DiPostEffectManager* peMgr = DiBase::Driver->GetMainRenderWindow()->GetPostEffectManager(); DiPostEffect* bloom = peMgr->GetEffect("Bloom"); if (bloom) bloom->SetEnable(false); }