User:Neverender

From Valve Developer Community
Revision as of 23:18, 6 March 2011 by Neverender (talk | contribs) (Created page with '==Notes== ===Compiler=== It's worth using Visual Studio 2005. In addition to the annoying little libcmtd/crtdbg hacks you have to do to build under VS 2008, code that links again…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Notes

Compiler

It's worth using Visual Studio 2005. In addition to the annoying little libcmtd/crtdbg hacks you have to do to build under VS 2008, code that links against Valve's public libraries and uses STL containers will outright crash when built in a debug configuration (see: vbsp). This is presumably due to ODR violations.

Shaders

Materials using custom shaders are not handled correctly by vbsp. Because vbsp does not load the game shader DLL, the material system falls back to Wireframe_DX6, and the surface is subsequently flagged as SURF_NOLIGHT. [1]

Tony mentions using a perl script to revert all materials to comparable standard shaders before map compilation. Here's my alternative, which is closer to what Marek proposed:

// vbsp, textures.cpp:181

	bool bSetBUMPLIGHT = g_BumpAll || GetMaterialShaderPropertyBool( matID, UTILMATLIB_NEEDS_BUMPED_LIGHTMAPS );
	bool bClearNOLIGHT = GetMaterialShaderPropertyBool( matID, UTILMATLIB_NEEDS_LIGHTMAP ) != 0;

	// HACK: Check to see if it's an unrecognized custom shader; probably needs lightmaps.
	{
		IMaterial* pMaterial = reinterpret_cast<IMaterial*>(matID);
		const char* shaderName = pMaterial->GetShaderName();

		if ( Q_strcmp("Wireframe_DX6", shaderName) == 0 )
		{
			bClearNOLIGHT = true;

			bool bFoundBump;
			pMaterial->FindVar( "$bump", &bFoundBump, false );
			if (bFoundBump)
			{
				bSetBUMPLIGHT = true;
				Msg( "xxx: Enabling bumped lightmap generation on material '%s'\n", pMaterial->GetName() );
			}
			else
			{
				Msg( "xxx: Enabling NON-bumped lightmap generation on material '%s'\n", pMaterial->GetName() );
			}
		}
	}

	if (bSetBUMPLIGHT)
		textureref[i].flags |= SURF_BUMPLIGHT;

	if (bClearNOLIGHT)
		textureref[i].flags &= ~SURF_NOLIGHT;
	else if ( !g_bLightIfMissing )
		textureref[i].flags |= SURF_NOLIGHT;