Esempio n. 1
0
	void Shadow::Do(Texture * depthTex)
	{
		RenderSystem * render = RenderSystem::Instance();

		RenderTarget * oldRt = render->GetRenderTarget(0);
		DepthStencil * oldDs = render->GetDepthStencil();

		_updateCamera();

		/*for (int i = 0; i < 4; ++i)
		{
		Mat4 matCrop = _calcuCropMatrix(i);
		mCascadedViewProjMatrix[i] = mLightCamera->GetViewProjMatrix() * matCrop;
		}*/

		_impVisibleCull();

		{
			RS_RenderEvent(ShadowMap);

			for (int i = 0; i < K_NumShadowLayers; ++i)
			{
				_calcuCascadedMatrix(i);
				_renderDepth(i);
				_genShadowMap(i, depthTex);
			}
		}

		render->SetRenderTarget(0, oldRt);
		render->SetDepthStencil(oldDs);
	}
Esempio n. 2
0
	void Water::_renderRelfection()
	{
		if (WaterManager::Instance()->IsUnderWater())
			return ;

		mRenderRefl = true;

		RenderSystem * render = RenderSystem::Instance();

		Plane mirrorPlane = Plane(Vec3(0, 1, 0), -mHeight);

		RenderTarget * oldRT = render->GetRenderTarget(0);
		DepthStencil * oldDS = render->GetDepthStencil();

		// ---> Bind RenderTarget
		render->SetRenderTarget(0, mRT_Refl.c_ptr());
		render->SetRenderTarget(1, NULL);
		render->SetRenderTarget(2, NULL);
		render->SetRenderTarget(3, NULL);
		render->SetDepthStencil(mDepthStencil.c_ptr());

		// ---> clear buffer
		render->ClearBuffer(NULL, true, true, false, Color::Black, 1, 0);

		Color4 deepColor = Environment::Instance()->GetEvParam()->WaterParam.reflColor;

		RenderRegister::Instance()->SetMirrorColor(deepColor);

		Engine::Instance()->GetRenderScheme()->RenderInMirror(mirrorPlane);

		mRT_Refl->Stretch(mTex_Refl.c_ptr());

		render->SetRenderTarget(0, oldRT);
		render->SetDepthStencil(oldDS);

		mRenderRefl = false;
	}
Esempio n. 3
0
	void Shadow::_renderDepth(int layer)
	{
		RenderSystem * render = RenderSystem::Instance();

		render->SetRenderTarget(0, mRT_Depth.c_ptr());
		render->SetDepthStencil(mDepthStencil.c_ptr());

		render->ClearBuffer(NULL, true, true, false, Color::White);

		const Array<Renderer *> & objs = mRenderQueue.GetSolidRender();

		ShaderParam * uMatWVP = mTech_ShadowDepth->GetVertexShaderParamTable()->GetParam("matWVP");
		ShaderParam * uMatWVPSkin = mTech_ShadowDepthSkin->GetVertexShaderParamTable()->GetParam("matWVP");

		for (int j = 0; j < objs.Size(); ++j)
		{
			Renderer * rd = objs[j];

			if (!IsVisible(rd->GetWorldAabb(), mCascadedMatrix[layer].mViewProj))
				continue;

			bool skined = (rd->GetBlendMatrix(NULL) > 0);

			Mat4 form;

			rd->GetWorldTransform(&form);

			form *= mCascadedMatrix[layer].mViewProj;

			uMatWVP->SetMatrix(form);
			uMatWVPSkin->SetMatrix(form);

			if (!skined)
				render->Render(mTech_ShadowDepth, rd);
			else
				render->Render(mTech_ShadowDepthSkin, rd);
		}

		OnRenderDepth(this, &layer);
	}
Esempio n. 4
0
	void Shadow::_genShadowMap(int layer, Texture * depthTex)
	{
		RenderSystem * render = RenderSystem::Instance();

		render->SetRenderTarget(0, mRT_Shadow.c_ptr());
		render->SetRenderTarget(1, NULL);
		render->SetRenderTarget(2, NULL);
		render->SetRenderTarget(3, NULL);
		render->SetDepthStencil(NULL);

		if (layer == 0)
			render->ClearBuffer(NULL, true, false, false, Color::White);

		Camera * cam = World::Instance()->MainCamera();
		const Vec3 * corner = cam->GetCorner();

		Mat4 matInverseView = cam->GetViewMatrix().Inverse();

		Vec3 cornerLeftTop = corner[4];
		Vec3 cornerRightDir = corner[5] - corner[4];
		Vec3 cornerDownDir = corner[6] - corner[4];

		Vec4 shadowInfo = Vec4::Zero;

		if (layer == 0)
			shadowInfo.x = cam->GetNearClip();
		else
			shadowInfo.x = mDist[layer - 1];

		shadowInfo.y = mDist[layer];
		shadowInfo.z = mBias[layer];

		ShaderParam * uShadowInfo = mTech_Shadow[layer]->GetPixelShaderParamTable()->GetParam("gShadowInfo");
		ShaderParam * uMatShadow = mTech_Shadow[layer]->GetPixelShaderParamTable()->GetParam("matShadow");
		ShaderParam * uCornerLeftTop = mTech_Shadow[layer]->GetPixelShaderParamTable()->GetParam("gCornerLeftTop");
		ShaderParam * uCornerRightDir = mTech_Shadow[layer]->GetPixelShaderParamTable()->GetParam("gCornerRightDir");
		ShaderParam * uCornerDownDir = mTech_Shadow[layer]->GetPixelShaderParamTable()->GetParam("gCornerDownDir");

		uCornerLeftTop->SetUnifom(cornerLeftTop.x, cornerLeftTop.y, cornerLeftTop.z, 0);
		uCornerRightDir->SetUnifom(cornerRightDir.x, cornerRightDir.y, cornerRightDir.z, 0);
		uCornerDownDir->SetUnifom(cornerDownDir.x, cornerDownDir.y, cornerDownDir.z, 0);

		uShadowInfo->SetUnifom(shadowInfo.x, shadowInfo.y, shadowInfo.z, 0);
		uMatShadow->SetMatrix(matInverseView * mCascadedMatrix[layer].mViewProj);
			
		SamplerState state;
		state.Address = TEXA_CLAMP;
		state.Filter = TEXF_POINT;

		render->SetTexture(0, state, depthTex);

		state.Address = TEXA_BORDER;
		state.BorderColor = Color::White;
		render->SetTexture(1, state, mTex_Depth.c_ptr());

		state.Address = TEXA_WRAP;
		state.Filter = TEXF_DEFAULT;
		RenderSystem::Instance()->SetTexture(2, state, mTex_Random.c_ptr());

		RenderHelper::Instance()->DrawScreenQuad(BM_ALPHA_TEST, mTech_Shadow[layer]);
	}