Something I found on the dev wiki, wondering how it works...

Discussion in 'Mapping Questions & Discussion' started by Pocket, Jan 18, 2013.

  1. Pocket

    aa Pocket func_croc

    Messages:
    4,489
    Positive Ratings:
    2,219
    First of all, this is for a Minecraft themed map. So if you have any moral objections to being an accessory to such a crime, feel free to ignore this thread.

    I was poking around the Valve Developer Wiki today and I ran across something that, at first glance, looked like it would be a tremendous help in rendering biome grass properly. For those uninitiated, in Minecraft, the color of grass varies by what biome of the map you're in, with large patches in a particular shade of green and soft fades between them, like so.

    [​IMG]

    As far as I can tell, the grass is rendered by applying a solid shade of green to each block and then overlaying a standard gray noise texture in multiply mode. I could just make dozens of different textures for all the intermediate shades, but I think I found an elegant solution in the form of an obscure Source shader called LightmappedTwoTexture. What it supposedly does is let you specify two texture files and it will overlay one on top of the other in multiply mode. Easy-peasy. So I figure, I'll just make a "grass map" where each block is represented by one pixel, set that as the base texture scaled up 16 times, and then use the gray noise texture as my second texture.

    Right now my VMT looks like this:

    Code:
    "LightmappedTwoTexture"
    {
    	"$basetexture" "minecraft/grass_base_plains"
    	"$texture2" "minecraft/grass_overlay"
    	"$surfaceprop" "Grass"
    }
    Which is how I'm supposedly meant to do it. But for some reason, it's not working. It's only rendering the base texture, a solid green. Any idea what's up? Does the TF2 engine even support this shader? It's not even officially documented; the closest thing in the Developer Wiki is UnlitTwoTexture, but I assume the syntax is supposed to be the same.
     
  2. tyler

    aa tyler snail prince, master of a ruined tower

    Messages:
    5,035
    Positive Ratings:
    3,992
    Are you sure this wasn't added for multiblend support in more modern Source games?

    As an alternative, why not just make a blend texture and carefully blend several areas?
     
  3. Dr. Spud

    aa Dr. Spud Grossly Incandescent

    Messages:
    879
    Positive Ratings:
    803
    • Thanks Thanks x 1
    Last edited: Jan 18, 2013
  4. Pocket

    aa Pocket func_croc

    Messages:
    4,489
    Positive Ratings:
    2,219
    I'd completely forgotten about $color! I'll definitely be switching to that for trees so I only have to make one VTF for leaves, but using it for biome transitions would still require me to produce a separate VMT for each block in the transition zones as well as break them up into separate brushes. Hardly ideal.

    Well, UnlitTwoTexture is in the Orange Box at least; it's used for textures that need one part to animate independently of the other, like the radar screen on the one bank of computers. (Presumably the dispenser's screen is another, but I can't seem to find the VMT for it.) And both VRAD and the game knew to treat my material as a lightmapped texture, so it must at least be programmed to recognize the shader's name and do something close to the intended purpose.

    I'm pretty sure I just have the syntax wrong. The only official materials I've found that use UnlitTwoTexture so far use $additive to make the second texture glow instead; I have yet to see one that's actually meant to use multiply. I'd like to see how the dispenser screen is set up, since that one clearly just layers the needle on top, so if nothing else I could make my overlay transparent instead and copy that method.

    I had thought of that, but I have no experience with blendmaps. Is it even possible to make one that produces that blocky look? I do want each block to be a visibly if subtly different color, not a perfectly smooth transition.
     
  5. Pocket

    aa Pocket func_croc

    Messages:
    4,489
    Positive Ratings:
    2,219
    Well, what do you know. Someone over on SPUF pointed me in the direction of WorldTwoTextureBlend, which as it turns out does exactly what I need. This is what I ended up with for my material:

    Code:
    WorldTwoTextureBlend
    {
    	$basetexture "minecraft/grass_base"
    	$basetexturetransform "center .5 .5 scale .0625 .0625 rotate 0 translate 0 0"
    	$detail "minecraft/grass_overlay"
    	$detailblendmode "2"
    	$detailscale "16"
    	$surfaceprop "Grass"
    	$reflectivity "[0.5 0.5 0.5]"
    }
    As an added bonus, this method uses an alpha channel to blend instead of multiply mode, so it can also work for those side textures with the dirt on them, though getting those lined up with the "grass map" correctly will take some extra gruntwork. I'll see about possibly recreating a basic landscape as proof-of-concept.
     
    • Thanks Thanks x 2