Ejemplo n.º 1
0
        private static async UniTask <Plain> CreateFloor(WorldLayer layer)
        {
            var timing = layer.GetValidScreen().TimingPoints.Update;
            var plain  = new Plain();

            plain.Scale  = new Vector3(40f);
            plain.Shader = new PhongShader();
            var config = new TextureConfig(TextureExpansionMode.NearestNeighbor, TextureShrinkMode.NearestNeighbor,
                                           TextureMipmapMode.None, TextureWrapMode.ClampToEdge, TextureWrapMode.ClampToEdge);
            var texture = await Resources.Sandbox["floor.png"].LoadTextureAsync(config, timing);

            plain.AddComponent(texture);
            plain.Rotation = Quaternion.FromAxisAngle(Vector3.UnitX, -90.ToRadian());
            plain.Updated += _ =>
            {
                var k = plain.GetValidScreen().Keyboard;
                if (k.IsPress(Elffy.InputSystem.Keys.Down))
                {
                    plain.Position.Y -= 0.5f;
                }
                else if (k.IsPress(Elffy.InputSystem.Keys.Up))
                {
                    plain.Position.Y += 0.5f;
                }
            };
            return(await plain.Activate(layer));
        }
Ejemplo n.º 2
0
        private static async UniTask <Plain> CreateFloor2(WorldLayer layer)
        {
            var bufSize    = new Vector2i(256, 256);
            var buffer     = ShaderStorageBuffer.CreateUninitialized <Color4>(bufSize.X * bufSize.Y);
            var dispatcher = new TestComputeShader(() => buffer.Ssbo).CreateDispatcher();
            var plain      = new Plain();

            plain.Position.Z = -10;
            plain.Dead      += _ =>
            {
                buffer.Dispose();
                dispatcher.Dispose();
            };
            plain.Updated += _ => dispatcher.Dispatch(bufSize.X, bufSize.Y, 1);
            plain.Scale    = new Vector3(10f);
            plain.Shader   = new TestShader(() => (buffer.Ssbo, bufSize.X, bufSize.Y));
            plain.Rotation = Quaternion.FromAxisAngle(Vector3.UnitX, -90.ToRadian());

            return(await plain.Activate(layer));
        }