Example #1
0
        public RenderCubemapSphere(Vector3 pos, float size, CubemapTexture tex, bool spining = false)
            : base()
        {
            myIsSpinning = spining;
            myPos        = pos;
            mySize       = size;

            if (myIsSpinning == true)
            {
                float rot = (float)(TimeSource.currentTime() / 2.0);
                theOrientation = Matrix4.CreateFromQuaternion(new Quaternion(0, rot, 0));
                renderState.setUniform(new UniformData(0, Uniform.UniformType.Mat4, theOrientation * Matrix4.CreateTranslation(myPos)));
            }
            else
            {
                renderState.setUniform(new UniformData(0, Uniform.UniformType.Mat4, Matrix4.CreateTranslation(myPos)));
            }
            renderState.setUniform(new UniformData(1, Uniform.UniformType.Float, size));

            renderState.setTexture(tex.id(), 0, tex.target);
            renderState.setUniform(new UniformData(20, Uniform.UniformType.Int, 0));

            renderState.setVertexBuffer(theVBO.id, 0, 0, V3.stride);
            renderState.setIndexBuffer(theIBO.id);

            pipelineState = thePipeline;
        }
        /// <summary>
        /// Decodes the texture from the specified stream.
        /// </summary>
        /// <param name="stream">The stream, where the texture should be decoded from. Cannot be null.</param>
        /// <returns>The decoded image.</returns>
        public Texture DecodeTexture(Stream stream)
        {
            this.ReadFileHeader(stream);

            if (this.ktxHeader.Width == 0)
            {
                throw new UnknownTextureFormatException("Width cannot be 0");
            }

            int width = (int)this.ktxHeader.Width;
            int height = (int)this.ktxHeader.Height;

            // Skip over bytesOfKeyValueData, if any is present.
            stream.Position += this.ktxHeader.BytesOfKeyValueData;

            var ktxProcessor = new KtxProcessor(this.ktxHeader);

            if (this.ktxHeader.NumberOfFaces == 6)
            {
                CubemapTexture cubeMapTexture = ktxProcessor.DecodeCubeMap(stream, width, height);
                return cubeMapTexture;
            }

            var texture = new FlatTexture();
            MipMap[] mipMaps = ktxProcessor.DecodeMipMaps(stream, width, height, this.ktxHeader.NumberOfMipmapLevels);
            texture.MipMaps.AddRange(mipMaps);
            return texture;
        }
