AVI Materials

From Valve Developer Community
Revision as of 19:41, 11 September 2006 by Ndnichols (talk | contribs) (First part of tutorial)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Under construction.png
This page is actively undergoing a major edit.
As a courtesy, please do not edit this while this message is displayed.
If this page has not been edited for at least several hours to a few days, please remove this template. This message is intended to help reduce edit conflicts; please remove it between editing sessions to allow others to edit the page.

The person who added this notice will be listed in its edit history should you wish to contact them.

Using Procedural Materials, it is possible to play movies (AVIs, specifically) in the place of materials in a map; using this technique, for example, you could have a movie theatre in your map that was actually displaying a full movie on the screen. While Source already allows you to easily view scripted events elsewhere in the map (using Point_cameras and func_monitors), this technique allows you to display actual movies from your harddrive. This code/mini-tutorial gives you everything you need to fairly easily add AVIMaterial entities to your map. Each entity controls drawing to a certain texture, and allows you to play a movie, pause the movie, change the movie, advance one frame, etc. This code draws heavily from the excellent Procedural_materials tutorial and code kindly provided from Valve (thanks again, Tom and Mike!)

Idea

Procedural_Materials allow you to identify certain materials as procedural meaning that its pixel values are set programmatically, as the level is running; conceptually, you get a 2d array of pixels representing the texture that you then set to be whatever color you want. In our case, we read in the appropriate frame of the movie (which frame is of course dependent on where we are in playback), read its pixels one-by-one, and write them to the texture. Since this is done roughly 60 times a second, we get a nice, smooth movie playback.

How to Install

Unfortunately, there is a fair amount of code to install, and some project settings to change. It's all fairly straight-forward, however, and I believe that if you follow these instructions everything should work correctly.

  1. Read the tutorial for procedural_materials. Everything in this tutorial builds off of that.
  1. Download this zip file. It has all the files necessary.
  1. Copy vf32.lib from C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib (or wherever your VS2003 is installed) to C:\MyMod\src\lib\public (changing the directory to be appropriate for your mod.) Add vf32.lib to the client project in Visual Studio. vfw32.lib is Video for Windows, which has the functions we'll use to read the AVI.
  1. Copy AVIMaterial.h and AVIMaterial.cpp to C:\MyMod\src\dlls. These files declare and define CAVIMaterial, the server-side entity that controls the movies.
  1. Copy c_aviMaterial.h, c_aviMaterial.cpp, AVIMaterialProxy.h, AVIMaterialProxy.cpp, AVIMaterialRegen.h, and AVIMaterial.cpp to C:\SecondCity\src\cl_dll. c_aviMaterial declares and defines C_AVIMaterial, the cleverly-named client-side version of CAVIMaterial. AVIMaterialProxy declares and defines CAviMaterialProxy which controls instances of CAviTextureRegen, which does the actual movie drawing.
  1. Add the entry in SecondCity.fgd to your mod's .fgd. This exposes our AVIMaterial entity to Hammer.
  1. Copy avi_panel1.vmt, avi_panel1.vtf, avi_panel2.vmt, and avi_panel2.vtf to your mod's materials directory. They go in the root.
  1. Copy quickone.vmf and quickone.bsp to your mod's maps directory. Again, they go in the root.
  1. Copy iran.avi and category.avi to the root of your c: drive. (If you don't want to put them there, feel free to put them somewhere else, just make sure to update the AVIMaterial entities in quickone to point at the right location.)
  1. Open Visual Studio, and add vfw32.lib to the client project. (Right-click on client->Add->Add Existing Item.)
  1. In Visual Studio, add c_aviMaterial.h, AVIMaterialProxy.h, and AVIMaterialRegen.h to the Header Files folder of your client project.
  1. In Visual Studio, add c_aviMaterial.cpp, AVIMaterialProxy.cpp, and AVIMaterialRegen.cpp to the Source Files folder of your client project.
  1. In Visual Studio, add AVIMaterial.h to the Header Files folder of your hl (server) project.
  1. In Visual Studio, add AVIMaterial.cpp to the Source Files folder of your hl (server) project.


How it works

How to use it

Potential improvements

Disclaimer