www.tombraiderforums.com

Go Back   www.tombraiderforums.com > Tomb Raider Modding > Tomb Raider Modding > XNALara

Reply
 
Thread Tools
Old 26-10-12, 17:57   #1
Goha
Explorer
 
Join Date: Jul 2011
Location: GMT+1
Posts: 729
Default Emissive maps in XNALara - tutorial.


This post covers Blender. For Max users, the alternative method can be found here

Since our little viewer doesn't support something a pro could call an "emissive map", we can work around it, and for that, we have render group 21 (which I'll call RG#21). It supports alpha channel, needs only one texture and it's unaffected by light, that means - doesn't matter what are you doing with light in your scene, the texture will always remain visible.

* Apart from that we have "thorglow" groups, which will not be covered in this tutorial.
* Images are stored on imgur, so for bigger simply r-click a miniature, and open in new tab/window



Pros: this tutorial will show you how to "fake" an emissive effect using all available textures extracted from the game.

Cons: because model's mesh and emissive mesh are close one to another, the lesser FoV and the far away model is from camera, both surfaces will clip, which will look like "flickering". I will show you how to reduce the clipping, but in XNALara I think it's not possible getting rid of it completely.

Difficulty: depends of how well do you use Blender 2.49b and Photoshop.



I picked a model from the game I already played and know how does it look, but just in case: get to know your model. Take reference screenshots, or use google or youtube if you have to.


So, here's our dude, already converted and textured with all his base textures, but if you look on the screenshots, he lacks something. Ishi's implants are glowing, the glow seems to spread on clothes and other adjacent surfaces, plus, he happens to be a bit of a schizophrenic :P


This glow is nothing else than additional texture, which is unaffected by changing light, just like RG#21 is. The rest of the effect, like the actual aura of the glow is caused by shaders the game is using or other tricks, like a one-dimensional surface that is always facing the camera.

Where to find this texture? It's usually a separate file, that contains few masks "hidden" in RGBA channels. For example, in Mass Effect games emissive maps were usually hidden as alpha channel of specular maps, in Bulletstorm, they are separate files with "mask" in their names. They probably can be stored in other types of textures, so it's always good to look everywhere, depending on a game's engine.

Masks-> Channels->

So, each channel here is a mask, by which game applies a "pigment", that actually gives us an impression of a "glow". I'd call that a stack texture, as it stores info for multiple meshes. But, waitaminute:
1. If it's your first time with such thing, you'll think this looks odd.
2. The glow that we need is contained in few separate channels, what do we do with it?

Intuition, references, observation, improvisation, Photoshop. This is what we basically need as amateurs.

First, we're going to make a simple version of the emissive texture, so let's see, what do we exactly have here:





Ishi_eye_mask.tga contains:
  1. Red channel - artificial eye iris area.
  2. Green channel - eyes area.
  3. Blue channel - eyes area and places that, if you look on the diffuse texture, are adjacent to where his skin meets the implants, Ishi's wounds are fresh, it's actually the place where his burned flesh was amputated. This may suggest it's an additional specular texture that adds shine to those wounds and both eyeballs.
  4. Alpha - area defining glow on Ishi's right temple.

Ishi_mask.tga contains:
  1. Red channel - again probably a specular texture or a different kind of mask that has probably nothing to do with the emissive map.
  2. Green channel - areas defining glow that changes colors from blue to red when Ishi is angry or in combat mode.
  3. Blue channel - areas defining glow of the blue cords on his back and on the adjacent clothes.
  4. Alpha - areas that on the diffuse texture are taken by skin, along with inner mouth, teeth, tongue. So probably another specular map.


So we're going to need to make two emissive textures. Why two? Originally Ishi's model consists of two base meshes: his implanted hand/leg and cords on his back is the first, and the rest of his body is the second mesh. To keep the XNALara's "max 59 bone per mesh" rule, body had to be split too, I also separated his eyes, because I simply want other rendergroups and specular shine value on each.