Example #3
0
        public Generator()
        {
            for (int i = 0; i < 6; i++)
            {
                myElevationTex[i] = new Texture(WorldParameters.theWorldTextureSize, WorldParameters.theWorldTextureSize, PixelInternalFormat.R32f);
                myElevationTex[i].setName(String.Format("Elevation Tex {0}", i));
                myBiomeTex[i] = new Texture(WorldParameters.theWorldTextureSize, WorldParameters.theWorldTextureSize, PixelInternalFormat.Rgba32f);
                myBiomeTex[i].setName(String.Format("Biome Tex {0}", i));
            }

            myElevationMap = new CubemapTexture(WorldParameters.theWorldTextureSize, WorldParameters.theWorldTextureSize, PixelInternalFormat.R32f);
            myElevationMap.setName("Elevation Cubemap");

            myBiomeMap = new CubemapTexture(WorldParameters.theWorldTextureSize, WorldParameters.theWorldTextureSize, PixelInternalFormat.Rgba32f);
            myBiomeMap.setName("Biome Cubemap");

            List <ShaderDescriptor> shadersDesc = new List <ShaderDescriptor>();

            shadersDesc.Add(new ShaderDescriptor(ShaderType.ComputeShader, "World Editor.shaders.applyElevation-cs.glsl"));
            ShaderProgramDescriptor sd = new ShaderProgramDescriptor(shadersDesc);

            myApplyElevationShader = Renderer.resourceManager.getResource(sd) as ShaderProgram;

            shadersDesc = new List <ShaderDescriptor>();
            shadersDesc.Add(new ShaderDescriptor(ShaderType.ComputeShader, "World Editor.shaders.applyHeat-cs.glsl"));
            sd = new ShaderProgramDescriptor(shadersDesc);
            myApplyHeatShader = Renderer.resourceManager.getResource(sd) as ShaderProgram;

            shadersDesc = new List <ShaderDescriptor>();
            shadersDesc.Add(new ShaderDescriptor(ShaderType.ComputeShader, "World Editor.shaders.applyMoisture-cs.glsl"));
            sd = new ShaderProgramDescriptor(shadersDesc);
            myApplyMoistureShader = Renderer.resourceManager.getResource(sd) as ShaderProgram;

            shadersDesc = new List <ShaderDescriptor>();
            shadersDesc.Add(new ShaderDescriptor(ShaderType.ComputeShader, "World Editor.shaders.applyBiome-cs.glsl"));
            sd = new ShaderProgramDescriptor(shadersDesc);
            myGenerateBiomeShader = Renderer.resourceManager.getResource(sd) as ShaderProgram;

            //setup generators
            myElevationGenerator   = new ModuleTree(WorldParameters.theWorldTextureSize, WorldParameters.theWorldTextureSize);
            myElevationFractals[0] = myElevationGenerator.addModule(Module.Type.Fractal, "fractal0") as Fractal;
            myElevationFractals[1] = myElevationGenerator.addModule(Module.Type.Fractal, "fractal") as Fractal;
            myElevationFractals[2] = myElevationGenerator.addModule(Module.Type.Fractal, "fractal2") as Fractal;
            myElevationFractals[3] = myElevationGenerator.addModule(Module.Type.Fractal, "fractal3") as Fractal;
            myElevationFractals[4] = myElevationGenerator.addModule(Module.Type.Fractal, "fractal4") as Fractal;
            myElevationFractals[5] = myElevationGenerator.addModule(Module.Type.Fractal, "fractal5") as Fractal;
            AutoCorrect Eac = myElevationGenerator.addModule(Module.Type.AutoCorect, "autocorrect") as AutoCorrect;

            myHeatGenerator     = createHeatGenerator();
            myMoistureGenerator = createMoistureGenerator();
        }
Example #4
0
        public Planet(Camera c, CubemapTexture elevationMap)
        {
            myCamera       = c;
            myNoiseTexture = elevationMap;
            for (int i = 0; i < MAX_TRI; i++)
            {
                myTris.Add(new Tri());
            }

            myFov    = MathHelper.DegreesToRadians(myCamera.fieldOfView);
            mySinFov = (float)Math.Sin(myFov);
            myCosFov = (float)Math.Cos(myFov);

            init();

            myTextureManager.init();

            //setup the shader
            List <ShaderDescriptor> desc = new List <ShaderDescriptor>();

            desc.Add(new ShaderDescriptor(ShaderType.VertexShader, "Test IcoPlanet.shaders.draw-planet-vs.glsl"));
            //desc.Add(new ShaderDescriptor(ShaderType.GeometryShader, "Test IcoPlanet.shaders.draw-planet-gs.glsl"));
            desc.Add(new ShaderDescriptor(ShaderType.FragmentShader, "Test IcoPlanet.shaders.draw-planet-ps.glsl"));
            ShaderProgramDescriptor sd     = new ShaderProgramDescriptor(desc);
            ShaderProgram           shader = Renderer.resourceManager.getResource(sd) as ShaderProgram;

            myRenderPlanetCommand = new StatelessDrawElementsCommand(PrimitiveType.Triangles, (int)myIndexCount, 0, IndexBufferObject.IndexBufferDatatype.UnsignedInt);
            myRenderPlanetCommand.pipelineState.shaderState.shaderProgram = shader;
            myRenderPlanetCommand.pipelineState.vaoState.vao = new VertexArrayObject();
            myRenderPlanetCommand.pipelineState.vaoState.vao.bindVertexFormat(shader, V3F1.bindings());
            myRenderPlanetCommand.pipelineState.generateId();

            desc.Clear();
            desc.Add(new ShaderDescriptor(ShaderType.VertexShader, "Test IcoPlanet.shaders.planet-water-vs.glsl"));
            desc.Add(new ShaderDescriptor(ShaderType.FragmentShader, "Test IcoPlanet.shaders.planet-water-ps.glsl"));
            sd     = new ShaderProgramDescriptor(desc);
            shader = Renderer.resourceManager.getResource(sd) as ShaderProgram;

            myRenderWaterCommand = new StatelessDrawElementsCommand(PrimitiveType.Triangles, (int)myIndexCount, 0, IndexBufferObject.IndexBufferDatatype.UnsignedInt);
            myRenderWaterCommand.pipelineState.shaderState.shaderProgram = shader;
            myRenderWaterCommand.pipelineState.vaoState.vao = new VertexArrayObject();
            myRenderWaterCommand.pipelineState.vaoState.vao.bindVertexFormat(shader, V3F1.bindings());
            myRenderWaterCommand.pipelineState.blending.enabled = true;
            myRenderWaterCommand.pipelineState.generateId();


            myHeightTexture = new Texture("../data/textures/EarthLookupTable.png");
        }
