コード例 #1
0
        private static int RenderHdrToCubemapSkybox(Matrix4 view, Matrix4 projection, ISceneObject skybox)
        {
            GL.CullFace(CullFaceMode.Front);
            GL.DepthFunc(DepthFunction.Lequal);
            SkyboxSceneObjectComponent skyboxComponent     = (SkyboxSceneObjectComponent)skybox.components["SkyboxSceneObjectComponent"];
            MeshSceneObjectComponent   skyboxMeshComponent = (MeshSceneObjectComponent)skybox.components["MeshSceneObjectComponent"];

            GL.UseProgram(skyboxComponent.Shader.ProgramID);
            skyboxComponent.Shader.EnableVertexAttribArrays();
            GL.UniformMatrix4(skyboxComponent.Shader.GetUniform("projection"), false, ref projection);
            Matrix4 clearTraslationViewMatrix = view.ClearTranslation();

            GL.UniformMatrix4(skyboxComponent.Shader.GetUniform("view"), false, ref clearTraslationViewMatrix);
            bool isSetted =
                new UniformHelper().
                TryAddUniformTextureCubemap(skyboxComponent.EnvironmentMap, "environmentMap", skyboxComponent.Shader, TextureUnit.Texture0);

            if (!isSetted)
            {
                Console.WriteLine("wrong uniform");
            }
            GL.DrawElements(BeginMode.Triangles, skyboxMeshComponent.ModelMesh.IndiceCount, DrawElementsType.UnsignedInt, 0 * sizeof(uint));
            GL.DepthFunc(DepthFunction.Less);
            skyboxComponent.Shader.DisableVertexAttribArrays();
            return(skyboxMeshComponent.ModelMesh.IndiceCount);
        }
コード例 #2
0
        public virtual void OnTransform()
        {
            MeshSceneObjectComponent meshCompnent = (MeshSceneObjectComponent)components["MeshSceneObjectComponent"];

            meshCompnent.ModelMesh.Transform.Position = _position;
            meshCompnent.ModelMesh.Transform.Scale    = _scale;
            meshCompnent.ModelMesh.Transform.Rotation = _rotaion;
        }
コード例 #3
0
        public Skybox(string skyboxLocation = "Resources//newport_loft.hdr") : base("HdriSkybox")
        {
            SkyboxSceneObjectComponent skyboxComponent =
                new SkyboxSceneObjectComponent(skyboxLocation,
                                               SkyboxSceneObjectComponent.SkyboxType.hdr);
            MeshSceneObjectComponent meshComponent = new MeshSceneObjectComponent(
                new WavefrontModelLoader(),
                "Resources/box.obj1"
                );

            AddComponent(meshComponent);
            AddComponent(skyboxComponent);
        }
コード例 #4
0
        public Skybox(ShaderProg shader, string skyboxLocation = "Resources//Cubemaps") : base("CubemapSkybox")
        {
            SkyboxSceneObjectComponent skyboxComponent =
                new SkyboxSceneObjectComponent(skyboxLocation,
                                               shader,
                                               SkyboxSceneObjectComponent.SkyboxType.cubemap);
            MeshSceneObjectComponent meshComponent = new MeshSceneObjectComponent(
                new WavefrontModelLoader(),
                "Resources/box.obj1"
                );

            AddComponent(meshComponent);
            AddComponent(skyboxComponent);
        }
コード例 #5
0
        public void OnUpdated()
        {
            // Update model view matrices
            foreach (SceneObject v in _objects)
            {
                MeshSceneObjectComponent meshComponent = (MeshSceneObjectComponent)v.components["MeshSceneObjectComponent"];

                // meshComponent.ModelMesh.Transform.CalculateModelMatrix();
                // meshComponent.ModelMesh.Transform.ViewProjectionMatrix =
                //  pipelineData.Cam.GetViewMatrix() * Matrix4.CreatePerspectiveFieldOfView(1.3f, (float)_gameWindow.ClientSize.Width
                // / (float)_gameWindow.ClientSize.Height, 1.0f, 120);

                // meshComponent.ModelMesh.Transform.ModelViewProjectionMatrix =
                // meshComponent.ModelMesh.Transform.ModelMatrix * meshComponent.ModelMesh.Transform.ViewProjectionMatrix;
            }
        }
コード例 #6
0
        public GLtf2Helm() : base("Gltf2Helm")
        {
            MaterialSceneObjectComponent material = new MaterialSceneObjectComponent(
                new Pbr(),
                "Resources/Gltf/DamagedHelmet/glTF/DamagedHelmet.gltf",
                new Gltf2MaterialLoader());

            MeshSceneObjectComponent meshComponent = new MeshSceneObjectComponent(
                new AssimpModelLoader(),
                "Resources/Gltf/DamagedHelmet/glTF/DamagedHelmet.gltf"
                );
            BasicManipulationsComponent manipulation = new BasicManipulationsComponent(meshComponent);

            AddComponent(manipulation);
            AddComponent(material);
            AddComponent(meshComponent);
        }
