コード例 #1
0
        private static void Initialize(string name)
        {
            if (cntr == 0)
            {
                TerrainTileMesh.Create(2, TerrainTileEdge.None, out var indices);
                indexBuffer = new StreamableBuffer(name + "_indices", (ulong)indices.Length * sizeof(uint), BufferUsage.Index);
                paramBuffer = new StreamableBuffer(name + "_params", 4096, BufferUsage.Uniform);
                indexCount  = (uint)indices.Length;

                unsafe
                {
                    var i_ptr = (uint *)indexBuffer.BeginBufferUpdate();
                    for (int i = 0; i < indices.Length; i++)
                    {
                        i_ptr[i] = indices[i];
                    }
                    indexBuffer.EndBufferUpdate();
                }

                vertexShader = new SpecializedShader()
                {
                    Name               = name + "_Vert",
                    Shader             = ShaderSource.Load(ShaderType.VertexShader, "PlanetTerrain/vertex.glsl"),
                    SpecializationData = null
                };

                fragmentShader = new SpecializedShader()
                {
                    Name               = name + "_Frag",
                    Shader             = ShaderSource.Load(ShaderType.FragmentShader, "UVRenderer/fragment.glsl"),
                    SpecializationData = null,
                };
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: himanshugoel2797/KokoroVR
        static void Main(string[] args)
        {
            Engine.AppName          = "Test";
            Engine.EnableValidation = true;
            Engine.Initialize();

            var graph = new FrameGraph(0);

            Engine.RenderGraph = graph;

            vertS = new SpecializedShader()
            {
                Name               = "FST_Vert",
                Shader             = ShaderSource.Load(ShaderType.VertexShader, "FullScreenTriangle/vertex.glsl"),
                SpecializationData = null
            };

            fragS = new SpecializedShader()
            {
                Name               = "UVR_Frag",
                Shader             = ShaderSource.Load(ShaderType.FragmentShader, "FullScreenTriangle/clear_frag.glsl"),
                SpecializationData = null,
            };

            depthImages     = new Image[GraphicsDevice.MaxFramesInFlight];
            depthImageViews = new ImageView[GraphicsDevice.MaxFramesInFlight];
            for (int i = 0; i < GraphicsDevice.MaxFramesInFlight; i++)
            {
                depthImages[i] = new Image($"depthImage_{i}")
                {
                    Cubemappable  = false,
                    Width         = GraphicsDevice.Width,
                    Height        = GraphicsDevice.Height,
                    Depth         = 1,
                    Dimensions    = 2,
                    InitialLayout = ImageLayout.Undefined,
                    Layers        = 1,
                    Levels        = 1,
                    MemoryUsage   = MemoryUsage.GpuOnly,
                    Usage         = ImageUsage.DepthAttachment | ImageUsage.Sampled,
                    Format        = ImageFormat.Depth32f,
                };
                depthImages[i].Build(0);

                depthImageViews[i] = new ImageView($"depthImageView_{i}")
                {
                    BaseLayer  = 0,
                    BaseLevel  = 0,
                    Format     = ImageFormat.Depth32f,
                    LayerCount = 1,
                    LevelCount = 1,
                    ViewType   = ImageViewType.View2D,
                };
                depthImageViews[i].Build(depthImages[i]);
            }

            planetBuffers = new StreamableBuffer("planetBuffer", 2049 * 2049 * 2 * 6, BufferUsage.Storage);
            unsafe
            {
                var us_ptr = (ushort *)planetBuffers.BeginBufferUpdate();
                for (int i = 0; i < 6; i++)
                {
                    using (FileStream fs = File.OpenRead($"face_eroded_{i}.bin"))
                        using (BinaryReader br = new BinaryReader(fs))
                            for (int j = 0; j < 2049 * 2049; j++)
                            {
                                us_ptr[j] = br.ReadUInt16();
                            }
                    us_ptr += 2049 * 2049;
                }
                planetBuffers.EndBufferUpdate();
            }

            planet = new Planet("terrain_", "planetBuffer", 6000, null);

            Engine.OnRebuildGraph += Engine_OnRebuildGraph;
            Engine.OnRender       += Engine_OnRender;
            Engine.OnUpdate       += Engine_OnUpdate;
            Engine.Start(0);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Engine.AppName          = "Test";
            Engine.EnableValidation = true;
            Engine.RebuildShaders   = true;
            Engine.Initialize();

            var graph = new FrameGraph(0);

            Engine.RenderGraph = graph;

            int trace_side       = 1024;
            var objLoaderFactory = new ObjLoaderFactory();
            var objLoader        = objLoaderFactory.Create();

            using (var fs = File.OpenRead("sponza.obj"))
            {
                var obj_loaded = objLoader.Load(fs);

                ulong idxCount = 0;
                for (int i = 0; i < obj_loaded.Groups.Count; i++)
                {
                    idxCount += (ulong)obj_loaded.Groups[i].Faces.Count * 3;
                }

                vertexBuffer     = new StreamableBuffer("vbo", (ulong)obj_loaded.Vertices.Count * 3 * sizeof(float), BufferUsage.Storage);
                indexBuffer      = new StreamableBuffer("ibo", idxCount * sizeof(uint), BufferUsage.Index | BufferUsage.Storage);
                rayIntersections = new RayIntersections("rayInter", (uint)trace_side * (uint)trace_side, 0);
                geometry         = new RayGeometry("rayGeom", (uint)obj_loaded.Vertices.Count);
                unsafe
                {
                    float *fp = (float *)vertexBuffer.BeginBufferUpdate();
                    for (int i = 0; i < obj_loaded.Vertices.Count; i++)
                    {
                        fp[0] = obj_loaded.Vertices[i].X;
                        fp[1] = obj_loaded.Vertices[i].Y;
                        fp[2] = obj_loaded.Vertices[i].Z;

                        fp += 3;
                    }
                    vertexBuffer.EndBufferUpdate();

                    uint *ui = (uint *)indexBuffer.BeginBufferUpdate();
                    for (int i = 0; i < obj_loaded.Groups.Count; i++)
                    {
                        for (int j = 0; j < obj_loaded.Groups[i].Faces.Count; j++)
                        {
                            ui[0] = (uint)(obj_loaded.Groups[i].Faces[j][0].VertexIndex - 1);
                            ui[1] = (uint)(obj_loaded.Groups[i].Faces[j][1].VertexIndex - 1);
                            ui[2] = (uint)(obj_loaded.Groups[i].Faces[j][2].VertexIndex - 1);

                            ui += 3;
                        }
                    }
                    indexBuffer.EndBufferUpdate();

                    float *rp = (float *)rayIntersections.RayBuffer.BeginBufferUpdate();
                    for (uint x = 0; x < trace_side; x++)
                    {
                        for (uint y = 0; y < trace_side; y++)
                        {
                            //uint i = 0;
                            //for(int j = 0; j < 15; j++)
                            //{
                            //    i |= ((x & (1u << j)) << j) | ((y & (1u << j)) << (j + 1));
                            //}

                            //i *= 8;
                            uint i = ((uint)trace_side * y + x) * 8;
                            rp[i + 0] = 0.0f;
                            rp[i + 1] = 15.0f;
                            rp[i + 2] = 0.0f;

                            rp[i + 4] = -1.0f;
                            rp[i + 5] = -1.0f + (2.0f / trace_side) * y;
                            rp[i + 6] = -1.0f + (2.0f / trace_side) * x;

                            rp[i + 3] = 0.001f;
                            rp[i + 7] = 100000.0f;
                        }
                    }
                    rayIntersections.RayBuffer.EndBufferUpdate();

                    geometry.SetupBuild(0, (uint)(idxCount / 3), vertexBuffer.LocalBuffer, 0, indexBuffer.LocalBuffer, 0, false);
                }
            }


            vertS = new SpecializedShader()
            {
                Name               = "FST_Vert",
                Shader             = ShaderSource.Load(ShaderType.VertexShader, "FullScreenTriangle/vertex.glsl"),
                SpecializationData = null
            };

            fragS = new SpecializedShader()
            {
                Name               = "UVR_Frag",
                Shader             = ShaderSource.Load(ShaderType.FragmentShader, "FullScreenTriangle/clear_frag.glsl"),
                SpecializationData = null,
            };

            depthImages     = new Image[GraphicsDevice.MaxFramesInFlight];
            depthImageViews = new ImageView[GraphicsDevice.MaxFramesInFlight];
            for (int i = 0; i < GraphicsDevice.MaxFramesInFlight; i++)
            {
                depthImages[i] = new Image($"depthImage_{i}")
                {
                    Cubemappable  = false,
                    Width         = GraphicsDevice.Width,
                    Height        = GraphicsDevice.Height,
                    Depth         = 1,
                    Dimensions    = 2,
                    InitialLayout = ImageLayout.Undefined,
                    Layers        = 1,
                    Levels        = 1,
                    MemoryUsage   = MemoryUsage.GpuOnly,
                    Usage         = ImageUsage.DepthAttachment | ImageUsage.Sampled,
                    Format        = ImageFormat.Depth32f,
                };
                depthImages[i].Build(0);

                depthImageViews[i] = new ImageView($"depthImageView_{i}")
                {
                    BaseLayer  = 0,
                    BaseLevel  = 0,
                    Format     = ImageFormat.Depth32f,
                    LayerCount = 1,
                    LevelCount = 1,
                    ViewType   = ImageViewType.View2D,
                };
                depthImageViews[i].Build(depthImages[i]);
            }

            Engine.OnRebuildGraph += Engine_OnRebuildGraph;
            Engine.OnRender       += Engine_OnRender;
            Engine.OnUpdate       += Engine_OnUpdate;
            Engine.Start(0);
        }