/*!
	\param storm Storm3D
	\param shadowQuality shadow quality
*/
void Storm3D_FakeSpotlight::createBuffers(Storm3D &storm, int shadowQuality)
{
	if(BUFFER_WIDTH <= 0 || BUFFER_HEIGHT <= 0)
		return;

	bool status = renderTargets.createAll(storm, shadowQuality);
	while(!status && shadowQuality >= 0)
	{
		IStorm3D_Logger *logger = storm.getLogger();
		if(logger)
			logger->warning("Failed creating fakelight's shadow rendertargets - trying again using lower resolution");

		shadowQuality -= 50;
		querySizes(storm, shadowQuality);
		status = renderTargets.createAll(storm, shadowQuality);
	}

	IStorm3D_Logger *logger = storm.getLogger();
	if(logger && !renderTargets.targets[0]->hasInitialized())
		logger->warning("Failed creating fakelight's shadow rendertargets - feature disabled!");

	Storm3D_FakeSpotlight::Data::indexBuffer = new frozenbyte::storm::IndexBuffer();
	{
		Storm3D_FakeSpotlight::Data::indexBuffer->create(4, false);
		WORD *pointer = Storm3D_FakeSpotlight::Data::indexBuffer->lock();
		
		*pointer++ = 4;
		*pointer++ = 0;
		*pointer++ = 1;

		*pointer++ = 2;
		*pointer++ = 0;
		*pointer++ = 4;

		*pointer++ = 4;
		*pointer++ = 3;
		*pointer++ = 2;

		*pointer++ = 3;
		*pointer++ = 4;
		*pointer++ = 1;

		Storm3D_FakeSpotlight::Data::indexBuffer->unlock();
	}

	Storm3D_FakeSpotlight::Data::shadowVertexShader = new frozenbyte::storm::VertexShader();
	Storm3D_FakeSpotlight::Data::shadowVertexShader->createFakePlaneShadowShader();

	Storm3D_FakeSpotlight::Data::depthPixelShader = new frozenbyte::storm::PixelShader();
	Storm3D_FakeSpotlight::Data::depthPixelShader->createFakeDepthPixelShader();
	Storm3D_FakeSpotlight::Data::shadowPixelShader = new frozenbyte::storm::PixelShader();
	Storm3D_FakeSpotlight::Data::shadowPixelShader->createFakeShadowPixelShader();
}
		bool createAll(Storm3D &storm, int quality)
		{
			freeAll();
			if(SHARE_BUFFERS)
			{
				sharedColor = storm.getColorTarget();
				sharedDepth = storm.getDepthTarget();
			}

			for(unsigned int i = 0; i < BUFFER_LIMIT; ++i)
			{
				targets[i] = new RenderTarget(sharedColor, sharedDepth);
				if(SHARE_BUFFERS)
				{
					if(i == 0)
					{
						sharedColor = targets[i]->color;
						sharedDepth = targets[i]->depth;
					}
				}

				VC2I pos(0, 0);
				if(i == 1)
					pos.x = 1;
				else if(i == 2)
					pos.y = 1;
				else if(i == 3)
				{
					pos.x = 1;
					pos.y = 1;
				}

				targets[i]->pos = pos;
			}

			if(targets[0]->color)
			{
				usedWidth = float(BUFFER_WIDTH * 2) / (targets[0]->color->getWidth());
				usedHeight = float(BUFFER_HEIGHT * 2) / (targets[0]->color->getHeight());

				soffsetX = usedWidth * .5f * .5f;
				soffsetY = usedHeight * .5f * .5f;
				scaleX = soffsetX;
				scaleY = soffsetY;
			}

			if(!sharedColor)
				return false;

			return true;
		}
