Exemplo n.º 1
0
    void UnderWaterCaustics::Render(Texture * colorTex, Texture * depthTex)
    {
        RenderSystem * render = RenderSystem::Instance();
        Camera * cam = World::Instance()->MainCamera();

        ShaderParam * uCornerLeftTop = mTech->GetPixelShaderParamTable()->GetParam("gCornerLeftTop");
        ShaderParam * uCornerRightDir = mTech->GetPixelShaderParamTable()->GetParam("gCornerRightDir");
        ShaderParam * uCornerDownDir = mTech->GetPixelShaderParamTable()->GetParam("gCornerDownDir");
        ShaderParam * uCameraPos = mTech->GetPixelShaderParamTable()->GetParam("gCameraPos");
        ShaderParam * uCausticsParam = mTech->GetPixelShaderParamTable()->GetParam("gCausticsParam");

        const Vec3 * corner = cam->GetWorldCorner();
        const Vec3 & camPos = cam->GetPosition();

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

        float waterY = 180;
        float depthLimit = 15;
        float uvScale = 0.05f;

        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);
        uCameraPos->SetUnifom(camPos.x, camPos.y, camPos.z, 0);
        uCausticsParam->SetUnifom(waterY, depthLimit, uvScale, 0);

        SamplerState state;
        render->SetTexture(0, state,  depthTex);
        render->SetTexture(1, state,  colorTex);
        render->SetTexture(2, state,  GetTexture());

        RenderHelper::Instance()->DrawScreenQuad(BM_OPATICY, mTech);
    }
Exemplo n.º 2
0
    void Moon::Render()
    {
        RenderSystem * render = RenderSystem::Instance();
        Camera * cam = World::Instance()->MainCamera();

        Vec3 moonPos = Environment::Instance()->GetEvParam()->MoonPos;
        Vec3 moonDir = Environment::Instance()->GetEvParam()->MoonDir;
        float moonLum = Environment::Instance()->GetEvParam()->MoonLum;
        float moonSize = Environment::Instance()->GetEvParam()->MoonSize;
        float moonPhase = Environment::Instance()->GetEvParam()->MoonPase;
        const char * moonTex = Environment::Instance()->GetGlobalParam()->MoonTexture.c_str();

        _setTexture(moonTex);

        ShaderParam * uTransform = mTech->GetVertexShaderParamTable()->GetParam("gTransform");
        ShaderParam * uMoonParam = mTech->GetPixelShaderParamTable()->GetParam("gMoonParam");

        uTransform->SetUnifom(moonPos.x, moonPos.y, moonPos.z, moonSize);
        uMoonParam->SetUnifom(moonPhase, moonLum, 0, 0);

        SamplerState s0;
        Texture * t0 = mTexture.c_ptr();
        
        render->SetTexture(0, s0, t0);
        render->Render(mTech, &mRender);
    }
Exemplo n.º 3
0
    void UnderWaterBubble::Render()
    {
        _update();
        _emit();
        _geom();

        Camera * cam = World::Instance()->MainCamera();
        RenderSystem * render = RenderSystem::Instance();

        SamplerState state;

        render->SetTexture(0, state, mTex_Bubble0.c_ptr());

        render->Render(mTech, &mRender);
    }
Exemplo n.º 4
0
    void UnderWaterGodRay::_blend()
    {
        RenderSystem * render = RenderSystem::Instance();
        Camera * cam = World::Instance()->MainCamera();

        ShaderParam * uHGg = mTech_Blend->GetPixelShaderParamTable()->GetParam("gHGg");
        ShaderParam * uIntensity = mTech_Blend->GetPixelShaderParamTable()->GetParam("gIntensity");
        ShaderParam * uSunColor = mTech_Blend->GetPixelShaderParamTable()->GetParam("gSunColor");
        ShaderParam * uCornerLeftTop = mTech_Blend->GetPixelShaderParamTable()->GetParam("gCornerLeftTop");
        ShaderParam * uCornerRightDir = mTech_Blend->GetPixelShaderParamTable()->GetParam("gCornerRightDir");
        ShaderParam * uCornerDownDir = mTech_Blend->GetPixelShaderParamTable()->GetParam("gCornerDownDir");
        ShaderParam * uSunDir = mTech_Blend->GetPixelShaderParamTable()->GetParam("gSunDir");

        const Vec3 * corner = cam->GetCorner();

        Vec3 cornerLeftTop = corner[4];
        Vec3 cornerRightDir = corner[5] - corner[4];
        Vec3 cornerDownDir = corner[6] - corner[4];
        Vec3 sunDir = Environment::Instance()->GetEvParam()->SunDir;
        sunDir = sunDir.TransformN(cam->GetViewMatrix());

        Color4 sunColor = Environment::Instance()->GetEvParam()->SunColor;
        mExposure.x = Environment::Instance()->GetEvParam()->WaterParam.godrayExp0;
        mExposure.y = Environment::Instance()->GetEvParam()->WaterParam.godrayExp1;
        mIntensity = Environment::Instance()->GetEvParam()->WaterParam.godrayLum;

        if (uHGg) uHGg->SetUnifom(mExposure.x, mExposure.y, mExposure.z, 0);
        if (uIntensity) uIntensity->SetUnifom(mIntensity, 0, 0, 0);
        if (uSunColor) uSunColor->SetUnifom(sunColor.r, sunColor.g, sunColor.b, 1);

        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);
        uSunDir->SetUnifom(sunDir.x, sunDir.y, sunDir.z, 0);

        SamplerState state;
        render->SetTexture(0, state,  mTexture.c_ptr());

        RenderHelper::Instance()->DrawScreenQuad(BM_ADD, mTech_Blend);

    }
