コード例 #1
0
	void renderCones(Storm3D_Scene &scene, bool renderShadows, float timeFactor, bool renderGlows)
	{
		// this draws spotlight cone
		frozenbyte::storm::PixelShader::disable();

		Storm3D_ShaderManager::GetSingleton()->setProjectedShaders();
		coneNvVertexShader.apply();

		Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera());

		glDepthMask(GL_FALSE);
		glDisable(GL_ALPHA_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE);

		StormSpotList::iterator it = spots.begin();
		for(; it != spots.end(); ++it)
		{
			Storm3D_Spotlight *spot = it->get();
			if(!spot || !spot->enabled() || !spot->featureEnabled(IStorm3D_Spotlight::ConeVisualization))
				continue;

			if(renderShadows)
				spot->renderCone(camera, timeFactor, renderGlows);
		}

		Storm3D_ShaderManager::GetSingleton()->setNormalShaders();
		frozenbyte::storm::PixelShader::disable();

		glDepthMask(GL_TRUE);
		glDisable(GL_BLEND);
	}
コード例 #2
0
	void renderCones(Storm3D_Scene &scene, bool renderShadows, float timeFactor, bool renderGlows)
	{
		// this draws spotlight cone
		device.SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED);
		device.SetPixelShader(0);

		Storm3D_ShaderManager::GetSingleton()->setProjectedShaders();
		coneNvVertexShader.apply();

		Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera());

		device.SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
		device.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
		device.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
		device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
		device.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

		SpotList::iterator it = spots.begin();
		for(; it != spots.end(); ++it)
		{
			Storm3D_Spotlight *spot = it->get();
			if(!spot || !spot->enabled() || !spot->featureEnabled(IStorm3D_Spotlight::ConeVisualization))
				continue;

			if(renderShadows)
				spot->renderCone(camera, timeFactor, renderGlows);
		}

		Storm3D_ShaderManager::GetSingleton()->setNormalShaders();
		device.SetPixelShader(0);

		device.SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
		device.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
		device.SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
	}
コード例 #3
0
	void renderSpotBuffers(Storm3D_Scene &scene, bool renderShadows)
	{
		bool atiShaders = false;
		int spotType = Storm3D_Spotlight::getSpotType();
		if(spotType == Storm3D_Spotlight::AtiBuffer)
			atiShaders = true;

		// FIXME: broken?
		glPolygonOffset(1, 1);
		glEnable(GL_POLYGON_OFFSET_FILL);

		if(atiShaders)
			Storm3D_ShaderManager::GetSingleton()->setAtiDepthShaders();
		else
		{
			glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
			//glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
			Storm3D_ShaderManager::GetSingleton()->setNormalShaders();
		}

		Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera());
		Storm3D_Spotlight::clearCache();

		if(renderShadows)
		{
			StormSpotList::iterator it = spots.begin();
			for(; it != spots.end(); ++it)
			{
				Storm3D_Spotlight *spot = it->get();
				if(!spot || !spot->enabled() || !spot->featureEnabled(IStorm3D_Spotlight::Shadows))
					continue;

				// Test spot visibility with foo scissor rect -- not really an optimal way of doing this
				if(!spot->setScissorRect(camera, VC2I(100, 100), scene))
					continue;
				glDisable(GL_SCISSOR_TEST);

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

				glErrors();
				renderer.render(IStorm3D_TerrainRendererBase::SpotBuffer, scene, spot);
				glErrors();
			}
		}

		Storm3D_ShaderManager::GetSingleton()->setNormalShaders();
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
		frozenbyte::storm::PixelShader::disable();

		glDisable(GL_POLYGON_OFFSET_FILL);
		camera.Apply();
	}
コード例 #4
0
	void renderSpotBuffers(Storm3D_Scene &scene, bool renderShadows)
	{
        GFX_TRACE_SCOPE("renderSpotBuffers");

		device.SetRenderState(D3DRS_COLORWRITEENABLE, 0);
		Storm3D_ShaderManager::GetSingleton()->setNormalShaders();

		Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera());
		Storm3D_Spotlight::clearCache();

		if(renderShadows)
		{
			SpotList::iterator it = spots.begin();
			for(; it != spots.end(); ++it)
			{
				Storm3D_Spotlight *spot = it->get();
				if(!spot || !spot->enabled() || !spot->featureEnabled(IStorm3D_Spotlight::Shadows))
					continue;

				// Test spot visibility with foo scissor rect -- not really an optimal way of doing this
				if(!spot->setScissorRect(camera, VC2I(100, 100), scene))
					continue;
				device.SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);

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

                /* debug
				static unsigned int count = 0;
				count++;
				device.Clear(0, NULL, D3DCLEAR_ZBUFFER, 0, float(count % 21) / 20.0f, 0);
                */
				//glClearDepth(float(count % 11) / 10.0f);
				//glClear(GL_DEPTH_BUFFER_BIT);

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

		device.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
		device.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);

		Storm3D_ShaderManager::GetSingleton()->setNormalShaders();
		device.SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);
		device.SetPixelShader(0);

		camera.Apply();
	}
