示例#1
0
        // initialize
        public void Init()
        {
            // initialize camera
            camera = new Camera(new Vector3(0, 10, 15), Quaternion.FromAxisAngle(Vector3.UnitX, -0.5f));

            // initialize stopwatch
            timer = new Stopwatch();
            timer.Start();

            // create model shaders
            shaderDefault    = Shader.Load("vs", "fs");
            shaderNormal     = Shader.Load("vs_normal", "fs_normal");
            shaderConstant   = Shader.Load("vs", "fs_const");
            shaderFur        = new FurShader("../../shaders/vs_fur.glsl", "../../shaders/fs_fur.glsl");
            shaderSkyBox     = Shader.Load("vs_skybox", "fs_skybox");
            shaderReflective = Shader.Load("vs", "fs_reflective");
            // create post processing shaders
            shaderPostProc       = Shader.Load("vs_post", "fs_post");
            shaderKernel         = new PostKernelShader("../../shaders/vs_post.glsl", "../../shaders/fs_kernel.glsl");
            shaderVigAndChrom    = new PostVigAndChromShader("../../shaders/vs_post.glsl", "../../shaders/fs_vigchrom.glsl");
            shaderPostBloomBlend = Shader.Load("vs_post", "fs_bloomblend");

            // load meshes
            meshTeapot    = new Mesh("../../assets/teapot.obj");
            meshFloor     = new Mesh("../../assets/floor.obj");
            meshCube      = new Mesh("../../assets/cube.obj");
            meshHeightMap = new HeightMap("../../assets/heightmap.png");

            // load textures
            textureFur       = Texture.Load("fur.png");
            textureWood      = Texture.Load("wood.jpg");
            textureTrump     = Texture.Load("thetrump.png");
            textureBrickWall = Texture.Load("brickwall.jpg");
            textureSkyBox    = new CubeTexture(
                "../../assets/sea_rt.JPG", "../../assets/sea_lf.JPG",
                "../../assets/sea_up.JPG", "../../assets/sea_dn.JPG",
                "../../assets/sea_bk.JPG", "../../assets/sea_ft.JPG"
                );
            // load normal maps
            normalNormal    = Texture.Load("normal_normal.png");
            normalBrickWall = Texture.Load("brickwall_normal.jpg");
            normalHeightMap = Texture.Load("heightmap_normal.png");

            ResizeWindow();
            quad = new ScreenQuad();

            // create models
            modelTeapot    = new Model(meshTeapot, textureWood, shaderNormal, Matrix4.CreateTranslation(new Vector3(0, 0.1f, 0)));
            modelFloor     = new Model(meshFloor, textureBrickWall, shaderNormal, Matrix4.Identity);
            modelLightPos  = new Model(meshCube, null, shaderConstant, Matrix4.Identity);
            modelHeightMap = new Model(meshHeightMap, textureTrump, shaderDefault, Matrix4.CreateScale(10f) * Matrix4.CreateTranslation(20f, 0f, 0f));
            Model teapot2 = new Model(meshTeapot, textureWood, shaderDefault, Matrix4.CreateScale(0.5f, 1f, 0.5f) * Matrix4.CreateRotationY(1.5f) * Matrix4.CreateTranslation(new Vector3(0, 24f, 0)));

            // set normal maps of specific models
            modelFloor.normalMap     = normalBrickWall;
            modelTeapot.normalMap    = normalBrickWall;
            modelLightPos.color      = new Vector3(1f, 1f, .5f);
            modelHeightMap.normalMap = normalHeightMap;

            // create special models
            ReflectiveModel refl   = new ReflectiveModel(meshTeapot, shaderReflective, Matrix4.CreateTranslation(0, 12f, 0), textureSkyBox);
            FurModel        furmod = new FurModel(meshTeapot, textureBrickWall, textureFur, shaderDefault, shaderFur, Matrix4.CreateRotationX((float)Math.PI / 2f) * Matrix4.CreateTranslation(new Vector3(0, 36f, 0)));

            // set up scenegraph
            SceneNode mainNode = new SceneNode();

            subScene = new SceneNode();
            subScene.AddChildModel(refl);
            subScene.AddChildModel(furmod);
            subScene.AddChildModel(teapot2);

            mainNode.AddChildNode(subScene);

            mainNode.AddChildModel(modelFloor);
            mainNode.AddChildModel(modelTeapot);
            mainNode.AddChildModel(modelLightPos);
            mainNode.AddChildModel(modelHeightMap);
            scene = new SceneGraph(mainNode);

            // set kernel used for final post processing step
            kernel = Kernel.SmallGaussianBlur;
        }
示例#2
0
文件: mesh.cs 项目: DvanLaar/Grafisch
        // render the mesh using the supplied shader and matrix
        public void RenderSkyBox(Shader shader, Matrix4 meshToWorld, Matrix4 worldToScreen, CubeTexture textureSkyBox)
        {
            GL.DepthMask(false);
            Prepare(shader);
            GL.UseProgram(shader.programID);

            // enable texture
            GL.Uniform1(GL.GetUniformLocation(shader.programID, "pixels"), 0);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.TextureCubeMap, textureSkyBox.id);

            // pass transform to vertex shader
            shader.SetUniforms(meshToWorld, worldToScreen);

            drawMesh(shader);
            GL.DepthMask(true);
        }
示例#3
0
文件: mesh.cs 项目: DvanLaar/Grafisch
        // render the mesh using the supplied shader and matrix
        public void ReflectiveRender(Shader shader, Matrix4 meshToWorld, Matrix4 worldToScreen, CubeTexture textureSkyBox, Vector3 materialColor)
        {
            Prepare(shader);
            GL.UseProgram(shader.programID);

            // enable texture
            GL.Uniform1(GL.GetUniformLocation(shader.programID, "skybox"), 0);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.TextureCubeMap, textureSkyBox.id);

            // pass transform to vertex shader
            shader.SetUniforms(meshToWorld, worldToScreen);
            GL.Uniform3(shader.uniform_materialcolor, materialColor);

            drawMesh(shader);
        }
示例#4
0
 public ReflectiveModel(Mesh mesh, Shader shader, Matrix4 transformation, CubeTexture skybox) : base(mesh, null, shader, transformation)
 {
     this.skyBox = skybox;
 }