Example #5
0
        public unsafe override void CreateDeviceObjects(RenderContext rc)
        {
            ResourceFactory factory = rc.ResourceFactory;

            _vb = factory.CreateVertexBuffer(s_vertices.Length * VertexPosition.SizeInBytes, false);
            _vb.SetVertexData(s_vertices, new VertexDescriptor(VertexPosition.SizeInBytes, 1, IntPtr.Zero));

            _ib = factory.CreateIndexBuffer(s_indices.Length * sizeof(int), false);
            _ib.SetIndices(s_indices);

            SkyboxSetInfo.CreateAll(
                factory,
                ShaderHelper.LoadBytecode(factory, "Skybox", ShaderStages.Vertex),
                ShaderHelper.LoadBytecode(factory, "Skybox", ShaderStages.Fragment),
                out _shaderSet,
                out _resourceSlots);

            _viewMatrixBuffer = factory.CreateConstantBuffer(ShaderConstantType.Matrix4x4);

            fixed(Rgba32 *frontPin = &_front.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            fixed(Rgba32 * backPin   = &_back.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            fixed(Rgba32 * leftPin   = &_left.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            fixed(Rgba32 * rightPin  = &_right.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            fixed(Rgba32 * topPin    = &_top.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            fixed(Rgba32 * bottomPin = &_bottom.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            {
                _cubemapTexture = factory.CreateCubemapTexture(
                    (IntPtr)frontPin,
                    (IntPtr)backPin,
                    (IntPtr)leftPin,
                    (IntPtr)rightPin,
                    (IntPtr)topPin,
                    (IntPtr)bottomPin,
                    _front.Width,
                    _front.Height,
                    _front.PixelSizeInBytes,
                    _front.Format);
                _cubemapBinding = factory.CreateShaderTextureBinding(_cubemapTexture);
            }

            _rasterizerState = factory.CreateRasterizerState(FaceCullingMode.None, TriangleFillMode.Solid, false, false);
        }
Example #6
0
        public GpuNoiseCubeMap(int width, int height, float seed = 0.0f)
        {
            myWidth  = width;
            myHeight = height;
            mySeed   = seed;

            for (int i = 0; i < 6; i++)
            {
                myTextures[i]     = new Texture(myWidth, myHeight, PixelInternalFormat.R32f);
                myFractal[i]      = new Fractal(myWidth, myHeight);
                myFractal[i].face = i;
            }

            myCubemap = new CubemapTexture(width, height, PixelInternalFormat.R32f);
            myCubemap.setName("Terrain Cubemap");

            myAutoCorrect = new AutoCorrect(myWidth, myHeight);

            generateTextures();
        }
Example #7
0
        /// <summary>
        /// Decodes the texture from the specified stream.
        /// </summary>
        /// <param name="stream">The stream, where the texture should be decoded from. Cannot be null.</param>
        /// <returns>The decoded image.</returns>
        public Texture DecodeTexture(Stream stream)
        {
            this.ReadFileHeader(stream);

            if (this.ktxHeader.PixelWidth == 0)
            {
                throw new UnknownTextureFormatException("Width cannot be 0");
            }

            int width  = (int)this.ktxHeader.PixelWidth;
            int height = (int)this.ktxHeader.PixelHeight;

            var levelIndices = new LevelIndex[this.ktxHeader.LevelCount];

            for (int i = 0; i < levelIndices.Length; i++)
            {
                stream.Read(this.buffer, 0, 24);
                LevelIndex levelIndex = MemoryMarshal.Cast <byte, LevelIndex>(this.buffer)[0];
                levelIndices[i] = levelIndex;
            }

            if (this.ktxHeader.SupercompressionScheme != 0)
            {
                throw new NotSupportedException("SupercompressionSchemes are not yet supported");
            }

            var ktxProcessor = new Ktx2Processor(this.ktxHeader);

            if (this.ktxHeader.FaceCount == 6)
            {
                CubemapTexture cubeMapTexture = ktxProcessor.DecodeCubeMap(stream, width, height, levelIndices);
                return(cubeMapTexture);
            }

            var texture = new FlatTexture();

            MipMap[] mipMaps = ktxProcessor.DecodeMipMaps(stream, width, height, levelIndices);
            texture.MipMaps.AddRange(mipMaps);

            return(texture);
        }
Example #8
0
        /// <summary>
        /// Decodes the texture from the specified stream.
        /// </summary>
        /// <param name="stream">The stream, where the texture should be decoded from. Cannot be null.</param>
        /// <returns>The decoded image.</returns>
        public Texture DecodeTexture(Stream stream)
        {
            try
            {
                this.ReadFileHeader(stream);

                if (this.ddsHeader.Width == 0 || this.ddsHeader.Height == 0)
                {
                    throw new UnknownTextureFormatException("Width or height cannot be 0");
                }

                var ddsProcessor = new DdsProcessor(this.ddsHeader, this.ddsDxt10header);

                int width  = (int)this.ddsHeader.Width;
                int height = (int)this.ddsHeader.Height;
                int count  = this.ddsHeader.TextureCount();

                if (this.ddsHeader.IsVolumeTexture())
                {
                    int depths = this.ddsHeader.ComputeDepth();

                    var texture  = new VolumeTexture();
                    var surfaces = new FlatTexture[depths];

                    for (int i = 0; i < count; i++)
                    {
                        for (int depth = 0; depth < depths; depth++)
                        {
                            if (i == 0)
                            {
                                surfaces[depth] = new FlatTexture();
                            }

                            MipMap[] mipMaps = ddsProcessor.DecodeDds(stream, width, height, 1);
                            surfaces[depth].MipMaps.AddRange(mipMaps);
                        }

                        depths >>= 1;
                        width  >>= 1;
                        height >>= 1;
                    }

                    texture.Slices.AddRange(surfaces);
                    return(texture);
                }
                else if (this.ddsHeader.IsCubemap())
                {
                    DdsSurfaceType[] faces = this.ddsHeader.GetExistingCubemapFaces();

                    var texture = new CubemapTexture();
                    for (int face = 0; face < faces.Length; face++)
                    {
                        MipMap[] mipMaps = ddsProcessor.DecodeDds(stream, width, height, count);
                        if (faces[face] == DdsSurfaceType.CubemapPositiveX)
                        {
                            texture.PositiveX.MipMaps.AddRange(mipMaps);
                        }

                        if (faces[face] == DdsSurfaceType.CubemapNegativeX)
                        {
                            texture.NegativeX.MipMaps.AddRange(mipMaps);
                        }

                        if (faces[face] == DdsSurfaceType.CubemapPositiveY)
                        {
                            texture.PositiveY.MipMaps.AddRange(mipMaps);
                        }

                        if (faces[face] == DdsSurfaceType.CubemapNegativeY)
                        {
                            texture.NegativeY.MipMaps.AddRange(mipMaps);
                        }

                        if (faces[face] == DdsSurfaceType.CubemapPositiveZ)
                        {
                            texture.PositiveZ.MipMaps.AddRange(mipMaps);
                        }

                        if (faces[face] == DdsSurfaceType.CubemapNegativeZ)
                        {
                            texture.NegativeZ.MipMaps.AddRange(mipMaps);
                        }
                    }

                    return(texture);
                }
                else
                {
                    var      texture = new FlatTexture();
                    MipMap[] mipMaps = ddsProcessor.DecodeDds(stream, width, height, count);
                    texture.MipMaps.AddRange(mipMaps);
                    return(texture);
                }
            }
            catch (IndexOutOfRangeException e)
            {
                throw new TextureFormatException("Dds image does not have a valid format.", e);
            }
        }