For first emissive map, I'm going to need alpha from the first texture and green from the second texture, for the second map - only blue channel from the second texture. So I'm going to make selections from all these channels and save them (left ctrl+left mouse click on a channel>Select>Save selection>New).

Then I'm creating a new image (RGB) in the same size as the mask textures/selections (512x512 in this case), filled with black color. I will load these two selections and fill each one on a separate layer with white color and keep a PSD copy of this file, save and close it. The original may be flatten. This flatten image is our alpha channel of the emissive texture, so were going to select it (ctrl+a), copy (ctrl+c), and paste (ctrl+v) as new alpha channel.

At this point, the background of our image can be filled with any color we want (almost - it can't be the pure white #FFFFFF) - it's the alpha channel defining where our texture will be visible (white color marks solid areas, black marks 100% transparent areas, all shades of grey mark the partially transparent areas, depending on intensity), but we will leave it exactly how it is. To make sure the background doesn't contain pure white color, I'm making a new layer on the top, fill it with #FAFAFA color, set blending mode to "darken" and flatten again.

It's important to save this image in format that stores alpha channel data, I use 32bit .TGA for that. So I'm gonna save this as body_e.tga, 32 bit, RLE compressed. Which means this is the emissive texture for the areas glowing on the body mesh.

Second emissive map, will be done with the same method and saved as implants_e.tga, which means it's the emissive texture for Ishi's cybernetic hand/leg and cords mesh.

Why I needed to save .psd versions and selections of them? Because later, I'm going to color them. For now, this will do.

Let's import our model to Blender, remove doubles blah blah. I'm going to start from the implants part, so I'm hiding the meshes I don't need. What I'm gonna do here is to duplicate this mesh (Object>Duplicate>esc or Shift+D>esc), name it and change the render group. In the UV editing, I'll change the texture to the prepared implants_e.tga map.




See, these will be our glowing cords!

Now for the clipping reducing part. In this moment both meshes are of the same size. For that, we have to enlarge the emissive mesh, so the "glow" will float a bit over the model, but it won't be actually that visible.

! Save the .blend project. !

To do that, while we still have our emissive mesh selected, go to EDIT mode, then either press: Mesh>Transform>Shrink/Fatten Along Normals>0.002>enter or ALT+S>0.002>enter.

That 0.002 number is a value you have to input on your keyboard. This is an example value, for less clipping it must be minimum 0.0015. 0.002 is optimal, while 0.003 may be too large, depending on the model. It's something you have to check on your own later in XNALara. You always have a .blend file to return to and start again.
Value more than 0 is fattening the mesh, while less than 0 will shrink it.

To more advanced users: to keep the file smaller and/or avoid the "max 59 bones per mesh" problem, you can basically select the faces on the UV that are "glowing" on the texture, invert the selection and delete it.

Analogically, I'll make a copy of the body mesh and the right eye. This is how it's gonna look before exporting:


In the exported file, we have to fix rendergroups for our copied meshes. For the eye for example, my rendergroup header looks like this:

21_emieye_0.0_0_0
1 # uv layers
1 # textures
body_e.tga
0 # uv layer index

After that, convert and open in XNALara. "Turn off" the lights and hey, our dude glows! Not exactly like in the game yet, but that's just a matter of photoshopping - changing the intensity of the alpha in our emissive textures, also coloring them by using the saved .psd files and selections:


How's that now?


Well, this is probably a makeshift method, for now I haven't worked out anything better. I hope this will be useful, of course if you have questions and suggestions, leave them here!

Last edited by Goha; 26-10-12 at 19:45. Reason: spelling again
Goha is offline   Reply With Quote
Old 26-10-12, 18:04   #2
XNAaraL
Professor
 
XNAaraL's Avatar
 
Join Date: Apr 2009
Location: The worthwhile problems are the U can really solve, the ones U can really contribute something to
Posts: 3,172
Default

Added to Links to XNALara Modding Tutorials
Thanks for the effort
__________________
Link removed. - Why ? google, google “Google is your friend!”
XNAaraL is offline   Reply With Quote
Old 26-10-12, 19:20   #3
Runa
Archaeologist
 
Runa's Avatar
 
Join Date: Nov 2011
Location: Milan, Italy *vomits*
Posts: 1,065
Default

Great tutorial, Goha!

I'd like to add something. Well, actually it's more about possible 'bugs' or problems related to this method... problems that I, sadly, have experienced many times.

First of all, I have to say that what I'm gonna explain will interest 3d studio max users only. Blender users won't need this.

With that said, when I sometimes tried to use this method in blender (duplicate and rename meshes), once I loaded the model back in 3ds I got an error message and the program could load just the bones and nothing else. I thought I had to try to export the model BEFORE renaming the groups and, at least once, it perfectly worked. The other times, it didn't matter if I renamed everything after or before the exportation, it was impossible for me to successfully load the XNA model in 3ds.

Well, there actually is a solution.

If you want, you can avoid the blender part and do everything in max:

1) Load your model (already converted or not, doesn't matter)

2) Select the mesh that needs a fake glowing effect and right-click on it, then click on "Clone".

