コード例 #1
0
        // We actually use our own Quad Data so ignore the input
        public void bindModelData(WorldObject worldObject)
        {
            GL.BindVertexArray(worldObject.mesh.vertexArrayObject);

            // Set the types of buffer data
            GL.BindBuffer(BufferTarget.ArrayBuffer, worldObject.mesh.vertexBufferObject);
            GL.VertexAttribPointer(positionLocation, 3, VertexAttribPointerType.Float, false, 0, 0);

            GL.BindBuffer(BufferTarget.ArrayBuffer, worldObject.mesh.normalBufferObject);
            GL.VertexAttribPointer(normalLocation, 3, VertexAttribPointerType.Float, false, 0, 0);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, worldObject.mesh.indexBufferObject);

            GL.BindBuffer(BufferTarget.ArrayBuffer, worldObject.mesh.texcoordsBuffer);
            GL.VertexAttribPointer(texcoordsLocation, 2, VertexAttribPointerType.Float, true, 0, 0);

            GL.BindVertexArray(0);
        }
コード例 #2
0
ファイル: DepthMapShader.cs プロジェクト: Aehrraid/komorebi
        // Render Objects into the ShadowMap
        public void render(WorldObject worldObject, Matrix4 viewMatrix)
        {
            // Activate the states for the buffers etc.
            GL.BindVertexArray(worldObject.mesh.vertexArrayObject);

            GL.BindTexture(TextureTarget.Texture2D, -1);

            // Enable the model data
            GL.EnableVertexAttribArray(positionLocation);
            GL.EnableVertexAttribArray(normalLocation);

            // Upload Parameters
            uploadParameters(worldObject.modelMatrix, viewMatrix);

            // Render Object
            GL.DrawElements(BeginMode.Triangles, worldObject.mesh.indices.Count, DrawElementsType.UnsignedInt, 0);

            // Clean Up
            GL.BindVertexArray(0);
            GL.DisableVertexAttribArray(positionLocation);
            GL.DisableVertexAttribArray(normalLocation);
        }
コード例 #3
0
 // We actually use our own Quad Data so ignore the input
 public void bindModelData(WorldObject sun)
 {
     GL.BindVertexArray(vertexArrayObject);
     GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_fbo_vertices);
     GL.VertexAttribPointer(
       positionLocation,  // attribute
       3,                  // number of elements per vertex, here (x,y,z)
       VertexAttribPointerType.Float,           // the type of each element
       false,           // take our values as-is
       0,                  // no extra data between each position
       0                   // offset of first element
     );
     GL.BindBuffer(BufferTarget.ArrayBuffer, tbo_fbo_texcoords);
     GL.VertexAttribPointer(
       texcoordsLocation,  // attribute
       2,                  // number of elements per vertex, here (x,y)
       VertexAttribPointerType.Float,           // the type of each element
       true,           // take our values as-is
       0,                  // no extra data between each position
       0                   // offset of first element
     );
     GL.BindVertexArray(0);
 }
コード例 #4
0
        private void uploadParameters(WorldObject worldObject, Matrix4 viewMatrix, Matrix4 projectionMatrix, Matrix4 depthViewProjectionMatrix, Vector3 lightDirection)
        {
            // Matrices for Shader
            Matrix4 mv = worldObject.modelMatrix * viewMatrix;
            Matrix4 mvp = mv * projectionMatrix;
            Matrix4 mNormal = Utility.getNormalMatrix(mv);

            GL.UniformMatrix4(mvpLocation, false, ref mvp);
            GL.UniformMatrix4(viewModelLocation, false, ref mv);
            GL.UniformMatrix4(normalMatrixLocation, false, ref mNormal);

            // Set Light Direction
            GL.Uniform3(lightDirectionLocation, Vector3.Transform(lightDirection, viewMatrix.ClearTranslation()));

            // Compute the MVP matrix from the light's point of view (and add a bias)
            Matrix4 depthMVP = worldObject.modelMatrix * depthViewProjectionMatrix * biasMatrix;

            GL.UniformMatrix4(depthBiasMVPLocation, false, ref depthMVP);
            GL.Uniform1(shadowMapLocation, 0);
            GL.Uniform1(textureLocation, 1);

            GL.Uniform1(useStratifiedPoissonSamplingLocation, useStratifiedPoissonSampling);
            if(worldObject.mesh.isTextured == true)
                GL.Uniform1(useModelTextureLocation, 1f);
            else GL.Uniform1(useModelTextureLocation, 0f);

            // Phong
            GL.Uniform3(diffuseLocation, worldObject.diffuse);
            GL.Uniform3(ambientLocation, worldObject. ambient);
            GL.Uniform3(specularLocation, worldObject.specular);
            GL.Uniform1(shininessLocation, worldObject.shininess);
        }
