Caulk: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
Fidcal (talk | contribs)
New page: For details of ''caulk'' texture see Performance: Essential Must-Knows Category:Editing
 
Reviewed the section about applying caulk for the sake of performance
 
(43 intermediate revisions by 9 users not shown)
Line 1: Line 1:
For details of ''caulk'' texture see [[Performance: Essential Must-Knows]]
== Introduction ==
"Caulk" is an old word, in verb form meaning "to make a ship or building watertight by filling the seams between planks with oakum or other material driven snug". A ship not properly caulked could leak, slow down, and sink. Reputedly, this inspired id co-founder John Carmack to chose the name "caulk" for a substance to seal internal and external leaks. The original purposes of caulk in Doom were likely to help avoid game slow-downs, and to close off any accidental tiny leaks by plastering the whole outside with it. From [https://forums.thedarkmod.com/index.php?/topic/18030-the-origins-of-caulk/&tab=comments#comment-388327 The Origins of Caulk]


[[Category:Editing]]
In TDM, the noun "caulk" can be used in two senses:
# as a texture (found in textures/common/caulk), that appears pink/magenta in DR, but is not drawn in-game. Like other textures, it can be applied to the faces of brushes (worldspawns), func_statics, and so on.
# as a '''worldspawn brush''' with the caulk texture applied to one or typically all surfaces.
 
== Caulk considered dangerous ==
 
The very idea of caulk contradicts itself:
* (rendering) It is not rendered and does not cast shadows, thus it does '''not''' block neither view nor light.
* (area-portal graph) It is opaque and thus closes areas, meaning that it blocks both view and light.
 
It means that when you apply caulk, you cannot expect fully defined behavior in game.
The exact behavior depends on internal algorithms of the renderer, and may change between TDM versions due to engine improvements.
 
For example, caulk brushes inside doorway models are known to [https://forums.thedarkmod.com/index.php?/topic/22241-new-shadow-leaks-in-212-dev-builds/ break the new light portal flow optimizations] [https://bugs.thedarkmod.com/view.php?id=5172#c16126 #5172]. This issue is caused by the fact that stencil shadows are only generated from backfaces.
 
A related '''shadowcaulk material''' can fix this issue, because it casts shadows and thus blocks light rays in all regards.
But the contradiction in whether it blocks view or not still remains.
Perhaps it does not cause undefined behavior if the caulk geometry is fully surrounded by non-translucent geometry...
 
Another example: if occlusion culling happens in the future, it will most likely use all the world geometry as occluders, but most likely will '''not''' use all the models.
So if you cover a piece of the wall with caulk because it is invisible under a model, the objects behind this caulky hole will not be removed from rendering.
 
== Main Use of Caulk - for Separating Vis Leafs ==
It is the second meaning in which caulk is actually most useful: '''for defining and sealing, in conjunction with visportals, individual ''vis leaf'' areas of your map'''. This often takes the form of thin caulk-brush sheets sandwiched between non-brush opaque interior walls. Creating vis leafs is important to avoid unnecessary, performance-sucking rendering, and to provide more-plausible sound propagation. For more about this, see [[Visportals]] and [[Sound Propagation: Part 1]].
 
Other transparent "no draw" textures on brushes do not have the sealing property that caulk has.
 
== Another Important Use - Caulk Sky ==
[[Image:Caulk sky with portal sky cube.png|200px|thumb|right|Figure 1a. Looking up at a caulk sky with portal sky cube in DR.]] While most any opaque worldspawn brush can be used to seal against the void (as discussed in [[Performance: Essential Must-Knows]] and other places), to specifically create a sky, the external, void-facing brushes have two choices for texture:
* portal_sky (found in textures/smf/portal_sky)
* caulk
[[Image:Caulk sky in-game.jpg|200px|thumb|right|Figure 1b. Looking up at the same sky in-game.]]For a caulk sky, besides the caulk brushes themselves, you must have at least one surface anywhere in the rendered area with the portal_sky texture. For example, in Figure 1 (from a 2013 example by Obsttorte), this is done using an out-of-the-way portal_sky-textured cube brush. The engine will never render anything on the caulk brush surfaces themselves; they are merely views into the void, and the engine uses the portal_sky texture sample to "fill in" those views. Figure 1b shows the same "pit" scene, but in-game, at a different angle.
 
There are two main reasons traditionally why caulk sky was useful in TDM.
 
=== Non-Clipping of Objects that Extend Into the Void ===
Consider a map object that pierces an external brush of your map. Assume that (in order to compile without leak) its origin is within the rendered volume, either naturally or by adjustment. If the external brush has portal_sky on its interior, the map object (prior to TDM 2.05) will be clipped there. Sometimes, that's not what you want.
 
While caulk does not render, it does cut into other textures, but only if they are worldspawn. If you've converted them into func_statics, they will be rendered completely and not be cut off at the caulk surface. To ensure this happens, the func_static must reaching into the rendered area a bit. In Figure 1, the roof eaves at the pit lips are part of larger roof wedges that the player can see when jumping up. They are func_statics that extend into the void, but with origins in the pit's vis leaf. (If the game had multiple vis leafs from which to view the func_statics, they would appear unclipped from all.)
 
To summarize, caulk is transparent, and in-effect shows the portal_sky through it, as well as any func_statics that pierce it into your vis leaf.  That means you can cut a func_static house in half with a caulk brush, and still see both sides of it.  Using portal_sky, this was not possible until recently. However, since TDM 2.05, the default behavior of portal_sky regarding clipping is now similar to caulk.
 
For more, see [https://forums.thedarkmod.com/index.php?/topic/10003-so-what-are-you-working-on-right-now/page/178/&tab=comments#comment-311195 this forum post] and [http://bugs.thedarkmod.com/view.php?id=4635 this bug tracker entry about portal sky modes].
 
=== Atmospheric Fog ===
Dealing with fog effects is often tricky, particularly at the boundary of fog volume and sky. Portal_sky versus caulk sky can differ. Some starting points:
* A ''Fog Light'' with spawnarg "noFogBoundary" lets fog paint on solid surfaces, while leaving empty space and caulk sky free of fog effects.
* For more, see [[Light_Properties#Fog_Light | Fog Light]] and [https://forums.thedarkmod.com/index.php?/topic/15802-simulating-atmospheric-perspective Simulating Atmospheric Perspective].
 
== Other, Secondary Uses of Caulk as a Texture ==
=== As a DR Mapper Convenience ===
[[Image:caulk_image3.png|200px|thumb|right|Figure 2. Benefits of caulking as a mapping tool.]] Some mappers like to caulk the exterior (void-facing) surfaces of their maps. While unnecessary for game play (since the engine ignores those surfaces automatically), it benefits editing. By using the DR Caulk filter, the mapper can easily switch off the exterior surfaces and see inside the map to get a better vantage point. Image 2 shows the view:
* (''top'') if you don't caulk the exterior (and just leave it as a stone texture). It is difficult to get a good overhead view of the work. Unless you set up caulking (or one of the alternative methods), you have to either select and hide the exterior brushes or fly inside the map.
* (''middle'') if you do caulk the exterior, when the caulk filter is not active.
* (''bottom'') with the caulk filter activated, for a superior overhead view into the work.
 
Alternative non-caulk methods to do this include:
* using DR Layers. Move all the exterior brushes into their own Layer, and hide that layer.
* with any brush used as a Portal Sky, keeping that texture on all faces, and adding a custom DR "Portal Sky" filter
 
=== To Avoid Cost of Drawing Unseeable Polygons ===
Caulk can be used to skip drawing of: [[Image:caulk_image.png|200px|thumb|right|Figure 3. Caulk applied to a func_static window.]]
* back-surface polygons (tris) of a ''prop'' object, such as a door or window as in Figure 3. There, surfaces touching the wall are caulked, so are not drawn in game, saving tris. But GPU immediately drops all backfacing triangles anyway, so you won't notice any difference. Testing (detailed further below) shows that such caulking is not worth the effort.
* worldspawn brush surfaces entirely covered by detail work like patches.[[Image:caulk_image2.png|200px|thumb|right|Figure 4. Caulk applied to a unseeable worldspawn brush surface.]] See Figure 4. The player can never see the caulked surface because it's hidden by the func_static vault. However, stencil shadows can might get broken in this case (see [https://forums.thedarkmod.com/index.php?/topic/22241-new-shadow-leaks-in-212-dev-builds/ thread]), and there is no noticeable performance difference anyway.
 
=== Avoiding Z-Fighting ===
As just seen with the vault in Figure 4, caulking helps in certain circumstances. The caulked worldspawn surface does not "sparkle" or z-fight through the highest point of the vault, where the vault patch and the worldspawn brush are at equal height.
 
== Caulking of Hidden Surfaces to Improve Performance? - Discussion, Testing, and Analysis ==
=== Introduction ===
Every now and then, caulking arises in debates: is it useful and beneficial to performance to spend a lot of time object-caulking? And if so, how much caulk is required to get a solid impact on fps rate?
 
As Figure 3 indicated, to save a few polygons (tris), one can apply caulk on surfaces the player can never see in any circumstances, like wall-facing surfaces of prop windows and doors. This reduces the number of tris, and thus could potentially improve performance in some cases. But what does testing reveal?
 
===  Caulking That Cannot Affect Performance ===
There is no ''performance'' advantage to using caulk on any of these surfaces:
* worldspawn surfaces on the outside of the map in contact with the void
* worldspawn surfaces that are flush against another surface, for instance the bottom of a brush aligned with the floor.
 
Dmap compiler removes these surfaces automatically, so caulk texture is not needed.
 
=== Testing and Estimating the Effect of Caulking on Performance ===
Tests performed in 2010 by Sotha gave the following results.
 
Caulking a medium complex scene with tens of windows and other objects (Knighton Manor start) did NOT have any effect on fps counts. Caulking did save roughly 1000 tris, but this is not sufficient to cause any fps improvement. Also it was noticed that memory usage decreased : 1000 saved tris saved 0.6MB of memory. This is about the size of one 1K x 1K diffuse texture, so the difference is absolutely negligible.
 
Testing indicated that on a rather high-end computer (for 2010) an increase of 23000 tris, 75 draws and 2500 shdw reduced the fps count by two (stgatilov: relative to how many? was that additional geometry invisible?).
If a window consists of 5 brushes and the wall facing surfaces are caulked, this saves 5 surfaces and thus 10 tris per window. This would mean that 2300 windows should be caulked to get an improvement of 2fps. Basically this shows that caulking does not have much impact on modern hardware. However, on an older piece of hardware the amount of caulking needed for performance effect is lower, but even in this case it should be remembered that 1000 tris is roughly 20% of a single AI character.
 
=== Conclusion ===
Applying caulk on brushes for the purpose of optimization is simply not worth it.
And given that it can cause problems with TDM updates, better not do it.
 
{{editing}}
[[Category:Mapping Tutorials]]

Latest revision as of 21:22, 5 January 2024

Introduction

"Caulk" is an old word, in verb form meaning "to make a ship or building watertight by filling the seams between planks with oakum or other material driven snug". A ship not properly caulked could leak, slow down, and sink. Reputedly, this inspired id co-founder John Carmack to chose the name "caulk" for a substance to seal internal and external leaks. The original purposes of caulk in Doom were likely to help avoid game slow-downs, and to close off any accidental tiny leaks by plastering the whole outside with it. From The Origins of Caulk

In TDM, the noun "caulk" can be used in two senses:

  1. as a texture (found in textures/common/caulk), that appears pink/magenta in DR, but is not drawn in-game. Like other textures, it can be applied to the faces of brushes (worldspawns), func_statics, and so on.
  2. as a worldspawn brush with the caulk texture applied to one or typically all surfaces.

Caulk considered dangerous

The very idea of caulk contradicts itself:

  • (rendering) It is not rendered and does not cast shadows, thus it does not block neither view nor light.
  • (area-portal graph) It is opaque and thus closes areas, meaning that it blocks both view and light.

It means that when you apply caulk, you cannot expect fully defined behavior in game. The exact behavior depends on internal algorithms of the renderer, and may change between TDM versions due to engine improvements.

For example, caulk brushes inside doorway models are known to break the new light portal flow optimizations #5172. This issue is caused by the fact that stencil shadows are only generated from backfaces.

A related shadowcaulk material can fix this issue, because it casts shadows and thus blocks light rays in all regards. But the contradiction in whether it blocks view or not still remains. Perhaps it does not cause undefined behavior if the caulk geometry is fully surrounded by non-translucent geometry...

Another example: if occlusion culling happens in the future, it will most likely use all the world geometry as occluders, but most likely will not use all the models. So if you cover a piece of the wall with caulk because it is invisible under a model, the objects behind this caulky hole will not be removed from rendering.

Main Use of Caulk - for Separating Vis Leafs

It is the second meaning in which caulk is actually most useful: for defining and sealing, in conjunction with visportals, individual vis leaf areas of your map. This often takes the form of thin caulk-brush sheets sandwiched between non-brush opaque interior walls. Creating vis leafs is important to avoid unnecessary, performance-sucking rendering, and to provide more-plausible sound propagation. For more about this, see Visportals and Sound Propagation: Part 1.

Other transparent "no draw" textures on brushes do not have the sealing property that caulk has.

Another Important Use - Caulk Sky

Figure 1a. Looking up at a caulk sky with portal sky cube in DR.

While most any opaque worldspawn brush can be used to seal against the void (as discussed in Performance: Essential Must-Knows and other places), to specifically create a sky, the external, void-facing brushes have two choices for texture:

  • portal_sky (found in textures/smf/portal_sky)
  • caulk
Figure 1b. Looking up at the same sky in-game.

For a caulk sky, besides the caulk brushes themselves, you must have at least one surface anywhere in the rendered area with the portal_sky texture. For example, in Figure 1 (from a 2013 example by Obsttorte), this is done using an out-of-the-way portal_sky-textured cube brush. The engine will never render anything on the caulk brush surfaces themselves; they are merely views into the void, and the engine uses the portal_sky texture sample to "fill in" those views. Figure 1b shows the same "pit" scene, but in-game, at a different angle.

There are two main reasons traditionally why caulk sky was useful in TDM.

Non-Clipping of Objects that Extend Into the Void

Consider a map object that pierces an external brush of your map. Assume that (in order to compile without leak) its origin is within the rendered volume, either naturally or by adjustment. If the external brush has portal_sky on its interior, the map object (prior to TDM 2.05) will be clipped there. Sometimes, that's not what you want.

While caulk does not render, it does cut into other textures, but only if they are worldspawn. If you've converted them into func_statics, they will be rendered completely and not be cut off at the caulk surface. To ensure this happens, the func_static must reaching into the rendered area a bit. In Figure 1, the roof eaves at the pit lips are part of larger roof wedges that the player can see when jumping up. They are func_statics that extend into the void, but with origins in the pit's vis leaf. (If the game had multiple vis leafs from which to view the func_statics, they would appear unclipped from all.)

To summarize, caulk is transparent, and in-effect shows the portal_sky through it, as well as any func_statics that pierce it into your vis leaf. That means you can cut a func_static house in half with a caulk brush, and still see both sides of it. Using portal_sky, this was not possible until recently. However, since TDM 2.05, the default behavior of portal_sky regarding clipping is now similar to caulk.

For more, see this forum post and this bug tracker entry about portal sky modes.

Atmospheric Fog

Dealing with fog effects is often tricky, particularly at the boundary of fog volume and sky. Portal_sky versus caulk sky can differ. Some starting points:

Other, Secondary Uses of Caulk as a Texture

As a DR Mapper Convenience

Figure 2. Benefits of caulking as a mapping tool.

Some mappers like to caulk the exterior (void-facing) surfaces of their maps. While unnecessary for game play (since the engine ignores those surfaces automatically), it benefits editing. By using the DR Caulk filter, the mapper can easily switch off the exterior surfaces and see inside the map to get a better vantage point. Image 2 shows the view:

  • (top) if you don't caulk the exterior (and just leave it as a stone texture). It is difficult to get a good overhead view of the work. Unless you set up caulking (or one of the alternative methods), you have to either select and hide the exterior brushes or fly inside the map.
  • (middle) if you do caulk the exterior, when the caulk filter is not active.
  • (bottom) with the caulk filter activated, for a superior overhead view into the work.

Alternative non-caulk methods to do this include:

  • using DR Layers. Move all the exterior brushes into their own Layer, and hide that layer.
  • with any brush used as a Portal Sky, keeping that texture on all faces, and adding a custom DR "Portal Sky" filter

To Avoid Cost of Drawing Unseeable Polygons

Caulk can be used to skip drawing of:

Figure 3. Caulk applied to a func_static window.
  • back-surface polygons (tris) of a prop object, such as a door or window as in Figure 3. There, surfaces touching the wall are caulked, so are not drawn in game, saving tris. But GPU immediately drops all backfacing triangles anyway, so you won't notice any difference. Testing (detailed further below) shows that such caulking is not worth the effort.
  • worldspawn brush surfaces entirely covered by detail work like patches.
    Figure 4. Caulk applied to a unseeable worldspawn brush surface.
    See Figure 4. The player can never see the caulked surface because it's hidden by the func_static vault. However, stencil shadows can might get broken in this case (see thread), and there is no noticeable performance difference anyway.

Avoiding Z-Fighting

As just seen with the vault in Figure 4, caulking helps in certain circumstances. The caulked worldspawn surface does not "sparkle" or z-fight through the highest point of the vault, where the vault patch and the worldspawn brush are at equal height.

Caulking of Hidden Surfaces to Improve Performance? - Discussion, Testing, and Analysis

Introduction

Every now and then, caulking arises in debates: is it useful and beneficial to performance to spend a lot of time object-caulking? And if so, how much caulk is required to get a solid impact on fps rate?

As Figure 3 indicated, to save a few polygons (tris), one can apply caulk on surfaces the player can never see in any circumstances, like wall-facing surfaces of prop windows and doors. This reduces the number of tris, and thus could potentially improve performance in some cases. But what does testing reveal?

Caulking That Cannot Affect Performance

There is no performance advantage to using caulk on any of these surfaces:

  • worldspawn surfaces on the outside of the map in contact with the void
  • worldspawn surfaces that are flush against another surface, for instance the bottom of a brush aligned with the floor.

Dmap compiler removes these surfaces automatically, so caulk texture is not needed.

Testing and Estimating the Effect of Caulking on Performance

Tests performed in 2010 by Sotha gave the following results.

Caulking a medium complex scene with tens of windows and other objects (Knighton Manor start) did NOT have any effect on fps counts. Caulking did save roughly 1000 tris, but this is not sufficient to cause any fps improvement. Also it was noticed that memory usage decreased : 1000 saved tris saved 0.6MB of memory. This is about the size of one 1K x 1K diffuse texture, so the difference is absolutely negligible.

Testing indicated that on a rather high-end computer (for 2010) an increase of 23000 tris, 75 draws and 2500 shdw reduced the fps count by two (stgatilov: relative to how many? was that additional geometry invisible?). If a window consists of 5 brushes and the wall facing surfaces are caulked, this saves 5 surfaces and thus 10 tris per window. This would mean that 2300 windows should be caulked to get an improvement of 2fps. Basically this shows that caulking does not have much impact on modern hardware. However, on an older piece of hardware the amount of caulking needed for performance effect is lower, but even in this case it should be remembered that 1000 tris is roughly 20% of a single AI character.

Conclusion

Applying caulk on brushes for the purpose of optimization is simply not worth it. And given that it can cause problems with TDM updates, better not do it.