Object3D::Object3D(ID3D10Device* device, std::string filename, D3DXVECTOR3 position, D3DXVECTOR3 lightPos) : mDevice(device), mEffect(NULL), mEffectShadows(NULL), mTechnique(NULL), mTechniqueShadows(NULL), mVertexLayout(NULL), mFont(NULL), mPosition(position), mRotation(0.0f), mLightPosition(lightPos), mVelocity(D3DXVECTOR3(1.2, 0.5, 0.8)), mFXEyePos(NULL), mFXLightPos(NULL), mFXWorld(NULL), mFXWorldViewProj(NULL), mFXShadowWVP(NULL) { if(!Load(filename)) return; mEffect = CreateEffect("Effect.fx"); mEffectShadows = CreateEffect("EffectShadows.fx"); CreateVertexLayout(); mMatrixWorld = new D3DXMATRIX(); D3DXMatrixIdentity(mMatrixWorld); D3DXVec3Normalize(&mVelocity, &mVelocity); mVelocity *= 30; UpdateWorldMatrix(); mFXEyePos = mEffect->GetVariableByName("gEyePos")->AsVector(); mFXLightPos = mEffect->GetVariableByName("gLightPosition")->AsVector(); mFXWorld = mEffect->GetVariableByName("gWorld")->AsMatrix(); mFXWorldViewProj = mEffect->GetVariableByName("gWVP")->AsMatrix(); mFXShadowWVP = mEffectShadows->GetVariableByName("gWVP")->AsMatrix(); for(std::map<std::string, Group>::iterator it = mGroups.begin(); it != mGroups.end(); ++it) it->second.Finalize(mDevice, mEffect); mFont = new GameFont(mDevice, "Times New Roman", 18); }
void EffectFactory::Init(COMObjectPointer<ID3D11Device>& aDevice) { myDevice = aDevice; myEffectNames.Init(8); CreateEffect("PostProcessShader", "Data/Shaders/PostProcessShader.fso", GE::eVertexType::VERTEX_POS_UV); CreateEffect("ComputeShader", "Data/Shaders/ComputeShader.fso", GE::eVertexType::NONE); }
// // StateInit // // Start the construction process // void UnitConstruct::StateInit() { // Unit should not have been added to the team list yet ASSERT(!subject->IsActivelyOnTeam()) // Get construction time F32 time = subject->UnitType()->GetConstructionTime(); // Setup progress counts progressTotal = 0.0F; progressMax = (time > 0.0F) ? (1.0F / (time * GameTime::SimTimeInv())) : 1.0F; // Grab total resource to be removed resourceRemoved = 0; resourceRemaining = subject->UnitType()->GetResourceCost(); // Setup number of hitpoints to add hitPointsLeft = subject->MapType()->GetHitPoints() - subject->UnitType()->GetConstructionHitPoints(); // Register construction of this object if ((constructListTeam = subject->GetTeam()) != NULL) { constructListTeam->RegisterConstructionBegin(subject); } // Create the construction effect CreateEffect(); NextState(0x4E5A04E4); // "Construct" }
void CWeaponEgon::UpdateEffect( const Vector &startPoint, const Vector &endPoint ) { if ( !m_hBeam ) { CreateEffect(); } if ( m_hBeam ) { m_hBeam->SetStartPos( endPoint ); } if ( m_hSprite ) { m_hSprite->SetAbsOrigin( endPoint ); m_hSprite->m_flFrame += 8 * gpGlobals->frametime; if ( m_hSprite->m_flFrame > m_hSprite->Frames() ) m_hSprite->m_flFrame = 0; } if ( m_hNoise ) { m_hNoise->SetStartPos( endPoint ); } }
void CEgon::UpdateEffect( const Vector &startPoint, const Vector &endPoint, float timeBlend ) { #ifndef CLIENT_DLL if ( !m_pBeam ) { CreateEffect(); } m_pBeam->SetStartPos( endPoint ); m_pBeam->SetBrightness( 255 - (timeBlend*180) ); m_pBeam->SetWidth( 40 - (timeBlend*20) ); if ( m_fireMode == FIRE_WIDE ) m_pBeam->SetColor( 30 + (25*timeBlend), 30 + (30*timeBlend), 64 + 80*fabs(sin(gpGlobals->time*10)) ); else m_pBeam->SetColor( 60 + (25*timeBlend), 120 + (30*timeBlend), 64 + 80*fabs(sin(gpGlobals->time*10)) ); // UTIL_SetOrigin( m_pSprite->pev, endPoint ); UTIL_SetOrigin( m_pSprite, endPoint ); m_pSprite->pev->frame += 8 * gpGlobals->frametime; if ( m_pSprite->pev->frame > m_pSprite->Frames() ) m_pSprite->pev->frame = 0; m_pNoise->SetStartPos( endPoint ); #endif }
void RPG_Pickup::CheckCharacterContact() { VArray<RPG_Character*> const& characters = RPG_GameManager::s_instance.GetCharacters(); hkvVec3 const& currentPosition = GetPosition(); for(int index = 0; index < characters.GetSize(); ++index) { RPG_Character* character = characters.GetAt(index); // only target players if(!character->IsOfType(V_RUNTIME_CLASS(RPG_PlayerCharacter))) { continue; } hkvVec3 const& targetPosition = character->GetPosition(); float currentRangeSquared = (currentPosition - targetPosition).getLengthSquared(); if(currentRangeSquared <= m_pickupRadius * m_pickupRadius) { // call OnPickup for subclasses OnPickup(character); // play the pickup effect CreateEffect(PKFX_Pickup, GetPosition(), GetOrientation()); // setup this object for deletion DisposeObject(); } } }
void RPG_Pickup::PostInitialize() { RPG_BaseEntity::PostInitialize(); // setup a rigid body and apply initial spawn forces if we need to. if(m_usePhysics) { // setup the inverse square of the max distance m_magnetMaxDistanceInverseSquared = 1.0f / (m_magnetMaxDistance * m_magnetMaxDistance); // create a rotation hkvVec3 rotation = GetOrientation(); rotation.x = Vision::Game.GetFloatRand() * 360.0f; SetOrientation(rotation); // setup a rigid body component m_rigidBodyComponent = Components().GetComponentOfType<vHavokRigidBody>(); if(!m_rigidBodyComponent) { m_rigidBodyComponent = new vHavokRigidBody(); VASSERT(m_rigidBodyComponent); m_rigidBodyComponent->Initialize(); m_rigidBodyComponent->Shape_Type = ShapeType_SPHERE; m_rigidBodyComponent->Havok_QualityType = QualityType_MOVING; m_rigidBodyComponent->Havok_CollisionLayer = vHavokPhysicsModule::HK_LAYER_COLLIDABLE_CUSTOM4; // this pickup should only collide with static geometry and terrain m_rigidBodyComponent->Havok_Mass = m_mass; AddComponent(m_rigidBodyComponent); } VASSERT(m_verticalSpawnForceMax >= m_verticalSpawnForceMin); float energy = m_verticalSpawnForceMin + (Vision::Game.GetFloatRand() * (m_verticalSpawnForceMax - m_verticalSpawnForceMin)); m_rigidBodyComponent->ApplyLinearImpulse( hkvVec3(0.0f, 0.0f, 1.0f) * energy); // Since the object is already rotated, just move forward VASSERT(m_horizontalSpawnForceMax >= m_horizontalSpawnForceMin); energy = m_horizontalSpawnForceMin + (Vision::Game.GetFloatRand() * (m_horizontalSpawnForceMax - m_horizontalSpawnForceMin)); m_rigidBodyComponent->ApplyLinearImpulse(GetDirection().getNormalized() * energy); } CreateEffect(PKFX_Spawn, GetPosition(), GetOrientation()); CreateEffect(PKFX_Ambient); }
PostProcessRenderer::PostProcessRenderer() : effectResource(nullptr), randomNormalsTexture(nullptr) { CreateEffect(); CreateFullQuadData(); randomNormalsTexture = ResourceManager::Get()->LoadTextureResource("Utilities\\random_normals.jpg"); }
void EffectFactory::CreateAllEffects() { CU::GrowingArray<std::string> files = WF::GetFilesWithExtension("Data\\Shaders\\", ".fso"); for (unsigned short i = 0; i < files.Size(); i++) { std::string fileName = WF::GetFileNameWithoutExtension(files[i]); if (fileName != "Default" && fileName != "VertexPosNormUVBiTanInclude" && fileName != "ParticleShader") { CreateEffect(fileName, files[i], eVertexType::VERTEX_POS_NORM_UV_BI_NORMAL_TAN); } else if (fileName == "ParticleShader") { CreateEffect(fileName, files[i], eVertexType::VERTEX_POS_VELOCITY_SIZE_ALPHA_TIME); } } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_EntityFlame::OnDataChanged( DataUpdateType_t updateType ) { if ( updateType == DATA_UPDATE_CREATED ) { CreateEffect(); } // FIXME: This is a bit of a shady path if ( updateType == DATA_UPDATE_DATATABLE_CHANGED ) { // If our owner changed, then recreate the effect if ( m_hEntAttached != m_hOldAttached ) { CreateEffect(); } } BaseClass::OnDataChanged( updateType ); }
TSRPlatformEffect* TSRGraphicsFactory::CreateEffect( const char* _pEffectFileName, uint32 _iFlags ) { TSRShaderMacro* pMacros = NULL; pMacros = TSRShaderUtils::GenerateMacros( _iFlags ); string suffix = ""; if ( _iFlags ) { suffix += "."; suffix += TSRShaderUtils::FormulateSuffix( _iFlags ); } return CreateEffect( _pEffectFileName, suffix.c_str(), pMacros ); }
void CSphereShape::Create(float radius, int grid, int color, bool hasNormal) { Release(); m_isCreatePrimitive = true; //インデックスバッファの作成。 std::vector<int> indexBuffer; CreateIndexBuffer(indexBuffer, grid); if (hasNormal) { std::vector<SShapeVertex_PNC> vertexBuffer; CreateVertexPosition(vertexBuffer, radius, grid, color); //頂点マージ MergeVertex(vertexBuffer, indexBuffer, 0.001f ); //法線を計算。 CreateVertexNormal(vertexBuffer, indexBuffer, CPrimitive::eTriangleList); //プリミティブの作成。 m_pPrimitive = new CPrimitive; m_pPrimitive->Create( CPrimitive::eTriangleList, vertexBuffer.size(), sizeof(SShapeVertex_PNC), scShapeVertex_PNC_Element, &vertexBuffer.at(0), (int)indexBuffer.size(), eIndexFormat32, &indexBuffer.at(0) ); } else { //ポジション+座標頂点バッファの作成。 std::vector<SShapeVertex_PC> vertexBuffer; CreateVertexPosition(vertexBuffer, radius, grid, color); //頂点マージ MergeVertex(vertexBuffer, indexBuffer, 0.01f ); //プリミティブの作成。 m_pPrimitive = new CPrimitive; m_pPrimitive->Create( CPrimitive::eTriangleList, vertexBuffer.size(), sizeof(SShapeVertex_PC), scShapeVertex_PC_Element, &vertexBuffer.at(0), (int)indexBuffer.size(), eIndexFormat32, &indexBuffer.at(0) ); } CreateEffect(hasNormal); }
bool CD3DEffect::Create(const std::string &effectString, DefinesMap* defines) { Release(); m_effectString = effectString; m_defines.clear(); if (defines != nullptr) m_defines = *defines; //FIXME: is this a copy of all members? if (CreateEffect()) { g_Windowing.Register(this); return true; } return false; }
void RPG_DestructibleEntity::PostInitialize() { RPG_DamageableEntity::PostInitialize(); // Preload the mesh and effect to be used when this prop is destroyed. RPG_VisionEffectHelper::LoadMesh(m_postDestructionMeshFilename); AddComponents(); AddObstacle(); m_health = m_healthMax; CreateEffect(DEFX_Ambient); }
int RPG_DestructibleEntity::TakeDamage( const int damageAmount, const hkvVec3& impactVelocity /*= hkvVec3(0,0,0)*/ ) { CreateEffect(DEFX_TakeHit); if(damageAmount >= m_health) { SetDestroyed(); return m_health; } else { m_health -= damageAmount; return damageAmount; } }
void RPG_Projectile::OnHit(RPG_DamageableEntity* target, hkvVec3 const& position, hkvVec3 const& normal) { hkvVec3 orientation = NormalToYpr(normal); if(!target) { // null target entity, so we have hit static geometry or terrain CreateEffect(PFX_Impact, position, orientation); return; } float damage = 0.0f; RPG_InventoryItem const* equippedWeapon = m_characterOwner->GetInventoryHandler().GetEquippedWeapon(); if(equippedWeapon) { damage = static_cast<float>(m_characterOwner->GetCharacterStats().GetBaseDamage()); float const damageMin = damage * equippedWeapon->GetMinDamage(); float const damageMax = damage * equippedWeapon->GetMaxDamage(); damage = (damageMin + Vision::Game.GetFloatRand() * (damageMax - damageMin)) + 0.5f; float impactSpeed = 0.0f; if(m_characterOwner) { RPG_InventoryItem const* equippedWeapon = m_characterOwner->GetInventoryHandler().GetEquippedWeapon(); RPG_CharacterActionData const& actionData = m_characterOwner->GetCharacterActionData(); if(equippedWeapon) { impactSpeed = equippedWeapon->GetImpactSpeed() * actionData.GetRangedAttackImpactSpeedMultiplier(); } } target->TakeDamage(static_cast<int>(damage), -normal * impactSpeed); CreateEffect(PFX_Impact, position, orientation); } }
// // Load // void UnitConstruct::Load(FScope *fScope) { FScope *sScope; while ((sScope = fScope->NextFunction()) != NULL) { switch (sScope->NameCrc()) { case 0x22C4A13F: // "StateMachine" inst.LoadState(sScope); break; case 0x97522DEF: // "ProgressTotal" progressTotal = StdLoad::TypeF32(sScope); break; case 0xDA11482A: // "ProgressMax" progressMax = StdLoad::TypeF32(sScope); break; case 0xF5B25A80: // "ResourceRemoved" resourceRemoved = S32(StdLoad::TypeU32(sScope)); break; case 0xE262D203: // "ResourceRemaining" resourceRemaining = S32(StdLoad::TypeU32(sScope)); break; case 0x8BD8D5BA: // "HitPointsLeft" hitPointsLeft = S32(StdLoad::TypeU32(sScope)); break; case 0xB73D3720: // "Constructor" StdLoad::TypeReaper(sScope, constructor); break; case 0x9574AB0C: // "ConstructListTeam" constructListTeam = Team::Name2Team(StdLoad::TypeString(sScope)); break; default: LoadTaskData(sScope); break; } } // Create the construction effect CreateEffect(); }
void c_system_motionblur::InitializeResources_Base(IDirect3DDevice9* device, D3DPRESENT_PARAMETERS* parameters) { HRESULT hr = E_FAIL; // create the direct3d resources of the shader do { if(FAILED(hr = CreateShader())) break; if(FAILED(hr = CreateEffect())) break; }while(false); Validate(); if(SUCCEEDED(hr)) { m_members.status = Enums::pp_component_status_initialised; } else { m_members.status = Enums::pp_component_status_initialisation_failed; } UpdateStatus(); }
void c_system_motionblur::Load() { HRESULT hr = E_FAIL; // create the direct3d resources of the shader do { if(FAILED(hr = CreateShader())) break; if(FAILED(hr = CreateEffect())) break; }while(false); Validate(); if(SUCCEEDED(hr)) { m_members.status = Enums::pp_component_status_initialised; } else { m_members.status = Enums::pp_component_status_initialisation_failed; } m_members.m_flags.is_unloaded = false; UpdateStatus(); }
void QOpenALEngine::openEFX() { if (ALFWIsEFXSupported()) { if (CreateAuxEffectSlot(&uiEffectSlot)) { if (CreateEffect(&uiEffect, AL_EFFECT_EAXREVERB)) { // ConvertReverbParameters(&eaxBathroom, &efxReverb); efxReverb=eaxBathroom; // Set the Effect parameters if (!SetEFXEAXReverbProperties(&efxReverb, uiEffect)) return; // Load Effect into Auxiliary Effect Slot alAuxiliaryEffectSloti(uiEffectSlot, AL_EFFECTSLOT_EFFECT, uiEffect); // Enable (non-filtered) Send from Source to Auxiliary Effect Slot alSource3i(uiSource, AL_AUXILIARY_SEND_FILTER, uiEffectSlot, 0, AL_FILTER_NULL); } } } }
void RPG_Projectile::Fire(hkvVec3 position, hkvVec3 direction, float speed) { VASSERT(m_characterOwner); m_spawnTime = Vision::GetTimer()->GetTime(); m_currentPosition = position; SetPosition(position); VASSERT_MSG(direction.isNormalized(), "Please normalize your projectile fire direction."); m_direction = direction; m_speed = speed; hkvMat3 vRotation; vRotation.setLookInDirectionMatrix(m_direction); SetRotationMatrix(vRotation); CreateShapePhantom(); // create inflight effect CreateEffect(PFX_Inflight); }
void RPG_DestructibleEntity::SetDestroyed() { m_isDestroyed = true; // remove the attackable component RPG_AttackableComponent* attackableComponent = static_cast<RPG_AttackableComponent*>(Components().GetComponentOfType(V_RUNTIME_CLASS(RPG_AttackableComponent))); if (attackableComponent) { RemoveComponent(attackableComponent); } vHavokRigidBody* rigidBodyComponent = static_cast<vHavokRigidBody*>(Components().GetComponentOfType(V_RUNTIME_CLASS(vHavokRigidBody))); if (rigidBodyComponent) { RemoveComponent(rigidBodyComponent); } // stop the ambient effect StopEffect(DEFX_Ambient); CreateEffect(DEFX_Destroy, GetPosition(), GetOrientation()); // remove collision if so instructed //if (m_removeCollisionAfterDestruction) { RemoveObstacle(); } if(!m_postDestructionMeshFilename.IsEmpty()) { // swap the mesh SetMesh(m_postDestructionMeshFilename); } else { DisposeObject(); } }
BOOL SAV_Load( int load_no ) { char fname[256]; DWORD rsize; int i; char *msgBuf; MySaveHead saveHead; if(load_no>=0) { wsprintf( fname, "save_%02d.sav", load_no ); } else { wsprintf( fname, "save___.sav" ); } exec_mode tmp_back_mode = sysInf.execMode; InitRestartData(); if(sysInf.execMode!=tmp_back_mode)changeExecMode(tmp_back_mode); if(load_no!=98){ HANDLE hFile = CreateFile(fname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0L ,NULL); if(INVALID_HANDLE_VALUE==hFile){ return FALSE; } ReadFile(hFile,saveWnd->saveBmp.pBuf,thumbnailW*thumbnailH*3,&rsize,NULL); ReadFile(hFile,&saveHead,sizeof(MySaveHead),&rsize,NULL); if(saveHead.ver!=MAKEWORD(SaveVerMajor,SaveVerMinor) || 0!=strnicmp(saveHead.head,"LSAV",4)){ MessageBox(sysInf.hWnd,"セーブデータ形式が異常です。このセーブデータは使用できません","データエラー",MB_OK|MB_ICONWARNING); return FALSE; } ReadFile(hFile,&SaveStruct, sizeof(SaveStruct), &rsize,NULL); ReadFile(hFile,&saveInf,sizeof(SaveInfo),&rsize,NULL); ReadFile(hFile,setBmpInf,sizeof(SetBmpInf)*STBMP_MAX,&rsize,NULL); ReadFile(hFile,&backSelectStruct, sizeof(SaveStruct), &rsize,NULL); ReadFile(hFile,&backSelectInf,sizeof(BackSelectInf),&rsize,NULL); CloseHandle(hFile); }else{ CopyMemory(&SaveStruct,&backSelectStruct,sizeof(SaveStruct)); CopyMemory(&saveInf,&backSelectInf.saveInf,sizeof(SaveInfo)); CopyMemory(&setBmpInf,&bak_setBmpInf,sizeof(SetBmpInf)*STBMP_MAX); } SAV_LoadScript(); memcpy( ESC_FlagBuf, SaveStruct.ESC_FlagBuf, sizeof(int)*ESC_FLAG_MAX ); toneConvert.ChangeTable( saveInf.tone_type[0], saveInf.tone_type[1], saveInf.tone_backOnly); SHORT tmp_shakeSize = saveInf.shakeSize; g_disp(saveInf.bak_no, _BAK_DIRECT, saveInf.cg_type, 0, saveInf.btRect.left, saveInf.btRect.top); saveInf.shakeSize = tmp_shakeSize; if(saveInf.shakeSize){ backColorBuf.RollBlt(&bgInf.colorBuf, saveInf.shakeSize*180.0f); bgInf.colorBuf.BltFast(0,0,&backColorBuf,NULL,FALSE); } for(i=0;i<STCHAR_MAX;i++){ if(saveInf.charSave[i].char_no){ c_disp(saveInf.charSave[i].char_no-1, saveInf.charSave[i].pose, saveInf.charSave[i].locate, _CHR_DIRECT, saveInf.charSave[i].layer,saveInf.charSave[i].alpha,0,saveInf.charSave[i].bright); } } for(i=0;i<STBMP_MAX;i++){ setBmpInf[i].Reload(); } if(saveInf.selectNum){ for(i=0;i<saveInf.selectNum;i++){ selectWnd.addSelect(&backSelectInf.selectMsg[i*60]); } sysInf.bMsgAtOnce = on; msgWnd.DisplayMessage((BYTE *)backSelectInf.msgBuf); backLog.SetBackLog(backSelectInf.msgBuf,backSelectInf.msgLine); sysInf.bMsgCLS = on; } if(saveInf.musicNum>=0){ lpSoundDS->ChangeMusic(bgmHandle, saveInf.musicNum,TRUE,0, 30,saveInf.musicVol); }else{ lpSoundDS->FadeOut( bgmHandle ); } for(i=0;i<hEvtSndMax;i++){ if(saveInf.loopSeNum[i]==0)continue; CreateEffect(evtHandle[i],saveInf.loopSeNum[i]-1); PlayEffect(evtHandle[i],saveInf.loopSeVol[i],TRUE); } if(backSelectInf.saveInf.selectNum){ EnableMenuItem( sysInf.hMenu, ID_BACKSELECT, MF_ENABLED ); }else{ EnableMenuItem( sysInf.hMenu, ID_BACKSELECT, MF_GRAYED ); } sysInf.FontSize = mainFontSize; lpSoundDS->voiceCnt = saveInf.voiceCnt; lpSoundDS->scriptNo = saveInf.voiceScriptNo; BOOL bPlayVoice = FALSE; if(saveInf.RestartVoice[0]>0){ char voicefile[32]; saveInf.RestartVoice[0] --; int charNo = checkPlayVoice(saveInf.RestartVoice[0]); if(charNo >= 0){ wsprintf(voicefile,"%05d_%03d_%03d",saveInf.RestartVoice[2], saveInf.RestartVoice[1], charNo); if(!keyState.data_skip && !sysInf.bReadSkip){ bPlayVoice = TRUE; } }else{ wsprintf(voicefile,"%05d_%03d_%03d",saveInf.RestartVoice[2], saveInf.RestartVoice[1], saveInf.RestartVoice[0]); } backLog.SetVoice(voicefile); saveInf.RestartVoice[0] = 0; if(saveWnd){ strcpy(saveWnd->voicefile,voicefile); } } if(FALSE==bPlayVoice){ if(saveWnd)saveWnd->voicefile[0] = '\0'; } return TRUE; } // SAV_Load
CAMeshSHSkin::CAMeshSHSkin (CAModel* pModel) : CAModelMesh (pModel), m_pEffect (NULL) { CreateEffect (); }
bool RazerChroma::SetLEDs(COLORREF pixels[64][256]) { CreateEffect = (CREATEEFFECT)GetProcAddress(hModule, "CreateEffect"); CreateKeyboardEffect = (CREATEKEYBOARDEFFECT)GetProcAddress(hModule, "CreateKeyboardEffect"); CreateMouseEffect = (CREATEMOUSEEFFECT)GetProcAddress(hModule, "CreateMouseEffect"); CreateHeadsetEffect = (CREATEHEADSETEFFECT)GetProcAddress(hModule, "CreateHeadsetEffect"); if (CreateEffect == NULL) { return FALSE; } else { //Blackwidow Chroma ChromaSDK::Keyboard::CUSTOM_EFFECT_TYPE BlackWidowEffect; for (int x = 0; x < 22; x++) { for (int y = 0; y < 6; y++) { BlackWidowEffect.Color[y][x] = (pixels[BlackWidowYIndex[y]][BlackWidowXIndex[x]] & 0x00FFFFFF); } } //Set Razer "Three Headed Snake" logo to the background color of the 11th column BlackWidowEffect.Color[0][20] = pixels[3][11 * (256 / 22)]; CreateEffect(ChromaSDK::BLACKWIDOW_CHROMA, ChromaSDK::CHROMA_CUSTOM, &BlackWidowEffect, NULL); //Blackwidow Chroma Tournament Edition ChromaSDK::Keyboard::CUSTOM_EFFECT_TYPE BlackWidowTEEffect; for (int x = 0; x < 18; x++) { for (int y = 0; y < 6; y++) { BlackWidowTEEffect.Color[y][x] = (pixels[BlackWidowTEYIndex[y]][BlackWidowTEXIndex[x]] & 0x00FFFFFF); } } //Set Razer "Three Headed Snake" logo to the background color of the 11th column BlackWidowTEEffect.Color[0][20] = pixels[3][11 * (256 / 22)]; CreateEffect(ChromaSDK::BLACKWIDOW_CHROMA_TE, ChromaSDK::CHROMA_CUSTOM, &BlackWidowTEEffect, NULL); //Blade Stealth ChromaSDK::Keyboard::CUSTOM_EFFECT_TYPE BladeStealthEffect; for (int x = 0; x < 16; x++) { for (int y = 0; y < 6; y++) { BladeStealthEffect.Color[y][x] = (pixels[BladeStealthYIndex[y]][BladeStealthXIndex[x]] & 0x00FFFFFF); } } CreateEffect(ChromaSDK::BLADE_STEALTH, ChromaSDK::CHROMA_CUSTOM, &BladeStealthEffect, NULL); //Firefly Chroma ChromaSDK::Mousepad::CUSTOM_EFFECT_TYPE FireflyEffect = {}; for (int x = 0; x < 15; x++) { FireflyEffect.Color[x] = pixels[0][FireflyIndex[x]]; } CreateEffect(ChromaSDK::FIREFLY_CHROMA, ChromaSDK::CHROMA_CUSTOM, &FireflyEffect, NULL); //Mamba Chroma Tournament Edition ChromaSDK::Mouse::CUSTOM_EFFECT_TYPE2 MouseEffect = {}; for (int x = 0; x < 7; x++) { for (int y = 0; y < 9; y++) { MouseEffect.Color[y][x] = pixels[MouseYIndex[y][x]][MouseXIndex[y][x]]; } } CreateMouseEffect(ChromaSDK::Mouse::CHROMA_CUSTOM2, &MouseEffect, NULL); //Kraken Chroma ChromaSDK::Headset::STATIC_EFFECT_TYPE KrakenEffect; KrakenEffect.Color = pixels[3][0]; CreateHeadsetEffect(ChromaSDK::Headset::CHROMA_NONE, &KrakenEffect, NULL); CreateHeadsetEffect(ChromaSDK::Headset::CHROMA_STATIC, &KrakenEffect, NULL); //DeathStalker Chroma ChromaSDK::Keyboard::CUSTOM_EFFECT_TYPE DeathStalkerEffect; for (int x = 0; x < 6; x++) { DeathStalkerEffect.Color[1][DeathStalkerXLEDIndex[x]] = (pixels[0][DeathStalkerXIndex[x]] & 0x00FFFFFF); } CreateEffect(ChromaSDK::DEATHSTALKER_CHROMA, ChromaSDK::CHROMA_CUSTOM, &DeathStalkerEffect, NULL); //Tartarus Chroma ChromaSDK::Keypad::CUSTOM_EFFECT_TYPE TartarusEffect; TartarusEffect.Color[0][0] = pixels[3][0]; CreateEffect(ChromaSDK::TARTARUS_CHROMA, ChromaSDK::CHROMA_CUSTOM, &TartarusEffect, NULL); //Orbweaver Chroma ChromaSDK::Keypad::CUSTOM_EFFECT_TYPE OrbweaverEffect; for (int x = 0; x < 5; x++) { for (int y = 0; y < 4; y++) { OrbweaverEffect.Color[y][x] = (pixels[OrbweaverYIndex[y]][OrbweaverXIndex[x]] & 0x00FFFFFF); } } CreateEffect(ChromaSDK::ORBWEAVER_CHROMA, ChromaSDK::CHROMA_CUSTOM, &OrbweaverEffect, NULL); return TRUE; } };
void CD3DEffect::OnCreateDevice() { CreateEffect(); }
//---------------------------------------------------------------------------- FxCompiler::FxCompiler (const std::string& fxName, bool alreadyCompiled) : mActiveProfile(0), mEffect(0), mAlreadyCompiled(alreadyCompiled) { if (!mAlreadyCompiled) { // Use a command interpreter to compile the shaders using the Cg // compiler. bool compileSucceeded = false; std::string command; int i; for (i = 1; i < Shader::MAX_PROFILES; ++i) { // Delete the old vertex shader output (if it exists). command = "del " + fxName + "." + msVProfileName[i] + ".txt"; system(command.c_str()); // Compile the vertex shader. command = "cgc -profile " + msVProfileName[i]; if (i == 1) { // VS_1_1 requires profile options for DX9 not to barf when // trying to assemble the program. command += " -profileopts dcls"; } command += " -entry v_" + fxName + " -o " + fxName + "."; command += msVProfileName[i] + ".txt " + fxName + ".fx"; int cgVStatus = system(command.c_str()); // Delete the old pixel shader output (if it exists). command = "del " + fxName + "." + msPProfileName[i] + ".txt"; system(command.c_str()); // Compile the pixel shader. command = "cgc -profile " + msPProfileName[i]; command += " -entry p_" + fxName + " -o " + fxName + "."; command += msPProfileName[i] + ".txt " + fxName + ".fx"; int cgPStatus = system(command.c_str()); if (cgVStatus == 0 && cgPStatus == 0) { // At least one profile compiled. compileSucceeded = true; Messages.push_back("The profile pair " + msVProfileName[i] + " and " + msPProfileName[i] + " compiled.\n"); } else { // Delete the output file when only one of the shaders // compiled. if (cgVStatus == 0) { // The vertex shader compiled but the pixel shader did // not. command = "del " + fxName + "." + msVProfileName[i] + ".txt"; system(command.c_str()); } else { Messages.push_back("Profile " + msVProfileName[i] + " did not compile.\n"); } if (cgPStatus == 0) { // The pixel shader compiled but the vertex shader did // not. command = "del " + fxName + "." + msPProfileName[i]; command += ".txt"; system(command.c_str()); } else { Messages.push_back("Profile " + msPProfileName[i] + " did not compile.\n"); } Messages.push_back("The profile pair " + msVProfileName[i] + " and " + msPProfileName[i] + " did not compile.\n"); } } if (!compileSucceeded) { Messages.push_back("All profiles failed to compile.\n"); return; } } InitializeMaps(); Program vProgram[Shader::MAX_PROFILES]; Program pProgram[Shader::MAX_PROFILES]; for (int i = 1; i < Shader::MAX_PROFILES; ++i) { mActiveProfile = i; std::string inVName = fxName + "." + msVProfileName[i] + ".txt"; bool hasVProfile = Parse(inVName, msVProfileName[i], vProgram[i]); std::string inPName = fxName + "." + msPProfileName[i] + ".txt"; bool hasPProfile = Parse(inPName, msPProfileName[i], pProgram[i]); if (hasVProfile && hasPProfile) { if (mEffect == 0) { if (!CreateEffect(vProgram[i], pProgram[i])) { return; } } else { if (!UpdateEffect(vProgram[i], pProgram[i])) { return; } } } } if (mEffect) { mEffect->SaveWMFX(fxName + ".wmfx"); } }
std::unique_ptr<Effect> EffectManager::CreateEffect(std::vector<char> const& effect) { return CreateEffect(ByteArray(effect)); }
uint8_t* LoadMaterialInfo(const char* i_pFile, uint32_t& o_lengthOfWholerMaterialBuffer, uint32_t& o_lengthOfEffectPath) { o_lengthOfWholerMaterialBuffer = 0; o_lengthOfEffectPath = 0; if (!i_pFile) return nullptr; std::ifstream infile(i_pFile, std::ifstream::binary); if (!infile) { std::stringstream decoratedErrorMessage; decoratedErrorMessage << "Failed to load binary material file: " << i_pFile; ErrorMessageBox(decoratedErrorMessage.str().c_str()); return nullptr; } // get size of file infile.seekg(0, infile.end); std::ifstream::pos_type size = infile.tellg(); infile.seekg(0); // allocate memory for file content o_lengthOfWholerMaterialBuffer = (uint32_t)size; char* pBuffer = new char[o_lengthOfWholerMaterialBuffer]; // read content of infile infile.read(pBuffer, size); if (!infile) { std::stringstream decoratedErrorMessage; decoratedErrorMessage << "Failed to load all data from: " << i_pFile << ", only " << infile.gcount() << "could be load."; ErrorMessageBox(decoratedErrorMessage.str().c_str()); infile.close(); delete[] pBuffer; return nullptr; } uint32_t offset = 0; // First, set the convert the buffer to MaterialDesc* MaterialDesc* pMaterialDesc = (MaterialDesc*)((uint8_t*)pBuffer + offset); // Second, load the path of the effect file { // Remember that I did a tricky solution in the MaterialBuilder // that I use the _pEffect to save the offset of the Name in Effect // Because the size of the _handler will be different on x64 and x86, // so I really really should be careful about it. size_t offsetForEffectPathName = *(size_t*)(&pMaterialDesc->_pEffect); char* pathOfEffect = _strdup(pBuffer + offsetForEffectPathName); o_lengthOfEffectPath = (uint32_t)strlen(pBuffer + offsetForEffectPathName) + 1; pMaterialDesc->_pEffect = CreateEffect(pathOfEffect); free(pathOfEffect); } // Set the buffer of each segement UniformBlockDesc* pUniformBlockDescBuffer = nullptr; uint8_t* pUniformBlockNameBuffer = nullptr; UniformDesc* pUniformDescBuffer = nullptr; uint8_t* pUniformVariableValueBuffer = nullptr; uint8_t* pUniformVariableNameBuffer = nullptr; TextureDesc* pTextureDescBuffer = nullptr; uint8_t* pTexturePathBuffer = nullptr; uint8_t* pTextureSamplerNameBuffer = nullptr; { if (pMaterialDesc->_uniformBlockCount > 0) { pUniformBlockDescBuffer = pMaterialDesc->GetUniformBlockDesc(); pUniformBlockNameBuffer = (uint8_t*)pMaterialDesc + pMaterialDesc->_offsetOfUniformBlockNameBuffer; } if (pMaterialDesc->_uniformCount > 0) { pUniformDescBuffer = pMaterialDesc->GetUniformDesc(); pUniformVariableValueBuffer = (uint8_t*)pMaterialDesc + pMaterialDesc->_offsetOfUniformVariableValueBuffer; pUniformVariableNameBuffer = (uint8_t*)pMaterialDesc + pMaterialDesc->_offsetOfUniformVariableNameBuffer; } if (pMaterialDesc->_textureCount > 0) { pTextureDescBuffer = pMaterialDesc->GetTextureDesc(); pTexturePathBuffer = (uint8_t*)pMaterialDesc + pMaterialDesc->_offsetOfTexturePathBuffer; pTextureSamplerNameBuffer = (uint8_t*)pMaterialDesc + pMaterialDesc->_offsetOfTextureSamplerBuffer; } } // Third, Set each UniformDesc of this MaterialDesc for (uint32_t ubIndex = 0; ubIndex < pMaterialDesc->_uniformBlockCount; ++ubIndex) { UniformBlockDesc* pUBD = &pUniformBlockDescBuffer[ubIndex]; size_t offsetInNameBuffer = pUBD->_offsetInUniformBlockNameBuffer; const char* pUBName = (char*)(pUniformBlockNameBuffer + offsetInNameBuffer); uint32_t startIndex = pUBD->_startUniformDescIndex; uint32_t endIndex = pUBD->_endUniformDescIndex; // For the UniformVariable/UniformBlock, // we will save the instance of them in UniformDesc*/UniformBlock*. // Since we have scaned the Uniform Blocks when we were creating Effect, // we should be able to get their reference. if (strcmp(pUBName, "Default") == 0) // Add the default block members to be the Uniform Variables. { for (uint32_t uIndex = startIndex; uIndex <= endIndex; ++uIndex) { UniformDesc* pUD = &pUniformDescBuffer[uIndex]; size_t offsetInNameBuffer = pUD->_offsetInNameBuffer; const char* pUniformName = (char*)(pUniformVariableNameBuffer + offsetInNameBuffer); pUD->SetUniformVariable(pUniformName, pMaterialDesc->_pEffect); } } else // Add the undefault block members to be Uniform Blocks { UniformBlock* pUniformBlock = UniformBlockManager::GetInstance()->GetUniformBlock(pUBName); pUBD->_pUniformBlock = pUniformBlock; } } // Forth, Set each TextureDesc of this MaterialDesc for (uint32_t index = 0; index < pMaterialDesc->_textureCount; ++index) { TextureDesc* pTex = &pTextureDescBuffer[index]; { // Set the value of the Texture. size_t offsetInTexturePathBuffer = pTex->_offsetInSamplerNameBuffer; const char* pTexName = (char*)(pTexturePathBuffer + offsetInTexturePathBuffer); pTex->_pTextureInfo = TextureManager::GetInstance()->LoadTexture(pTexName); // Set the value of the samplerID tSamplerID offsetInSamplerNameBuffer = *(tSamplerID*)(&pTex->_samplerID); const char* pTexSamplerName = (char*)(pTextureSamplerNameBuffer + offsetInSamplerNameBuffer); pTex->_samplerID = pMaterialDesc->_pEffect->GetSamplerID(pTexSamplerName, pTex->_shaderType); } } //Finally, don't forget to close the file infile.close(); return reinterpret_cast<uint8_t*>(pBuffer); }