void ArGame::Init() { mEntityMgr = DI_NEW ArEntityManager(); DiPostEffectManager* peMgr = DiBase::Driver->GetMainRenderWindow()->GetPostEffectManager(); DiPostEffect* bloom = peMgr->GetEffect("Bloom"); if (bloom) bloom->SetEnable(true); #if 0 SetCamera(ArGameCamera::STYLE_FREE); mCamera->GetCamera()->SetPosition(3358,800,4067); mCamera->GetCamera()->SetOrientation(DiQuat(0.923f,-0.38f,0,0)); #else SetCamera(ArGameCamera::STYLE_CHARACTER); #endif mLevel = DI_NEW ArLevel(); }
void SetupPostEffects() { DiBase::Driver->GetPipeline()->SetEnableGBuffer(true); DiPostEffectManager* peMgr = DiApp::GetApp()->GetRenderWindow()->GetPostEffectManager(); DiPostEffect* ssaoCrytek = peMgr->CreatePostEffect("SSAO_Crytek"); ssaoCrytek->SetEnable(true); DiSceneManager* sm = DiBase::Driver->GetSceneManager(); passSSAO = ssaoCrytek->CreatePass("output"); passSSAO->SetQuadScale(1); passSSAO->BuildMaterial("screen_quad.vsh","ssao_crytek_orig.psh"); passSSAO->SetInputGBuffer("sSceneDepthSampler",0); passSSAO->SetInputTex2D("sRotSampler4x4","PointsOnSphere4x4.dds"); passSSAO->SetInput("SSAO_params", ssaoParams); passSSAO->SetInput("cFov",0.6f); //passSSAO->SetInput("cFov",sm->GetCamera()->GetFOVy().valueRadians()); passSSAO->SetInput("cSampleLengthWorldSpace",0.38f); passSSAO->SetInput("cOffsetScale",1.63f); passSSAO->SetInput("cDefaultAccessibility",-0.32f); passSSAO->SetInput("cEdgeHighlight",2.03f); DiPostEffect* effectBox = peMgr->CreatePostEffect("BoxFilter"); effectBox->SetEnable(true); DiPostEffectPass* passFilter = effectBox->CreatePass("output"); passFilter->SetQuadScale(1); passFilter->BuildMaterial("screen_quad.vsh","post_box_filter.psh"); passFilter->SetInput("image",INPUT_PREV_EFFECT); }
void DiPostEffectPass::SetInput( const DiString& paramName, PassInputType inputtype ) { if (!mMaterial) return; mInput.first = paramName; mInput.second = inputtype; DiTexturePtr canvas = mParent->GetPostEffectManager( )->GetRenderWindow()->GetCanvasTexture(); if (inputtype == INPUT_SCENE_CANVAS) { mMaterial->GetShaderParameter()->WriteTexture2D(paramName,canvas); } else if (inputtype == INPUT_PREV_PASS) { DiPostEffectPass* prePass = mParent->GetPrevValidPass(GetPassName()); if (prePass) mMaterial->GetShaderParameter()->WriteTexture2D(paramName,prePass->GetOutTexture()); else mMaterial->GetShaderParameter()->WriteTexture2D(paramName,canvas); } else if (inputtype == INPUT_PREV_EFFECT) { DiPostEffect* preEffect = mParent->GetPostEffectManager()->GetPrevEnabledEffect(mParent); if (!preEffect) mMaterial->GetShaderParameter()->WriteTexture2D(paramName,canvas); else { DiPostEffectPass* lastvalid = preEffect->GetLastValidPass(); if (lastvalid) mMaterial->GetShaderParameter()->WriteTexture2D(paramName,lastvalid->GetOutTexture()); else mMaterial->GetShaderParameter()->WriteTexture2D(paramName,canvas); } } }
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); }