Game Development Community

Material System. Layers, envMap, cubemaps, etc

by Steve Acaster · in Torque 3D Professional · 10/21/2013 (8:55 am) · 12 replies

Cubemap reflection on meshes

After a bit of faffing I realised a few things don't work as I had expected - or at least I though that they worked in a different way.

First up, adding a cubeMap to an object. I had been under the impression (probably wrongly from the looks of things) that an alpha channel was required (probably on the diffuse) to decide how much/strongly the cubemap showed/reflected on a material. But apparently that's not how it works at all.

It appears that it uses the alpha in the diffuseColor of the layer1 (cubemap going in layer0).

diffuseColor[1] = "1 1 1 0.5";

So layer0 needs diffuse, normal, specular maps - and layer1 needs the same diffuse, specular maps (normal map here doesn't do anything) and then lower transparency of diffuseColor[1] to set the cubemap reflection.

Unfortunately then the cubemap covers the entire map making it look kinda flat as reflection is uniformed across light/dark areas, differing textures within the diffuse (eg: brick and grouting).

Anyone got any tremendous successes using cubemaps on meshes?

envMap WTFBBQ in Material Editor

addField("envMap", TypeImageFilename, Offset(mEnvMapFilename, Material), MAX_STAGES,
         "The name of an environment map cube map to apply to this material." );

What the hell is this!? And how are you supposed to add a cubemap to an image slot? Anyone have any idea whether envMap actually works or does anything? I don't see how it functions. (which goes the same for lightMap slot but as ToneMaps work we shall ignore that for the time being ...)

docs.garagegames.com/torque-3d/official/content/documentation/World%20Editor/Editors/images/MatEdTextureMaps2.jpg
In the docs - docs.garagegames.com/torque-3d/official/index.html?content/documentation/World%2... - there isn't a mouse over info block for it like the others either.

#1
10/22/2013 (12:10 am)
Adding a cubemap to an image slot is easy... Add a cubemap. ;) It's a property of DDS images, can be defined as a cubemap image. It's also how the cubemap masking works for point lights.
#2
10/22/2013 (6:21 am)
Not for envMap it isn't ... which is why I'm baffled to how envMap works.
#3
10/24/2013 (11:01 pm)
no idea if this is the same in T3D but heres what valve say it is:-
developer.valvesoftware.com/wiki/
#4
10/25/2013 (5:28 am)
envMap is a slot, it doesn't actually take a cubemap, nor can one be applied manually by modding the material.cs ... hence why I am confused as to how it works or what it does - if anything.
#6
10/26/2013 (8:06 am)
I haven't looked, but I wonder if the envMap feature was ever ported up to the T3D material system or if it still wants to work the same way that it did back in TGE -- which used a special 7th image in a skybox in combination with an object's texture alpha for the envmap and could be toggled on/off per object... or something like that.
#7
10/28/2013 (9:59 am)

Okeedokee


Got cubemaps and layers working as I thought they should - the alpha in the alpha channel of the upper layer DOES control reflection without the need for the alpha slider in the diffuseColor. (previously I hadn't made the masking black enough so it was hard to tell that it wasn't reflecting as much. Also the layer0 diffuseMap MUST NOT HAVE ALPHA or it doesn't work and cancels out layer1 alpha.

Hurray!

Tried the old TGE method of using envMap but nothing happened.

Anyhow, the important bit is that the cubemaps are fully maskable with layer1 diffuseMap alpha. This means that crevices, creases and other non-rflecting parts of a diffuse texture can be made to not reflect the cubemap. This means that lightmaps/tonemaps, emissive and cubemap reflections can all work nicely together and save and tonnes of performance by disabling dynamic shadows and use that saving for cool meshes.

www.yorkshirerifles.com/random/alpha_test.jpg
#8
10/28/2013 (10:08 am)
That's great Steve, nice research!
#9
10/28/2013 (11:57 am)

Basic test for using cubemaps with lightmaps, emissive matierals without specular, and how to get the alpha channel of higher layers to mask parts of the cubemap. Note: only the floor actually has full masking in the alpha channel - all the others use the diffuseColor fade system.

Halfway through the video the test is restarted with with "Advanced Lightmap Support" enabled - which seems to give more cubemap reflection.

Old model, not correctly set up for a cubemap - those pillars are bad.

Lightmaps created in pureLight.
#10
11/04/2013 (1:33 am)
That's a nice vid, Steve.

Am I understanding you right on how to create it: in layer0 the basic diffuse texture and the env map, in layer1 just a diffuse map with an alpha mask which defines the reflection?
#11
11/04/2013 (7:48 am)
layer0: diffuse NO ALPHA! or it doesn't work. I even made it emmisive as the cubemap is the reflection which I want.

layer1: diffuse with alpha. With an alpha channel you don't have to fade the alpha in the diffuseColor section (the little box). I set this layer to not emissive but you can if you want.

Cubemap in the cubemap section at the bottom of the materials - this affects the bottom layer only.

Play around with various settings (like emissive) in the layers and see what happens.
#12
11/04/2013 (2:23 pm)
Thanks for the explanation Steve, very useful.