コード例 #7
0
        public PbrShperes()
        {
            MaterialSceneObjectComponent material = new MaterialSceneObjectComponent(
                new Pbr(),
                "Resources/MetalRoughSpheres/glTF/MetalRoughSpheres.gltf",
                new Gltf2MaterialLoader());

            MeshSceneObjectComponent meshComponent = new MeshSceneObjectComponent(
                new Gltf2ModelLoader(),
                "Resources/MetalRoughSpheres/glTF/MetalRoughSpheres.gltf"
                );
            BasicManipulationsComponent manipulation = new BasicManipulationsComponent(meshComponent);

            AddComponent(manipulation);
            AddComponent(material);
            AddComponent(meshComponent);
        }
コード例 #8
0
        public MiraFbx() : base("MiraFbx")
        {
            MaterialSceneObjectComponent material = new MaterialSceneObjectComponent(
                new Pbr(),
                "C:/Users/kpbil/source/models/mira/source/Mira2.fbx",
                new AssimpMaterialLoader());

            MeshSceneObjectComponent meshComponent = new MeshSceneObjectComponent(
                new AssimpModelLoader(),
                "C:/Users/kpbil/source/models/mira/source/Mira2.fbx"
                );
            BasicManipulationsComponent manipulation = new BasicManipulationsComponent(meshComponent);

            AddComponent(manipulation);
            AddComponent(material);
            AddComponent(meshComponent);
        }
コード例 #9
0
ファイル: Knight.cs プロジェクト: Gribochek277/IeCore
        public Knight()
        {
            MaterialSceneObjectComponent material = new MaterialSceneObjectComponent(
                new SpecularNormal(),
                "Resources/knight3.mtl",
                new WavefrontMaterialLoader()
                );

            MeshSceneObjectComponent meshComponent = new MeshSceneObjectComponent(
                new WavefrontModelLoader(),
                "Resources/knight3.obj1"
                );

            BasicManipulationsComponent manipulation = new BasicManipulationsComponent(meshComponent);

            AddComponent(manipulation);
            AddComponent(material);
            AddComponent(meshComponent);
        }
コード例 #10
0
        public CerberusGltf()
        {
            MaterialSceneObjectComponent material = new MaterialSceneObjectComponent(
                new Pbr(),
                // "Resources/Gltf/sphere/sphere.gltf",
                "Resources/Gltf/cerebrus/scene.gltf",
                new Gltf2MaterialLoader());

            MeshSceneObjectComponent meshComponent = new MeshSceneObjectComponent(
                new Gltf2ModelLoader(),
                //    "Resources/Gltf/sphere/sphere.gltf"
                "Resources/Gltf/cerebrus/scene.gltf"
                );
            BasicManipulationsComponent manipulation = new BasicManipulationsComponent(meshComponent);

            AddComponent(manipulation);
            AddComponent(material);
            AddComponent(meshComponent);
        }
コード例 #11
0
ファイル: Lion.cs プロジェクト: Gribochek277/IeCore
        public Lion()
        {
            MaterialSceneObjectComponent materialComponent =
                new MaterialSceneObjectComponent(
                    new SpecularNormal(),
                    "Resources/Lion/Lion-snake.mtl",
                    new WavefrontMaterialLoader()
                    );


            MeshSceneObjectComponent meshComponent = new MeshSceneObjectComponent(
                new WavefrontModelLoader(),
                "Resources/Lion/Lion-snake.obj"
                );
            BasicManipulationsComponent manipulation = new BasicManipulationsComponent(meshComponent);

            AddComponent(manipulation);
            AddComponent(materialComponent);
            AddComponent(meshComponent);
        }
コード例 #12
0
        public AnimatedModelTest()
        {
            MaterialSceneObjectComponent materialComponent =
                new MaterialSceneObjectComponent(
                    new SimpleDiffuse(),
                    "C:/Users/kpbil/source/repos/glTF-Sample-Models/2.0/RiggedSimple/glTF/RiggedSimple.gltf",
                    new AssimpMaterialLoader()
                    );


            MeshSceneObjectComponent meshComponent = new MeshSceneObjectComponent(
                new AssimpModelLoader(),
                "C:/Users/kpbil/source/repos/glTF-Sample-Models/2.0/RiggedSimple/glTF/RiggedSimple.gltf"
                );
            BasicManipulationsComponent manipulation = new BasicManipulationsComponent(meshComponent);

            AddComponent(manipulation);
            AddComponent(materialComponent);
            AddComponent(meshComponent);
        }
