Esempio n. 1
0
	void renderFakeSpotLights(Storm3D_Scene &scene, bool renderShadows)
	{
        GFX_TRACE_SCOPE("renderFakeSpotLights");

		// Renders fake shadows to screen?
		Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera());
		Storm3D_ShaderManager::GetSingleton()->setFakeShadowShaders();

		device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
		device.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR);
		device.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
		device.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
		device.SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
		device.SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED);
		device.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED);
		device.SetTextureStageState(2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED);
		device.SetTextureStageState(3, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED);

		device.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
		device.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
		device.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
		device.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);

		frozenbyte::storm::enableMipFiltering(device, 0, 4, false);

		FakeSpotList::iterator it = fakeSpots.begin();
		for(; it != fakeSpots.end(); ++it)
		{
			Storm3D_FakeSpotlight *spot = it->get();
			if(!spot || !spot->enabled())
				continue;

			const float *cameraView = camera.GetView4x4Matrix();
			spot->applyTextures(cameraView);

			renderer.render(IStorm3D_TerrainRendererBase::FakeSpotProjection, scene, 0, spot);
		}

		frozenbyte::storm::enableMipFiltering(device, 0, 4, true);

		device.SetPixelShader(0);
		device.SetVertexShader(0);
		device.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
		device.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
		device.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
		device.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
		device.SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
		device.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
		device.SetTextureStageState(2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
		device.SetTextureStageState(3, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);

		Storm3D_ShaderManager::GetSingleton()->setNormalShaders();

		device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
		device.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
		device.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
		device.SetRenderState(D3DRS_CLIPPLANEENABLE, FALSE);
	}
	void renderFakeSpotBuffers(Storm3D_Scene &scene, bool renderShadows)
	{
		// Renders fake shadows to texture?
		Storm3D_ShaderManager::GetSingleton()->setFakeDepthShaders();
		Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera());

		// FIXME: this does not appear to do anything
		// d3d9 tinkers with these parameters here
		// but this is incorrect on opengl
		// because texture sampling state is part of the texture
		glActiveTexture(GL_TEXTURE1);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

		Storm3D_FakeSpotlight::clearCache();
		// bool rendered = false;

		FakeSpotList::iterator it = fakeSpots.begin();
		for(; it != fakeSpots.end(); ++it)
		{
			Storm3D_FakeSpotlight *spot = it->get();
			if(!spot || !spot->enabled())
				continue;

			const float *cameraView = camera.GetView4x4Matrix();
			if(!spot->setAsRenderTarget(cameraView))
				continue;

			renderer.render(IStorm3D_TerrainRendererBase::FakeSpotBuffer, scene, 0, spot);
			// rendered = true;
		}

		//if(rendered)
		//	Storm3D_FakeSpotlight::filterBuffers(storm, device);

		// FIXME: this does not appear to do anything
		// d3d9 tinkers with these parameters here
		// but this is incorrect on opengl
		// because texture sampling state is part of the texture
		glActiveTexture(GL_TEXTURE1);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

		frozenbyte::storm::PixelShader::disable();

		Storm3D_ShaderManager::GetSingleton()->setNormalShaders();
		camera.Apply();
	}
Esempio n. 3
0
	void renderFakeSpotBuffers(Storm3D_Scene &scene, bool renderShadows)
	{
        GFX_TRACE_SCOPE("renderFakeSpotBuffers");

		// Renders fake shadows to texture?
		Storm3D_ShaderManager::GetSingleton()->setFakeDepthShaders();
		Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera());

		device.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
		device.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
		//device.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED);

		Storm3D_FakeSpotlight::clearCache();
		bool rendered = false;

		FakeSpotList::iterator it = fakeSpots.begin();
		for(; it != fakeSpots.end(); ++it)
		{
			Storm3D_FakeSpotlight *spot = it->get();
			if(!spot || !spot->enabled())
				continue;

			const float *cameraView = camera.GetView4x4Matrix();
			if(!spot->setAsRenderTarget(cameraView))
				continue;

			renderer.render(IStorm3D_TerrainRendererBase::FakeSpotBuffer, scene, 0, spot);
			rendered = true;
		}

		//if(rendered)
		//	Storm3D_FakeSpotlight::filterBuffers(storm, device);

		device.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
		device.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
		device.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
		device.SetPixelShader(0);

		Storm3D_ShaderManager::GetSingleton()->setNormalShaders();
		camera.Apply();
	}
	void renderFakeSpotLights(Storm3D_Scene &scene, bool renderShadows)
	{
		// Renders fake shadows to screen?
		Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera());
		Storm3D_ShaderManager::GetSingleton()->setFakeShadowShaders();

		glBlendFunc(GL_ZERO, GL_SRC_COLOR);
		glEnable(GL_BLEND);
		glDisable(GL_ALPHA_TEST);
		glDepthMask(GL_FALSE);

		// D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED done in shader in OpenGL

		FakeSpotList::iterator it = fakeSpots.begin();

		unsigned int count = 0;

		for(; it != fakeSpots.end(); ++it)
		{
			Storm3D_FakeSpotlight *spot = it->get();
			if(!spot || !spot->enabled())
				continue;

			const float *cameraView = camera.GetView4x4Matrix();
			spot->applyTextures(cameraView);

			for (int i = 0; i < 4; i++)
			{
				glActiveTexture(GL_TEXTURE0 + i);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
				float temp[4] = { 0.0, 0.0f, 0.0f, 0.0f };
				glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, temp);
			}

			if (count == 0)
			{
				// this is the most horrific f****d up WTF thing ever
				// without this we get strangely colored artifacts in strange places
				// someone please explain what is going on
				// for some reason first draw of fakespotlight is messed up
				// so when drawing the first one, "fix it" by drawing it twice
				glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
				renderer.render(IStorm3D_TerrainRendererBase::FakeSpotProjection, scene, 0, spot);
				glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
			}
			renderer.render(IStorm3D_TerrainRendererBase::FakeSpotProjection, scene, 0, spot);

			++count;

		}

		frozenbyte::storm::PixelShader::disable();
		frozenbyte::storm::VertexShader::disable();

		for (int i = 0; i < 4; i++)
		{
			glActiveTexture(GL_TEXTURE0 + i);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		}

		Storm3D_ShaderManager::GetSingleton()->setNormalShaders();

		glBlendFunc(GL_ONE, GL_ONE);
		glDisable(GL_BLEND);
		glDisable(GL_CLIP_PLANE0);
		glDisable(GL_CLIP_PLANE1);
		glDisable(GL_CLIP_PLANE2);
	}