IMaterial *CEngineSprite::GetMaterial( RenderMode_t nRenderMode, int nFrame ) { if ( nRenderMode == kRenderNone || nRenderMode == kRenderEnvironmental ) return NULL; if ( IsAVI() ) { avi->SetFrame( m_hAVIMaterial, nFrame ); return m_material[ 0 ]; // render mode is ignored for avi } #if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 ) if ( IsBIK() ) { bik->SetFrame( m_hBIKMaterial, nFrame ); return m_material[ 0 ]; // render mode is ignored for bink } #endif IMaterial *pMaterial = m_material[nRenderMode]; Assert( pMaterial ); if ( pMaterial == NULL ) return NULL; IMaterialVar* pFrameVar = pMaterial->FindVarFast( "$frame", &frameCache ); if ( pFrameVar ) { pFrameVar->SetIntValue( nFrame ); } return pMaterial; }
void CC_PickerShader ( const CCommand &args ) { C_BasePlayer *pPlayer = (C_BasePlayer *) C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return; trace_t tr; Vector vecAbsStart, vecAbsEnd, vecDir; AngleVectors( pPlayer->EyeAngles(), &vecDir ); vecAbsStart = pPlayer->EyePosition(); vecAbsEnd = vecAbsStart + (vecDir * MAX_TRACE_LENGTH); UTIL_TraceLine( vecAbsStart, vecAbsEnd, MASK_ALL, pPlayer, COLLISION_GROUP_NONE, &tr ); if ( tr.DidHitWorld() ) { IMaterial *pMaterial = materials->FindMaterial( tr.surface.name, TEXTURE_GROUP_PRECACHED ); if ( !IsErrorMaterial( pMaterial ) ) { const char* shadername = pMaterial->GetShaderName(); Msg("Material shader name: %s\n", shadername); } else { Msg("Could not get material shader name.\n"); } } else { Msg("This command only supports world geometry.\n"); } }
void RaceScene::Render() { if (mDeferredShading) { mVideoDriver->setDeferredShading(false); //mVideoDriver->setRenderTarget(mTireTrailTexture->getRenderTarget()); mVideoDriver->setRenderTargetAndDepthStencil(mTireTrailTexture->getRenderTarget(), mTireTrailDepthSurface); static const f32 color[] = { 1.0f, 1.0f, 1.0f, 1.0f }; mVideoDriver->clearRenderTarget(color); mVideoDriver->clearDepth(1.0f); mPlayerVehicle->renderTireTrail(); mVideoDriver->setDefaultRenderTargetAndDepthStencil(); IMaterial* terrainMaterial = mTerrainNode->getMaterial(); terrainMaterial->setTexture(4, mTireTrailTexture); mVideoDriver->setDeferredShading(true); mSceneManager->drawAll(); mVideoDriver->setDeferredShading(false); //mSceneManager->draw(mSceneManager->getSkyNode()); mSceneManager->draw(4); } else { mVideoDriver->setDeferredShading(false); mSceneManager->drawAll(); } }
IMaterial* GLGraphics::GetMaterial (const String& name, bool createIfMissing) { IMaterial* mat = 0; if (name.IsValid()) { mMaterials.Lock(); { for (uint i = 0; i < mMaterials.GetSize(); ++i) { mat = mMaterials[i]; if (mat != 0 && mat->GetName() == name) { mMaterials.Unlock(); return mat; } } if (createIfMissing) { GLMaterial* glMat = new GLMaterial(name); glMat->_SetGraphics(this); mMaterials.Expand() = glMat; mat = glMat; } else mat = 0; } mMaterials.Unlock(); } return mat; }
void CEngineSprite::SetFrame( RenderMode_t nRenderMode, int nFrame ) { if ( IsAVI() ) { avi->SetFrame( m_hAVIMaterial, nFrame ); return; } #if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 ) if ( IsBIK() ) { bik->SetFrame( m_hBIKMaterial, nFrame ); return; } #endif IMaterial *pMaterial = m_material[nRenderMode]; if ( !pMaterial ) return; IMaterialVar* pFrameVar = pMaterial->FindVarFast( "$frame", &frameCache ); if ( pFrameVar ) { pFrameVar->SetIntValue( nFrame ); } }
void CCoherentUISystem::ChangeEntityDiffuseTextureForMaterial( CCoherentViewListener* pViewListener, const char* entityName, const char* materialName ) { IMaterial* pMaterial = gEnv->p3DEngine->GetMaterialManager()->FindMaterial( materialName ); IEntity* pEntity = gEnv->pEntitySystem->FindEntityByName( entityName ); if ( pEntity && !pMaterial ) { pMaterial = pEntity->GetMaterial(); } if ( pMaterial ) { STexSamplerRT& sampler = pMaterial->GetShaderItem().m_pShaderResources->GetTexture( EFTT_DIFFUSE )->m_Sampler; // Create a new texture and scrap the old one void* pD3DTextureDst = NULL; ITexture* pCryTex = gD3DSystem->CreateTexture( &pD3DTextureDst, sampler.m_pITex->GetWidth(), sampler.m_pITex->GetHeight(), 1, eTF_A8R8G8B8, FT_USAGE_DYNAMIC ); int oldTextureID = sampler.m_pITex->GetTextureID(); gEnv->pRenderer->RemoveTexture( oldTextureID ); sampler.m_pITex = pCryTex; pCryTex->AddRef(); pViewListener->SetTexture( pD3DTextureDst, pCryTex->GetTextureID() ); } }
//----------------------------------------------------------------------------- // Purpose: Updates and renders all effects //----------------------------------------------------------------------------- int C_HopwireExplosion::DrawModel( int flags ) { AddParticles(); #ifndef C17 CMatRenderContextPtr pRenderContext( materials ); pRenderContext->Flush(); UpdateRefractTexture(); IMaterial *pMat = materials->FindMaterial( "effects/strider_pinch_dudv", TEXTURE_GROUP_CLIENT_EFFECTS ); float refract = m_FXCoreAlpha.Interp( gpGlobals->curtime ); float scale = m_FXCoreScale.Interp( gpGlobals->curtime ); IMaterialVar *pVar = pMat->FindVar( "$refractamount", NULL ); pVar->SetFloatValue( refract ); pRenderContext->Bind( pMat, (IClientRenderable*)this ); float sin1 = sinf( gpGlobals->curtime * 10 ); float sin2 = sinf( gpGlobals->curtime ); float scaleY = ( sin1 * sin2 ) * 32.0f; float scaleX = (sin2 * sin2) * 32.0f; // FIXME: The ball needs to sort properly at all times static color32 white = {255,255,255,255}; DrawSpriteTangentSpace( GetRenderOrigin() + ( CurrentViewForward() * 128.0f ), scale+scaleX, scale+scaleY, white ); #endif return 1; }
// Level init, shutdown void CPixelVisibilitySystem::LevelInitPreEntity() { bool fastqueries = HasFastQueries(); // printf("\n ** fast queries: %s **", fastqueries?"true":"false" ); m_hwCanTestGlows = r_dopixelvisibility.GetBool() && fastqueries && engine->GetDXSupportLevel() >= 80; if ( m_hwCanTestGlows ) { CMatRenderContextPtr pRenderContext( materials ); OcclusionQueryObjectHandle_t query = pRenderContext->CreateOcclusionQueryObject(); if ( query != INVALID_OCCLUSION_QUERY_OBJECT_HANDLE ) { pRenderContext->DestroyOcclusionQueryObject( query ); } else { m_hwCanTestGlows = false; } } m_pProxyMaterial = materials->FindMaterial("engine/occlusionproxy", TEXTURE_GROUP_CLIENT_EFFECTS); m_pProxyMaterial->IncrementReferenceCount(); m_pDrawMaterial = materials->FindMaterial("engine/occlusionproxy_countdraw", TEXTURE_GROUP_CLIENT_EFFECTS); m_pDrawMaterial->IncrementReferenceCount(); m_freeQueriesList = m_queryList.CreateList(); m_activeSetsList = m_setList.CreateList(); m_freeSetsList = m_setList.CreateList(); }
//----------------------------------------------------------------------------- // Purpose: Load any materials that reference this texture. Used so we can refresh a // material's preview image if a relevant .vtf changes. //----------------------------------------------------------------------------- void CTextureSystem::ReloadMaterialsUsingTexture( ITexture *pTestTexture ) { for ( int i=0; i < m_Textures.Count(); i++ ) { IEditorTexture *pEditorTex = m_Textures[i]; IMaterial *pMat = pEditorTex->GetMaterial( false ); if ( !pMat ) continue; IMaterialVar **pParams = pMat->GetShaderParams(); int nParams = pMat->ShaderParamCount(); for ( int iParam=0; iParam < nParams; iParam++ ) { if ( pParams[iParam]->GetType() != MATERIAL_VAR_TYPE_TEXTURE ) continue; ITexture *pTex = pParams[iParam]->GetTextureValue(); if ( !pTex ) continue; if ( pTex == pTestTexture ) { pEditorTex->Reload( true ); } } } }
void HSV_Select_SV::Paint() { surface()->DrawSetTexture(m_iMat); surface()->DrawSetColor(Color(255, 255, 255, 255)); int x, y, sx, sy; GetBounds(x, y, sx, sy); Vertex_t points[4]; points[0].m_TexCoord.Init(0, 0); points[1].m_TexCoord.Init(1, 0); points[2].m_TexCoord.Init(1, 1); points[3].m_TexCoord.Init(0, 1); IMaterial *pMatColorpicker = materials->FindMaterial("vgui/colorpicker", TEXTURE_GROUP_OTHER); if (IsErrorMaterial(pMatColorpicker)) return; bool bFound = false; IMaterialVar *pVar_00 = pMatColorpicker->FindVar("$COLOR_00", &bFound); IMaterialVar *pVar_10 = pMatColorpicker->FindVar("$COLOR_10", &bFound); IMaterialVar *pVar_11 = pMatColorpicker->FindVar("$COLOR_11", &bFound); IMaterialVar *pVar_01 = pMatColorpicker->FindVar("$COLOR_01", &bFound); if (!bFound) return; Vector col; HSV2RGB(m_flH, 1, 1, col); pVar_00->SetVecValue(1, 1, 1); pVar_10->SetVecValue(col.Base(), 3); pVar_11->SetVecValue(0, 0, 0); pVar_01->SetVecValue(0, 0, 0); surface()->DrawTexturedRect(0, 0, sx, sy); }
//-------------------------------------------------------------------------------------------------- // Name: CacheItemModel // Desc: Cache item model //-------------------------------------------------------------------------------------------------- void CFrontEndModelCache::CacheItemModel(const char* pItemName) { CItemSharedParams* pItemSharedParams = g_pGame->GetGameSharedParametersStorage()->GetItemSharedParameters(pItemName, false); if(pItemSharedParams) { const SGeometryDef* pGeomDef = pItemSharedParams->GetGeometryForSlot(eIGS_ThirdPerson); if(pGeomDef) { const char* pModelFileName = pGeomDef->modelPath.c_str(); FE_LOG ("Caching \"%s\" (for item '%s')", pModelFileName, pItemName); INDENT_LOG_DURING_SCOPE(); m_myGeometryCache.CacheGeometry(pModelFileName, false, IStatObj::ELoadingFlagsIgnoreLoDs); const char *pMaterialName = pGeomDef->material.c_str(); FE_LOG(" caching material '%s'", pMaterialName); IMaterial* pMaterial = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(pMaterialName); if(pMaterial) { m_materialCache.push_back(pMaterial); pMaterial->RequestTexturesLoading(0.0f); } } } else { GameWarning("Failed to find shared parameters for item '%s' - can't cache model", pItemName); } }//-------------------------------------------------------------------------------------------------
void OpenGLRenderManager::doRender(IVertexBuffer* _buffer, ITexture* _texture, size_t _count) { UIRenderable* pUIRenderable = static_cast<UIRenderable*>(_buffer); //unsigned int buffer_id = buffer->getBufferID(); //MYGUI_PLATFORM_ASSERT(buffer_id, "Vertex buffer is not created"); /*unsigned int texture_id = 0; if (_texture) { MyGuiOpenGLTexture* texture = static_cast<MyGuiOpenGLTexture*>(_texture); texture_id = texture->getTextureID(); //MYGUI_PLATFORM_ASSERT(texture_id, "Texture is not created"); } glBindTexture(GL_TEXTURE_2D, texture_id);*/ MyGuiOpenGLTexture* texture = static_cast<MyGuiOpenGLTexture*>(_texture); texture->bind(); //create material //std::string matName = pUIRenderable->getName(); //matName.append(" mat"); IMaterial *pMat = gEngModule->pMaterialMgr->create("Res/mat_util/ui.mtl"); pMat->setTexture(texture->getTexHandle(), 0); pUIRenderable->setMaterial(gEngModule->pMaterialMgr->getHandle("Res/mat_util/ui.mtl")); pUIRenderable->setRenderIndexValue(_count); gEngModule->pRenderSequence->pushToRenderSequence(pUIRenderable, RENDER_LAYER_UI); }
void CASWHudCrosshair::DrawSniperScope( int x, int y ) { C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer(); if ( !pPlayer ) return; C_ASW_Marine *pMarine = pPlayer->GetMarine(); if ( !pMarine ) return; const int NUM_CIRCLE_POINTS = 40; static vgui::Vertex_t points[ NUM_CIRCLE_POINTS ]; float width = YRES( asw_sniper_scope_radius.GetFloat() ); float height = YRES( asw_sniper_scope_radius.GetFloat() ); for ( int i = 0; i < NUM_CIRCLE_POINTS; i++ ) { float flAngle = 2.0f * M_PI * ( (float) i / (float) NUM_CIRCLE_POINTS ); points[ i ].Init( Vector2D( x + width * cos( flAngle ), y + height * sin( flAngle ) ), Vector2D( 0.5f + 0.5f * cos( flAngle ), 0.5f + 0.5f * sin( flAngle ) ) ); } surface()->DrawSetColor( Color(255,255,255,255) ); surface()->DrawSetTexture( m_nSniperMagnifyTexture ); IMaterial *pMaterial = materials->FindMaterial( "effects/magnifyinglens", TEXTURE_GROUP_OTHER ); IMaterialVar *pMagnificationCenterVar = pMaterial->FindVar( "$magnifyCenter", NULL ); float flCenterX = ( ( float )x / ( float )ScreenWidth() ) - 0.5f; float flCenterY = ( ( float )y / ( float )ScreenHeight() ) - 0.5f; pMagnificationCenterVar->SetVecValue( flCenterX, flCenterY, 0, 0 ); vgui::surface()->DrawTexturedPolygon( NUM_CIRCLE_POINTS, points ); }
void CSceneManager::collectMeshNodeShaders(IMeshNode* node) { // collect all the shaders ( for per-frame variables optimization) u32 subsetCount = node->getSubsetCount(); for (u32 i = 0; i < subsetCount; i++) { IMaterial* material = node->getMaterial(i); if (material) { for (u32 j = 0; j < material->getPipelineCount(); j++) { IPipeline* pipeline = material->getPipeline(j); if (pipeline) { for (u32 k = 0; k < EST_SHADER_COUNT; k++) { IShader* shader = pipeline->getShader((E_SHADER_TYPE)k); if (shader != nullptr) mActiveShaders.insert(shader); } } } } } }
void Entity::setMaterial(const std::string &name) { //setMaterial(name, 0); IMaterialMgr *pMatMgr = gEngModule->pMaterialMgr; MaterialHandle handle = pMatMgr->getHandle(name); IMaterial *pMat = 0; if (handle.isNull() == true) { IMaterial *pCreateMat = pMatMgr->create(name); if (pCreateMat != 0) { mMaterialHandle = pMatMgr->getHandle(name); pMat = pCreateMat; } } for (int i = 0; i < mSubRenderableVec.size(); ++i) { if (i == 0) { mSubRenderableVec[i]->setMaterial(mMaterialHandle); } else { SubMaterialVec subMaterialVec = pMat->getSubMaterialVec(); IMaterial *pSubMat = subMaterialVec[i - 1]; mSubRenderableVec[i]->setMaterial(pSubMat->getName()); } } }
bool CCamoMaterialProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues ) { return false; // hack! Need to make sure that the TGA loader has a valid filesystem before trying // to load the camo pattern. #if 0 // set how big our instance data is. SetInstanceDataSize( sizeof( CamoInstanceData_t ) ); #endif // remember what material we belong to. m_pMaterial = pMaterial; // get pointers to material vars. bool found; m_pCamoTextureVar = m_pMaterial->FindVar( "$baseTexture", &found ); if( !found ) { m_pCamoTextureVar = NULL; return false; } ITexture *pCamoTexture = m_pCamoTextureVar->GetTextureValue(); if (pCamoTexture) pCamoTexture->SetTextureRegenerator( &m_TextureRegen ); // Need to get the palettized texture to create the procedural texture from // somewhere. m_pCamoPatternTextureVar = m_pMaterial->FindVar( "$camoPatternTexture", &found ); if( !found ) { m_pCamoTextureVar = NULL; return false; } IMaterialVar *subBoundingBoxMinVar, *subBoundingBoxMaxVar; subBoundingBoxMinVar = m_pMaterial->FindVar( "$camoBoundingBoxMin", &found, false ); if( !found ) { m_SubBoundingBoxMin = Vector( 0.0f, 0.0f, 0.0f ); } else { subBoundingBoxMinVar->GetVecValue( m_SubBoundingBoxMin.Base(), 3 ); } subBoundingBoxMaxVar = m_pMaterial->FindVar( "$camoBoundingBoxMax", &found, false ); if( !found ) { m_SubBoundingBoxMax = Vector( 1.0f, 1.0f, 1.0f ); } else { subBoundingBoxMaxVar->GetVecValue( m_SubBoundingBoxMax.Base(), 3 ); } LoadCamoPattern(); GenerateRandomPointsInNormalizedCube(); return true; }
//------------------------------------------------------------------------------ // Purpose : Create leak effect if material requests it // Input : // Output : //------------------------------------------------------------------------------ void LeakEffect( trace_t &tr ) { Vector diffuseColor, baseColor; Vector vTraceDir = (tr.endpos - tr.startpos); VectorNormalize(vTraceDir); Vector vTraceStart = tr.endpos - 0.1*vTraceDir; Vector vTraceEnd = tr.endpos + 0.1*vTraceDir; IMaterial* pTraceMaterial = engine->TraceLineMaterialAndLighting( vTraceStart, vTraceEnd, diffuseColor, baseColor ); if (!pTraceMaterial) return; bool found; IMaterialVar *pLeakVar = pTraceMaterial->FindVar( "$leakamount", &found, false ); if( !found ) return; C_Splash* pLeak = new C_Splash(); if (!pLeak) return; ClientEntityList().AddNonNetworkableEntity( pLeak->GetIClientUnknown() ); IMaterialVar* pLeakColorVar = pTraceMaterial->FindVar( "$leakcolor", &found ); if (found) { Vector color; pLeakColorVar->GetVecValue(color.Base(),3); pLeak->m_vStartColor = pLeak->m_vEndColor = color; } IMaterialVar* pLeakNoiseVar = pTraceMaterial->FindVar( "$leaknoise", &found ); if (found) { pLeak->m_flNoise = pLeakNoiseVar->GetFloatValue(); } IMaterialVar* pLeakForceVar = pTraceMaterial->FindVar( "$leakforce", &found ); if (found) { float flForce = pLeakForceVar->GetFloatValue(); pLeak->m_flSpeed = flForce; pLeak->m_flSpeedRange = pLeak->m_flNoise * flForce; } pLeak->m_flSpawnRate = pLeakVar->GetFloatValue();; pLeak->m_flParticleLifetime = 10; pLeak->m_flWidthMin = 1; pLeak->m_flWidthMax = 5; pLeak->SetLocalOrigin( tr.endpos ); QAngle angles; VectorAngles( tr.plane.normal, angles ); pLeak->SetLocalAngles( angles ); pLeak->Start(&g_ParticleMgr, NULL); pLeak->m_flStopEmitTime = gpGlobals->curtime+5.0; pLeak->SetNextClientThink(gpGlobals->curtime+20.0); }
void NoSmoke::Cleanup() { for (auto material_name : smoke_materials) { IMaterial* mat = material->FindMaterial(material_name, TEXTURE_GROUP_OTHER); mat->SetMaterialVarFlag(MATERIAL_VAR_NO_DRAW, false); } }
//----------------------------------------------------------------------------- // Purpose: // Input : pDC - // dstRect - // detectErrors - //----------------------------------------------------------------------------- void CMaterial::DrawBrowserIcons( CDC *pDC, RECT& dstRect, bool detectErrors ) { static CMaterial* pTranslucentIcon = 0; static CMaterial* pOpaqueIcon = 0; static CMaterial* pSelfIllumIcon = 0; static CMaterial* pBaseAlphaEnvMapMaskIcon = 0; static CMaterial* pErrorIcon = 0; if (!pTranslucentIcon) { pTranslucentIcon = CreateMaterial("editor/translucenticon", true); pOpaqueIcon = CreateMaterial("editor/opaqueicon", true); pSelfIllumIcon = CreateMaterial("editor/selfillumicon", true); pBaseAlphaEnvMapMaskIcon = CreateMaterial("editor/basealphaenvmapmaskicon", true); pErrorIcon = CreateMaterial("editor/erroricon", true); Assert( pTranslucentIcon && pOpaqueIcon && pSelfIllumIcon && pBaseAlphaEnvMapMaskIcon && pErrorIcon ); } bool error = false; IMaterial* pMaterial = GetMaterial(); if ( pMaterial->GetMaterialVarFlag( MATERIAL_VAR_TRANSLUCENT ) ) { DrawIcon( pDC, pTranslucentIcon, dstRect ); if (detectErrors) { error = error || !m_TranslucentBaseTexture; } } else { DrawIcon( pDC, pOpaqueIcon, dstRect ); } if ( pMaterial->GetMaterialVarFlag( MATERIAL_VAR_SELFILLUM )) { DrawIcon( pDC, pSelfIllumIcon, dstRect ); if (detectErrors) { error = error || !m_TranslucentBaseTexture; } } if ( pMaterial->GetMaterialVarFlag( MATERIAL_VAR_BASEALPHAENVMAPMASK )) { DrawIcon( pDC, pBaseAlphaEnvMapMaskIcon, dstRect ); if (detectErrors) { error = error || !m_TranslucentBaseTexture; } } if (error) { DrawIcon( pDC, pErrorIcon, dstRect ); } }
void D3DRenderContext::AddToRenderingQueue(const IRenderable* renderableObjectPtr) { IMaterial* materialPtr = renderableObjectPtr->GetMaterial(); if (renderableObjectPtr->HasAlpha()) { m_alphaObjectsQueue[renderableObjectPtr->GetZ()][materialPtr->GetMaterialId()].push_back(renderableObjectPtr); } else { m_solidObjectsQueue[materialPtr->GetMaterialId()].push_back(renderableObjectPtr); } m_materials[materialPtr->GetMaterialId()] = materialPtr; }
//----------------------------------------------------------------------------- // Purpose: relayouts out the panel after any internal changes //----------------------------------------------------------------------------- void CMaterialViewPanel::PerformLayout() { // Get the current size, see if it's big enough to view the entire thing int iWidth, iHeight; GetSize( iWidth, iHeight ); // In the case of stretching, just stretch to the size and blow off // the scrollbars. Same holds true if there's no material if (!m_bUseActualSize || !m_pMaterial) { m_iViewableWidth = iWidth; m_iViewableHeight = iHeight; m_pHorizontalBar->SetVisible(false); m_pVerticalBar->SetVisible(false); return; } // Check the size of the material... int iMaterialWidth = m_pMaterial->GetMappingWidth(); int iMaterialHeight = m_pMaterial->GetMappingHeight(); // Check if the scroll bars are visible bool bHorizScrollVisible = (iMaterialWidth > iWidth); bool bVertScrollVisible = (iMaterialHeight > iHeight); m_pHorizontalBar->SetVisible(bHorizScrollVisible); m_pVerticalBar->SetVisible(bVertScrollVisible); // Shrink the bars if both are visible m_iViewableWidth = bVertScrollVisible ? iWidth - SCROLLBAR_SIZE - WINDOW_BORDER_WIDTH : iWidth; m_iViewableHeight = bHorizScrollVisible ? iHeight - SCROLLBAR_SIZE - WINDOW_BORDER_WIDTH : iHeight; // Set the position of the horizontal bar... if (bHorizScrollVisible) { m_pHorizontalBar->SetPos(0, iHeight - SCROLLBAR_SIZE); m_pHorizontalBar->SetSize( m_iViewableWidth, SCROLLBAR_SIZE ); m_pHorizontalBar->SetRangeWindow( m_iViewableWidth ); m_pHorizontalBar->SetRange( 0, iMaterialWidth ); // FIXME: Change scroll amount based on how much is not visible? m_pHorizontalBar->SetButtonPressedScrollValue( 5 ); } // Set the position of the vertical bar... if (bVertScrollVisible) { m_pVerticalBar->SetPos(iWidth - SCROLLBAR_SIZE, 0); m_pVerticalBar->SetSize(SCROLLBAR_SIZE, m_iViewableHeight); m_pVerticalBar->SetRangeWindow( m_iViewableHeight ); m_pVerticalBar->SetRange( 0, iMaterialHeight); m_pVerticalBar->SetButtonPressedScrollValue( 5 ); } }
//----------------------------------------------------------------------------- // Material precache //----------------------------------------------------------------------------- void CHLClient::PrecacheMaterial( const char *pMaterialName ) { bool bFound; IMaterial *pMaterial = materials->FindMaterial( pMaterialName, &bFound ); if ( bFound && pMaterial ) { pMaterial->IncrementReferenceCount(); m_CachedMaterials.AddToTail( pMaterial ); } }
//----------------------------------------------------------------------------- // Debugging aid to display a texture //----------------------------------------------------------------------------- static void OverlayShowTexture( const char* textureName, float scale ) { bool foundVar; IMaterial *pMaterial; IMaterialVar *BaseTextureVar; ITexture *pTex; float x, y, w, h; // ___error is created in code in CMaterialSystem::CreateDebugMaterials() pMaterial = materials->FindMaterial( "___error", TEXTURE_GROUP_OTHER, true ); BaseTextureVar = pMaterial->FindVar( "$basetexture", &foundVar, false ); if (!foundVar) return; CMatRenderContextPtr pRenderContext( materials ); if ( textureName && textureName[0] ) { pTex = materials->FindTexture( textureName, TEXTURE_GROUP_OTHER, false ); BaseTextureVar->SetTextureValue( pTex ); w = pTex->GetActualWidth() * scale; h = pTex->GetActualHeight() * scale; } else { w = h = 64.0f * scale; } // Center relative to current viewport int nViewportX, nViewportY, nViewportWidth, nViewportHeight; pRenderContext->GetViewport( nViewportX, nViewportY, nViewportWidth, nViewportHeight ); x = ( nViewportWidth - w ) * 0.5f; y = ( nViewportHeight - h ) * 0.5f; pRenderContext->Bind( pMaterial ); IMesh* pMesh = pRenderContext->GetDynamicMesh( true ); CMeshBuilder meshBuilder; meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); meshBuilder.Position3f( x, y, 0.0f ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x+w, y, 0.0f ); meshBuilder.TexCoord2f( 0, 1.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x+w, y+h, 0.0f ); meshBuilder.TexCoord2f( 0, 1.0f, 1.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x, y+h, 0.0f ); meshBuilder.TexCoord2f( 0, 0.0f, 1.0f ); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); }
void CGameVolume_Water::SetupVolume() { IGameVolumes::VolumeInfo volumeInfo; if (GetVolumeInfoForEntity(GetEntityId(), volumeInfo) == false) return; if (volumeInfo.verticesCount < 3) return; WaterProperties waterProperties(GetEntity()); if(waterProperties.isRiver) { if(volumeInfo.verticesCount < 4 || volumeInfo.verticesCount % 2 != 0) return; int numSegments = (volumeInfo.verticesCount / 2) - 1; m_segments.resize(numSegments); for(int i = 0; i < numSegments; ++i) { SetupVolumeSegment(waterProperties, i, &volumeInfo.pVertices[0], volumeInfo.verticesCount); } } else { SetupVolumeSegment(waterProperties, 0, &volumeInfo.pVertices[0], volumeInfo.verticesCount); } #if CRY_PLATFORM_WINDOWS && !defined(_RELEASE) { if (gEnv->IsEditor()) { IEntity* pEnt = GetEntity(); IMaterial* pMat = pEnt ? pEnt->GetMaterial() : 0; if (pMat) { const SShaderItem& si = pMat->GetShaderItem(); if (si.m_pShader && si.m_pShader->GetShaderType() != eST_Water) { CryWarning(VALIDATOR_MODULE_3DENGINE, VALIDATOR_ERROR, "Incorrect shader set for water / water fog volume \"%s\"!", pEnt->GetName()); } } } } #endif m_baseMatrix = GetEntity()->GetWorldTM(); m_initialMatrix = m_baseMatrix; m_volumeDepth = waterProperties.depth; m_streamSpeed = waterProperties.streamSpeed; m_awakeAreaWhenMoving = waterProperties.awakeAreaWhenMoving; m_isRiver = waterProperties.isRiver; }
IMaterial* IMaterialManager::CreateMaterial(N_UID matName,const N_MaterialDesc& matDesc) { if (matName == mDefaultMatName) { ERROR_MSG("CreateMaterial: uid occupied (by default material, how lucky you are- -.)"); return nullptr; } IMaterial* pMat = IFactory<IMaterial>::CreateObject(matName); pMat->SetDesc(matDesc); return pMat; }
bool CResourceLoader::loadMaterial(const std::string& fullpath, const IResourceXmlParser::SMaterialCreateParams& createParams) const { IMaterial* material = mMaterialManager->get(createParams.Name); if (material) { GF_PRINT_CONSOLE_INFO("Material '%s' (in the file '%s') has already been loaded. It can't been loaded again. \ Do you put materials with same names in material files ?\n", createParams.Name.c_str(), fullpath.c_str()); return false; } IPipeline* pipelines[8]; for (u32 i = 0; i < createParams.PipelineNames.size(); i++) { const std::string& pipelineName = createParams.PipelineNames[i]; IPipeline* pipeline = mPipelineManager->get(pipelineName); if (!pipeline) { GF_PRINT_CONSOLE_INFO("The pipeline named '%s' doesn't exist in material '%s' (file location: %s).\n", pipelineName.c_str(), createParams.Name.c_str(), fullpath.c_str()); return false; } pipelines[i] = pipeline; } material = mMaterialManager->create(createParams.Name, createParams.MaterialColors, pipelines, createParams.PipelineNames.size()); if (!material) { GF_PRINT_CONSOLE_INFO("The material named '%s' created failed! ( file location: %s ).\n", createParams.Name.c_str(), fullpath.c_str()); return false; } for (u32 i = 0; i < createParams.TextureParams.size(); i++) { ITexture* texture = mTextureManager->get(createParams.TextureParams[i].Name); if (!texture) { GF_PRINT_CONSOLE_INFO("Texture '%s' doesn't exist in material '%s'. (file location: %s).\n", createParams.TextureParams[i].Name.c_str(), createParams.Name.c_str(), fullpath.c_str()); } else { material->setTexture(createParams.TextureParams[i].Index, texture); } } return true; }
//----------------------------------------------------------------------------- // Creates, destroys particles attached to an attachment //----------------------------------------------------------------------------- void C_EnvParticleScript::CreateParticle( const char *pAttachmentName, const char *pSpriteName ) { // Find the attachment int nAttachment = LookupAttachment( pAttachmentName ); if ( nAttachment <= 0 ) return; // Get the sprite materials PMaterialHandle hMat = m_ParticleEffect.FindOrAddMaterial( pSpriteName ); ParticleScriptParticle_t *pParticle = (ParticleScriptParticle_t*)m_ParticleEffect.AddParticle(sizeof(ParticleScriptParticle_t), hMat); if ( pParticle == NULL ) return; // Get the sprite size from the material's materialvars bool bFound = false; IMaterialVar *pMaterialVar = NULL; IMaterial *pMaterial = ParticleMgr()->PMaterialToIMaterial( hMat ); if ( pMaterial ) { pMaterialVar = pMaterial->FindVar( "$spritesize", &bFound, false ); } if ( bFound ) { pParticle->m_flSize = pMaterialVar->GetFloatValue(); } else { pParticle->m_flSize = 100.0f; } // Make sure the particle cull size reflects our particles if ( pParticle->m_flSize > m_flMaxParticleSize ) { m_flMaxParticleSize = pParticle->m_flSize; m_ParticleEffect.SetParticleCullRadius( m_flMaxParticleSize ); } // Place the particle on the attachment specified pParticle->m_nAttachment = nAttachment; QAngle vecAngles; GetAttachment( nAttachment, pParticle->m_Pos, vecAngles ); if ( m_flSequenceScale != 1.0f ) { pParticle->m_Pos -= GetAbsOrigin(); pParticle->m_Pos *= m_flSequenceScale; pParticle->m_Pos += GetAbsOrigin(); } }
//----------------------------------------------------------------------------- // Purpose: // Input : filter - // delay - // pos - // player - // entity - //----------------------------------------------------------------------------- void TE_PlayerDecal( IRecipientFilter& filter, float delay, const Vector* pos, int player, int entity ) { if ( cl_playerspraydisable.GetBool() ) return; // No valid target? C_BaseEntity *ent = cl_entitylist->GetEnt( entity ); if ( !ent ) return; // Find player logo for shooter player_info_t info; engine->GetPlayerInfo( player, &info ); // Make sure we've got the material for this player's logo char texname[ 512 ]; IMaterial *logo = CreateTempMaterialForPlayerLogo( player, &info, texname, 512 ); if ( !logo ) return; ITexture *texture = materials->FindTexture( texname, TEXTURE_GROUP_DECAL ); if ( IsErrorTexture( texture ) ) { return; // not found } // Update the texture used by the material if need be. bool bFound = false; IMaterialVar *pMatVar = logo->FindVar( "$basetexture", &bFound ); if ( bFound && pMatVar ) { if ( pMatVar->GetTextureValue() != texture ) { pMatVar->SetTextureValue( texture ); logo->RefreshPreservingMaterialVars(); } } color32 rgbaColor = { 255, 255, 255, 255 }; effects->PlayerDecalShoot( logo, (void *)player, entity, ent->GetModel(), ent->GetAbsOrigin(), ent->GetAbsAngles(), *pos, 0, 0, rgbaColor ); }
//----------------------------------------------------------------------------- // Debugging aid to display a texture //----------------------------------------------------------------------------- static void OverlayShowTexture( const char* textureName, float scale ) { bool foundVar; IMaterial *pMaterial; IMaterialVar *BaseTextureVar; ITexture *pTex; float x, y, w, h; // screen safe x = 32; y = 32; pMaterial = materials->FindMaterial( "___debug", TEXTURE_GROUP_OTHER, true ); BaseTextureVar = pMaterial->FindVar( "$basetexture", &foundVar, false ); if (!foundVar) return; CMatRenderContextPtr pRenderContext( materials ); if ( textureName && textureName[0] ) { pTex = materials->FindTexture( textureName, TEXTURE_GROUP_OTHER, false ); BaseTextureVar->SetTextureValue( pTex ); w = pTex->GetActualWidth() * scale; h = pTex->GetActualHeight() * scale; } else { w = h = 64.0f * scale; } pRenderContext->Bind( pMaterial ); IMesh* pMesh = pRenderContext->GetDynamicMesh( true ); CMeshBuilder meshBuilder; meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); meshBuilder.Position3f( x, y, 0.0f ); meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x+w, y, 0.0f ); meshBuilder.TexCoord2f( 0, 1.0f, 0.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x+w, y+h, 0.0f ); meshBuilder.TexCoord2f( 0, 1.0f, 1.0f ); meshBuilder.AdvanceVertex(); meshBuilder.Position3f( x, y+h, 0.0f ); meshBuilder.TexCoord2f( 0, 0.0f, 1.0f ); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); }
void CPixelVisibilitySystem::LevelShutdownPostEntity() { m_pProxyMaterial->DecrementReferenceCount(); m_pProxyMaterial = NULL; m_pDrawMaterial->DecrementReferenceCount(); m_pDrawMaterial = NULL; DeleteUnusedSets(true); m_setList.Purge(); m_queryList.Purge(); m_freeQueriesList = m_queryList.InvalidIndex(); m_activeSetsList = m_setList.InvalidIndex(); m_freeSetsList = m_setList.InvalidIndex(); }