void RendererCommon::ApplySamplerState(const uint SamplerStage, const SSamplerState& SamplerState) { SetTexture(SamplerStage, SamplerState.m_Texture); SetAddressing(SamplerStage, SamplerState.m_AddressU, SamplerState.m_AddressV); SetMinMipFilters(SamplerStage, SamplerState.m_MinFilter, SamplerState.m_MipFilter); SetMagFilter(SamplerStage, SamplerState.m_MagFilter); }
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); }
void InitFx_Repeater01() { // effect auto _ps = DiEffectManager::GetInstance().CreateParticleSystemTemplate("Fx_repeater1"); std::shared_ptr<DiTransformUnit> ps(_ps); _ps->Start(); { DiParticleElement* element = _ps->CreateElement(); element->SetRenderer("Billboard"); auto emitter = element->CreateEmitter("Box"); auto mat = DiMaterial::QuickCreate("basic_v", "basic_p", SHADER_FLAG_USE_COLOR | SHADER_FLAG_USE_MAP); mat->GetShaderParameter()->WriteTexture2D("map", "glow_01.dds"); mat->SetBlendMode(BLEND_ADD); mat->SetDepthWrite(false); element->SetMaterialName(mat->GetName()); ((DiBoxEmitter*)emitter)->SetWidth(50); ((DiBoxEmitter*)emitter)->SetHeight(70); ((DiBoxEmitter*)emitter)->SetDepth(50); emitter->position = DiVec3(0, 165, 5); auto rt = DI_NEW DiAttributeFixed(); rt->SetValue(30); emitter->SetDynEmissionRate(rt); auto spd = DI_NEW DiAttributeFixed(); spd->SetValue(20); emitter->SetDynVelocity(spd); auto ttl = DI_NEW DiAttributeRandom(); ttl->SetMinMax(1, 2); emitter->SetDynTotalTimeToLive(ttl); auto sz = DI_NEW DiAttributeRandom(); sz->SetMinMax(20, 40); emitter->SetDynParticleAllDimensions(sz); DiColorController* colorCtrl = (DiColorController*)element->CreateController("Color"); colorCtrl->AddColour(0, DiColor::Black); colorCtrl->AddColour(0.5f, DiColor(0.25f, 1, 0.5f)); colorCtrl->AddColour(1, DiColor::Black); } { DiParticleElement* element = _ps->CreateElement(); element->SetRenderer("Billboard"); auto emitter = element->CreateEmitter("Box"); auto mat = DiMaterial::QuickCreate("basic_v", "basic_p", SHADER_FLAG_USE_COLOR | SHADER_FLAG_USE_MAP); auto texture = mat->GetShaderParameter()->WriteTexture2D("map", "mysticenergy2.dds"); mat->SetBlendMode(BLEND_ADD); mat->SetDepthWrite(false); element->SetMaterialName(mat->GetName()); texture->SetAddressing(AM_CLAMP); ((DiBoxEmitter*)emitter)->SetWidth(50); ((DiBoxEmitter*)emitter)->SetHeight(70); ((DiBoxEmitter*)emitter)->SetDepth(50); emitter->position = DiVec3(0, 165, 5); auto rt = DI_NEW DiAttributeFixed(); rt->SetValue(6); emitter->SetDynEmissionRate(rt); auto spd = DI_NEW DiAttributeFixed(); spd->SetValue(20); emitter->SetDynVelocity(spd); auto ttl = DI_NEW DiAttributeRandom(); ttl->SetMinMax(1, 2); emitter->SetDynTotalTimeToLive(ttl); auto sz = DI_NEW DiAttributeRandom(); sz->SetMinMax(20, 40); emitter->SetDynParticleAllDimensions(sz); DiColorController* colorCtrl = (DiColorController*)element->CreateController("Color"); colorCtrl->AddColour(0, DiColor::Black); colorCtrl->AddColour(0.5f, DiColor(0.25f, 1, 0.5f)); colorCtrl->AddColour(1, DiColor::Black); DiTextureRotatorController* texrotCtrl = (DiTextureRotatorController*)element->CreateController("TextureRotator"); texrotCtrl->SetUseOwnRotationSpeed(true); auto rotspeed = DI_NEW DiAttributeRandom(); rotspeed->SetMinMax(-100, 100); texrotCtrl->SetRotationSpeed(rotspeed); auto rot = DI_NEW DiAttributeRandom(); rot->SetMinMax(0, 300); texrotCtrl->SetRotation(rot); } // create the editor object from the particle system DiEditorManager::Get()->LoadParticleSystem(_ps); }