コード例 #5
0
void Storm3D_TerrainLightManager::setDebug(void) {
	static unsigned int count = 0;
	// set first spotlight depth texture as stage 0 texture
	if (data->spots.size() != 0) {
		unsigned int i = (count / 10) % data->spots.size();
		//LOG_WARNING("Storm3D_TerrainLightManager::setDebug: spotlight %d\n", i);
		Storm3D_Spotlight *spot = data->spots[i].get();
		spot->setDebug();
	} else {
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, 0);
		glDisable(GL_TEXTURE_2D);
	}
	++count;
}
コード例 #6
0
	void renderSpotLights(Storm3D_Scene &scene, bool renderShadows, LightType type)
	{
		// this renders spotlight light & shadows
		Storm3D_ShaderManager::GetSingleton()->setProjectedShaders();

		glBlendFunc(GL_ONE, GL_ONE);
		glEnable(GL_BLEND);
		glDisable(GL_ALPHA_TEST);
		glDepthMask(GL_FALSE);

		Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera());
		StormSpotList::iterator it = spots.begin();
		for(; it != spots.end(); ++it)
		{
			Storm3D_Spotlight *spot = it->get();
			if(!spot || !spot->enabled())
				continue;

			// Test spot visibility with foo scissor rect -- not really an optimal way of doing this
			if(!spot->setScissorRect(camera, VC2I(100, 100), scene))
				continue;
			// glDisable below makes at least some spotlights visible through movie top & bottom "black bars"
			//glDisable(GL_SCISSOR_TEST);

			spot->applyTextures(camera.GetViewMatrix(), storm, renderShadows);

			for(int i = 0; i < 4; ++i)
			{
				if(i != 2)
				{
					glActiveTexture(GL_TEXTURE0 + i);
					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
				}
			}
	
			if(type == RealSolid)
				renderer.render(IStorm3D_TerrainRendererBase::SpotProjectionSolid, scene, spot);
			else
			{
				renderer.render(IStorm3D_TerrainRendererBase::SpotProjectionDecal, scene, spot);
				renderer.render(IStorm3D_TerrainRendererBase::SpotProjectionAlpha, scene, spot);
			}
		}

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

		glActiveTexture(GL_TEXTURE1);
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_TEXTURE_3D);
		glDisable(GL_TEXTURE_CUBE_MAP);
		glBindTexture(GL_TEXTURE_2D, 0);

		glActiveTexture(GL_TEXTURE2);
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_TEXTURE_3D);
		glDisable(GL_TEXTURE_CUBE_MAP);
		glBindTexture(GL_TEXTURE_2D, 0);

		glActiveTexture(GL_TEXTURE3);
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_TEXTURE_3D);
		glDisable(GL_TEXTURE_CUBE_MAP);
		glBindTexture(GL_TEXTURE_2D, 0);

		glActiveTexture(GL_TEXTURE4);
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_TEXTURE_3D);
		glDisable(GL_TEXTURE_CUBE_MAP);
		glBindTexture(GL_TEXTURE_2D, 0);

		frozenbyte::storm::PixelShader::disable();
		glDisable(GL_BLEND);
		glDisable(GL_SCISSOR_TEST);
		glDisable(GL_CLIP_PLANE0);
		glDisable(GL_CLIP_PLANE1);
		glDisable(GL_CLIP_PLANE2);
	}
コード例 #7
0
	void renderSpotLights(Storm3D_Scene &scene, bool renderShadows, LightType type)
	{
        GFX_TRACE_SCOPE("renderSpotLights");

		// this renders spotlight light & shadows
		//setTracing(true);

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

		device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
		device.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
		device.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
		device.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
		device.SetRenderState(D3DRS_ALPHAREF, 0x1);
		device.SetRenderState(D3DRS_ZWRITEENABLE, FALSE);

		for(int i = 0; i < 4; ++i)
		{
			if(i != 2)
			{
				device.SetSamplerState(i, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
				device.SetSamplerState(i, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
			}
		}

		Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera());
		SpotList::iterator it = spots.begin();
		for(; it != spots.end(); ++it)
		{
			Storm3D_Spotlight *spot = it->get();
			if(!spot || !spot->enabled())
				continue;

			// Test spot visibility with foo scissor rect -- not really an optimal way of doing this
			if(!spot->setScissorRect(camera, VC2I(100, 100), scene))
				continue;
			device.SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);

			if(!false)
			{
				device.SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED);
				device.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED);
				device.SetTextureStageState(2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
				device.SetTextureStageState(3, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
			}

			const float *cameraView = camera.GetView4x4Matrix();
			const float *cameraViewProjection = camera.GetViewProjection4x4Matrix();
			spot->applyTextures(cameraView, cameraViewProjection, storm, renderShadows);

			if(type == RealSolid)
				renderer.render(IStorm3D_TerrainRendererBase::SpotProjectionSolid, scene, spot);
			else
			{
				renderer.render(IStorm3D_TerrainRendererBase::SpotProjectionDecal, scene, spot);
				renderer.render(IStorm3D_TerrainRendererBase::SpotProjectionAlpha, scene, spot);
			}
		}

		Storm3D_ShaderManager::GetSingleton()->setNormalShaders();
		for(int i = 0; i < 4; ++i)
		{
			device.SetSamplerState(i, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
			device.SetSamplerState(i, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
		}
		//setTracing(false);

		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);

		device.SetTexture(1, 0);
		device.SetTexture(2, 0);
		device.SetTexture(3, 0);
		device.SetTexture(4, 0);

		device.SetPixelShader(0);
		device.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
		device.SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
		device.SetRenderState(D3DRS_CLIPPLANEENABLE, FALSE);
	}