3) A small window should pop up. Select "Instance" (note: it's important you don't select "copy", or else the method won't work)

4) You will get another mesh identical to the one you just cloned. Export the model for XNALara, then import it back again.

5) In the material editor add your textures correctly. The upper mesh should have the main diffuse texture set on opacity, the one behind should have the emissive applied, also set on opacity.

6) Apply any other texture (spec, normal, whatever) and convert the model once again.

7) Open the mesh.ascii file and search for your emissive texture(s). Change the render group from 7 to 21 and save it.

8) Drag the modified ascii file on the converter and open XNALara for a test load of your model. Everything should look fine.

Doing this in max, I never got any error message and the emissive maps always look good in XNALara. If you use blender for every conversion and such, it won't be a problem for you... but if you use max all the time like I do, I think it's better to directly create the emissive mesh in there. Of course you can always use blender to remove doubles and everything.
__________________
My WIP http://www.tombraiderforums.com/showpost.php?p=6500670&postcount=11416

Last edited by Runa; 26-10-12 at 20:19.
Runa is offline   Reply With Quote
Old 26-10-12, 19:44   #4
Goha
Explorer
 
Join Date: Jul 2011
Location: GMT+1
Posts: 729
Default

Awesome addition for Max users, thanks a bunch! Gonna add link to the first post.

The loading problems never occurred to me though. I was importing several models with Blender-copied meshes to Max to reduce seams and seriously nothing never popped up.
I'm using probably very old version of mario's script though, the one I sent you once when we were discussing seams removal - if that makes a difference. I'm lazy to update things that are working fine for me. xD
Goha is offline   Reply With Quote
Old 26-10-12, 20:18   #5
Runa
Archaeologist
 
Runa's Avatar
 
Join Date: Nov 2011
Location: Milan, Italy *vomits*
Posts: 1,065
Default

Ah yes, I now remember that. I am using the latest version of the script, so maybe that's why I often had that issue with emissive meshes >_<
__________________
My WIP http://www.tombraiderforums.com/showpost.php?p=6500670&postcount=11416
Runa is offline   Reply With Quote
Old 26-10-12, 21:49   #6
Cochrane
Gold Contributor
 
Cochrane's Avatar
 
Join Date: Apr 2006
Location: Germany
Posts: 16,100
Default

Cool! I'm thinking about adding built-in support for such maps to GLLara (and, possibly, with XNAaraL's help, to XPS). Are you interested in that, and if yes, how would you like that to work? My idea right now is to have them work like groups 28 and 29, only instead of an environment map, they get an emissive map; one single map for the entire model. Make it black or alpha=0 where no emissive component should be added.

I'm not sure how easy it would be to add this to XPS, but I can write the shader for it. Adding it to vanilla XNALara is probably not possible, though; that would require cooperation from Dusan, and he's too busy for that at the moment.
__________________
Güter auf die Bahn!
Cochrane is offline   Reply With Quote
Old 27-10-12, 18:04   #7
XNAaraL
Professor
 
