RS File commands explained

Lots of cool and useful tips to mod either serverside or clientside
Post Reply
User avatar
Apache Thunder
Posts: 1202
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA

RS File commands explained

Post by Apache Thunder »

At the request of Waldek and Swaffy, I have posted my explanation of all the commands I know of that are valid for use in the RS files. Swaffy made the suggestion of making this it's own topic, so I have. :D

So here's my breakdown on what I know about the RS files. If something is incorrect, don't be afraid to point it out. I am just going based on my own experience with these commands during my modding adventures. :P

The RS files define the "material" for the faces on a mesh ingame. RS files are only used with SM files and the terrain ( found in each level RFA). TM files (TreeMeshes) don't use RS files from what I can tell as they store the texture path in the TM file itself and don't allow any custom material settings. The only other geometry class able to use RS files is the SimpleGeom geometry class, but explaining that geometry class is best saved for a different topic. :D

Example of a valid material as defined in a RS file. This could be the only material in the RS file or it could be one of many. If a LOD mesh is exported with multiple materials then you'll find more then one in the RS file.

Code: Select all

subshader "decal_scorch01_m1_Material0" "StandardMesh/Default"
	lighting true;
	lightingSpecular false;
	materialDiffuse 0.588 0.588 0.588;
	texture "texture/Decal_scorch01_c";
	blendSrc sourceAlpha; 
	blendDest invsourceAlpha;
	transparent true;
	depthWrite false;

So now I will explain each line of code in the RS file.

Code: Select all

subshader "ExampleMesh_m1_Material0" "StandardMesh/Default"
This defines the "subshader" for a particular material used in a SM file. Each material always starts out with "subshader" proceeded by the material name and then the material type. After that the various shader commands are set up to define the properties for that material.

The first setting defines the name of the material defined in the SM file. It must match the material name in the SM file for it to work. That's how the game knows which material and thus which faces on the mesh that material should be applied to. BF2/BF2142 merged the material code into the mesh file so it's not as easy to minipulate. But in BF1942 (thankfully) this is all stored in the RS files.

If a SM file has a material not defined in the RS file, the game will use the default shader color on the material instead.

