예제 #1
0
 public RawModel(VBOArrayF attributes)
 {
     this.shaderAttributes = attributes;
     Buffer = new VAO(this.shaderAttributes);
     VAOManager.genVAO(Buffer);
     VAOManager.setBufferData(OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, Buffer);
 }
예제 #2
0
        public void renderEntities(DirectionalLight sun, BaseCamera camera, Matrix4 projectionMatrix, Landscape terrain = null,
                                   Vector4 clipPlane = new Vector4())
        {
            postConstructor(terrain);

            _shader.startProgram();

            _texture[0].BindTexture(TextureUnit.Texture0);
            if (_texture.Count > 1)
            {
                _texture[1].BindTexture(TextureUnit.Texture1);
                if (_texture.Count == 3)
                {
                    _texture[2].BindTexture(TextureUnit.Texture2);
                }
            }

            _shader.setTextureSampler(0);
            _shader.setMaterial(_grassMaterial);
            _shader.setViewMatrix(camera.GetViewMatrix());
            _shader.setProjectionMatrix(ref projectionMatrix);
            _shader.setSun(sun);
            _shader.setWind(_wind);
            _shader.setTime(timeElapsed);
            _shader.setClipPlane(ref clipPlane);
            _shader.setMist(_mist);

            VAOManager.renderInstanced(_buffer, PrimitiveType.Triangles, _plants.Count);
            _shader.stopProgram();
        }
        public virtual void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix)
        {
            Matrix4 worldMatrix = GetWorldMatrix();

            texture.BindTexture(TextureUnit.Texture0);
            shader.startProgram();
            shader.SetTransformatrionMatrices(worldMatrix, viewMatrix, projectionMatrix);
            shader.SetDiffuseTexture(0);
            shader.SetOpacity(0.2f);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            VAOManager.renderBuffers(model.Buffer, OpenTK.Graphics.OpenGL.PrimitiveType.Triangles);
            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.CullFace);
            shader.stopProgram();

            foreach (var item in ChildrenComponents)
            {
                SceneComponent comp = item as SceneComponent;
                if (comp != null)
                {
                    comp.Render(viewMatrix, projectionMatrix);
                }
            }
        }
예제 #4
0
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix)
        {
            if (bPostConstructor)
            {
                shader  = PoolProxy.GetResource <ObtainShaderPool, ShaderAllocationPolicy <SkyboxShader>, string, SkyboxShader>(String.Format("{0}{1},{0}{2}", ProjectFolders.ShadersPath, "skyboxVS.glsl", "skyboxFS.glsl"));
                model   = new RawModel(attribs);
                cubemap = ProxyTextureLoader.LoadCubemap(new string[] {
                    ProjectFolders.SkyboxTexturesPath + "/Day/" + "right.bmp",
                    ProjectFolders.SkyboxTexturesPath + "/Day/" + "left.bmp",
                    ProjectFolders.SkyboxTexturesPath + "/Day/" + "top.bmp",
                    ProjectFolders.SkyboxTexturesPath + "/Day/" + "bottom.bmp",
                    ProjectFolders.SkyboxTexturesPath + "/Day/" + "back.bmp",
                    ProjectFolders.SkyboxTexturesPath + "/Day/" + "front.bmp"
                });


                bPostConstructor = false;
            }

            shader.startProgram();
            cubemap.BindTexture(OpenTK.Graphics.OpenGL.TextureUnit.Texture0);
            shader.SetTransformationMatrices(Matrix4.Identity, viewMatrix, projectionMatrix);
            shader.SetCubemap(0);
            VAOManager.renderBuffers(model.Buffer, OpenTK.Graphics.OpenGL.PrimitiveType.Triangles);
            shader.stopProgram();
        }
예제 #5
0
 public void cleanUp()
 {
     _plants.Clear();
     VAOManager.cleanUp(_buffer);
     PoolProxy.FreeResourceMemory <ObtainShaderPool, ShaderAllocationPolicy <PlantShader>, string, PlantShader>(_shader);
     foreach (var item in _texture)
     {
         PoolProxy.FreeResourceMemory <ObtainTexturePool, TextureAllocationPolicy, string, ITexture>(item);
     }
 }
