/*! \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 Storm3D_Spotlight::setAsRenderTarget(const float *cameraView) { data->updateMatrices(cameraView); if(data->shadowMap && data->shadowMap->hasInitialized()) { if(data->shadowMap->set()) { D3DMATRIX dm = { 0 }; dm._11 = 1.f; dm._22 = 1.f; dm._33 = 1.f; dm._44 = 1.f; data->device.SetTransform(D3DTS_WORLD, &dm); data->device.SetTransform(D3DTS_VIEW, &data->properties.lightView[1]); data->device.SetTransform(D3DTS_PROJECTION, &data->properties.lightProjection); Storm3D_ShaderManager::GetSingleton()->SetViewProjectionMatrix(data->properties.lightViewProjection[1], data->properties.lightViewProjection[1]); Storm3D_ShaderManager::GetSingleton()->setSpot(data->properties.color, data->properties.position, data->properties.direction, data->properties.range, .1f); if(type == Storm3D_Spotlight::AtiFloatBuffer) data->atiFloatDepthPixelShader->apply(); else if(type == Storm3D_Spotlight::AtiBuffer) { data->device.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); data->device.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); data->atiDepthPixelShader->apply(); } else { data->device.SetPixelShader(0); data->device.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); data->device.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); data->device.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); data->device.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); data->device.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); } return true; } IStorm3D_Logger *logger = data->storm.logger; if(logger) { logger->error("Failed to set render target"); } } return false; }
/*! \param name effect name \param effect effect to add */ void addEffect(const string &name, const Effect &effect) { ProceduralEffect result; result.effect = effect; result.init(storm); if(result.texture1 && result.texture2) effects[name] = result; else if(logger) { string message = "Cannot find both textures for procedural effect: "; message += name; logger->error(message.c_str()); logger->info(result.effect.source1.texture.texture.c_str()); logger->info(result.effect.source2.texture.texture.c_str()); } }
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(); }