Exemplo n.º 1
0
        public static void Initialize()
        {
            var graphics = AtomicNET.GetSubsystem <Graphics>();

            pixelShader  = graphics.GetShader(ShaderType.PS, "Atomic2D");
            vertexShader = graphics.GetShader(ShaderType.VS, "Atomic2D");

            vertexBuffer = new VertexBuffer();
            vertexBuffer.SetSize(maxVertices, Constants.MASK_POSITION | Constants.MASK_COLOR | Constants.MASK_TEXCOORD1, true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates necessary GUI elements for selecting a material variation.
        /// </summary>
        /// <param name="material">Material for which to provide variation selection.</param>
        /// <param name="layout">GUI layout to which to append GUI elements.</param>
        internal MaterialVariationGUI(Material material, GUILayout layout)
        {
            this.material = material;
            variation     = material.Variation;

            Shader shader = material.Shader.Value;

            if (shader == null)
            {
                return;
            }

            ShaderVariationParamInfo[] variationParams = shader.VariationParams;
            foreach (var param in variationParams)
            {
                if (param.isInternal)
                {
                    continue;
                }

                LocString[] names  = new LocString[param.values.Length];
                int[]       values = new int[names.Length];
                for (int i = 0; i < names.Length; i++)
                {
                    names[i]  = new LocEdString(param.values[i].name);
                    values[i] = param.values[i].value;
                }

                GUIListBoxField listBox = new GUIListBoxField(names, new LocEdString(param.name));
                listBox.OnSelectionChanged += idx =>
                {
                    int value = values[idx];
                    variation.SetInt(param.identifier, value);

                    material.Variation = variation;
                };

                int curValue = variation.GetInt(param.identifier);
                for (int j = 0; j < values.Length; j++)
                {
                    if (curValue == values[j])
                    {
                        listBox.Index = j;
                        break;
                    }
                }

                layout.AddElement(listBox);
            }
        }
Exemplo n.º 3
0
            public void Read(FileReader reader, TreeNodeCustom node)
            {
                reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;

                reader.ReadSignature(4, "BNSH");
                uint padding = reader.ReadUInt32();
                uint Version = reader.ReadUInt32();

                SetVersionInfo(Version);
                ushort ByteOrderMark = reader.ReadUInt16();
                byte   Alignment     = reader.ReadByte();
                byte   Target        = reader.ReadByte();

                FileName = reader.LoadString(0, DataType.uint32);
                uint PathOffset            = reader.ReadUInt32();
                uint RelocationTableOffset = reader.ReadUInt32();
                uint FileSize = reader.ReadUInt32();

                reader.Seek(0x40); //padding
                reader.ReadSignature(4, "grsc");

                uint  BlockOffset = reader.ReadUInt32();
                ulong BlockSize   = reader.ReadUInt64();

                reader.Seek(0x0C);
                uint VariationCount  = reader.ReadUInt32();
                long VariationOffset = reader.ReadUInt32();

                reader.Seek(VariationOffset, SeekOrigin.Begin);
                for (int i = 0; i < VariationCount; i++)
                {
                    ShaderVariation var = new ShaderVariation();
                    var.Text = "Shader Variation" + i;
                    var.Read(reader);
                    ShaderVariations.Add(var);
                    node.Nodes.Add(var);
                }

                reader.Close();
                reader.Dispose();
            }
Exemplo n.º 4
0
    public override void Start()
    {
        // We get the variables we are going to use in this example
        Renderer renderer = GetSubsystem <Renderer>();

        graphics = GetSubsystem <Graphics>();
        viewport = renderer.GetViewport(0);

        // We create a new Scene
        scene = new Scene();
        // The Octree should be added to the root scene node (mandatory?) TODO: answer this
        scene.CreateComponent <Octree>();
        // We pass the scene we just created to be displayed in the viewport
        viewport.Scene = scene;

        // We create a new camera on the scene, called "Camera". Tip: you can think of a camera as a glorified projection matrix
        // - Scene.CreateChild(string name) returns a new Node with that name.
        // - Node.CreateComponent<ComponentType>() returns a component attached to that Node
        camera = scene.CreateChild("Camera").CreateComponent <Camera>();
        // We can access the Node any component is attached to using Component.Node
        camera.Node.Position = new Vector3(0.5f, 0.5f, 0.0f);
        // Remember, 'camera' is a Camera component, so we access it directly here
        camera.Orthographic = true;
        camera.OrthoSize    = 1.5f;
        // We pass our newly created camera to the viewport so it's used to display our scene
        viewport.Camera = camera;

        // We create an XML from string so this code is fully self-contained
        XMLFile xml = new XMLFile(); xml.FromString("<renderpath><command type=\"sendevent\"/></renderpath>");

        // We create a new RenderPath. A Viewport comes by default with some events, and you can use viewport.GetRenderPath().Clone()
        // to clone the default RenderPath and Append instructions to it instead (see AtomicBlaster for examples on how to do effects)
        RenderPath renderpath = new RenderPath();

        renderpath.Append(xml);
        // We replace the viewport's default renderpath by the one we just created
        viewport.SetRenderPath(renderpath);
        // We subscribe to the RenderPathEvent. Here we pass an anonymous function that just absorbs the argument and calls Render()
        SubscribeToEvent <RenderPathEvent>(e => { Render(); });

        // Here we setup our shaders, we are using the BasicVColUnlitAlpha "technique" and selecting DIFFMAP and VERTEXCOLOR
        // DIFFMAP is the diffuse texture and VERTEXCOLOR is a color each vertex holds that is used to 'tint' the surface
        // See this link: github.com/AtomicGameEngine/AtomicGameEngine/tree/master/Resources/CoreData/Techniques
        ShaderVariation pixelShader  = graphics.GetShader(ShaderType.PS, "Basic", "DIFFMAP VERTEXCOLOR");
        ShaderVariation vertexShader = graphics.GetShader(ShaderType.VS, "Basic", "DIFFMAP VERTEXCOLOR");

        graphics.SetShaders(vertexShader, pixelShader);
        // This vertex shader parameter just applies no transformation (Identity Matrix means no transformation) so the vertices
        // display in world coordinates what allow us to use the camera properly. NOTE: Identity Matrix is also called Unit Matrix
        graphics.SetShaderParameter(ShaderParams.VSP_MODEL, Matrix3x4.IDENTITY);
        // We set the pixel shader diffuse color to be white. You can change this to 'tint' the texture similar to vertex colors
        // but this applies to the whole material and in this example vertex colors will also affect it
        graphics.SetShaderParameter(ShaderParams.PSP_MATDIFFCOLOR, Color.White);
        // We set cull mode to NONE so our geometry won't be culled (ignored), for this example we don't really need any culling
        graphics.SetCullMode(CullMode.CULL_NONE);

        // We create a texture from literal data so this code is fully self-contained, you can safely skip the lines below.
        // In your real projects you're most likely going to load textures from the disk using Texture.Load
        Image image = new Image();

        image.SetSize(16, 16, 3);

        Color z = Color.White;
        Color M = Color.Blue;
        Color k = Color.Black;

        Color[] imageData =
        {
            k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k,
            k, z, z, z, z, z, z, z, z, z, z, z, z, z, M, k,
            k, z, z, z, z, z, z, M, M, z, z, z, z, z, z, k,
            k, z, z, z, z, z, z, M, M, z, z, z, z, z, z, k,
            k, z, z, z, z, z, M, z, z, M, z, z, z, z, z, k,
            k, z, z, z, z, z, M, z, z, M, z, z, z, z, z, k,
            k, z, z, z, z, M, z, z, z, z, M, z, z, z, z, k,
            k, z, z, z, z, M, z, z, z, z, M, z, z, z, z, k,
            k, z, z, z, M, z, z, z, z, z, z, M, z, z, z, k,
            k, z, z, z, M, z, z, z, z, z, z, M, z, z, z, k,
            k, z, z, M, M, M, M, M, M, M, M, M, M, z, z, k,
            k, z, z, M, z, z, z, z, z, z, z, z, M, z, z, k,
            k, z, M, z, z, z, z, z, z, z, z, z, z, M, z, k,
            k, z, M, z, z, z, z, z, z, z, z, z, z, M, z, k,
            k, z, z, z, z, z, z, z, z, z, z, z, z, z, z, k,
            k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k,
        };

        for (int pixel = 0; pixel < imageData.Length; pixel++)
        {
            image.SetPixel(pixel % 16, 15 - pixel / 16, imageData[pixel]);
        }

        texture = new Texture2D();
        texture.SetData(image);

        // We call this function that creates the quad geometry
        CreateQuad();
    }
 public void Render(ShaderVariation variation)
 {
 }
 public ShaderVariationWrapper(ShaderVariation variation)
 {
     VariationData = variation;
 }
Exemplo n.º 7
0
        public static void Initialize()
        {
            var graphics = AtomicNET.GetSubsystem<Graphics>();

            pixelShader = graphics.GetShader(ShaderType.PS, "Atomic2D");
            vertexShader = graphics.GetShader(ShaderType.VS, "Atomic2D");

            vertexBuffer = new VertexBuffer();
            vertexBuffer.SetSize(maxVertices, Constants.MASK_POSITION | Constants.MASK_COLOR | Constants.MASK_TEXCOORD1, true);
        }