$Phong on brushes*: The Hacky Way

Discussion in 'Tutorials & Resources' started by Stiffy360, Jan 1, 2016.

  1. Stiffy360

    Stiffy360 L1: Registered

    Messages:
    20
    Positive Ratings:
    45
    You may have seen some models with their shiny point specular and thought "I got to get me some of that!" Excitedly you open up notepad, slam down the commands "phong 1" and "phongfresenal ranges "[ .2 .5 1]" and quickly boot up the game, only to see that it does not work on "LightmappedGeneric" surfaces. In a fit of rage you are about to throw yourself off a cliff. Worry Not! I have come in a cloud of light to deliver you the good news that you can achieve phong on a lightmappedgeneric surface!* (*Using models)

    This is a fairly simple operation; however it requires a few things

    =========================================================================
    A modelling editor package (Propper will work)
    A normal map
    A strong will to hold yourself off from commiting suicide to perform these operations
    =========================================================================

    First thing you want to do is duplicate your ideal brushes in some form or fashion to another vmf. From there, you tesselate it and use either propper or your software editing package (In my case I use wallworm and 3DS max to edit things) to export it to an smd format. if you have propper you can auto compile it, if you have 3DS max, you'll need to export it and use crowbar or wallworm's compile tools to compile it into a mdl file.

    Now for the textures. I suggest making a subdirectory for your phong textures. E.G. models/phongtextures/texturename.vmt The only new texture you'll need is a black 256x256 texture. You can generate it in nearly all programs. (doesn't have to be 256x256 but works best with that) Once you have that, you just duplicate the vmt that your brush uses and make a few changes.

    Original materials/tile/floor_tile_001a

    =========================================================================
    "LightmappedGeneric"
    {
    "$baseTexture" "Tile/floor_tile_001a"
    "$envmap" "env_cubemap"
    "$envmapcontrast" 1
    "$envmapsaturation" 1
    "$envmaptint" "[ .75 .75 .75]"
    "$normalmapalphaenvmapmask" 1
    "$bumpmap" "Tile/floor_tile_001a_normal"
    "%keywords" "tf"
    }
    =========================================================================

    New materials/models/phongtextures/floor_tile_001a

    =========================================================================
    "VertexlitGeneric"
    {
    "$baseTexture" "models/phongtextures/black"
    "$additive" 1
    "$bumpmap" "Tile/floor_tile_001a_normal"
    "$phong" 1
    "$phongexponent" 60
    "$phongfresnelranges" "[ .2 .5 1]"
    "$phongboost" 3
    "%keywords" "tf"
    }
    =========================================================================

    You'll notice a few changes

    I changed LightmappedGeneric to VertexlitGeneric
    I ditched the envmap because phong does the main work.
    My base texture is the newly created black texture.
    I added phong commands

    And most importantly, there's this new command

    "$additive" 1

    What does this do? exactly what it says. It adds the colors of the textures together, and this is my base texture is black. 1+0 = 1 Black will show up invisible in-game, however the specular highlight from $phong will not. Thus replicating the holy grail effect.

    In hammer you simply place this in your map just ever so slightly above the brush (1 unit looks fine)

    Bam!

    Phong.


    [​IMG]

     
    • Like Like x 5
    • Thanks Thanks x 2
    • Creative Creative x 1
    Last edited: Jan 1, 2016
  2. Moonrat

    aa Moonrat The end of an era

    Messages:
    877
    Positive Ratings:
    502
    Wow! Just in the nick of time! If you had uploaded this a minute later, I would have already hit the bottom of a cliff!
     
    • Funny Funny x 3
  3. Pocket

    aa Pocket func_croc

    Messages:
    4,488
    Positive Ratings:
    2,213
    Yeah, I was considering doing that ages ago for Fort Frolic, back when I was still working on it. But I figured I'd have to compile it as a model, so I never bothered. I had no idea you could use VertexLitGeneric for brushes!

    What's sad though is that it doesn't seem like it would be hard to mod the engine to incorporate additive phong exponents to the LightmappedGeneric shader itself. It would just require adding another "layer" to the rendering setup that imitates what your technique does. Hey, people who are working on Team Fortress 2 Classic, I'd love to see if you can get that working.
     
  4. henke37

    aa henke37

    Messages:
    1,834
    Positive Ratings:
    420
    I wouldn't make any such claims without even knowing basic shader coding. I don't so, I will not make any claimes.
     
  5. Stiffy360

    Stiffy360 L1: Registered

    Messages:
    20
    Positive Ratings:
    45
    It's ideal that you model it. Although you CAN use Vertexlitgeneric on brushes, it samples its lighting from your viewmodel. Also normalmaps and whatnot don't work.
     
    • Agree Agree x 1
  6. wiregrind

    wiregrind L1: Registered

    Messages:
    2
    Positive Ratings:
    0
    I wonder how a map based on this (plus nodraw brushes for vvis) would run, every surface could have a rough fresnel reflection to simulate dryness/wetness. Also with some dedication you could optimize LOD and collision meshes in propper.

    Edit: this would also allow lightwarp / cel-shaded brushes
     
    Last edited: Jul 20, 2016
  7. Pocket

    aa Pocket func_croc

    Messages:
    4,488
    Positive Ratings:
    2,213
    Yeah this could do with a bump since Propper is back in action, making it incredibly easy to build these surfaces and update them as the map develops. I might have to go back to work on Fort Frolic just as an excuse to try this out.
     
    • Like Like x 1