/*!
	\param storm Storm3D
	\param shadowQuality shadow quality
*/
void Storm3D_FakeSpotlight::querySizes(Storm3D &storm, int shadowQuality)
{
	if(shadowQuality >= 100)
	{
		BUFFER_WIDTH = 1024;
		BUFFER_HEIGHT = 1024;
	}
	/*else if(shadowQuality >= 75)
	{
		BUFFER_WIDTH = 768;
		BUFFER_HEIGHT = 768;
	}*/
	else if(shadowQuality >= 50)
	{
		BUFFER_WIDTH = 512;
		BUFFER_HEIGHT = 512;
	}
	/*else if(shadowQuality >= 25)
	{
		BUFFER_WIDTH = 384;
		BUFFER_HEIGHT = 384;
	}*/
	else if(shadowQuality >= 0)
	{
		BUFFER_WIDTH = 256;
		BUFFER_HEIGHT = 256;
	}
	else if(shadowQuality == -1)
	{
		BUFFER_WIDTH = -1;
		BUFFER_HEIGHT = -1;
	}

	if(BUFFER_WIDTH > 0 && BUFFER_HEIGHT > 0)
	{
		storm.setNeededColorTarget(VC2I(BUFFER_WIDTH * 2, BUFFER_HEIGHT * 2));
		storm.setNeededDepthTarget(VC2I(BUFFER_WIDTH * 2, BUFFER_HEIGHT * 2));
	}
}
		void init(Storm3D &storm)
		{
			if (!effect.source1.texture.texture.empty())
			{
				Storm3D_Texture *t1 = static_cast<Storm3D_Texture *> (storm.CreateNewTexture(effect.source1.texture.texture.c_str()));
				if(t1)
				{
					texture1.reset(t1, std::mem_fun(&IStorm3D_Texture::Release));
					texture1->setAutoRelease(false);
				}
			}
			if (!effect.source2.texture.texture.empty())
			{
				Storm3D_Texture *t2 = static_cast<Storm3D_Texture *> (storm.CreateNewTexture(effect.source2.texture.texture.c_str()));
				if(t2)
				{
					texture2.reset(t2, std::mem_fun(&IStorm3D_Texture::Release));
					texture2->setAutoRelease(false);
				}
			}

			if (!effect.source1.offset.texture.empty())
			{
				Storm3D_Texture *t3 = static_cast<Storm3D_Texture *> (storm.CreateNewTexture(effect.source1.offset.texture.c_str()));
				if(t3)
				{
					offset1.reset(t3, std::mem_fun(&IStorm3D_Texture::Release));
					offset1->setAutoRelease(false);
				}
			}

			if (!effect.source2.offset.texture.empty())
			{
				Storm3D_Texture *t4 = static_cast<Storm3D_Texture *> (storm.CreateNewTexture(effect.source2.offset.texture.c_str()));
				if(t4)
				{
					offset2.reset(t4, std::mem_fun(&IStorm3D_Texture::Release));
					offset2->setAutoRelease(false);
				}
			}

			if (!effect.distortion1.offset.texture.empty())
			{
				Storm3D_Texture *t5 = static_cast<Storm3D_Texture *> (storm.CreateNewTexture(effect.distortion1.offset.texture.c_str()));
				if(t5)
				{
					distortion1.reset(t5, std::mem_fun(&IStorm3D_Texture::Release));
					distortion1->setAutoRelease(false);
				}
			}
			if (!effect.distortion2.offset.texture.empty())
			{
				Storm3D_Texture *t6 = static_cast<Storm3D_Texture *> (storm.CreateNewTexture(effect.distortion2.offset.texture.c_str()));
				if(t6)
				{
					distortion2.reset(t6, std::mem_fun(&IStorm3D_Texture::Release));
					distortion2->setAutoRelease(false);
				}
			}

			if (!effect.fallback.empty())
			{
				Storm3D_Texture *f = static_cast<Storm3D_Texture *> (storm.CreateNewTexture(effect.fallback.c_str()));
				if(f)
				{
					fallback.reset(f, std::mem_fun(&IStorm3D_Texture::Release));
					fallback->setAutoRelease(false);
				}
			} else {
				storm.getLogger()->warning("ProceduralEffect::init - effect has no fallback texture.");
			}
		}