Exemplo n.º 5
0
void SkinRenderer::Render(Event * _sender)
{
	if (!mEnable)
		return ;

	RenderSystem * render = RenderSystem::Instance();

	ShaderParam * gScale = mTech->GetVertexShaderParamTable()->GetParam("gScale");
	ShaderParam * gBackUVScale = mTech->GetVertexShaderParamTable()->GetParam("gBackUVScale");

	int viewW, viewH;
	App::Instance()->GetViewSize(viewW, viewH);

	int texW = 512, texH = 256;

	if (mSkinTexture != NULL)
	{
		texW = mSkinTexture->GetWidth();
		texH = mSkinTexture->GetHeight();
	}

	float xScale = texW / (float)viewW;
	float yScale = texH / (float)viewH;

	gScale->SetUnifom(xScale, yScale, 0, 0);

	int backW = mBackTexture->GetWidth();
	int backH = mBackTexture->GetHeight();

	xScale = backW / (float)texW;
	yScale = backH / (float)texH;

	gBackUVScale->SetUnifom(1 / xScale, 1 / yScale, 0, 0);

	SamplerState state;
	render->SetTexture(0, state, mBackTexture.c_ptr());
	render->SetTexture(1, state, mSkinTexture.c_ptr());

	render->Render(mTech, mRenderOp);
}
Exemplo n.º 6
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]);
	}
