Ok, so here's the setup: I'm working on a model of a spaceship, using Cycles as the renderer. Eventually, this model may end up in a game (possibly under Unity or Unreal Engine). The ship has multiple light objects (running lights, cockpit lighting, etc.)

While the exact materials for each light will depend on the lamp, all will have materials for an Off/On state. Some lights may have multiple colors to indicate status (IE, the engine lights will have Off, Red, Amber, and Green depending on the engine's condition).

Right now, I'm selecting faces and manually applying the materials when I want to render lights off vs. on. Which is fine when I'm working in Blender and only want to adjust one light at a time. However what about when I actually try to bring this into a game engine? I may not be able to swap materials in and out in this manner. And is there a way I can dynamically switch between the On/Off state when working in Blender, especially once I begin rigging and animating the switches and toggles on the control panel?

  • $\begingroup$ You could use a value node to control your node setting. And in game engine, it should be a separated part or at least you need more then one material to switch. How to switch material depend on how you want to use them, game engine should contain plenty of method to deal with these situation by scripting or something else. $\endgroup$ – HikariTW Dec 15 '19 at 5:20
  • $\begingroup$ And if in unity, you can directly change the diffuse color in code and runtime. That should be the most common case to deal with it. $\endgroup$ – HikariTW Dec 15 '19 at 5:22
  • $\begingroup$ There's actually several places where I would want to change materials: 1) Lighting: Having a "Lights Off" and "Lights On," as well as various light status codes (Red, Yellow, Green). This is particularly complicated because it's not just changing colors, but emission properties. 2) Engine Emissions. Again, an "Engines On" vs. "Engines Off." 3) Squadron Markings: In the ship I'm working on, the squadron is identified by the tail color. So one squadron may have a red tail, another may have black, etc. $\endgroup$ – Ambaryerno Dec 15 '19 at 7:26
  • $\begingroup$ 4) Flight Markings: Similarly to the above, what flight (four-ship division of a squadron) the ship belongs to would have a different color (Red Flight, Blue Flight, White Flight, Yellow Flight) for ID bands and other markings (think the "Yellow Wing" USN/USMC marking system prior to WWII). Bonus: I'd love to have dynamic text, IE plane #1, 2, 3, etc. I'm using Decal Machine for those markings, so that may take a little more doing. Right now I just want to get the lighting/colors figured out. $\endgroup$ – Ambaryerno Dec 15 '19 at 7:31
  • $\begingroup$ Wait... so it has nothing to do with Blender? It seems like your asking at a wrong place BTW. $\endgroup$ – HikariTW Dec 15 '19 at 7:54

You need to do all this on one material. Applying materials to individual faces is not going to work for rapid testing.

Once you are using only one material toggling On and off is easy and changing the color is super simple.

First off you will need a mask to differentiate what parts of the mesh will get what. I'd recommend using an image (easy to paint in texture paint mode and transferable to any game engine), but you can also use vertex colors, or proxy objects inside blender.

For my example I'm using an image, and vertex colors.

The image texture node is the mask I painted. The key to the toggling is the MixRGB node(s). The Value input node is what I'm using to control the toggling. When the value is 0 the MixRGB node is outputting 100% black, which is feed into the Fac for the Mix Shader node. (0 uses the top socket, 1 is the bottom socket) Likewise when the value is changed to 1, the MixRGB outputs the mask image which has white painted in the proper places. Thus the Emission shader gets to shine.

Its the exact same thing for the one I have labeled "Engine toggle" except here I'm using the vertex colors as the mask instead of an image.

The RGB input is how I'm changing the color of the "lights." You could also use a image and a special UV map just to re color (You would simply move the UVs to a different color) but for in blender the node is much easier.

material nodes

The nodes can look much neater when wrapped in a node group, but for testing I prefer access straight to the nodes.

  • $\begingroup$ Maybe instead of using 0 .333 .666 and 1, have each color as an on/off value. So if Yellow is 1 and all other lights are 0, the light will be yellow. Ditto Red and Green. $\endgroup$ – Ambaryerno Dec 16 '19 at 1:45
  • $\begingroup$ Ah, I've got it. It took adding a couple extra mix shaders to cover the other light statuses, but I've got it set so that if all values are 0, the light is off, and I can then switch between the statuses by setting each value to 1. $\endgroup$ – Ambaryerno Dec 16 '19 at 1:55
  • $\begingroup$ I can see where I can use this for my squadron/flight colors, as well, including NOT showing them (IE, a flight leader in my marking scheme has a band around the fuselage, but a wingman would not). $\endgroup$ – Ambaryerno Dec 16 '19 at 2:02
  • $\begingroup$ So I've got two materials working, but I'm running into problems trying to get a third. I'm using Vertex Colors for the mask, and have a base color that's painted Black, while the other two are White and Blue. I can get the White group to work, but not the Blue. $\endgroup$ – Ambaryerno Dec 18 '19 at 7:42

Ok, so here's an update based on my response to @David. This is what the mesh looks like right now:

enter image description here

Right now, I have my new material applied in three places: The metal grate on the floor, everything that's green, and that stripe across the top of the dashboard.

My floor and the base color are working just fine. However that stripe across the top of the dash SHOULD be the same color as the rest (so...black). As you can see, that's obviously not the case.

Here's what my shader looks like right now:

enter image description here

The base cockpit color has been painted Black with Vertex Paint. The metal grate on the floor has been painted White. The stripe on the dash has been painted Blue. However I've tried a number of tweaks and permutations of the shader, and just can't get that stripe to the correct color (it should be using the AntiGlare group). I've tried changing the Factor to Color 1 and Color 2, I've tried using the Color node, I've tried changing the unlinked Color to Black, White, and Blue, and I've tried changing the Value

Eventually I want to get as much of this onto one material as possible, I'm just going a little at a time so I don't screw it all up at once.

Also, I'm having a little trouble figuring out how exactly to connect the Displacement node on the floor.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.