コード例 #13
0
        public void OnLoad()
        {
            _pipelineData.OnLoad();
            _objects = _pipelineData.Objects;

            foreach (SceneObject v in _objects)
            {
                v.OnLoad();
            }

            GL.GenBuffers(1, out ibo_elements);
            GL.Enable(EnableCap.TextureCubeMapSeamless);
            GL.Viewport(0, 0, windowWidth, windowHeight);

            _pipelineData.Cam.Position += new Vector3(0f, 0f, 3f);
            GL.ClearColor(0, 0, 1, 1);
            GL.PointSize(5f);

            // Assemble vertex and index data for all volumes
            int vertcount = 0;

            List <Vector3> vertices = new List <Vector3>();
            List <int>     indices  = new List <int>();
            //List <Vector3> colors = new List<Vector3>();
            List <Vector2> texcoords = new List <Vector2>();
            List <Vector3> normals   = new List <Vector3>();

            foreach (SceneObject v in _objects)
            {
                MeshSceneObjectComponent meshComponent = (MeshSceneObjectComponent)v.components["MeshSceneObjectComponent"];
                vertices.AddRange(meshComponent.ModelMesh.GetVerts().ToList());
                indices.AddRange(meshComponent.ModelMesh.GetIndicesWithOffcet(vertcount).ToList());
                //colors.AddRange(meshComponent.ModelMesh.GetColorData().ToList());
                texcoords.AddRange(meshComponent.ModelMesh.GetTextureCoords());
                normals.AddRange(meshComponent.ModelMesh.GetNormals().ToList());
                vertcount += meshComponent.ModelMesh.VertCount;
            }

            vertdata   = vertices.ToArray();
            indicedata = indices.ToArray();
            //coldata = colors.ToArray();
            texCoordinatesData = texcoords.ToArray();
            normdata           = normals.ToArray();


            Console.WriteLine("Vertexes: " + vertdata.Length);
            Console.WriteLine("Triangles: " + vertdata.Length / 3);

            foreach (SceneObject v in _objects)
            {
                ISceneObjectComponent meshComponent;
                v.components.TryGetValue("MeshSceneObjectComponent", out meshComponent);

                ISceneObjectComponent extractedMaterialComponent;
                if (v.components.TryGetValue("MaterialSceneObjectComponent", out extractedMaterialComponent))
                {
                    MaterialSceneObjectComponent materialComponent = (MaterialSceneObjectComponent)extractedMaterialComponent;

                    GL.BindBuffer(BufferTarget.ArrayBuffer, materialComponent.ShaderImplementation.shaderProg.GetBuffer("vPosition"));
                    GL.BufferData <Vector3>(BufferTarget.ArrayBuffer, (IntPtr)(vertdata.Length * Vector3.SizeInBytes), vertdata, BufferUsageHint.StaticDraw);
                    GL.VertexAttribPointer(materialComponent.ShaderImplementation.shaderProg.GetAttribute("vPosition"), 3, VertexAttribPointerType.Float, false, 0, 0);

                    // Buffer vertex color if shader supports it. Currently commented out because not used for first implementation.

                    /*  if (materialComponent.ShaderImplementation.shaderProg.GetAttribute("vColor") != -1)
                     * {
                     *    GL.BindBuffer(BufferTarget.ArrayBuffer, materialComponent.ShaderImplementation.shaderProg.GetBuffer("vColor"));
                     *    GL.BufferData<Vector3>(BufferTarget.ArrayBuffer, (IntPtr)(coldata.Length * Vector3.SizeInBytes), coldata, BufferUsageHint.StaticDraw);
                     *    GL.VertexAttribPointer(materialComponent.ShaderImplementation.shaderProg.GetAttribute("vColor"), 3, VertexAttribPointerType.Float, true, 0, 0);
                     * }*/


                    // Buffer texture coordinates if shader supports it
                    if (materialComponent.ShaderImplementation.shaderProg.GetAttribute("texcoord") != -1)
                    {
                        GL.BindBuffer(BufferTarget.ArrayBuffer, materialComponent.ShaderImplementation.shaderProg.GetBuffer("texcoord"));
                        GL.BufferData <Vector2>(BufferTarget.ArrayBuffer, (IntPtr)(texCoordinatesData.Length * Vector2.SizeInBytes), texCoordinatesData, BufferUsageHint.StaticDraw);
                        GL.VertexAttribPointer(materialComponent.ShaderImplementation.shaderProg.GetAttribute("texcoord"), 2, VertexAttribPointerType.Float, true, 0, 0);
                    }

                    if (materialComponent.ShaderImplementation.shaderProg.GetAttribute("vNormal") != -1)
                    {
                        GL.BindBuffer(BufferTarget.ArrayBuffer, materialComponent.ShaderImplementation.shaderProg.GetBuffer("vNormal"));
                        GL.BufferData <Vector3>(BufferTarget.ArrayBuffer, (IntPtr)(normdata.Length * Vector3.SizeInBytes), normdata, BufferUsageHint.StaticDraw);
                        GL.VertexAttribPointer(materialComponent.ShaderImplementation.shaderProg.GetAttribute("vNormal"), 3, VertexAttribPointerType.Float, true, 0, 0);
                    }
                }
            }
        }