예제 #6
0
        public static void AddBuilderUserAttribute(PlantUnit plant, VAO buffer, Int32 plantsCountBeforeAddition)
        {
            float windS = 0.0f, tSampler = 0.0f;

            float[,] matrixColumn1 = new float[1, 4];
            float[,] matrixColumn2 = new float[1, 4];
            float[,] matrixColumn3 = new float[1, 4];
            float[,] matrixColumn4 = new float[1, 4];

            var modelMatrix = Matrix4.Identity;

            modelMatrix *= Matrix4.CreateRotationY(plant.Rotation.Y);
            modelMatrix *= Matrix4.CreateScale(plant.Scale);
            modelMatrix *= Matrix4.CreateTranslation(plant.Translation);

            matrixColumn1[0, 0] = modelMatrix[0, 0];
            matrixColumn1[0, 1] = modelMatrix[0, 1];
            matrixColumn1[0, 2] = modelMatrix[0, 2];
            matrixColumn1[0, 3] = modelMatrix[0, 3];

            matrixColumn2[0, 0] = modelMatrix[1, 0];
            matrixColumn2[0, 1] = modelMatrix[1, 1];
            matrixColumn2[0, 2] = modelMatrix[1, 2];
            matrixColumn2[0, 3] = modelMatrix[1, 3];

            matrixColumn3[0, 0] = modelMatrix[2, 0];
            matrixColumn3[0, 1] = modelMatrix[2, 1];
            matrixColumn3[0, 2] = modelMatrix[2, 2];
            matrixColumn3[0, 3] = modelMatrix[2, 3];

            matrixColumn4[0, 0] = modelMatrix[3, 0];
            matrixColumn4[0, 1] = modelMatrix[3, 1];
            matrixColumn4[0, 2] = modelMatrix[3, 2];
            matrixColumn4[0, 3] = modelMatrix[3, 3];

            windS    = plant.WindLoop;
            tSampler = plant.textureID;

            IntPtr singleAttributeOffset    = new IntPtr(sizeof(float) * plantsCountBeforeAddition);
            IntPtr singleAttributeValueSize = new IntPtr(sizeof(float));
            IntPtr vectorAttributeOffset    = new IntPtr(sizeof(float) * matrixColumn1.Length * plantsCountBeforeAddition);
            IntPtr vectorAttributeValueSize = new IntPtr(sizeof(float) * matrixColumn1.Length);

            VAOManager.AddUserSingleAttribute(buffer, 0, windS, singleAttributeOffset, singleAttributeValueSize);
            VAOManager.AddUserSingleAttribute(buffer, 1, tSampler, singleAttributeOffset, singleAttributeValueSize);
            VAOManager.AddUserVectorAttribute(buffer, 0, matrixColumn1, vectorAttributeOffset, vectorAttributeValueSize);
            VAOManager.AddUserVectorAttribute(buffer, 1, matrixColumn2, vectorAttributeOffset, vectorAttributeValueSize);
            VAOManager.AddUserVectorAttribute(buffer, 2, matrixColumn3, vectorAttributeOffset, vectorAttributeValueSize);
            VAOManager.AddUserVectorAttribute(buffer, 3, matrixColumn4, vectorAttributeOffset, vectorAttributeValueSize);
        }
예제 #7
0
        private void postConstructor(Landscape terrain = null)
        {
            if (this._postConstructor)
            {
                AlignPlantsToTerrain(terrain);
                this._attribs = PlantUserAttributeBuilder.BuildReadyUserAttributeBuffer(_plants, _attribs);
                _buffer       = new VAO(_attribs);

                VAOManager.genVAO(_buffer);
                VAOManager.setBufferData(BufferTarget.ArrayBuffer, _buffer);

                _shader = PoolProxy.GetResource <ObtainShaderPool, ShaderAllocationPolicy <PlantShader>, string, PlantShader>(ProjectFolders.ShadersPath + "plantVertexShader.glsl" + "," + ProjectFolders.ShadersPath + "plantFragmentShader.glsl");
                this._postConstructor = !this._postConstructor;
            }
        }
예제 #8
0
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix)
        {
            UpdateWorldMatrix();
            shader.startProgram();
            texture.BindTexture(OpenTK.Graphics.OpenGL.TextureUnit.Texture0);
            shader.SetDiffuseTexture(0);
            shader.SetTransformatrionMatrices(WorldMatrix, viewMatrix, projectionMatrix);
            shader.SetOpacity(1);
            VAOManager.renderBuffers(rawModel.Buffer, OpenTK.Graphics.OpenGL.PrimitiveType.Triangles);
            shader.stopProgram();

            foreach (var item in ChildrenComponents)
            {
                SceneComponent comp = item as SceneComponent;
                if (comp != null)
                {
                    comp.Render(viewMatrix, projectionMatrix);
                }
            }
        }
예제 #9
0
        public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix)
        {
            if (bPostConstructor)
            {
                model   = new RawModel(attribs);
                shader  = new SkyboxShader(Environment.CurrentDirectory + "/../../Shaders/skyboxVS.glsl", Environment.CurrentDirectory + "/../../Shaders/skyboxFS.glsl");
                cubemap = ProxyTextureLoader.LoadCubemap(new string[] {
                    Environment.CurrentDirectory + "/../../Textures/Right.bmp",
                    Environment.CurrentDirectory + "/../../Textures/Left.bmp",
                    Environment.CurrentDirectory + "/../../Textures/top.bmp",
                    Environment.CurrentDirectory + "/../../Textures/bottom.bmp",
                    Environment.CurrentDirectory + "/../../Textures/Back.bmp",
                    Environment.CurrentDirectory + "/../../Textures/Front.bmp"
                });
                bPostConstructor = false;
            }

            shader.startProgram();
            cubemap.BindTexture(OpenTK.Graphics.OpenGL.TextureUnit.Texture0);
            shader.SetTransformationMatrices(viewMatrix, projectionMatrix);
            shader.SetCubemap(0);
            VAOManager.renderBuffers(model.Buffer, OpenTK.Graphics.OpenGL.PrimitiveType.Triangles);
            shader.stopProgram();
        }