XNAaraL's Avatar
 
Join Date: Apr 2009
Location: The worthwhile problems are the U can really solve, the ones U can really contribute something to
Posts: 3,172
Default

Adding it to vanilla XNALara is probably possible, if you can write the shader WITHOUT new parameters(, because the DirectX 9 maximum 256 parameters (59 bones) problem).

Probably, the next 9.7.9 vanilla XNALara, solve also this limit.
__________________
Link removed. - Why ? google, google “Google is your friend!”

Last edited by XNAaraL; 27-10-12 at 18:05.
XNAaraL is offline   Reply With Quote
Old 27-10-12, 19:12   #8
Cochrane
Gold Contributor
 
Cochrane's Avatar
 
Join Date: Apr 2006
Location: Germany
Posts: 16,100
Default

That'll be absolutely no problem. I wasn't planning on adding any new parameters anyway.

Edit to add: Here's the shader code:
Code:
/***********************************************************
 * Emissive shader
 *
 * Works like DiffuseBump, but then adds an emissive
 * component. The emissive texture uses the name "lightmap",
 * to avoid adding another parameter and going over the
 * limit (I have no idea if textures count against the limit
 * in HLSL). Rename it if you like.
 ***********************************************************/
 
float4 DiffuseBumpEmissionPS_1(BumpVertexShaderOutput input) : COLOR0
{
	float4 emissionColor = tex2D(LightmapTextureSampler, input.TexCoord);
	return DiffuseBumpPS_1(input) + emissionColor;
}


float4 DiffuseBumpEmissionPS_2(BumpVertexShaderOutput input) : COLOR0
{
	float4 emissionColor = tex2D(LightmapTextureSampler, input.TexCoord);
	return DiffuseBumpPS_2(input) + emissionColor;
}


float4 DiffuseBumpEmissionPS_3(BumpVertexShaderOutput input) : COLOR0
{	
	float4 emissionColor = tex2D(LightmapTextureSampler, input.TexCoord);
	return DiffuseBumpPS_3(input) + emissionColor;
}
This needs to go into EffectsArmature.fx. I put it after MetallicBump3PS_3. You also need to add the techniques somewhere as
Code:
technique DiffuseBumpEmission_1
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 BumpVS();
        PixelShader = compile ps_2_0 DiffuseBumpEmissionPS_1();
    }
}


technique DiffuseBumpEmission_2
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 BumpVS();
        PixelShader = compile ps_2_0 DiffuseBumpEmissionPS_2();
    }
}


technique DiffuseBumpEmission_3
{
    pass Pass1
    {
        VertexShader = compile vs_3_0 BumpVS();
        PixelShader = compile ps_3_0 DiffuseBumpEmissionPS_3();
    }
}
Note: I've been clever to keep the code short. I really hope that works. If not, I can create a non-clever version in five minutes, it will just be more ugly.

I'm not sure how to add it to the renderer in XPS. I can make some guesses, but if you already have an idea, it's probably best to go with that. Note that the emissive texture is stored in the "LightmapTexture" parameter, to avoid adding a new parameter.
__________________
Güter auf die Bahn!

Last edited by Cochrane; 27-10-12 at 19:30.
Cochrane is offline   Reply With Quote
Old 28-10-12, 17:38   #9
XNAaraL
Professor
 
XNAaraL's Avatar
 
Join Date: Apr 2009
Location: The worthwhile problems are the U can really solve, the ones U can really contribute something to
Posts: 3,172
Default



Works like designed
__________________
Link removed. - Why ? google, google “Google is your friend!”
XNAaraL is offline   Reply With Quote
Old 28-10-12, 21:29   #10
Cochrane
Gold Contributor
 
Cochrane's Avatar
 
Join Date: Apr 2006
Location: Germany
Posts: 16,100
Default

That's awesome to hear! Then I'll get to implementing it in GLLara, too. I might make a new release of that soonish, even though some key UI improvements I had been planning have not been implemented yet…
__________________
Güter auf die Bahn!
Cochrane is offline   Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 11:25.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.