Exemplo n.º 7
0
	void Water::_renderUpWater(WaterBlock * block, Texture * depthTex, Texture * colorTex)
	{
		RenderSystem * render = RenderSystem::Instance();
		Camera * cam = World::Instance()->MainCamera();
		float time = Engine::Instance()->GetTime();

		const Vec3 * worldCorner = cam->GetWorldCorner();
		const Vec3 & camPos = cam->GetPosition();

		Vec3 worldCornerLeftTop = worldCorner[4] - camPos;
		Vec3 worldCornerRightDir = worldCorner[5] - worldCorner[4];
		Vec3 worldCornerDownDir = worldCorner[6] - worldCorner[4];

		const Vec3 * viewCorner = cam->GetCorner();

		Vec3 viewCornerLeftTop = viewCorner[4];
		Vec3 viewCornerRightDir = viewCorner[5] - viewCorner[4];
		Vec3 viewCornerDownDir = viewCorner[6] - viewCorner[4];

		ShaderParam * uFresnelParam = mTech->GetPixelShaderParamTable()->GetParam("gFresnelParam");
		ShaderParam * uCamPos = mTech->GetPixelShaderParamTable()->GetParam("gCameraPos");
		ShaderParam * uWorldCornerLeftTop = mTech->GetPixelShaderParamTable()->GetParam("gWorldCornerLeftTop");
		ShaderParam * uWorldCornerRightDir = mTech->GetPixelShaderParamTable()->GetParam("gWorldCornerRightDir");
		ShaderParam * uWorldCornerDownDir = mTech->GetPixelShaderParamTable()->GetParam("gWorldCornerDownDir");
		ShaderParam * uViewCornerLeftTop = mTech->GetPixelShaderParamTable()->GetParam("gViewCornerLeftTop");
		ShaderParam * uViewCornerRightDir = mTech->GetPixelShaderParamTable()->GetParam("gViewCornerRightDir");
		ShaderParam * uViewCornerDownDir = mTech->GetPixelShaderParamTable()->GetParam("gViewCornerDownDir");
		ShaderParam * uDeepColor = mTech->GetPixelShaderParamTable()->GetParam("gDeepColor");
		ShaderParam * uRefractionDist = mTech->GetPixelShaderParamTable()->GetParam("gRefractionDist");

		ShaderParam * uSunDir = mTech->GetPixelShaderParamTable()->GetParam("gSunDir");
		ShaderParam * uSunColor = mTech->GetPixelShaderParamTable()->GetParam("gSunColor");
		ShaderParam * uSunLightParam = mTech->GetPixelShaderParamTable()->GetParam("gSunLightParam");

		ShaderParam * uNoiseScale = mTech->GetPixelShaderParamTable()->GetParam("gNoiseScale");
		ShaderParam * uNoiseUVParam = mTech->GetPixelShaderParamTable()->GetParam("gNoiseUVParam");

		ShaderParam * uNormalUVParam = mTech->GetPixelShaderParamTable()->GetParam("gNormalUVParam");
		ShaderParam * uNormalWeight = mTech->GetPixelShaderParamTable()->GetParam("gNormalWeight");

		ShaderParam * uInvScreenSize = mTech->GetPixelShaderParamTable()->GetParam("gInvScreenSize");
		ShaderParam * uFarClip = mTech->GetPixelShaderParamTable()->GetParam("gFarClip");

		Vec3 sunDir = Environment::Instance()->GetEvParam()->SunDir;
		Color4 sunColor = Environment::Instance()->GetEvParam()->SunColor;
		Color4 deepColor = Environment::Instance()->GetEvParam()->WaterParam.deepColor;

		uCamPos->SetUnifom(camPos.x, camPos.y, camPos.z, 0);

		uWorldCornerLeftTop->SetUnifom(worldCornerLeftTop.x, worldCornerLeftTop.y, worldCornerLeftTop.z, 0);
		uWorldCornerRightDir->SetUnifom(worldCornerRightDir.x, worldCornerRightDir.y, worldCornerRightDir.z, 0);
		uWorldCornerDownDir->SetUnifom(worldCornerDownDir.x, worldCornerDownDir.y, worldCornerDownDir.z, 0);

		uViewCornerLeftTop->SetUnifom(viewCornerLeftTop.x, viewCornerLeftTop.y, viewCornerLeftTop.z, 0);
		uViewCornerRightDir->SetUnifom(viewCornerRightDir.x, viewCornerRightDir.y, viewCornerRightDir.z, 0);
		uViewCornerDownDir->SetUnifom(viewCornerDownDir.x, viewCornerDownDir.y, viewCornerDownDir.z, 0);

		uDeepColor->SetUnifom(deepColor.r, deepColor.g, deepColor.b, 1);
		uRefractionDist->SetUnifom(40, 0, 0, 0);

		uSunColor->SetUnifom(sunColor.r, sunColor.g, sunColor.b, 0);
		uSunDir->SetUnifom(-sunDir.x, -sunDir.y, -sunDir.z, 0);
		uSunLightParam->SetUnifom(0.8f, 200, 0, 0);

		float uvNoiseScroll = time * 0.02f;

		uNoiseUVParam->SetUnifom(0.01f, 0.01f, uvNoiseScroll, uvNoiseScroll);
		uNoiseScale->SetUnifom(0.03f, 0, 0 , 0);

		Vec4 uvNormalParam[4] = {
			Vec4 (0.02f, 0.02f, time * 0.03f, time * 0.03f),
			Vec4 (0.01f, 0.01f, time * 0.03f, time * 0.03f),
			Vec4 (0.015f, 0.015f, time * 0.03f, time * 0.03f),
			Vec4 (0.005f, 0.005f, time * 0.03f, time * 0.03f)
		};

		uNormalUVParam->SetVector(uvNormalParam, 4);
		uNormalWeight->SetUnifom(0.08f, 0.1f, 0.06f, 0.1f);

		float screenW = (float)Engine::Instance()->GetDeviceProperty()->Width;
		float screenH = (float)Engine::Instance()->GetDeviceProperty()->Height;

		uInvScreenSize->SetUnifom(1 / screenW, 1 / screenW, 0, 0);
		uFarClip->SetUnifom(cam->GetFarClip(), 0, 0, 0);

		SamplerState state;
		render->SetTexture(0, state, mTex_Wave.c_ptr());
		state.Address = TEXA_CLAMP;
		state.Filter = TEXF_POINT;
		render->SetTexture(1, state, depthTex);
		render->SetTexture(2, state, colorTex);
		render->SetTexture(3, state, mTex_Refl.c_ptr());
		state.Filter = TEXF_LINEAR;
		render->SetTexture(4, state, mTex_Fresnel.c_ptr());

		SamplerState state1;
		render->SetTexture(5, state1, mTex_Wave.c_ptr());
		render->SetTexture(6, state1, mTex_Wave.c_ptr());

		render->Render(mTech, block->mRenderOp);
	}