Jump to content

Understanding the layers.


Yue
 Share

Go to solution Solved by Josh,

Recommended Posts

I am trying to understand the layers, when I create an initial 3d camera in which layer is it created, layer 0 or layer 1, when I create a camera for the GUI it is created in the next layer, example layer 2, and to show the correct interface, the interface must be in the same layer of the GUI camera?

  • Confused 1

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

  • Solution

The render layers are a bitwise flag. This allows you to set multiple values in a single integer variable.

Each flag is a power of two number, like 1, 2, 4, 8, 16, etc.

You can add these numbers together, and it is possible to tell which numbers are packed into the value. For example, if I see the value '3' I know it contains 1 and 2, and thus the first two flags are set. If I see 17, I know that means 16 + 1.

By default every entity has its render layers set to 1. (Except maybe probes, I think I might have set it to have all possible values active.)

There is also a simple math operation to tell if two flag sets have any flags in common:

a = 17
b = 3
if ((a & b) != 0)
{
	// at least one value must be in common in the two flag sets, in this example it would be 1.    
}

This is how render layers tell which objects can see which other objects.

In the future, I think the editor interface will get a little simpler, but I need to add checkboxes to combobox items in order to do that.

For programming, you may find it easier to declare render layer constants like this:

enum RenderLayers
{
	RENDERLAYER_1 = 1
	RENDERLAYER_2 = 2
	RENDERLAYER_3 = 4
	RENDERLAYER_4 = 8
	RENDERLAYER_5 = 16
	RENDERLAYER_6 = 32
	RENDERLAYER_7 = 64
	RENDERLAYER_8 = 128
}

An unsigned 32-bit integer supports up to 32 flags like this (because it has 32 bits).

Then you can set render layers like this:

entity->SetRenderLayers(RENDERLAYER_1 | RENDERLAYER_3 | RENDERLAYER_6);

This may be easier than remembering a lot of power-of-two numbers and is equivalent to this:

entity->SetRenderLayers(37);

When two entities have a flag in common, they can see each other. Cameras can see objects, or objects can cast shadows from a light.

A similar system is used for controlling which decals can appear on which objects, although it is stored in a different variable.

  • Like 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...