Rss

A Basic Scene, with a single Surface and sub-scene

ISE 3.1-Compatible

Untitled

 

This example shows how to render a scene, with anothe rscene rendered into a Surface. A Surface is a texture with an optional depth buffer, and can be rendered to any specific resolution.

First, some standard Panel setup:

    public class Panel_25 : Panel
    {
        public Panel_25()
            : base("Icarus Scene Engine 3.1 Panel 25: Surfaces Test") { }

        Camera cam1 = new Camera(new PerspectiveLens(45,0,1,1000), new Trajectory(new Vector(25, 25, 25), new Vector(0, 0, 0), new Vector(0, 1, 0)));
        Shape.Box box1 = new Shape.Box(15, 15, 15);
        Shape.Box box2 = new Shape.Box(15, 15, 15, new Vector(-15,0,-15));

        Light myLight = new Light(DefaultColors.darkgrey,    // Ambient (background or "minimum" Colour)
                            DefaultColors.lightgrey,   // Diffuse Colour (primary colour of the object when hit by Light)
                            DefaultColors.lightyellow, // Specular Colour (Highlight colour of the light)
                            new Vector(6, 26, 10));         // Position of the light. Specifying a Vector defines an Omni-directional Light.

        Light mySurfaceLight = new Light(DefaultColors.darkgrey,    // Ambient (background or "minimum" Colour)
                                    DefaultColors.lightred,   // Diffuse Colour (primary colour of the object when hit by Light)
                                    DefaultColors.lightyellow, // Specular Colour (Highlight colour of the light)
                                    new Vector(6, 26, 10));         // Position of the light. Specifying a Vector defines an Omni-directional Light.

        Camera surfcam = new Camera(new PerspectiveLens(45, 0, 1, 100), new Trajectory(new Vector(5, 5, 5), new Vector(0, 0, 0), new Vector(0, 1, 0)));
        Shape.Sphere surfball = new Shape.Sphere(5, 5, 5, true, true, new Vector(0,0,0));
        Scene CamAnimator = new Scene();

Now, add in the Surface. As it’s attached to the class as a class-variable, we can’t initialise it yet.

        Surface surface;

Then, in the Initialise override, we’ll put the scene together

        public override void Initialise()
        {

            Add(cam1);
            Add(CamAnimator);
            cam1.Add(myLight);
            cam1.Add(box1);

            currcam = cam1;

Now we will initialise the Surface:

            surface = new Surface(42,42, new Color(0.1f, 0.1f, 0.3f, 1f));           			

            Add(surface);
            surface.Add(mySurfaceLight);
            surface.Add(surfcam);          
            surfcam.Add(surfball);

This creates a Surface that is 42 pixels wide x 42 pixels high, with a default background color of a medium-light yellow.

The surface is then added to the Panel. It doesn’t need to be in a Scene or Camera to be able to render, as it is it’s own context. It’s better if it’s not under a Camera anyway as this will cause excessive context switching internally in ISE.

After it’s added (although it doesn’t need to be after, it just looks neater that way), we then add a light, and a Camera. We then add a Sphere (surfball) to the camera.

That will create the Surface, which will then be rendered in, but we still won’t be able to see it, basically it’s just rendered the surface scene to a texture. We now need to render that texture to be able to see it. Fortunately, that’s easy as well!

To do that, we simply assign the Surface to a Material, which is then assigned to something that renders. It’s easier to see here, where the surface is assigned to render on a Box.

The other proeprties on the Material just set up some general material properties, so that it rendes transparently.

            box1.Material = new TexturedMaterial(surface.AsTexture());
			box1.Material.DepthAffecting = false;
            box1.Material.Blended = true;
            box1.Material.Colored.BlendSource = BlendFactor.SrcAlpha;
            box1.Material.Colored.BlendDestination = BlendFactor.One;
        }
    }
}

And that’s it!

Untitled