Ejemplo n.º 1
0
        private void PrepareTexturedModel(TexturedModel texturedModel)
        {
            RawModel model = texturedModel.model;

            //rendo il vao attivo
            GL.BindVertexArray(model.VaoHandle);

            //Indico che voglio usare le informazioni nella riga 0
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            ModelTexture texture = texturedModel.Texture;

            shader.LoadNumberOfRows(texture.NumberOfRows);
            if (texture.hasTransparency)
            {
                MasterRenderer.DisableCulling();
            }
            shader.LoadFakeLighting(texture.useFakeLighting);
            shader.LoadShineVariables(texture.shineDamper, texture.reflectivity);

            //Rendo attiva l`area della texture 0
            GL.ActiveTexture(TextureUnit.Texture0);
            //Riempio l`area texture 0
            GL.BindTexture(TextureTarget.Texture2D, texturedModel.Texture.handle);
        }
Ejemplo n.º 2
0
 public SkyboxRenderer(Loader loader, Matrix4 projectionMatrix)
 {
     cube    = loader.LoadToVao(VERTICES, 3);
     texture = loader.LoadCubeMap(textureFileNames);
     shader  = new SkyboxShader();
     shader.Start();
     shader.LoadProjectionMatrix(projectionMatrix);
     shader.Stop();
 }
Ejemplo n.º 3
0
 public GuiRenderer(Loader loader)
 {
     float[] positions = new float[] { -1.0f, 1.0f,
                                       -1.0f, -1.0f,
                                       1.0f, 1.0f,
                                       1.0f, -1.0f };
     quad   = loader.LoadToVao(positions, 2);
     shader = new GuiShader();
 }
Ejemplo n.º 4
0
        private void PrepareTerrain(Terrain terrain)
        {
            RawModel model = terrain.Model;

            //rendo il vao attivo
            GL.BindVertexArray(model.VaoHandle);

            //Indico che voglio usare le informazioni nella riga 0
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);
            BindTextures(terrain);
            shader.LoadShineVariables(1.0f, 0.0f);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Renderizza entità sulla shadowMap
 /// </summary>
 /// <param name="entities">Le entità da renderizzare e il loro modello associato</param>
 public void Render(Dictionary <TexturedModel, List <Entity> > entities)
 {
     foreach (TexturedModel model in entities.Keys)
     {
         RawModel rawModel = model.model;
         BindModel(rawModel);
         foreach (Entity entity in entities[model])
         {
             PrepareInstance(entity);
             GL.DrawElements(PrimitiveType.Triangles, rawModel.VertexCount, DrawElementsType.UnsignedInt, 0);
         }
     }
     GL.DisableVertexAttribArray(0);
     GL.BindVertexArray(0);
 }
Ejemplo n.º 6
0
 public ParticleRenderer(Loader loader, Matrix4 projectionMatrix)
 {
     this.loader = loader;
     vbo         = loader.CreateEmptyVbo(INSTANCE_DATA_LENGTH * MAX_INSTANCES);
     quad        = loader.LoadToVao(VERTICES, 2);
     loader.AddInstancedAttribute(quad.VaoHandle, vbo, 1, 4, INSTANCE_DATA_LENGTH, 0);
     loader.AddInstancedAttribute(quad.VaoHandle, vbo, 2, 4, INSTANCE_DATA_LENGTH, 4);
     loader.AddInstancedAttribute(quad.VaoHandle, vbo, 3, 4, INSTANCE_DATA_LENGTH, 8);
     loader.AddInstancedAttribute(quad.VaoHandle, vbo, 4, 4, INSTANCE_DATA_LENGTH, 12);
     loader.AddInstancedAttribute(quad.VaoHandle, vbo, 5, 4, INSTANCE_DATA_LENGTH, 16);
     loader.AddInstancedAttribute(quad.VaoHandle, vbo, 6, 1, INSTANCE_DATA_LENGTH, 20);
     shader = new ParticleShader();
     shader.Start();
     shader.LoadProjectionMatrix(projectionMatrix);
     shader.Stop();
 }
Ejemplo n.º 7
0
        private void PrepareTexturedModel(TexturedModel model)
        {
            RawModel rawModel = model.model;

            GL.BindVertexArray(rawModel.VaoHandle);
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);
            GL.EnableVertexAttribArray(3);
            ModelTexture texture = model.Texture;

            shader.LoadNumberOfRows(texture.NumberOfRows);
            if (texture.hasTransparency)
            {
                MasterRenderer.DisableCulling();
            }
            shader.LoadShineVariables(texture.shineDamper, texture.reflectivity);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, model.Texture.handle);
            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, model.Texture.NormalMap);
        }