Example, in the init.con file the command that defines what color a broken shader will have. (in maps that don't have this command specified, the color will be black)

Code: Select all

shaderManager.setDefaultShaderSolidColor 0.2/0.2/0.2
(RGB float values)

Also, odd things happen if there's a missing/broken shader on a material that is lightmapped. The second half of the shader command defines the shader type. "StandardMesh/Default" is used by most/if not all SM files. "PatchTerrain/Water" is used exclusively with the water used on the terrain. (found in the file).

I would not recommend you attempt to use the PatchTerrain material type on a SM file as it can cause massive graphics bugs with nearby objects. The one exception is the SimpleGeom geometry class which does not induce this bug with SM files because unlike other geometry classes, this creates a geometry entirely with code and only uses a RS file to define the texture. So no SM file is loaded. Though this geometry class doesn't support alpha which results in water textures not looking correct on it. So it serves little use with this geometry type.

Code: Select all

lighting true;
Command Type: Boolean (True/False)

Enables lighting. Example: Sun light direction will light object but faces that are facing away from sun will not. Turning this off will result in all faces being lit the same. Though this will not impact it's behavior with the lightmapshadowbits.lsb file for the level. If the object goes into a shadowed region, it will still get darker. Also, if the object has a lightmap channel, then this command seems to have no effect on the mesh anymore.

Code: Select all

lightingSpecular true;
Command Type: Boolean (True/False)

This enables "shine" on a mesh. Typically used on vehicles. I think having a lightmap channel on the mesh will also cause this command to no longer function.

Code: Select all

materialDiffuse 1 1 1;
Command Type: Vector 3 Float Value (Red Green Blue)

Honestly for static objects anyway, I have seen this command have little impact on anything. Perhaps it only functions if lighting is disabled or when the mesh has no uvmap channel for the lightmap channel. It's a float value with 0 being lowest and 1 being highest. First number is for Red, second is Green, and third is for Blue. I'm thinking perhaps instead, this command defines to what degree the map's global DiffuseColor setting impacts the material in question. Same may hold true with the materialSpecular command.

Code: Select all

materialAmbient 1 1 1;
Command Type: Vector 3 Float Value (Red Green Blue)

Similar to mateialDiffuse. This is a little used command in Battlefield 1942. (in fact I don't think it's used anywhere in the vanilla files) It's used most often in a older game that uses the same game engine. Rallisport Challenge uses this on many of it's meshes. It uses the same number system as MaterialDiffuse and MaterialSpecular. I would have to assume this impacts the ambient color of the material. Basically sorta like a global brightness of the material.

Code: Select all

materialSpecular 1 1 1;
Command Type: Vector 3 Float Value (Red Green Blue)

Defines the color for the specular effect. Works in the same way as the MaterialDiffuse and MaterialAmbient commands.

Code: Select all

materialSpecularPower 10;
Command Type: Float Value

Defines the "power" or intensity of the specular effect used on the material. It's a single float value. Not limited to 0-1. You can use 40 as a value for example.

Code: Select all

texture "texture/YourTexture";
Command Type: String Value

Obviously this defines what texture to use. If you don't want a texture on a material, you can leave this command unspecified. The game would then use the default texture (usually 50% gray in vanilla BF1942).

Do not use the ../ method to attempt to path outside the RFAs. This will result in a CTD. Instead to path to an external texture (most commonly BIK files) use something like this: "Mods/YourMod/Movies/YourBIKFile.bik"

Code: Select all

envmap true;
Command Type: Boolean (True/False)

Enables the environment cube map. These are the 6 DDS files the level's RCM file assigns as a fake reflection of sorts. The alpha level in the texture defines the intensity of the reflection effect. The object does not need to have transparency enabled for this command to work. So it can add a reflection effect to both a transparent object (like a window) or a non transparent object like a vehicle's bumper chrome for example. Though the main requirement is that there be some degree of alpha in the texture file. Simply enabling this command won't instantly mean having a reflection on anything you want. You will also have to add alpha to the texture so the game knows how much of the material will be the reflection.

However note that it appears to no longer function on statics with a lightmap channel if transparency is disabled. Windows can still have the reflection effect because they have the "transparency true" command. But if this command is not specified or you don't want the material to have transparency, then you can't have environment map reflection for the lightmapped object in question.

Code: Select all

transparent true;
Command Type: Boolean (True/False)

Enables transparency. Is not the same as the alphaTestRef command. This allows full use of the alpha channel in a texture for gradual degrees of transparency. Do NOT enable this command on materials used on a AnimatedMesh geometry. It appears AnimatedMesh objects don't support this method of transparency and will become completely invisible if you attempt to use this. AlphaTestRef however still works for AnimatedMeshes, so your stuck using that if you want any alpha in your AnimatedMesh.

Code: Select all

AlphaTestRef 1;
Command Type: Float Value (0 through 1, though odd things happen if you use values above 1 or if you attempt to use negative values)

A single pixal in the alpha channel of a texture usually has a grayscale value of 0 through 255 with 255 being white and 0 being black. In BF1942, this means a pixel is 100% alpha at 0 and 0% alpha at 255. This command sets the "cut off point". A alphaTestRef value of 0.5 for example will have any transparency value above 50% become 100% transparent. If you want a completely invisible material, you can leave out all other commands and simply use alphaTestRef at a value of 1. It will make the material 100% alpha regardless what texture or lack of texture used on the material.

This command can be used in combination with the transparent command. But is most often used on it's own. Best used if you don't want any partial transparency on a material and want hard edges or need to enable simple transparency for AnimatedMeshes (since full transparency doesn't function correctly for AnimatedMeshes).

But if you want softer edges or partial transparency, you'll need to use the transparent command to enable that.

Code: Select all

depthwrite true;
Command Type: Boolean (True/False)

The default value for this command is true unless otherwise specified in the RS file. From what I can tell this alters how multiple transparent objects/materials blend with each other. Turning on depthwrite will result in any other partially transparent material/object becoming 100% transparent when viewed through a material with this command enabled Thus resulting in them becoming invisible.

However if you disable this command by specifying it with the false setting. This results in any material with partial alpha being visible through the material. HOWEVER! I've noticed with treeMeshes that they will not be obscured at all by the transparent material as a result so they appear to be "infront" of the mesh instead of behind it because the material isn't dimming or otherwise causing any obstruction to the rendering of the sprites/branches on a treeMesh.

Code: Select all

twosided true;
Command Type: Boolean (True/False)

This enables backfaces of a material to become visible. Useful for single sided faces you want to make double sided without having to create duplicate polygons via Gmax/3DS Max. Does not impact collision meshes, so if you want a double sided collision mesh face, you'll still need to export the mesh with the collision mesh having duplicate polygons with the normals flipped if you want the collision to be double sided. ;)

Same holds true for shadow meshes. You also have to manually create extra faces if you want them to be double sided. The exception being the AnimatedMeshes as they do not use a shadow mesh. They use the lowest detail LOD of a SM file for shadow generation. (Example, if you exported a animated Mesh with LOD01, LOD02, and LOD03, LOD03 will become the shadow mesh for the mesh. This is why removing the low detail lods from a soldier mesh for example will improve the shadow mesh accuracy in BF1942. Though I've noticed in Battlefield Vietnam they changed it so the game engine uses the first lod instead of the last. So shadows would look better in BFV.

Code: Select all

blendSrc sourceAlpha;
blendDest invsourceAlpha;
These alter the blend methods of transparent materials if the transparent command is enabled. I think these should be the valid options for both commands. (I think they can share these blend methods. So for example the blandDest command can use settings usually found used on the blendSrc command and vise versa): ("Two" does not appear to be a valid blend mode)


Code: Select all

texturefade true;
Command Type: Boolean (True/False)

This enables texture fade function. The geometry template must also define the distance for this fade to start at. (example: geometryTemplate.textureFadeMaxDist 70 )

So for example, with materials with the fade function enabled, if you are within the 70 meters defined by the textureFadeMaxDist command for the geometry template of the object, then the material is invisible. If however you move away from the object and begin to approach the 70 meters that command defines, the material "fades in" until it's 100% opaque (or as opaque as it's alpha channel allows if it has transparency enabled, though I've never seen the fade command used in combination with the transparent command, so I don't know if they even work correctly together).

Also if you are needed to make a material invisible and wish to save on file space you can do something like this and it will still work. :D

Code: Select all

subshader "ExampleMesh_m1_Material0" "StandardMesh/Default" { alphaTestRef 1; }
Pretty much all the commands could in theory be placed on the same line like above. But is pain to actually work with if using a normal text editor so Dice and most other modders place things on multiple lines. The semi-colon tells the game engine when the command ends and the { and } brackets define the group. Also you may have noticed the RS files found in a "Art" folder in some locations in the objects.rfa (example, most of the tanks in vanilla bf1942 have these RS files). I have no idea what purpose they served, but now they have no functional purpose. They aren't in the normal location in the StandardMesh RFA and thus not part of any mesh file.

If you look inside them, they use commands that no longer exist in BF1942. They also use "shader" instead of "subshader" to define the materials as well. Something else BF1942 doesn't support anymore. Perhaps they are left overs from early development.

Those are pretty much all the RS file commands I can recall off the top of my head. :P
I have cameras in your head!
User avatar
Posts: 1428
Joined: Fri Oct 16, 2009 4:21 pm
Location: UK

Re: RS File commands explained

Post by fo0k »

awesome. thanks will come back n read this with a coffee some day :)
Posts: 1
Joined: Sat Mar 07, 2020 7:10 pm

Re: RS File commands explained

Post by henk »

great post!
I'd like to add my knowledge to this thread. I see Apache added ALL material setting in his list. I only want to correct the BlendMode list he gave:
#### BlendModes for blendSrc and blendDest in .rs files ####
And concerning the use of materialDiffuse and materialSpecular:
I have the feeling that they (partly) overwrite or mix with these global settings:
renderer.diffuseColor [Vec3] -> Vec3
renderer.specularColor [Vec3] -> Vec3
Post Reply