//-----------------------------------------------------------------------------
// Will actually load the material bits
// We don't want to load them all at once because it takes way too long
//-----------------------------------------------------------------------------
bool CMaterial::LoadMaterial()
{
	bool bFound = true;
	if (!m_bLoaded)
	{
		m_bLoaded = true;

		IMaterial *pMat = materials->FindMaterial(m_szFileName, TEXTURE_GROUP_OTHER);
		if ( IsErrorMaterial( pMat ) )
			bFound = false;

		Assert( pMat );

		if (!pMat)
		{
			return false;
		}

		if (!LoadMaterialHeader(pMat))
		{
			// dvs: yeaaaaaaaaah, we're gonna disable this until the spew can be reduced
			//Msg( mwError,"Load material header failed: %s", m_szFileName );

			bFound = false;
			pMat = materials->FindMaterial("debug/debugempty", TEXTURE_GROUP_OTHER);

			if (pMat)
			{
				LoadMaterialHeader(pMat);
			}
		}
	}

	return bFound;
}
Example #2
0
void OverlayCameraRenderTarget( const char *pszMaterialName, float flX, float flY, float w, float h )
{
	float offsetS = ( 0.5f / 256.0f );
	float offsetT = ( 0.5f / 256.0f );
	IMaterial *pMaterial;
	pMaterial = materials->FindMaterial( pszMaterialName, TEXTURE_GROUP_OTHER, true );
	if( !IsErrorMaterial( pMaterial ) )
	{
		CMatRenderContextPtr pRenderContext( materials );
		pRenderContext->Bind( pMaterial );
		IMesh* pMesh = pRenderContext->GetDynamicMesh( true );

		CMeshBuilder meshBuilder;
		meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

		meshBuilder.Position3f( flX, flY, 0.0f );
		meshBuilder.TexCoord2f( 0, 0.0f + offsetS, 0.0f + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( flX+w, flY, 0.0f );
		meshBuilder.TexCoord2f( 0, 1.0f + offsetS, 0.0f + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( flX+w, flY+h, 0.0f );
		meshBuilder.TexCoord2f( 0, 1.0f + offsetS, 1.0f + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( flX, flY+h, 0.0f );
		meshBuilder.TexCoord2f( 0, 0.0f + offsetS, 1.0f + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.End();
		pMesh->Draw();
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
IMaterial *CreateTempMaterialForPlayerLogo( int iPlayerIndex, player_info_t *info, char *texname, int nchars )
{
	// Doesn't have a logo?
	if ( !info->customFiles[0] )	
		return NULL;

	IMaterial *logo = materials->FindMaterial( VarArgs("decals/playerlogo%2.2d", iPlayerIndex), TEXTURE_GROUP_DECAL );
	if ( IsErrorMaterial( logo ) )
		return NULL;

	char logohex[ 16 ];
	Q_binarytohex( (byte *)&info->customFiles[0], sizeof( info->customFiles[0] ), logohex, sizeof( logohex ) );

	// See if logo has been downloaded.
	Q_snprintf( texname, nchars, "temp/%s", logohex );
	char fulltexname[ 512 ];
	Q_snprintf( fulltexname, sizeof( fulltexname ), "materials/temp/%s.vtf", logohex );

	if ( !filesystem->FileExists( fulltexname ) )
	{
		char custname[ 512 ];
		Q_snprintf( custname, sizeof( custname ), "download/user_custom/%c%c/%s.dat", logohex[0], logohex[1], logohex );
		// it may have been downloaded but not copied under materials folder
		if ( !filesystem->FileExists( custname ) )
			return NULL; // not downloaded yet

		// copy from download folder to materials/temp folder
		// this is done since material system can access only materials/*.vtf files

		if ( !engine->CopyLocalFile( custname, fulltexname) )
			return NULL;
	}

	return logo;
}
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 CDAViewRender::PerformSlowMoEffect( const CViewSetup &view )
{
	C_DAPlayer *pPlayer = C_DAPlayer::GetLocalOrSpectatedPlayer();

	if ( !pPlayer )
		return;

	if (!da_postprocess_shaders.GetBool())
		return;

	if (!pPlayer->IsAlive())
		m_flStyleLerp = 0;

	ConVarRef da_postprocess_slowmo("da_postprocess_slowmo");
	ConVarRef da_postprocess_deathcam("da_postprocess_deathcam");
	ConVarRef da_postprocess_skill("da_postprocess_skill");
	ConVarRef da_postprocess_vr("da_postprocess_vr");

	da_postprocess_vr.SetValue(UseVR());

	if (pPlayer->IsStyleSkillActive())
		m_flStyleLerp = Approach(1, m_flStyleLerp, gpGlobals->frametime*2);
	else
		m_flStyleLerp = Approach(0, m_flStyleLerp, gpGlobals->frametime);

	bool bShowPostProcess = false;
	if (pPlayer->GetSlowMoMultiplier() < 1)
		bShowPostProcess = true;
	else if (m_flStyleLerp)
		bShowPostProcess = true;
	else if (!pPlayer->IsAlive() && pPlayer->GetObserverMode() == OBS_MODE_FREEZECAM)
		bShowPostProcess = true;
	else if (da_postprocess_compare.GetInt() || da_postprocess_slowmo.GetInt())
		bShowPostProcess = true;

	if (pPlayer->IsAlive())
		da_postprocess_deathcam.SetValue(false);
	else
		da_postprocess_deathcam.SetValue(true);

	da_postprocess_skill.SetValue(m_flStyleLerp);

	if (bShowPostProcess)
	{
		IMaterial *pMaterial = materials->FindMaterial( "shaders/slowmo", TEXTURE_GROUP_CLIENT_EFFECTS, true );

		if ( !IsErrorMaterial(pMaterial) )
		{
			if (da_postprocess_compare.GetInt() == 1)
				DrawScreenEffectMaterial( pMaterial, view.x, view.y, view.width/2, view.height );
			else
				DrawScreenEffectMaterial( pMaterial, view.x, view.y, view.width, view.height );
		}
	}
}
void Sepia( const CViewSetup &view )
{
	if (dev_post_sepia.GetInt() != 1)
		return;

	static IMaterial *pMaterialSepia = materials->FindMaterial( "postprocess/sepia", TEXTURE_GROUP_CLIENT_EFFECTS, true );

	if ( IsErrorMaterial( pMaterialSepia ))
		return;
	
	draw_pp_shader(view, pMaterialSepia);
}
void Vignette( const CViewSetup &view )
{
	if (dev_post_vignette.GetInt() != 1)
		return;

	static IMaterial *pMaterialVignette = materials->FindMaterial( "postprocess/vignette", TEXTURE_GROUP_CLIENT_EFFECTS, true );

	if ( IsErrorMaterial( pMaterialVignette ))
		return;
	
	draw_pp_shader(view, pMaterialVignette);
}
//-----------------------------------------------------------------------------
// Attach to a material
//-----------------------------------------------------------------------------
void CMaterialReference::Init( char const* pMaterialName, const char *pTextureGroupName, bool bComplain )
{
	IMaterial *pMaterial = materials->FindMaterial( pMaterialName, pTextureGroupName, bComplain);
	if( IsErrorMaterial( pMaterial ) )
	{
		if (IsOSX())
		{
			printf("\n ##### CMaterialReference::Init got error material for %s in tex group %s", pMaterialName, pTextureGroupName );
		}
	}

	Assert( pMaterial );
	Init( pMaterial );
}
Example #9
0
MaterialSystemMaterial_t FindMaterial( const char *materialName, bool *pFound, bool bComplain )
{
	IMaterial *pMat = g_pMaterialSystem->FindMaterial( materialName, TEXTURE_GROUP_OTHER, bComplain );
	MaterialSystemMaterial_t matHandle = pMat;
	
	if ( pFound )
	{
		*pFound = true;
		if ( IsErrorMaterial( pMat ) )
			*pFound = false;
	}

	return matHandle;
}
Example #10
0
static void OverlayWaterTexture( IMaterial *pMaterial, int xOffset, int yOffset, bool bFlip )
{
	// screen safe
	float xBaseOffset = IsPC() ? 0 : 32;
	float yBaseOffset = IsPC() ? 0 : 32;
	float offsetS = ( 0.5f / 256.0f );
	float offsetT = ( 0.5f / 256.0f );
	float fFlip0 = bFlip ? 1.0f : 0.0f;
	float fFlip1 = bFlip ? 0.0f : 1.0f;

	if( !IsErrorMaterial( pMaterial ) )
	{
		CMatRenderContextPtr pRenderContext( materials );
		pRenderContext->Bind( pMaterial );
		IMesh* pMesh = pRenderContext->GetDynamicMesh( true );

		float w = mat_wateroverlaysize.GetFloat();
		float h = mat_wateroverlaysize.GetFloat();

		CMeshBuilder meshBuilder;
		meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

		meshBuilder.Position3f( xBaseOffset + xOffset * w, yBaseOffset + yOffset * h, 0.0f );
		meshBuilder.TexCoord2f( 0, 0.0f + offsetS, fFlip1 + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( xBaseOffset + ( xOffset + 1 ) * w, yBaseOffset + yOffset * h, 0.0f );
		meshBuilder.TexCoord2f( 0, 1.0f + offsetS, fFlip1 + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( xBaseOffset + ( xOffset + 1 ) * w, yBaseOffset + ( yOffset + 1 ) * h, 0.0f );
		meshBuilder.TexCoord2f( 0, 1.0f + offsetS, fFlip0 + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( xBaseOffset + xOffset * w, yBaseOffset + ( yOffset + 1 ) * h, 0.0f );
		meshBuilder.TexCoord2f( 0, 0.0f + offsetS, fFlip0 + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.End();
		pMesh->Draw();
	}
}
Example #11
0
//-----------------------------------------------------------------------------
// Renders a material orthographically to screen...
//-----------------------------------------------------------------------------
static void RenderMaterial( const char *pMaterialName )
{
	// So it's not in the very top left
	float x = 100.0f, y = 100.0f;
	// float x = 0.0f, y = 0.0f;

	IMaterial *pMaterial = materials->FindMaterial( pMaterialName, TEXTURE_GROUP_OTHER, false );
	if ( !IsErrorMaterial( pMaterial ) )
	{
		CMatRenderContextPtr pRenderContext( materials );
		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.Color4ub( 255, 255, 255, 255 );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( x + pMaterial->GetMappingWidth(), y, 0.0f );
		meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
		meshBuilder.Color4ub( 255, 255, 255, 255 );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( x + pMaterial->GetMappingWidth(), y + pMaterial->GetMappingHeight(), 0.0f );
		meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
		meshBuilder.Color4ub( 255, 255, 255, 255 );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( x, y + pMaterial->GetMappingHeight(), 0.0f );
		meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
		meshBuilder.Color4ub( 255, 255, 255, 255 );
		meshBuilder.AdvanceVertex();

		meshBuilder.End();
		pMesh->Draw();
	}
}
Example #12
0
static void OverlayFrameBufferTexture( int nFrameBufferIndex )
{
	float offsetS = ( 0.5f / 256.0f );
	float offsetT = ( 0.5f / 256.0f );
	IMaterial *pMaterial;
	char buf[MAX_PATH];
	Q_snprintf( buf, MAX_PATH, "debug/debugfbtexture%d", nFrameBufferIndex );
	pMaterial = materials->FindMaterial( buf, TEXTURE_GROUP_OTHER, true );
	if( !IsErrorMaterial( pMaterial ) )
	{
		CMatRenderContextPtr pRenderContext( materials );
		pRenderContext->Bind( pMaterial );
		IMesh* pMesh = pRenderContext->GetDynamicMesh( true );

		float w = mat_framebuffercopyoverlaysize.GetFloat();
		float h = mat_framebuffercopyoverlaysize.GetFloat();

		CMeshBuilder meshBuilder;
		meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

		meshBuilder.Position3f( w * nFrameBufferIndex, 0.0f, 0.0f );
		meshBuilder.TexCoord2f( 0, 0.0f + offsetS, 0.0f + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( w * ( nFrameBufferIndex + 1 ), 0.0f, 0.0f );
		meshBuilder.TexCoord2f( 0, 1.0f + offsetS, 0.0f + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( w * ( nFrameBufferIndex + 1 ), h, 0.0f );
		meshBuilder.TexCoord2f( 0, 1.0f + offsetS, 1.0f + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.Position3f( w * nFrameBufferIndex, h, 0.0f );
		meshBuilder.TexCoord2f( 0, 0.0f + offsetS, 1.0f + offsetT );
		meshBuilder.AdvanceVertex();

		meshBuilder.End();
		pMesh->Draw();
	}
}
int C_NPC_Surface::DrawModel( int flags )
{
#if !defined( _X360 ) // X360TBD: Enable blobulator for EP3

	if (sv_surface_wireframe.GetBool())
	{
		if(sv_surface_material.GetInt() == 0) {
			m_pMaterial = materials->FindMaterial("shadertest/wireframe", TEXTURE_GROUP_OTHER);
		} else {
			m_pMaterial = materials->FindMaterial("shadertest/wireframevertexcolornocull", TEXTURE_GROUP_OTHER);
		}
	}
	else if (strlen( sv_surface_shader.GetString() ) > 0)
	{
		m_pMaterial = materials->FindMaterial( sv_surface_shader.GetString(), TEXTURE_GROUP_OTHER, true );
	}
	else
	{
		if(sv_surface_material.GetInt() == 0) {
			m_pMaterial = materials->FindMaterial( "models/debug/debugwhite", TEXTURE_GROUP_OTHER, true );
		} else if(sv_surface_material.GetInt() == 1) {
			m_pMaterial = materials->FindMaterial( "models/debug/debugwhite2", TEXTURE_GROUP_OTHER, true );
		} else if(sv_surface_material.GetInt() == 2) {
			m_pMaterial = materials->FindMaterial( "models/debug/debugwhite3", TEXTURE_GROUP_OTHER, true );
		} else if(sv_surface_material.GetInt() == 3) {
			m_pMaterial = materials->FindMaterial( "debug/debugvertexcolor", TEXTURE_GROUP_OTHER, true );
		} else if(sv_surface_material.GetInt() == 4) {
			m_pMaterial = materials->FindMaterial( "debug/env_cubemap_model", TEXTURE_GROUP_OTHER, true );
		} else if(sv_surface_material.GetInt() == 5) {
			m_pMaterial = materials->FindMaterial( "debug/env_cubemap_model_translucent_fountain", TEXTURE_GROUP_OTHER, true );
		} else if(sv_surface_material.GetInt() == 6) {
			m_pMaterial = materials->FindMaterial( "models/debug/debugmesh", TEXTURE_GROUP_OTHER, true );
		} else if(sv_surface_material.GetInt() == 7) {
			m_pMaterial = materials->FindMaterial( "models/debug/debugmesh_transparent", TEXTURE_GROUP_OTHER, true );
		} else if(sv_surface_material.GetInt() == 8) {
			m_pMaterial = materials->FindMaterial( "models/ihvtest/tongue_bumped", TEXTURE_GROUP_OTHER, true );
		} else if(sv_surface_material.GetInt() == 9) {
			m_pMaterial = materials->FindMaterial( "models/debug/debugbumps", TEXTURE_GROUP_OTHER, true );
		} else if(sv_surface_material.GetInt() == 10) {
			m_pMaterial = materials->FindMaterial( "debug/env_cubemap_model_translucent_no_bumps", TEXTURE_GROUP_OTHER, true );
		} else {
			//pMaterial = materials->FindMaterial( "effects/tp_refract", TEXTURE_GROUP_OTHER, true );
			//m_pMaterial = materials->FindMaterial( "debug/debugrefract", TEXTURE_GROUP_OTHER, true );
			//m_pMaterial = materials->FindMaterial( "shadertest/water_refract_only", TEXTURE_GROUP_OTHER, true );
			//m_pMaterial = materials->FindMaterial( "nature/sewer_water001", TEXTURE_GROUP_OTHER, true );
			
			m_pMaterial = materials->FindMaterial( "models/shadertest/predator", TEXTURE_GROUP_OTHER, true );
		}
	}

	Vector fountainOrigin(-1980, -1792, 1);
	if(sv_surface_fountain.GetBool())
	{
		modelrender->SetupLighting( fountainOrigin );
	}
	else
	{
		modelrender->SetupLighting( GetRenderOrigin() );
		//modelrender->SetupLighting( Vector(0,0,300) );
	}


	#define MAX_EXTRA_ELEMENTS 400
	static ImpParticle imp_particles[MAX_SURFACE_ELEMENTS + MAX_EXTRA_ELEMENTS]; // This doesn't specify alignment, might have problems with SSE
	int n_particles = 0;

	if(sv_surface_testshape.GetBool())
	{
		for (int i = -10; i <= 10; i++)
		{
			ImpParticle* imp_particle = &imp_particles[i+10];
			imp_particle->center.set(i*2.0f*m_flRadius, 0.0f, 0.0f);
			n_particles++;
		}
	}
	else
	{
		for (int i = 0 ; i < m_nActiveParticles; i++)
		{
			ImpParticle* imp_particle = &imp_particles[i];
			imp_particle->center = m_vecSurfacePos[i];
			imp_particle->setFieldScale( m_flSurfaceR[i] );
			imp_particle->interpolants[3] = m_flSurfaceV[i];
			n_particles++;
		}

		// This code adds a water surface to the fountain trough
		// using particles that oscillate up and down
		if(sv_surface_fountain.GetBool())
		{
			static float time = 0.0f;
			
			bool paused = m_vecSurfacePos[0] == lastPoint0Pos;
			lastPoint0Pos = m_vecSurfacePos[0]; //((CAI_BaseNPC::m_nDebugBits & bits_debugDisableAI) != 0);
			if(!paused) time += 0.1f;

			for (int i = -7; i <= 7; i++)
			for (int j = -7; j <= 7; j++)
			{
					ImpParticle* imp_particle = &imp_particles[n_particles++];
					imp_particle->center = fountainOrigin + Vector(i * 2.0f * m_flRadius, j * 2.0f * m_flRadius, 15.0f);
					float dist = sqrtf(sqr(imp_particle->center[0]) + sqr(imp_particle->center[1]));
					
					imp_particle->center[2] += 2.0f*sin(2.0f*time + 2.0f*dist);
					imp_particle->setFieldScale( 1.0f );
					imp_particle->interpolants[3] = 0.0f;
			}
			for (int i = -2; i <= 2; i++)
			for (int j = -2; j <= 2; j++)
			{
					ImpParticle* imp_particle = &imp_particles[n_particles++];
					imp_particle->center = fountainOrigin + Vector(i * 2.0f * m_flRadius, j * 2.0f * m_flRadius, 15.0f - 2.0f * m_flRadius);
					imp_particle->setFieldScale( 1.0f );
					imp_particle->interpolants[3] = 0.0f;
			}
			ImpParticle* imp_particle = &imp_particles[n_particles++];
			imp_particle->center = fountainOrigin + Vector(0.0f, 0.0f, 15.0f - 4.0f * m_flRadius);
			imp_particle->setFieldScale( 1.0f );
			imp_particle->interpolants[3] = 0.0f;
		}
	}



	if( !IsErrorMaterial( m_pMaterial ) )
	{
		if( !sv_surface_draw.GetBool())
		{
			Point3D eye = view->GetViewSetup()->origin;

			struct sortParticles_t
			{
				int no;
				float dist;
			};
			class C
			{
			public:
				static bool gt(sortParticles_t a, sortParticles_t b)
				{
					return a.dist < b.dist;
				}
			};
			SmartArray<sortParticles_t> sort_particles;
			sort_particles.ensureCapacity(n_particles);
			sort_particles.size = n_particles;
			for(int i = 0; i < n_particles; i++)
			{
				sort_particles[i].no = i;
				sort_particles[i].dist = imp_particles[i].center.length(eye);
			}
			sort_particles.sort<C>();

			CMatRenderContextPtr pRenderContext( materials );
			
			pRenderContext->MatrixMode( MATERIAL_MODEL );
			pRenderContext->Bind( m_pMaterial );

			IMesh* pMesh = pRenderContext->GetDynamicMesh( true );

			int vertMax = min( 24000 / 51, 32768 / (84 * 3) );

			int j = 0;
			// Msg( "point %.2f %.2f %.2f\n", m_vecSurfacePos[0].x, m_vecSurfacePos[0].y, m_vecSurfacePos[0].z );
			while (j < n_particles)
			{
				int total = min( n_particles - j, vertMax );

				CMeshBuilder meshBuilder;
				meshBuilder.Begin( pMesh, MATERIAL_TRIANGLES, total * 51, total * 84 * 3 );

				int i = 0;
				while (i < vertMax && j < n_particles)
				{
					ImpParticle* imp_particle = &imp_particles[sort_particles[j].no];
					if (imp_particle->scale > 0.01)
					{
						DrawFastSphere( meshBuilder, imp_particle->center.AsVector(), m_flRadius * imp_particle->scale, 255, 255, 255 );
						i++;
					}
					j++;
				}

				meshBuilder.End();
				pMesh->Draw();
			}
		}
		else
		{
			// Note: it is not good to have these static variables here.
			static RENDERER_CLASS* sweepRenderer = NULL;
			static ImpTiler* tiler = NULL;

			if(!sweepRenderer)
			{
				sweepRenderer = new RENDERER_CLASS();
				tiler = new ImpTiler(sweepRenderer);
			}

			tiler->setMaxNoTilesToDraw(sv_surface_max_tiles.GetInt());
			sweepRenderer->setMaxNoSlicesToDraw(sv_surface_max_slices.GetInt());

			RENDERER_CLASS::setCubeWidth(sv_blr_cubewidth.GetFloat());
			RENDERER_CLASS::setRenderR(sv_blr_render_radius.GetFloat());
			RENDERER_CLASS::setCutoffR(sv_blr_cutoff_radius.GetFloat());

			if(sv_surface_calc_uv_and_tan.GetBool())
			{
				RENDERER_CLASS::setCalcSignFunc(calcSign);
				RENDERER_CLASS::setCalcSign2Func(calcSign2);
				RENDERER_CLASS::setCalcCornerFunc(calcCornerNormalColorUVTan);
				RENDERER_CLASS::setCalcVertexFunc(calcVertexNormalNColorUVTan);
			}
			else if(sv_surface_calc_tan_only.GetBool())
			{
				RENDERER_CLASS::setCalcSignFunc(calcSign);
				RENDERER_CLASS::setCalcSign2Func(calcSign2);
				RENDERER_CLASS::setCalcCornerFunc(calcCornerNormalColorTanNoUV);
				RENDERER_CLASS::setCalcVertexFunc(calcVertexNormalNColorTanNoUV);
			}
			else if	(sv_surface_calc_color.GetBool())
			{
				RENDERER_CLASS::setCalcSignFunc(calcSign);
				RENDERER_CLASS::setCalcSign2Func(calcSign2);
				RENDERER_CLASS::setCalcCornerFunc(calcCornerNormalColor);
				RENDERER_CLASS::setCalcVertexFunc(calcVertexNormalNColor);
			}
			else if (sv_surface_calc_hifreq_color.GetBool())
			{
				RENDERER_CLASS::setCalcSignFunc(calcSign);
				RENDERER_CLASS::setCalcSign2Func(calcSign2);
				RENDERER_CLASS::setCalcCornerFunc(calcCornerNormalHiFreqColor);
				RENDERER_CLASS::setCalcVertexFunc(calcVertexNormalNColor);
			}
			else if (sv_surface_calc_tile_color.GetBool())
			{
				RENDERER_CLASS::setCalcSignFunc(calcSign);
				RENDERER_CLASS::setCalcSign2Func(calcSign2);
				RENDERER_CLASS::setCalcCornerFunc(calcCornerNormal);
				RENDERER_CLASS::setCalcVertexFunc(calcVertexNormalDebugColor);
			}
			else
			{
				RENDERER_CLASS::setCalcSignFunc(calcSign);
				RENDERER_CLASS::setCalcSign2Func(calcSign2);
				RENDERER_CLASS::setCalcCornerFunc(calcCornerNormal);
				RENDERER_CLASS::setCalcVertexFunc(calcVertexNormal);
			}
				

			Vector center; 
			if(sv_surface_testshape.GetBool())
			{
				center.Init(); // set center to 0,0,0
			}
			else if(sv_surface_fountain.GetBool())
			{
				center = fountainOrigin;
			}
			else
			{
				center.Init();

				if(sv_surface_center.GetBool())
				{
					for(int i = 0; i < m_nActiveParticles; i++)
					{
						center += m_vecSurfacePos[i];
					}
					center /= m_nActiveParticles;
				}
			}

			Vector transformedCenter = center * (1.0f/m_flRadius);

			CMatRenderContextPtr pRenderContext( materials );
			pRenderContext->MatrixMode( MATERIAL_MODEL );
			pRenderContext->Bind( m_pMaterial );
			pRenderContext->PushMatrix();
			pRenderContext->LoadIdentity();

			if(sv_surface_testshape.GetBool())
			{
				pRenderContext->Translate(-150.0f, 50.0f, 150.0f);
			}
			else
			{
				pRenderContext->Translate(center.x, center.y, center.z);
			}

			pRenderContext->Scale(m_flRadius, m_flRadius, m_flRadius);

			VMatrix rotationMatrix;
			VMatrix invRotationMatrix;
			Vector transformedEye;
			float angle = 0.0f;
			if(sv_surface_rotate.GetBool())
			{
				angle = view->GetViewSetup()->angles.y+180.0f;

				//ConMsg("Angle = %f\n", angle);
				pRenderContext->Rotate(angle, 0.0f, 0.0f, 1.0f);

				//VMatrix rotationMatrix2 = SetupMatrixAngles(view->GetViewSetup()->angles);
				//pRenderContext->MultMatrix(rotationMatrix2);
				//VMatrix rotationMatrix = rotationMatrix2.InverseTR(); //SetupMatrixAngles(-(view->GetViewSetup()->angles));

				rotationMatrix = SetupMatrixAxisRot(Vector(0.0f, 0.0f, 1.0f), -angle);
				invRotationMatrix = SetupMatrixAxisRot(Vector(0.0f, 0.0f, 1.0f), angle);
				Vector eye = view->GetViewSetup()->origin;
				transformedEye = (eye-center)*(1.0f/m_flRadius);
				transformedEye = rotationMatrix.ApplyRotation(transformedEye);
			}
			else
			{
				rotationMatrix.Identity();
				invRotationMatrix.Identity();
				transformedEye.Init();
				angle = 0.0f;
			}

			if(sv_surface_use_tiler.GetBool())
			{
				tiler->beginFrame(Point3D(0.0f, 0.0f, 0.0f), (void*)&pRenderContext, !(sv_surface_draw_margin.GetBool()));
			}
			else
			{
				sweepRenderer->beginFrame(!(sv_surface_draw_margin.GetBool()), (void*)&pRenderContext);
				sweepRenderer->setOffset(Point3D(0.0f, 0.0f, 0.0f));
				//sweepRenderer->beginTile();
			}

			for (int i = 0 ; i < n_particles; i++)
			{
				ImpParticle* imp_particle = &imp_particles[i];
				if(imp_particle->scale <= 0.1f) continue;

				Vector vParticle = imp_particle->center.AsVector();
				//vParticle.Init(imp_particle->center[0], imp_particle->center[1], imp_particle->center[2]);
				Vector transformedParticle = (vParticle-center) * (1.0f/m_flRadius);

				if(sv_surface_rotate.GetBool())
				{
					transformedParticle = rotationMatrix.ApplyRotation(transformedParticle);
				}

				Point3D pParticle = transformedParticle; 
				Point3D pCenter = transformedCenter;
				Point3D vec = (pParticle - pCenter);

				imp_particle->center = pParticle;
				//imp_particle->setFieldScale( max(1.2f - vec.length()/30.0f, 0.25f) );

				// interpolants[0..2] is the color. interpolants[3] is the v coordinate
				// imp_particle->interpolants[3] = min(max(1.4f - vec.length()/17.0f, 0.0f), 1.0f);
				// interpolants2[0..2] is the tangent vector.
				// interpolants3[0..2] and interpolants4[0..2] are the normal and
				// binormal which are used to generate a u coordinate
				imp_particle->interpolants2 = vec.unit();
				imp_particle->interpolants4.set(0.0f, 0.0f, -1.0f);
				imp_particle->interpolants3 = imp_particle->interpolants2.crossProduct(imp_particle->interpolants4);
				imp_particle->interpolants3.normalize();
				imp_particle->interpolants4 = imp_particle->interpolants2.crossProduct(imp_particle->interpolants3);
				imp_particle->interpolants4.normalize();
				
				if(sv_surface_use_tiler.GetBool())
				{
					tiler->insertParticle(imp_particle);
				}
				else
				{
					sweepRenderer->addParticle(imp_particle);
				}
			}

			if(sv_surface_use_tiler.GetBool())
			{
				if(sv_surface_tile.GetBool())
				{
					if(sv_surface_rotate.GetBool())
					{
						tiler->drawSurfaceSorted(Point3D(transformedEye));
					}
					else
					{
						tiler->drawSurface();
					}
				}
				else
				{
					tiler->drawTile(0,0,0);
				}
				tiler->endFrame();
			}
			else
			{
				sweepRenderer->endTile();
				sweepRenderer->endFrame();
			}

			if(sv_surface_max_tiles.GetInt() > 0 || sv_surface_tile.GetBool()==false)
			{
				//debugoverlay->AddBoxOverlay( fountainOrigin, Vector(-30, -30, -30), Vector(30, 30, 30), QAngle( 0, 0, 0 ), 0, 255, 0, 0, 0 );
				Vector overlayCenter = invRotationMatrix.ApplyRotation(tiler->getLastTilesOffset().AsVector() * m_flRadius);
				Vector mins = (tiler->getRenderDim() * (-0.5f* m_flRadius)).AsVector();
				Vector maxs = (tiler->getRenderDim() * (0.5f*m_flRadius)).AsVector();
				debugoverlay->AddBoxOverlay( overlayCenter + fountainOrigin, mins, maxs, QAngle( 0, angle, 0 ), 0, 255, 0, 0, 0 );

				if(sv_surface_max_slices.GetInt() > 0)
				{
					Vector sliceMins = mins;
					Vector sliceMaxs = maxs;
					sliceMins.x += (sweepRenderer->getLastSliceDrawn() - sweepRenderer->getMarginNCubes()) * sweepRenderer->getCubeWidth() * m_flRadius;
					sliceMaxs.x = sliceMins.x + sweepRenderer->getCubeWidth() * m_flRadius;
					
					debugoverlay->AddBoxOverlay( overlayCenter + fountainOrigin, sliceMins, sliceMaxs, QAngle( 0, angle, 0 ), 255, 0, 0, 0, 0 );
				}
			}

			pRenderContext->PopMatrix();
		}
	}

	#endif // !_X360

	return 1;
}
Example #14
0
int C_NEOPlayer::DrawModel( int flags )
{
	C_NEOPlayer* localPlayer = C_NEOPlayer::GetLocalNEOPlayer();

	int result = -1;

	if ( localPlayer )
	{
		if ( GetTeamNumber() == localPlayer->GetTeamNumber() )
			m_bUnknown = true;

		if ( m_iOldVision != 3 )
		{
			if ( m_bUnknown2 )
			{
				m_bUnknown2 = false;

				dlight_t* light = effects->CL_AllocDlight( LIGHT_INDEX_TE_DYNAMIC + index );

				light->origin = GetAbsOrigin();
				light->radius = 96.f;
				light->decay = 192.f;
				light->color.r = 64;
				light->color.g = 64;
				light->color.b = 255;
				light->color.exponent = 10;
				light->die = gpGlobals->curtime + 0.1f;

				return 0;
			}

			if ( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_0() )
				return 0;

			UpdateRefractTexture();

			IMaterial* thermopticMaterial = GetThermopticMaterial();

			UpdateThermopticMaterial( thermopticMaterial, m_flUnknown );

			modelrender->ForcedMaterialOverride( thermopticMaterial );
			result = BaseClass::InternalDrawModel( flags );
			modelrender->ForcedMaterialOverride( nullptr );
		}		

		else
		{
			if ( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_0() )
				return BaseClass::DrawModel( flags );

			IMaterial* matThermal = g_pMaterialSystem->FindMaterial( "dev/thermal", TEXTURE_GROUP_OTHER );

			if ( IsErrorMaterial( matThermal ) )
			{
				DevMsg( SPEW_MESSAGE, "F**k me...\n" ); // Their message, not mine kek
				BaseClass::DrawModel( flags );
			}

			bool found = false;
			IMaterialVar* matVar = matThermal->FindVar( "$eyevec", &found );

			if ( found )
			{
				Vector forward;
				GetVectors( &forward, nullptr, nullptr );
				matVar->SetVecValue( forward.x, forward.y, forward.z, 3.f );
			}

			modelrender->ForcedMaterialOverride( matThermal );
			result = BaseClass::InternalDrawModel( flags );
			modelrender->ForcedMaterialOverride( nullptr );
		}

		if ( m_iThermoptic == 1 )
		{
			if ( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_0() )
				return BaseClass::DrawModel( flags );

			IMaterial* matMotion = g_pMaterialSystem->FindMaterial( "dev/motion", TEXTURE_GROUP_OTHER );

			if ( IsErrorMaterial( matMotion ) )
			{
				DevMsg( SPEW_MESSAGE, "F**k me...\n" );
				BaseClass::DrawModel( flags );
			}

			float velocity = localPlayer->GetLocalVelocity().Length() / 75.f;

			if ( velocity > 4.f )
				velocity = 4.f;

			bool found = false;
			IMaterialVar* matVar = matMotion->FindVar( "$eyevec", &found );

			if ( found )
			{
				Vector forward;
				GetVectors( &forward, nullptr, nullptr );
				matVar->SetVecValue( forward.x, forward.y, forward.z, velocity );
			}

			modelrender->ForcedMaterialOverride( matMotion );
			result = BaseClass::InternalDrawModel( flags );
			modelrender->ForcedMaterialOverride( nullptr );
		}

		if ( m_iVision == 3 ) // Thermal vision
		{
			if ( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_0() )
				return BaseClass::DrawModel( flags );

			IMaterial* matThermal = g_pMaterialSystem->FindMaterial( "dev/vm_thermal", "Other textures" );

			if ( IsErrorMaterial( matThermal ) )
			{
				DevMsg( SPEW_MESSAGE, "F**k me...\n" );
				BaseClass::DrawModel( flags );
			}

			bool found = false;
			IMaterialVar* matVar = matThermal->FindVar( "$eyevec", &found );

			if ( found )
			{
				Vector forward;
				GetVectors( &forward, nullptr, nullptr );
				matVar->SetVecValue( forward.x, forward.y, forward.z, 3.f );
			}

			modelrender->ForcedMaterialOverride( matThermal );
			result = BaseClass::InternalDrawModel( flags );
			modelrender->ForcedMaterialOverride( nullptr );
		}

		if ( m_bUnknown2 )
			m_bUnknown2 = false;

		if ( result >= 0 )
			return result;
	}

	return BaseClass::DrawModel( flags );
}
Example #15
0
int SEditModelRender::MaterialPicker( char ***szMat )
{
	int mx, my;
#ifdef SOURCE_2006
	vgui::input()->GetCursorPos( mx, my );
#else
	vgui::input()->GetCursorPosition( mx, my );
#endif

	Vector ray;
	const CViewSetup *pViewSetup = view->GetPlayerViewSetup();
	float ratio =engine->GetScreenAspectRatio(
#ifdef SWARM_DLL
		pViewSetup->width, pViewSetup->height
#endif
		);

	ratio = ( 1.0f / ratio ) * (4.0f/3.0f);
	float flFov = ScaleFOVByWidthRatio( pViewSetup->fov, ratio );
	ScreenToWorld( mx, my, flFov, pViewSetup->origin, pViewSetup->angles, ray );

	Vector start = pViewSetup->origin;
	Vector end = start + ray * MAX_TRACE_LENGTH;
	trace_t tr;
	C_BaseEntity *pIgnore = input->CAM_IsThirdPerson() ? NULL : C_BasePlayer::GetLocalPlayer();
	UTIL_TraceLine( start, end, MASK_SOLID, pIgnore, COLLISION_GROUP_NONE, &tr );

	if ( !tr.DidHit() )
		return 0;

	int numMaterials = 0;
	IMaterial **MatList = NULL;
	studiohdr_t *pSHdr = NULL;

	if ( tr.DidHitWorld() )
	{
		if ( tr.hitbox == 0 )
		{
			Vector dummy;
			IMaterial *pMat = engine->TraceLineMaterialAndLighting( start, end, dummy, dummy );
			if ( pMat )
			{
				numMaterials = 1;
				MatList = new IMaterial*[1];
				MatList[0] = pMat;
			}
		}
		else
		{
			ICollideable *prop = staticpropmgr->GetStaticPropByIndex( tr.hitbox - 1 );
			if ( prop )
			{
				IClientRenderable *pRenderProp = prop->GetIClientUnknown()->GetClientRenderable();
				if ( pRenderProp )
				{
					const model_t *pModel = pRenderProp->GetModel();
					if ( pModel )
						pSHdr = modelinfo->GetStudiomodel( pModel );
				}
			}
		}
	}
	else if ( tr.m_pEnt )
	{
		const model_t *pModel = tr.m_pEnt->GetModel();
		if ( pModel )
			pSHdr = modelinfo->GetStudiomodel( pModel );
	}

	if ( pSHdr )
	{
		Assert( !numMaterials && !MatList );
		numMaterials = pSHdr->numtextures;
		const int numPaths = pSHdr->numcdtextures;

		if ( numMaterials )
		{
			CUtlVector< IMaterial* >hValidMaterials;
			for ( int i = 0; i < numMaterials; i++ )
			{
				mstudiotexture_t *pStudioTex = pSHdr->pTexture( i );
				const char *matName = pStudioTex->pszName();

				for ( int p = 0; p < numPaths; p++ )
				{
					char tmpPath[MAX_PATH];
					Q_snprintf( tmpPath, MAX_PATH, "%s%s\0", pSHdr->pCdtexture( p ), matName );
					Q_FixSlashes( tmpPath );
					IMaterial *pTempMat = materials->FindMaterial( tmpPath, TEXTURE_GROUP_MODEL );
					if ( !IsErrorMaterial( pTempMat ) )
					{
						hValidMaterials.AddToTail( pTempMat );
						break;
					}
				}
			}

			numMaterials = hValidMaterials.Count();
			if ( numMaterials )
			{
				MatList = new IMaterial*[ numMaterials ];
				for ( int i = 0; i < numMaterials; i++ )
					MatList[i] = hValidMaterials[i];
			}

			hValidMaterials.Purge();
		}
	}

	*szMat = new char*[ numMaterials ];

	int iTotalLength = 0;
	for ( int i = 0; i < numMaterials; i++ )
		iTotalLength += Q_strlen( MatList[i]->GetName() ) + 1;

	**szMat = new char[ iTotalLength ];

	int curpos = 0;
	for ( int i = 0; i < numMaterials; i++ )
	{
		const char *pszName = MatList[i]->GetName();

		int curLength = Q_strlen( pszName ) + 1;
		(*szMat)[ i ] = **szMat + curpos;
		Q_strcpy( (*szMat)[ i ], pszName );
		curpos += curLength;
	}

	if ( MatList )
		delete [] MatList;

	return numMaterials;
}
Example #16
0
//-----------------------------------------------------------------------------
// Draws all the debugging info
//-----------------------------------------------------------------------------
void CDebugViewRender::Draw2DDebuggingInfo( const CViewSetup &view )
{
	if ( IsX360() && IsRetail() )
		return;

	// HDRFIXME: Assert NULL rendertarget
	if ( mat_yuv.GetInt() && (engine->GetDXSupportLevel() >= 80) )
	{
		IMaterial *pMaterial;
		pMaterial = materials->FindMaterial( "debug/yuv", TEXTURE_GROUP_OTHER, true );
		if( !IsErrorMaterial( pMaterial ) )
		{
			DrawScreenEffectMaterial( pMaterial, view.x, view.y, view.width, view.height );
		}
	}

	if ( mat_hsv.GetInt() && (engine->GetDXSupportLevel() >= 90) )
	{
		IMaterial *pMaterial;
		pMaterial = materials->FindMaterial( "debug/hsv", TEXTURE_GROUP_OTHER, true );
		if( !IsErrorMaterial( pMaterial ) )
		{
			DrawScreenEffectMaterial( pMaterial, view.x, view.y, view.width, view.height );
		}
	}

	// Draw debugging lightmaps
	if ( mat_showlightmappage.GetInt() != -1 )
	{
		CLightmapDebugView clientView( assert_cast<CViewRender *>( ::view ) );
		clientView.Setup( view );
		clientView.Draw();
	}

	if ( cl_drawshadowtexture.GetInt() )
	{
		int nSize = cl_shadowtextureoverlaysize.GetInt();
		g_pClientShadowMgr->RenderShadowTexture( nSize, nSize );
	}

	const char *pDrawMaterial = cl_drawmaterial.GetString();
	if ( pDrawMaterial && pDrawMaterial[0] )
	{
		RenderMaterial( pDrawMaterial ); 
	}

	if ( mat_showwatertextures.GetBool() )
	{
		OverlayWaterTextures();
	}

	if ( mat_showcamerarendertarget.GetBool() )
	{
		float w = mat_wateroverlaysize.GetFloat();
		float h = mat_wateroverlaysize.GetFloat();
#ifdef PORTAL
		g_pPortalRender->OverlayPortalRenderTargets( w, h );
#else
		OverlayCameraRenderTarget( "debug/debugcamerarendertarget", 0, 0, w, h );
#endif
	}

	if ( mat_showframebuffertexture.GetBool() )
	{
		// HDRFIXME: Get rid of these rendertarget sets assuming that the assert at the top of this function is true.
		CMatRenderContextPtr pRenderContext( materials );
		pRenderContext->PushRenderTargetAndViewport( NULL );
		OverlayFrameBufferTexture( 0 );
		OverlayFrameBufferTexture( 1 );
		pRenderContext->PopRenderTargetAndViewport( );
	}

	const char *pDrawTexture = mat_drawTexture.GetString();
	if ( pDrawTexture && pDrawTexture[0] )
	{		
		OverlayShowTexture( pDrawTexture, mat_drawTextureScale.GetFloat() );
	}

#ifdef _X360
	if ( mat_drawColorRamp.GetBool() )
	{
		OverlayColorRamp( mat_drawColorRamp.GetInt() == 2 );
	}
#endif

	if ( r_flashlightdrawdepth.GetBool() )
	{
		shadowmgr->DrawFlashlightDepthTexture( );
	}

	if ( mat_drawTitleSafe.GetBool() )
	{
		OverlayTitleSafe();
	}
}
//-----------------------------------------------------------------------------
// 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 );

	// Doesn't have a logo
	 if ( !info.customFiles[0] )	
		return;

	IMaterial *logo = materials->FindMaterial( VarArgs("decals/playerlogo%2.2d", player), TEXTURE_GROUP_DECAL );
	if ( IsErrorMaterial( logo ) )
		return;

	char logohex[ 16 ];
	Q_binarytohex( (byte *)&info.customFiles[0], sizeof( info.customFiles[0] ), logohex, sizeof( logohex ) );

	// See if logo has been downloaded.
	char texname[ 512 ];
	Q_snprintf( texname, sizeof( texname ), "temp/%s", logohex );
	char fulltexname[ 512 ];
	Q_snprintf( fulltexname, sizeof( fulltexname ), "materials/temp/%s.vtf", logohex );

	if ( !filesystem->FileExists( fulltexname ) )
	{
		char custname[ 512 ];
		Q_snprintf( custname, sizeof( custname ), "downloads/%s.dat", logohex );
		// it may have been downloaded but not copied under materials folder
		if ( !filesystem->FileExists( custname ) )
			return; // not downloaded yet

		// copy from download folder to materials/temp folder
		// this is done since material system can access only materials/*.vtf files

		if ( !engine->CopyFile( custname, fulltexname) )
			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 );
}