void UnderWaterGodRay::_renderRay() { Camera * cam = World::Instance()->MainCamera(); RenderSystem * render = RenderSystem::Instance(); render->SetRenderTarget(0, mRenderTarget.c_ptr()); render->ClearBuffer(NULL, true, false, false); ShaderParam * uWorldMatrix = mTech_Ray->GetVertexShaderParamTable()->GetParam("matWorld"); uWorldMatrix->SetMatrix(mProjMatrix); render->Render(mTech_Ray, &mRender); mRenderTarget->Stretch(mTexture.c_ptr()); }
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); }
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; }
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]); }