コード例 #14
0
        public void OnRendered()
        {
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
            GL.Enable(EnableCap.FramebufferSrgb);

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            // Buffer index data
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo_elements);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indicedata.Length * sizeof(int)), indicedata, BufferUsageHint.StaticDraw);

            Matrix4 projection =
                Matrix4.CreatePerspectiveFieldOfView(1.3f, (float)windowWidth / (float)windowHeight, 0.1f, 120.0f);
            Matrix4 view = _pipelineData.Cam.GetViewMatrix();
            // Update object positions


            int indiceat = 36; //start rendering after skybox

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            // Draw all our objects
            for (int i = 1; i < _objects.Count; i++)
            {
                MeshSceneObjectComponent     meshComponent     = (MeshSceneObjectComponent)_objects[i].components["MeshSceneObjectComponent"];
                MaterialSceneObjectComponent materialComponent = (MaterialSceneObjectComponent)_objects[i].components["MaterialSceneObjectComponent"];


                GL.UseProgram(materialComponent.ShaderImplementation.shaderProg.ProgramID);
                materialComponent.ShaderImplementation.shaderProg.EnableVertexAttribArrays();

                Matrix4 modelMatrix = meshComponent.ModelMesh.Transform.ModelMatrix;
                GL.UniformMatrix4(materialComponent.ShaderImplementation.shaderProg.GetUniform("model"), false, ref modelMatrix);
                GL.UniformMatrix4(materialComponent.ShaderImplementation.shaderProg.GetUniform("projection"), false, ref projection);
                GL.UniformMatrix4(materialComponent.ShaderImplementation.shaderProg.GetUniform("view"), false, ref view);//think about adding to uniform helper Matrix4 type, but for now it's not required.

                /* _uniformHelper.TryAddUniformTexture2D(texId, "maintexture", materialComponent.Shader, TextureUnit.Texture0);
                 * _uniformHelper.TryAddUniformTexture2D(normId, "normaltexture", materialComponent.Shader, TextureUnit.Texture1);
                 * _uniformHelper.TryAddUniformTexture2D(metRoughId, "metallicroughness", materialComponent.Shader, TextureUnit.Texture2);
                 * _uniformHelper.TryAddUniformTexture2D(ambientId, "defaultAO", materialComponent.Shader, TextureUnit.Texture3);
                 * W
                 *
                 * //TODO retrieve it properly skybox texture
                 * _uniformHelper.TryAddUniformTextureCubemap(3, "irradianceMap", materialComponent.Shader, TextureUnit.Texture4);
                 * _uniformHelper.TryAddUniformTextureCubemap(4, "prefilterMap", materialComponent.Shader, TextureUnit.Texture5);
                 * _uniformHelper.TryAddUniformTexture2D(5,"brdfLUT", materialComponent.Shader, TextureUnit.Texture6);
                 * _uniformHelper.TryAddUniform1(1f, "ambientStr", shaderProg);
                 */
                materialComponent.ShaderImplementation.SetSpecificUniforms(_pipelineData);

                //_uniformHelper.TryAddUniform1(1f, "specStr", materialComponent.ShaderImplementation.shaderProg);//TODO : find a way how to extract specular exponent from material. Additional refactoring is required.
                //PBR uniforms

                /*_uniformHelper.TryAddUniform1((float)Math.Abs(Math.Sin(time*0.1f)), "metallic", materialComponent.ShaderImplementation.shaderProg);
                 * _uniformHelper.TryAddUniform1((float)Math.Abs(Math.Cos(time*0.1f)), "roughness", materialComponent.ShaderImplementation.shaderProg);*/

                GL.DrawElements(BeginMode.Triangles, meshComponent.ModelMesh.IndiceCount, DrawElementsType.UnsignedInt, indiceat * sizeof(uint));
                indiceat += meshComponent.ModelMesh.IndiceCount;

                materialComponent.ShaderImplementation.shaderProg.DisableVertexAttribArrays();
            }
            GL.Disable(EnableCap.FramebufferSrgb);

            SkyboxRenderHelper.RenderSkybox(view, projection, _pipelineData.Skybox);

            GL.Flush();
        }