-
Notifications
You must be signed in to change notification settings - Fork 36
Render Layer
Jonathan Schnee edited this page Mar 1, 2022
·
2 revisions
The RenderLayer component is used control the visibility of object when rendered with different Cameras. This feature can be used in various situations, e. g. to implement an overview map using an individual camera rendering different objects than the camera used to render the 3D main view.
The objects that should be present in a Render Layer need the Render Layer as the first component. The camera itself also needs to specify which Render Layer it should use. This can be entered as a parameter when creating the camera or changed later. Render Layers can also work with multiple cameras, but note that the higher camera layer is displayed above the lower camera layer.
// This example builds two rockets rendered by 2 cameras.
// - The left camera is on RenderLayers.Layer01 the right is on RenderLayers.Layer02.
// - The left rocket is on RenderLayers.Layer01 => only rendered by the left camera.
// - The right rocket is on RenderLayers.Layer02 => only rendered by the right camera.
public override void Init()
{
_scene = new SceneContainer();
// Loading the rocket
var rocket = AssetStorage.Get<SceneContainer>("RocketFus.fus");
// Picking it apart for resuse
var gray = rocket.Children[0].Children[0];
var white = rocket.Children[0].Children[1];
var green = rocket.Children[0].Children[2];
var rocketTransform = rocket.Children[0].GetTransform();
// Split into individual components to assemble them all later as SceneNode.
var grayShEf = gray.GetComponent<DefaultSurfaceEffect>();
var grayMesh = gray.GetComponent<Mesh>();
var whiteShEf = white.GetComponent<DefaultSurfaceEffect>();
var whiteMesh = white.GetComponent<Mesh>();
var greenShEf = green.GetComponent<DefaultSurfaceEffect>();
var greenMesh = green.GetComponent<Mesh>();
// RenderLayer Components
var rl1 = new RenderLayer { Layer = RenderLayers.Layer01 };
var rl2 = new RenderLayer { Layer = RenderLayers.Layer02 };
// Create SceneNodes
var n1 = new SceneNode();
var n2 = new SceneNode();
_scene.Children.Add(n1);
_scene.Children.Add(n2);
// Create Rocket on the left with a rotation
var c1 = new SceneNode();
c1.AddComponent(rl1);
c1.AddComponent(new Transform { Rotation = new float3(0, 1, 0) });
c1.Children.Add(new SceneNode { Components = { rocketTransform, grayShEf, grayMesh, greenShEf, greenMesh, whiteShEf, whiteMesh } });
n1.Children.Add(c1);
// Create Rocke on the right
var c2 = new SceneNode();
c2.AddComponent(rl2);
c2.Children.Add(new SceneNode { Components = { rocketTransform, grayShEf, grayMesh, greenShEf, greenMesh, whiteShEf, whiteMesh } });
n2.Children.Add(c2);
// Cameras
var cam = new SceneNode();
cam.AddComponent(new Transform { Translation = new float3(0, 1.7f, -10), Rotation = new float3(0, 0, 0) });
var cam1 = new Camera(ProjectionMethod.Perspective, 1, 1000, M.PiOver4)
{
Viewport = new float4(0, 0, 50, 100),
BackgroundColor = new float4(1, 0.8f, 0.8f, 1),
Layer = 1,
FrustumCullingOn = false,
RenderLayer = RenderLayers.Layer01
};
cam.AddComponent(cam1);
var cam2 = new Camera(ProjectionMethod.Perspective, 1, 1000, M.PiOver4)
{
Viewport = new float4(50, 0, 50, 100),
BackgroundColor = new float4(0.8f, 1, 0.8f, 1),
Layer = 1,
FrustumCullingOn = false,
RenderLayer = RenderLayers.Layer02
};
cam.AddComponent(cam2);
_scene.Children.Add(cam);
_sceneRenderer = new SceneRendererForward(_scene);
}
- Using FUSEE
- Tutorials
- Examples
- In-Depth Topics
- Input and Input Devices
- The Rendering Pipeline
- Render Layer
- Camera
- Textures
- FUSEE Exporter Blender Add on
- Assets
- Lighting & Materials
- Serialization and protobuf-net
- ImGui
- Blazor/WebAssembly
- Miscellaneous
- Developing FUSEE