Ejemplo n.º 8
0
 public TexturedModel(RawModel model, ModelTexture texture)
 {
     this.model   = model;
     this.Texture = texture;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Attiva un rawModel prima del rendering
 /// </summary>
 /// <param name="rawModel">Il rawModel da attivare</param>
 private void BindModel(RawModel rawModel)
 {
     GL.BindVertexArray(rawModel.VaoHandle);
     GL.EnableVertexAttribArray(0);
 }
Ejemplo n.º 10
0
        protected override void OnLoad(EventArgs e)
        {
            Random random = new Random();

            loader      = new Loader();
            entities    = new List <Entity>();
            guiTextures = new List <GuiTexture>();
            //********************Player***********************
            playerData     = OBJLoader.LoadOBJ("Person.obj");
            playerModel    = loader.LoadToVao(playerData.vertices, playerData.textureCoords, playerData.normals, playerData.indices);
            playerTextured = new TexturedModel(playerModel, new ModelTexture(loader.LoadTexture("PlayerTexture.png")));
            playerEntity   = new Player(playerTextured, new Vector3(77.0f, 85.0f, -80.0f), 0.0f, -209.0f, 0.0f, 0.7f);
            entities.Add(playerEntity);
            //*************************************************

            //********************Camera***********************
            camera = new Camera(playerEntity);
            //*************************************************

            TextMaster.Init(loader, Width, Height);
            renderer = new MasterRenderer(loader, camera, Width, Height);

            terrains = new List <Terrain>();

            normalMapEntities = new List <Entity>();
            lights            = new List <Light>();

            //*****************Particelle**********************
            particleTexture = new ParticleTexture(loader.LoadTexture("ParticleAtlas.png"), 4);

            ParticleMaster.Init(loader, renderer.ProjectionMatrix);
            particles = new ParticleSystem(50.0f, 25.0f, 0.3f, 4.0f, particleTexture);
            #region Sistema di particelle avanzato (da fixare)
            //particles = new ParticleSystem(50.0f, 25.0f, 0.3f, 4.0f, 1.0f);
            //particles.RandomizeRotation();
            //particles.SetDirection(new Vector3(0.0f, 1.0f, 0.0f), 0.1f);
            //particles.SetLifeError(0.1f);
            //particles.SetSpeedError(0.4f);
            //particles.SetScaleError(0.8f);
            #endregion
            //*************************************************

            //*********************Font************************
            FontType font = new FontType(loader.LoadFontTexture("FontDistanceField.png"), "FontDistanceField.fnt");
            GUIText  text = new GUIText("Enacoid text!", 1, font, new Vector2(0.0f, 0.0f), 1.0f, true);
            //*************************************************

            //********************TerrainTexture***************
            backgroundTexture = new TerrainTexture(loader.LoadTexture("Grassy2.png"));
            rTexture          = new TerrainTexture(loader.LoadTexture("Mud.png"));
            gTexture          = new TerrainTexture(loader.LoadTexture("GrassFlowers.png"));
            bTexture          = new TerrainTexture(loader.LoadTexture("Path.png"));
            texturePack       = new TerrainTexturePack(backgroundTexture, rTexture, gTexture, bTexture);
            blendMap          = new TerrainTexture(loader.LoadTexture("BlendMap.png"));
            //*************************************************

            //********************Terreno**********************
            terrain = new Terrain(0.0f, -1.0f, loader, texturePack, blendMap, "HeightMap.png");
            terrains.Add(terrain);
            //*************************************************

            //*******************TexturedModel*****************
            rocks = new TexturedModel(loader.LoadToVao(OBJLoader.LoadOBJ("rocks.obj")), new ModelTexture(loader.LoadTexture("rocks.png")));

            ModelTexture fernTextureAtlas = new ModelTexture(loader.LoadTexture("TextureAtlas.png"));
            fernTextureAtlas.NumberOfRows = 2;
            TexturedModel fern = new TexturedModel(loader.LoadToVao(OBJLoader.LoadOBJ("fern.obj")), fernTextureAtlas);
            fern.Texture.hasTransparency = true;

            TexturedModel bobble = new TexturedModel(loader.LoadToVao(OBJLoader.LoadOBJ("pine.obj")), new ModelTexture(loader.LoadTexture("pine.png")));
            bobble.Texture.hasTransparency = true;

            TexturedModel lamp = new TexturedModel(loader.LoadToVao(OBJLoader.LoadOBJ("lamp.obj")), new ModelTexture(loader.LoadTexture("lamp.png")));
            lamp.Texture.useFakeLighting = true;
            //*************************************************

            //******************Entità*************************
            rockEntity = new Entity(rocks, new Vector3(75.0f, terrain.GetHeightOfTerrain(75.0f, -75.0f), -75.0f), 0.0f, 0.0f, 0.0f, 10.0f);
            entities.Add(rockEntity);
            bobbleEntity = new Entity(bobble, new Vector3(85.0f, terrain.GetHeightOfTerrain(85.0f, -75.0f), -75.0f), 0.0f, 0.0f, 0.0f, 1.0f);
            entities.Add(bobbleEntity);
            lampEntity = new Entity(lamp, new Vector3(65.0f, terrain.GetHeightOfTerrain(65.0f, -75.0f), -75.0f), 0.0f, 0.0f, 0.0f, 1.0f);
            entities.Add(lampEntity);

            for (int i = 0; i < 60; i++)
            {
                if (i % 3 == 0)
                {
                    float x = (float)random.NextDouble() * 150;
                    float z = (float)random.NextDouble() * -150;
                    if (!((x > 50 && x < 100) || (z < -50 && z > -100)))
                    {
                        float y = terrain.GetHeightOfTerrain(x, z);
                        entities.Add(new Entity(fern, new Vector3(x, y, z), 0, (float)random.NextDouble() * 360, 0, 0.9f, random.Next(3)));
                    }
                }
                if (i % 2 == 0)
                {
                    float x = (float)random.NextDouble() * 150;
                    float z = (float)random.NextDouble() * -150;
                    if (!((x > 50 && x < 100) || (z < -50 && z > -100)))
                    {
                        float y = terrain.GetHeightOfTerrain(x, z);
                        entities.Add(new Entity(bobble, new Vector3(x, y, z), 0, (float)random.NextDouble() * 360, 0, (float)random.NextDouble() * 0.6f + 0.8f, random.Next(3)));
                    }
                }
            }
            //*************************************************

            //*******************NormalMapped******************
            TexturedModel barrelModel = new TexturedModel(NormalMappedObjLoader.LoadOBJ("Barrel.obj", loader), new ModelTexture(loader.LoadTexture("Barrel.png")));
            barrelModel.Texture.shineDamper  = 10.0f;
            barrelModel.Texture.reflectivity = 0.5f;
            barrelModel.Texture.NormalMap    = loader.LoadTexture("BarrelNormal.png");
            normalMapEntities.Add(new Entity(barrelModel, new Vector3(163.0f, terrain.GetHeightOfTerrain(163.0f, -67.0f) + 6.5f, -67.0f), 0.0f, 0.0f, 0.0f, 1.0f));

            TexturedModel boulderModel = new TexturedModel(NormalMappedObjLoader.LoadOBJ("Boulder.obj", loader), new ModelTexture(loader.LoadTexture("Boulder.png")));
            boulderModel.Texture.shineDamper  = 5.0f;
            boulderModel.Texture.reflectivity = 0.3f;
            boulderModel.Texture.NormalMap    = loader.LoadTexture("BoulderNormal.png");
            normalMapEntities.Add(new Entity(boulderModel, new Vector3(59.0f, terrain.GetHeightOfTerrain(59, -149) + 6.5f, -149), 0.0f, 0.0f, 0.0f, 1.0f));
            ///*******************Luci*************************
            lights.Add(new Light(new Vector3(199000.0f, 200000.0f, -84000.0f), new Vector3(0.6f, 0.6f, 0.6f)));

            //*************************************************

            //********************Acqua************************
            waterShader       = new WaterShader();
            waterFrameBuffers = new WaterFrameBuffer(Width, Height);
            waterRenderer     = new WaterRenderer(loader, waterShader, renderer.ProjectionMatrix, waterFrameBuffers);
            waters            = new List <WaterTile>();
            water             = new WaterTile(187.0f, -199.0f, terrain.GetHeightOfTerrain(187.0f, -199.0f) + 7.0f);
            waters.Add(water);
            //*************************************************

            mousePicker = new MousePicker(camera, renderer.ProjectionMatrix);

            //*********************GUIs************************
            GuiTexture shadowMap = new GuiTexture(renderer.GetShadowMapTexture(), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f));
            //guiTextures.Add(shadowMap);

            guiRenderer = new GuiRenderer(loader);
            //*************************************************

            base.OnLoad(e);

            FrameTime = watch.GetCurrentTime();
        }
Ejemplo n.º 11
0
 private void SetUpVAO(Loader loader)
 {
     // Just x and z vectex positions here, y is set to 0 in v.shader
     float[] vertices = { -1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, 1 };
     quad = loader.LoadToVao(vertices, 2);
 }