示例#5
0
void Storm3D_Spotlight::createShadowBuffers(Storm3D &storm, IDirect3D9 &d3d, IDirect3DDevice9 &device, bool ps14, bool ps20, int shadowQuality)
{
	bool status = staticBuffers.createAll(storm, d3d, device, ps14, shadowQuality);
	while(!status && shadowQuality > 0)
	{
		IStorm3D_Logger *logger = storm.getLogger();
		if(logger)
			logger->warning("Failed creating light's shadow depth rendertargets - trying again using lower resolution");

		shadowQuality -= 50;
		querySizes(storm, ps14, shadowQuality);
		status = staticBuffers.createAll(storm, d3d, device, ps14, shadowQuality);
	}

	IStorm3D_Logger *logger = storm.getLogger();
	if(logger && !staticBuffers.buffers[0]->hasInitialized())
		logger->warning("Failed creating light's shadow depth rendertargets - shadows disabled!");

	if(ps14)
	{
		if(type == Storm3D_Spotlight::AtiFloatBuffer)
		{
			Storm3D_SpotlightData::atiFloatDepthPixelShader = new frozenbyte::storm::PixelShader(device);
			Storm3D_SpotlightData::atiFloatDepthPixelShader->createAtiFloatDepthPixelShader();
			Storm3D_SpotlightData::atiFloatShadowPixelShader = new frozenbyte::storm::PixelShader(device);
			Storm3D_SpotlightData::atiFloatShadowPixelShader->createAtiFloatShadowPixelShader();
			Storm3D_SpotlightData::atiFloatShadowTerrainPixelShader = new frozenbyte::storm::PixelShader(device);
			Storm3D_SpotlightData::atiFloatShadowTerrainPixelShader->createAtiFloatShadowTerrainPixelShader();
			Storm3D_SpotlightData::atiFloatNoShadowPixelShader = new frozenbyte::storm::PixelShader(device);
			Storm3D_SpotlightData::atiFloatNoShadowPixelShader->createAtiFloatNoShadowPixelShader();
			Storm3D_SpotlightData::atiFloatNoShadowTerrainPixelShader = new frozenbyte::storm::PixelShader(device);
			Storm3D_SpotlightData::atiFloatNoShadowTerrainPixelShader->createAtiFloatNoShadowTerrainPixelShader();
		}

		Storm3D_SpotlightData::atiDepthPixelShader = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::atiDepthPixelShader->createAtiDepthPixelShader();
		Storm3D_SpotlightData::atiShadowPixelShader = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::atiShadowPixelShader->createAtiShadowPixelShader();
		Storm3D_SpotlightData::atiShadowSolidPixelShader = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::atiShadowSolidPixelShader->createAtiShadowSolidPixelShader();
		Storm3D_SpotlightData::atiShadowTerrainPixelShader = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::atiShadowTerrainPixelShader->createAtiShadowTerrainPixelShader();
		Storm3D_SpotlightData::atiNoShadowPixelShader = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::atiNoShadowPixelShader->createAtiNoShadowPixelShader();
		Storm3D_SpotlightData::atiNoShadowTerrainPixelShader = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::atiNoShadowTerrainPixelShader->createAtiNoShadowTerrainPixelShader();

		Storm3D_SpotlightData::coneAtiPixelShader_Texture = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::coneAtiPixelShader_Texture->createAtiLightConeShader_Texture();
		Storm3D_SpotlightData::coneAtiPixelShader_NoTexture = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::coneAtiPixelShader_NoTexture->createAtiLightConeShader_NoTexture();

		if(type == Storm3D_Spotlight::AtiFloatBuffer)
		{
			Storm3D_SpotlightData::coneAtiFloatPixelShader_Texture = new frozenbyte::storm::PixelShader(device);
			Storm3D_SpotlightData::coneAtiFloatPixelShader_Texture->createAtiFloatLightConeShader_Texture();
			Storm3D_SpotlightData::coneAtiFloatPixelShader_NoTexture = new frozenbyte::storm::PixelShader(device);
			Storm3D_SpotlightData::coneAtiFloatPixelShader_NoTexture->createAtiFloatLightConeShader_NoTexture();
		}
	}
	if(type == Storm3D_Spotlight::DepthBuffer)
	{
		if(ps20)
		{
			Storm3D_SpotlightData::nvSmoothShadowPixelShader = new frozenbyte::storm::PixelShader(device);
			Storm3D_SpotlightData::nvSmoothShadowPixelShader->createNvSmoothShadowShader();
		}

		Storm3D_SpotlightData::nvShadowPixelShader = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::nvShadowPixelShader->createNvShadowShader();
		Storm3D_SpotlightData::nvNoShadowPixelShader = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::nvNoShadowPixelShader->createNvNoShadowShader();

		Storm3D_SpotlightData::coneNvPixelShader_Texture = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::coneNvPixelShader_Texture->createNvConeShader_Texture();
		Storm3D_SpotlightData::coneNvPixelShader_NoTexture = new frozenbyte::storm::PixelShader(device);
		Storm3D_SpotlightData::coneNvPixelShader_NoTexture->createNvConeShader_NoTexture();
	}

	Storm3D_SpotlightData::coneStencilVertexShader = new frozenbyte::storm::VertexShader(device);
	Storm3D_SpotlightData::coneStencilVertexShader->createConeStencilShader();
}
示例#6
0
void Storm3D_Spotlight::querySizes(Storm3D &storm, bool ps14, int shadowQuality)
{
	if(shadowQuality >= 100)
	{
		SHADOW_WIDTH = 1024;
		SHADOW_HEIGHT = 1024;
		//SHADOW_WIDTH = 2048;
		//SHADOW_HEIGHT = 2048;
	}
	else if(shadowQuality >= 75)
	{
		SHADOW_WIDTH = 1024;
		SHADOW_HEIGHT = 512;
	}
	else if(shadowQuality >= 50)
	{
		SHADOW_WIDTH = 512;
		SHADOW_HEIGHT = 512;
	}
	else if(shadowQuality >= 25)
	{
		SHADOW_WIDTH = 512;
		SHADOW_HEIGHT = 256;
	}
	else
	{
		SHADOW_WIDTH = 256;
		SHADOW_HEIGHT = 256;
	}

	/*
	if(shadowQuality >= 100)
	{
		SHADOW_WIDTH = 768;
		SHADOW_HEIGHT = 768;
	}
	else if(shadowQuality >= 66)
	{
		SHADOW_WIDTH = 512;
		SHADOW_HEIGHT = 512;
	}
	else if(shadowQuality >= 33)
	{
		SHADOW_WIDTH = 384;
		SHADOW_HEIGHT = 384;
	}
	else
	{
		SHADOW_WIDTH = 256;
		SHADOW_HEIGHT = 256;
	}
	*/

	if(type == Legacy)
	{
		bool enableFloats = true;
		if(shadowQuality <= 33)
			enableFloats = false;

		findDepthType(*storm.D3D, ps14, enableFloats);
	}

	if(type != DepthBuffer)
		storm.setNeededDepthTarget(VC2I(SHADOW_WIDTH * 2, SHADOW_HEIGHT * 2));
	//else
		//storm.setNeededColorTarget(VC2I(SHADOW_WIDTH * 2, SHADOW_HEIGHT * 2));
}