Skip to content

Shader Changes

Blixibon edited this page Dec 7, 2020 · 15 revisions

Shaders are used for rendering a scene on a user's GPU. The Source SDK comes with Source's shaders and allows modders to modify or add shaders to the engine.

As part of some of the new features covered in Graphical Changes, Mapbase changes common shaders used by most materials.

Normally, changing Source's shaders requires a lot of time, effort, and planning. Mapbase changes the shaders for many reasons, but part of it is to make common or easy changes accessible to users who wouldn't know how to implement them.

Even though Mapbase handles most of the heavy lifting, there is a steep and demanding caveat of modifying existing shaders which Mapbase users must know if they're using custom materials.

The Shader Caveat (IMPORTANT)

The Source SDK comes with the original shader source code and files which you could compile yourself, but Source doesn't actually allow modders to change existing shaders for security reasons. New shaders can be created using code from existing shaders, but existing shaders cannot be overwritten in the engine. This means things cannot be added to the existing LightmappedGeneric, but an identical shader called SDK_LightmappedGeneric could be created with its own changes. This is how Mapbase modifies Source's shaders. It uses custom SDK_ versions of the original shaders.

The problem is that materials still using the original shaders won't use Mapbase's shader changes, so in order to take advantage of these changes, all materials must be changed to use the custom shaders.

Some mods go for things like an automatic passthrough system, which means all materials are changed to the new shaders without requiring the modificaton of any VMT files. This is useful for when you can't easily change every VMT that could be used in-game, e.g. when there's tons of VMTs embedded in tons of MP maps, but that has problems like material proxies being lost or decals not working with it. It also increases loading times.

For Mapbase, we instead opted for renaming all of the shaders in the VMTs themselves, which is the most basic and tedious solution, but the end result is much more efficient than the alternative. This isn't really too much of a problem, as these are just the plain-text VMTs, not the actual texture VTFs. Mapbase also comes with converted versions of all of Half-Life 2/EP1/EP2's VMTs, neatly packed in VPKs and staying at only about 2-3 MB total, so you'd only have to worry about this if you're adding custom materials or mounting materials from another game/mod.

If you are using custom materials or mounting materials from another game/mod, the Mapbase Multi-Tool can automatically change all of the materials in a directory to the new shaders. It's recommended that you pack converted VMTs into a VPK file.

You could technically get away with using the original shaders if you don't need Mapbase's shader changes, as there's nothing inherently wrong with them, but they wouldn't look right if they're used alongside modded shaders because features like radial fog and projected texture changes would make their differences visible.

The only real outright requirement related to new shaders is that rope materials must use the SDK_Cable shader due to some other code changes that make the original Cable unusable.



Here's a list of vanilla Source shaders which Mapbase has custom SDK_ counterparts for:

  • LightmappedGeneric
  • VertexLitGeneric
  • UnlitGeneric
  • WorldVertexTransition
  • Water
  • Sprite
  • Refract
  • LightmappedReflective
  • WorldTwoTextureBlend
  • EyeRefract
  • Eyes
  • EyeGlint
  • Teeth
  • Cable
  • DepthWrite
  • DecalModulate
  • UnlitTwoTexture
  • MonitorScreen
  • ShatteredGlass

The majority of Mapbase's large-scale shader changes come from other projects or are based off of other versions of the engine. They're covered on the Graphical Changes article.

However, there's also a few other minor shader fixes covered below which originated from Mapbase itself.


$blendmodulatetexture fixes

Mapbase fixes $blendmodulatetexture not appearing under a flashlight, not working with transforms, and lets it show up in Hammer. It also uses the Alien Swarm SDK's version of the shader code.

You can find the VDC article here.


$phongdisablehalflambert

Mapbase ports this parameter from Alien Swarm, which allows $phong to be used without $halflambert being forced enabled.

You can find the VDC article for $phong here, which lists $phongdisablehalflambert.


$basetexturetransform2 on WorldVertexTransition in DX9

Mapbase adds $basetexturetransform2 to the DX9 version of the shader.

The issue was that $basetexturetransform2 actually only existed in the DirectX 8 version of the shader, simply not appearing in the DirectX 9 version. It's a strange anomaly and it's hard to decide whether Valve didn't think it was worth the trouble or literally just forgot. There's definitely a FIXME or two related to it.

Before this, $basetexture2 followed the original $basetexturetransform in DX9, so this only functions if you declare $basetexturetransform2 first:

$basetexturetransform2 "center .5 .5 scale 1 1 rotate 0 translate 0 0"

It doesn't work with $seamless_scale or the C17:EP1 brush phong.

Clone this wiki locally