Beispiel #1
0
        /// <summary>
        /// Initialise the editor.
        /// </summary>
        /// <param name="terrainEditorProgram">The terrain editor effect to clone. In the default content, this is stored as "Terracotta/TerrainEditorEffect".</param>
        /// <param name="terrain">The terrain to edit.</param>
        public TerrainEditor(PlanarTerrainBlock block)
        {
            this.terrainBlock = block;

            var builder = ShaderBuilder.CreateFromAssemblyResource("Glare.Graphics.Shaders.TerrainEditor.glsl");

            Program = new Program(
                builder.VertexShader("Common", "Vertex"),
                builder.FragmentShader("Common", "Fragment"));

            Program.Uniforms["TerrainSize"].Set(Terrain.BlockSize);
            Program.Uniforms["InverseTerrainSize"].Set(1.0 / Terrain.BlockSize);
            Rng = new Random();

            byte[] permutations = new byte[PerlinSize];
            for (int i = 0; i < permutations.Length; i++)
            {
                permutations[i] = (byte)i;
            }
            for (int i = 0; i < permutations.Length; i++)
            {
                Extensions.Swap(ref permutations[i], ref permutations[Rng.Next(permutations.Length)]);
            }

            CreatePerlinPermutationTexture(permutations);
            CreatePerlinGradientTexture(permutations);
            CreateTemporaryTexture();
            //LoadRandomPerlinTransform();
            PerlinTransform = Matrix4d.Identity;
        }
Beispiel #2
0
        public DynamicTexture(Context context, Format format, Vector4i size)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            this.format      = format;
            this.frameBuffer = new FrameBuffer();
            this.mainProgram = new Program();
            this.dimensions  = size;

            var builder = ShaderBuilder.CreateFromAssemblyResource("Glare.Graphics.Shaders.DynamicTexture.glsl");

            mainProgram.Shaders.AddRange(
                builder.VertexShader("Common", "Vertex"),
                builder.FragmentShader("Common", "Fragment"));
            mainProgram.MustLink();
            mainProgramAction = mainProgram.FragmentStage.Uniforms["Act"];
            mainProgram.Attributes["Position"].BindArray(new Vector2f[] {
                new Vector2f(-1, 1), new Vector2f(-1, -1),
                new Vector2f(1, 1), new Vector2f(1, -1)
            });
        }
Beispiel #3
0
        public PlanarTerrain(int blockSize)
            : base()
        {
            //if (terrainEffect == null) throw new ArgumentNullException("terrainEffect");

            BlockSize = blockSize;

            NarrowHeightTexture = new Texture2D(Formats.Vector2f, blockSize / 16, blockSize);
            SmallHeightTexture  = new Texture2D(Formats.Vector2f, blockSize / 16, blockSize / 16);
            SmallHeightData     = new float[(blockSize / 16) * (blockSize / 16) * 2];

            BlockBuffer = CreateBlockBuffer();

            Texture2D randomTexture = Texture.CreateRandom4nb(256, 256);

            var builder = ShaderBuilder.CreateFromAssemblyResource("Glare.Graphics.Shaders.Terrain.glsl");

            Program = new Program(
                builder.VertexShader("Common", "Vertex"),
                builder.FragmentShader("Common", "Fragment"));
            Program.Uniforms["terrainSize"].Set(blockSize);
            Program.Uniforms["randomTexture"].Set(randomTexture);

            UnitBuffer = GraphicsBuffer.Create(UnitVertices);
        }
Beispiel #4
0
 static ModelProgram()
 {
     shaderBuilder = ShaderBuilder.CreateFromAssemblyResource(ResourceName);
 }