コード例 #5
0
        public void render(WorldObject worldObject, Matrix4 viewMatrix, Matrix4 projectionMatrix, Matrix4 depthViewProjectionMatrix, Vector3 lightDirection, int shadowMapTexture)
        {
            // Activate the states for the buffers etc.
            GL.BindVertexArray(worldObject.mesh.vertexArrayObject);

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, shadowMapTexture);

            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, worldObject.mesh.textureID);

            // Enable the model data
            GL.EnableVertexAttribArray(positionLocation);
            GL.EnableVertexAttribArray(normalLocation);
            GL.EnableVertexAttribArray(texcoordsLocation);

            // Upload Parameters
            uploadParameters(worldObject, viewMatrix, projectionMatrix, depthViewProjectionMatrix, lightDirection);

            // Render Object
            GL.DrawElements(BeginMode.Triangles, worldObject.mesh.indices.Count, DrawElementsType.UnsignedInt, 0);

            // Clean Up
            GL.BindVertexArray(0);
            GL.BindTexture(TextureTarget.Texture2D, -1);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, -1);
            GL.DisableVertexAttribArray(positionLocation);
            GL.DisableVertexAttribArray(normalLocation);
            GL.DisableVertexAttribArray(texcoordsLocation);
        }
コード例 #6
0
ファイル: Window.cs プロジェクト: Aehrraid/komorebi
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            inputManager = new InputManager(this, camera);

            phongShader = new PhongShader(FileManager.getMediaFile("phongVS.glsl"), FileManager.getMediaFile("phongFS.glsl"));
            postProcessShader = new PostProcessShader(FileManager.getMediaFile("postProcessVS.glsl"), FileManager.getMediaFile("postProcessFS.glsl"));
            volumetricLightingShader = new VolumetricLightingShader(FileManager.getMediaFile("volumetricLightingVS.glsl"), FileManager.getMediaFile("volumetricLightingFS.glsl"));
            blurShader = new PostProcessShader(FileManager.getMediaFile("gaussianBlurVS.glsl"), FileManager.getMediaFile("gaussianBlurFS.glsl"));
            blurShader2 = new PostProcessShader(FileManager.getMediaFile("gaussianBlurVS.glsl"), FileManager.getMediaFile("gaussianBlurFS.glsl"));
            shadowMapShader = new DepthMapShader(FileManager.getMediaFile("depthMapVS.glsl"), FileManager.getMediaFile("depthMapFS.glsl"));
            depthMapShader = new DepthMapShader(FileManager.getMediaFile("depthMapVS.glsl"), FileManager.getMediaFile("depthMapFS.glsl"), screenWidth, screenHeight);
            shadowMappingShader = new ShadowMappingShader(FileManager.getMediaFile("shadowMappingVS.glsl"), FileManager.getMediaFile("shadowMappingFS.glsl"));
            blackShader = new PhongShader(FileManager.getMediaFile("blackVS.glsl"), FileManager.getMediaFile("blackFS.glsl"));
            whiteShader = new PhongShader(FileManager.getMediaFile("whiteVS.glsl"), FileManager.getMediaFile("whiteFS.glsl"));

            // Load Models
            sun.loadModelFromFile("sun.3ds");
            sun.position = new Vector3(20f, 30f, -70f);
            sun.scale = new Vector3(2f);
            sun.update();

            monkey.loadModelFromFile("monkey.3ds");
            monkey.position = new Vector3(20f, 4f, 2f);
            monkey.update();
            monkey.diffuse = new Vector3(0.1f, 0.1f, 0.8f);
            monkey.ambient = new Vector3(0.05f, 0.05f, 0.4f);

            magicBox.loadModelFromFile("magicBox.3ds");
            magicBox.position = new Vector3(20f, 6f, 0f);
            magicBox.scale = new Vector3(5f);
            magicBox.update();
            magicBox.diffuse = new Vector3(0.2f, 0.2f, 0f);
            magicBox.ambient = new Vector3(0.1f, 0.1f, 0f);
            // No Specular for the magicBox
            magicBox.specular = new Vector3(0f);
            magicBox.shininess = 1f;

            //Load floor
            floor.loadModelFromFile("floor.3ds");
            floor.position = new Vector3(0f, 0f, -10f);
            // Scale the Floor (and the texCoords)
            floor.scale = new Vector3(1000f, 1f, 1000f);
            //floor.scale = new Vector3(0.05f, 0.05f, 0.05f);
               // floor.rotation = new Vector3(45, 0, 0);
             for (int i = 0; i < floor.mesh.textureCoordinates.Count; i++)
              floor.mesh.textureCoordinates[i] *= 200f;
             floor.mesh.updateTextureCoordinates();
            floor.update();
            // No Specular for floor
            floor.specular = new Vector3(0f);
            floor.shininess = 1f;

            //Load trees
            Random random = new Random();
            for (int x = 0; x < 2; x++)
            {
                for (int z = 0; z < 10; z++)
                {
                    WorldObject tree = new WorldObject();
                    tree.loadModelFromFile("tree.3ds");
                    tree.position = new Vector3((x * 10f) - 5f, 0f, -z * 6f);
                    tree.scale = new Vector3(2f);
                    tree.rotation = new Vector3(0f, (float)(random.NextDouble() * Math.PI * 2.0), 0f);
                    tree.update();
                    tree.diffuse = new Vector3(0.6f, 0.3f, 0f);
                    tree.ambient = new Vector3(0.3f, 0.15f, 0f);
                    trees.Add(tree);
                }
            }

            // Move initial Position of the Camera away from origin
            camera.Position += new Vector3(10f, 10f, 10f);

            // Hide Mouse Cursor
            CursorVisible = false;
        }