Beispiel #1
0
        public MainVisual(IRenderState renderState, IContentLoader contentLoader)
        {
            renderState.Set(new DepthTest(true));
            renderState.Set(new FaceCullingModeState(FaceCullingMode.BACK_SIDE));

            shaderProgramPhong = contentLoader.Load <IShaderProgram>("phong.*");
            var mesh     = new DefaultMesh();
            var roomSize = 8;
            //off-center plane
            var plane = Meshes.CreatePlane(roomSize, roomSize, 2, 2).Transform(Transformation.Translation(0, -roomSize / 2, 0));

            mesh.Add(plane);
            //rotate plane to create box
            mesh.Add(plane.Transform(Transformation.Rotation(90f, Axis.Z)));
            mesh.Add(plane.Transform(Transformation.Rotation(180f, Axis.Z)));
            mesh.Add(plane.Transform(Transformation.Rotation(270f, Axis.Z)));
            mesh.Add(plane.Transform(Transformation.Rotation(90f, Axis.X)));
            mesh.Add(plane.Transform(Transformation.Rotation(-90f, Axis.X)));

            var sphere = Meshes.CreateSphere(1);

            sphere.SetConstantUV(Vector2.Zero);             //all other meshes have texture coordinates
            mesh.Add(sphere);
            var suzanne = contentLoader.Load <DefaultMesh>("suzanne");

            mesh.Add(suzanne.Transform(Transformation.Translation(2, 2, -2)));
            geometryPhong = VAOLoader.FromMesh(mesh, shaderProgramPhong);

            shaderProgramToon = contentLoader.Load <IShaderProgram>("toon.*");
            geometryToon      = VAOLoader.FromMesh(suzanne.Transform(Transformation.Translation(2, 0, 0)), shaderProgramToon);
        }
Beispiel #2
0
        public MainVisual(IRenderState renderState, IContentLoader contentLoader)
        {
            renderState.Set(BoolState <IDepthState> .Enabled);
            renderState.Set(BoolState <IBackfaceCullingState> .Enabled);
            renderState.Set(BlendStates.AlphaBlend);

            shaderProgram = contentLoader.Load <IShaderProgram>("phong.*");
            var mesh     = new DefaultMesh();
            var roomSize = 8;
            //off-center plane
            var plane = Meshes.CreatePlane(roomSize, roomSize, 2, 2).Transform(new Translation3D(0, -roomSize / 2, 0));

            mesh.Add(plane);
            //rotate plane to create box
            mesh.Add(plane.Transform(new Rotation3D(Axis.Z, 90f)));
            mesh.Add(plane.Transform(new Rotation3D(Axis.Z, 180f)));
            mesh.Add(plane.Transform(new Rotation3D(Axis.Z, 270f)));
            mesh.Add(plane.Transform(new Rotation3D(Axis.X, 90f)));
            mesh.Add(plane.Transform(new Rotation3D(Axis.X, -90f)));

            var sphere = Meshes.CreateSphere(1);

            sphere.SetConstantUV(new Vector2(0, 0));
            mesh.Add(sphere);
            var suzanne = contentLoader.Load <DefaultMesh>("suzanne");

            mesh.Add(suzanne.Transform(new Translation3D(2, 2, -2)));
            geometry = VAOLoader.FromMesh(mesh, shaderProgram);
        }
        public VisualPlane(IRenderState renderState, IContentLoader contentLoader)
        {
            shdPlane = contentLoader.Load <IShaderProgram>("plane.*");
            var mesh = Meshes.CreatePlane(2, 2, 1, 1);

            plane            = VAOLoader.FromMesh(mesh, shdPlane);
            this.renderState = renderState;
        }
Beispiel #4
0
        public MainVisualHeightField(IRenderState renderState, IContentLoader contentLoader)
        {
            renderState.Set(BoolState <IDepthState> .Enabled);
            renderState.Set(BoolState <IBackfaceCullingState> .Enabled);
            texDiffuse    = contentLoader.Load <ITexture2D>("capsule0.jpg");
            shaderProgram = contentLoader.Load <IShaderProgram>("shader.*");
            //load geometry
            var mesh = Meshes.CreatePlane(100, 100, 1024, 1024);

            geometry = VAOLoader.FromMesh(mesh, shaderProgram);
            camera   = new CameraOrbit();
        }
        public MainVisual(IRenderState renderState, IContentLoader contentLoader)
        {
            renderState.Set(BoolState <IDepthState> .Enabled);
            renderState.Set(BoolState <IBackfaceCullingState> .Enabled);
            shaderProgram = contentLoader.Load <IShaderProgram>("shader.*");
            var mesh = contentLoader.Load <DefaultMesh>("suzanne");

            geometryBody = VAOLoader.FromMesh(mesh, shaderProgram);

            floorShaderProgram = contentLoader.Load <IShaderProgram>("floor.*");

            floor     = VAOLoader.FromMesh(Meshes.CreatePlane(100, 100, 1, 1).Transform(new Translation3D(new Vector3(0, -30, 0))), floorShaderProgram);
            waterCube = VAOLoader.FromMesh(Meshes.CreateCubeWithNormals(100).Transform(new Translation3D(new Vector3(-50, -50, 0))), floorShaderProgram);
        }
        public MainVisual(IRenderState renderState, IContentLoader contentLoader)
        {
            renderState.Set(new DepthTest(true));
            fboShadowMap.Texture.Filter = TextureFilterMode.Nearest;

            shaderProgram = contentLoader.Load <IShaderProgram>("shadowMap.*");
            var mesh   = Meshes.CreatePlane(10, 10, 10, 10);
            var sphere = Meshes.CreateSphere(0.5f, 2);

            sphere.SetConstantUV(new Vector2(0.5f, 0.5f));
            mesh.Add(sphere.Transform(Transformation.Translation(0, 2, -2)));
            mesh.Add(sphere.Transform(Transformation.Translation(0, 2, 0)));
            mesh.Add(sphere.Transform(Transformation.Translation(2, 2, -1)));
            geometry = VAOLoader.FromMesh(mesh, shaderProgram);

            shaderProgramDepth = contentLoader.Load <IShaderProgram>("depth.*");
            //todo: radeon cards created errors with geometry bound to one shader and used in other shaders because of binding id changes
        }
Beispiel #7
0
        public MainVisual(IRenderContext renderContext, IContentLoader contentLoader)
        {
            renderContext.RenderState.Set(new DepthTest(true));
            renderContext.RenderState.Set(new FaceCullingModeState(FaceCullingMode.BACK_SIDE));

            var mesh = Meshes.CreatePlane(2, 2, 1024, 1024);

            var texHeightfield = contentLoader.Load <ITexture2D>("mountain_height");
            var bindings       = new TextureBinding[]
            {
                new TextureBinding("texHeightfield", texHeightfield),
                new TextureBinding("texColor", contentLoader.Load <ITexture2D>("mountain_color")),
                new TextureBinding("texStone", contentLoader.Load <ITexture2D>("stone")),
            };
            var shaderProgram = contentLoader.Load <IShaderProgram>("shader.*");

            mountain = new MeshVisual(mesh, shaderProgram, bindings);
        }
Beispiel #8
0
        private void GenerateVoronoi(int sizeX, int sizeY, Vector3 scale)
        {
            Random rand = new Random(345546);

            float RandFloat() => (float)rand.NextDouble();

            float[,] heights   = new float[sizeX + 2, sizeY + 2];
            Vector2[,] centers = new Vector2[sizeX + 2, sizeY + 2];

            for (int x = 0; x < sizeX + 2; x++)
            {
                for (int y = 0; y < sizeY + 2; y++)
                {
                    heights[x, y] = RandFloat() * scale.Y;
                    centers[x, y] = new Vector2((RandFloat() + x - ((sizeX + 2)) / 2) * scale.X, (RandFloat() + y - ((sizeY + 2) / 2)) * scale.Z);
                }
            }

            for (int x = 1; x < sizeX + 1; x++)
            {
                for (int y = 1; y < sizeY + 1; y++)
                {
                    List <Vector2> neighbors = new List <Vector2>()
                    {
                        centers[x - 1, y - 1],
                        centers[x - 1, y],
                        centers[x - 1, y + 1],
                        centers[x, y - 1],
                        centers[x, y + 1],
                        centers[x + 1, y - 1],
                        centers[x + 1, y],
                        centers[x + 1, y + 1]
                    };

                    GenerateVoronoiTower(centers[x, y], neighbors, heights[x, y]);
                }
            }

            DefaultMesh plane = Meshes.CreatePlane(sizeX * scale.X, sizeY * scale.Z, 1, 1);

            plane.TexCoord.Clear();
            Mesh.Add(plane);
        }
        public ParticleSystem(DeferredRenderer renderer, IContentLoader contentLoader)
        {
            random = new Random();
            //Rendering
            this.renderer      = renderer;
            deferredRenderable = new Renderable();
            var            plane    = Meshes.CreatePlane(1, 1, 1, 1).Transform(Transformation.Rotation(-90, Axis.X));
            IShaderProgram shader   = renderer.GetShader(DeferredRenderer.DrawableType.particleMesh);
            VAO            planeVao = renderer.GetDrawable(plane, DeferredRenderer.DrawableType.particleMesh);

            deferredRenderable.SetDeferredGeometryMesh(planeVao, shader);
            ITexture2D defaultAlpha = contentLoader.Load <ITexture2D>("particleDefault.png");

            deferredRenderable.SetAlbedoTexture(defaultAlpha);
            deferredRenderable.SetAlphaMap(defaultAlpha);
            deferredRenderable.faceCullingMode = FaceCullingMode.NONE;
            VAO            shadowPlaneVao = renderer.GetDrawable(plane, DeferredRenderer.DrawableType.particleShadowLightView);
            IShaderProgram shadowShader   = renderer.GetShader(DeferredRenderer.DrawableType.particleShadowLightView);

            shadowRenderable = new Renderable();
            shadowRenderable.SetDeferredGeometryMesh(shadowPlaneVao, shadowShader);
            shadowRenderable.SetAlbedoTexture(defaultAlpha);
            shadowRenderable.SetAlphaMap(defaultAlpha);
            shadowRenderable.faceCullingMode = FaceCullingMode.NONE;
            //ParticleSystemSetup
            globalModules       = new List <ParticleModule>();
            perParticleModules  = new List <ParticleModule>();
            particleColor       = new Range3D(new Vector3(1, 1, 1));
            keepScaleRatio      = true;
            scaleAspect         = new AspectRatio3D(AspectRatio3D.Axis.XAxis, 1);
            particlePoolList    = new List <Particle>();
            spawnedParticleList = new List <Particle>();
            particleRemoveList  = new List <Particle>();
            SetMaxParticles(100);
            spawnArea           = new Range3D(new Vector3(-0.1f, 0, -0.1f), new Vector3(0.1f, 0, 0.1f));
            spawnScale          = new Range3D(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 1f));
            spawnAcceleration   = new Range3D(new Vector3(0, 0.1f, 0), new Vector3(0, 5f, 0));
            spawnIntervallRange = new Range(0f, 1f);
            spawnIntervall      = spawnIntervallRange.GetRandomValue(random);
            spawnRate           = new Range(1, 1);
            lifeTimeRange       = new Range(10.0f);
        }
Beispiel #10
0
        public MainView(IRenderState renderState, IContentLoader contentLoader)
        {
            _renderState = renderState;
            _renderState.Set(new BackFaceCulling(true));

            var sphere = contentLoader.Load <DefaultMesh>("maze.obj");

            sphere = sphere.SwitchTriangleMeshWinding();

            _meshes.Add(Enums.EntityType.Maze, sphere);
            _meshes.Add(Enums.EntityType.Plane, new TBNMesh(Meshes.CreatePlane(1, 1, 1, 1)));
            _meshes.Add(Enums.EntityType.Mercury, contentLoader.Load <DefaultMesh>("icosphere.obj"));
            _meshes.Add(Enums.EntityType.Mars, contentLoader.Load <DefaultMesh>("icosphere.obj"));



            _disableBackFaceCulling.Add(Enums.EntityType.Mercury);
            _disableBackFaceCulling.Add(Enums.EntityType.Mars);

            _textures.Add(Enums.EntityType.Mercury, contentLoader.Load <ITexture2D>("mercury8.jpg"));
            _textures.Add(Enums.EntityType.Mars, contentLoader.Load <ITexture2D>("mars8.jpg"));

            _textures.Add(Enums.EntityType.Plane, contentLoader.Load <ITexture2D>("haumea.jpg"));


            _deferred        = _renderInstanceGroup.AddShader <Deferred>(new Deferred(contentLoader, _meshes));
            _directShadowMap = _renderInstanceGroup.AddShader <DirectionalShadowMapping>(new DirectionalShadowMapping(contentLoader, _meshes));
            _ssaoWithBlur    = _renderInstanceGroup.AddShader <SSAOWithBlur>(new SSAOWithBlur(contentLoader, 15));
            _environmentMap  = _renderInstanceGroup.AddShader <EnvironmentMap>(new EnvironmentMap(1024, contentLoader, _meshes));
            _addEnvMap       = _renderInstanceGroup.AddShader <Add>(new Add(contentLoader));
            _lighting        = _renderInstanceGroup.AddShader <Lighting>(new Lighting(contentLoader));
            _sphereCut       = _renderInstanceGroup.AddShader <SphereCut>(new SphereCut(contentLoader, 100));

            _skybox    = _renderInstanceGroup.AddShader <Skybox>(new Skybox(contentLoader, 100, "space"));
            _addSkybox = _renderInstanceGroup.AddShader <Add>(new Add(contentLoader));
            _bloom     = _renderInstanceGroup.AddShader <Bloom>(new Bloom(contentLoader));

            _lights.Add(new LightSource(Vector3.Zero, Vector3.Normalize(new Vector3(-1f, -1f, 0.6f)), new Vector3(1.0f, 0.77f, 0.56f)));

            Bloom = true;
        }
Beispiel #11
0
        public MainVisual(IRenderState renderState, IContentLoader contentLoader)
        {
            this.renderState = renderState;
            var shaderMaterial = contentLoader.Load <IShaderProgram>("material.*");

            var plane = Meshes.CreatePlane(4, 4, 1, 1);

            meshVisuals.Add(new MeshVisual(plane, shaderMaterial));
            var instanceMesh     = contentLoader.Load <DefaultMesh>("suzanne").Transform(Transformation.Scale(0.03f));
            var instanceData     = CreateInstancePositionMaterial(20, 20);
            var suzanneInstances = VAOLoader.FromMesh(instanceMesh, shaderMaterial);

            suzanneInstances.SetAttribute(shaderMaterial.GetResourceLocation(ShaderResourceType.Attribute, nameof(instanceData)), instanceData, true);
            meshVisuals.Add(new MeshVisual(suzanneInstances, shaderMaterial));
            var shaderLighting = contentLoader.Load <IShaderProgram>("lighting.*");
            var lightMesh      = Meshes.CreateSphere(1f, 2);        // either make it bigger or you need good subdivision to avoid border artifacts
            var lightGeometry  = VAOLoader.FromMesh(lightMesh, shaderLighting);

            lightGeometry.SetAttribute(shaderLighting.GetResourceLocation(ShaderResourceType.Attribute, "lightData"), instanceData, true);
            lightsVisual = new MeshVisual(lightGeometry, shaderLighting);
        }
Beispiel #12
0
        List <GameObject> GetSphereSampleScene()
        {
            List <GameObject> goList = new List <GameObject>();
            DefaultMesh       plane  = Meshes.CreatePlane(10, 10, 10, 10).Transform(Transformation.Translation(new Vector3(0, -1f, 0)));
            VAO         planeMesh    = VAOLoader.FromMesh(plane, renderer.GetPBRShader());
            GameObject  planeGO      = new GameObject();
            PBRMaterial planemat     = new PBRMaterial();

            planemat.albedoColor = new Vector3(1);
            planemat.roughness   = 1;
            planemat.metal       = 0;
            planeGO.mesh         = planeMesh;
            planeGO.material     = planemat;
            //goList.Add(planeGO);
            //return goList;
            int        gridSize      = 7;
            float      sphereSize    = 0.1f;
            float      spacing       = sphereSize + sphereSize * 2f;
            float      startX        = gridSize / 2 * spacing;
            Vector3    startVector   = new Vector3(startX, startX, 0);
            float      paramSteps    = 1.0f / gridSize;
            string     texPrefix     = "rustediron2_";
            ITexture2D albedoText    = contentLoader.Load <ITexture2D>(texPrefix + "basecolor.png");
            ITexture2D metallicText  = contentLoader.Load <ITexture2D>(texPrefix + "metallic.png");
            ITexture2D normalText    = contentLoader.Load <ITexture2D>(texPrefix + "normal.png");
            ITexture2D roughnessText = contentLoader.Load <ITexture2D>(texPrefix + "roughness.png");

            DefaultMesh mesh = contentLoader.Load <DefaultMesh>("uvSphere").Transform(Transformation.Scale(0.1f));
            //DefaultMesh mesh = Meshes.CreateSphere(sphereSize, 2);
            VAO geom = VAOLoader.FromMesh(mesh, renderer.GetPBRShader());


            TangentSpaceData tangentData = GetTangentSpaceData(mesh.Position, mesh.TexCoord);
            int tangentLocation          = renderer.GetPBRShader().GetResourceLocation(ShaderResourceType.Attribute, "tangent");
            int biTangentLocation        = GL.GetAttribLocation(renderer.GetPBRShader().ProgramID, "biTangent");

            geom.SetAttribute(tangentLocation, tangentData.tangent);
            geom.SetAttribute(biTangentLocation, tangentData.biTangent);


            for (int i = 0; i < gridSize; i++)
            {
                Vector3 tmpStart = startVector;
                for (int j = 0; j < gridSize; j++)
                {
                    GameObject go = new GameObject();
                    go.transform.position   = tmpStart;
                    go.material.metal       = i * paramSteps;
                    go.material.roughness   = j * paramSteps;
                    go.material.albedoColor = new Vector3(1, 0, 0);
                    go.mesh = geom;

                    /*
                     * go.material.albedoMap = albedoText;
                     * go.material.metallicMap = metallicText;
                     * go.material.normalMap = normalText;
                     * go.material.roughnessMap = roughnessText;
                     */

                    goList.Add(go);
                    tmpStart.X -= spacing;
                }
                startVector.Y -= spacing;
            }
            return(goList);
        }
        private List <Entity> GetGeometry(DeferredRenderer renderer)
        {
            IShaderProgram defaultShader = renderer.GetShader(DeferredRenderer.DrawableType.deferredDefaultMesh);
            List <Entity>  res           = new List <Entity>();
            float          islandScale   = 30f;
            var            islePlane     = Meshes.CreatePlane(30, 30, 120, 120).Transform(Transformation.Translation(0, islandScale / 2, 0));
            Renderable     isle          = ContentFactory.GetDefaultRenderable(renderer, islePlane);


            ITexture2D isleAlbedo = contentLoader.Load <ITexture2D>("terrain.png");

            isleAlbedo.Filter = TextureFilterMode.Linear;
            //ITexture2D isleNormal = contentLoader.Load<ITexture2D>("normalTest1.jpg");
            isle.SetAlbedoTexture(isleAlbedo);
            //isle.SetNormalMap(isleNormal);
            ITexture2D isleHeightmap = contentLoader.Load <ITexture2D>("hmapUnity.png");

            isle.SetHeightMap(isleHeightmap);
            isle.heightScaleFactor = islandScale;
            Entity isleEntity = new Entity();

            isleEntity.name       = "isle";
            isleEntity.renderable = isle;

            Terrain isleTerrain = new Terrain(contentLoader, "hmapUnity.png", islandScale, 30, 30);

            isleTerrain.transform.position = new Vector3(0, islandScale / 2, 0);



            var        waterplane       = Meshes.CreatePlane(100, 100, 225, 225).Transform(Transformation.Translation(0, 1f, 0));
            VAO        waterDrawable    = renderer.GetDrawable(waterplane, DeferredRenderer.DrawableType.deferredDefaultMesh);
            Renderable water            = ContentFactory.GetDefaultRenderable(renderer, waterplane);
            ITexture2D waterEnvironment = contentLoader.Load <ITexture2D>("sky_low.jpg");

            water.SetEnvironmentMap(waterEnvironment);
            water.reflectivity = 1;
            //water.SetAlbedoTexture(isleAlbedo);
            Entity waterEntity = new Entity();

            waterEntity.name       = "water";
            waterEntity.renderable = water;

            var        grassPlane = Meshes.CreatePlane(1, 1, 2, 2).Transform(Transformation.Rotation(-90, Axis.X));
            Renderable grass      = ContentFactory.GetDefaultRenderable(renderer, grassPlane);

            grass.faceCullingMode = FaceCullingMode.NONE;
            ITexture2D grassAlbedo = contentLoader.Load <ITexture2D>("Grass_512_albedo.tif");
            ITexture2D grassAlpha  = contentLoader.Load <ITexture2D>("tGrass_512_alpha.tif");

            grass.SetAlbedoTexture(grassAlbedo);
            grass.SetAlphaMap(grassAlpha);
            //Entity grassEntity = new Entity();
            //grassEntity.renderable = grass;
            Vector3[]    spawnPositions = { new Vector3(-0.1f, 7.1f, 2.5f), new Vector3(-3.5f, 7.1f, -1.5f),
                                            new Vector3(6f,       7.1f, 2.5f), new Vector3(6f,    7.1f, -1.5f),new Vector3(5f,7.1f, -6f), new Vector3(1f, 7.1f, -8f), new Vector3(-3f, 7.1f, -8f) };
            float[]      radius      = { 2f, 1.9f, 2f, 2f, 2f, 2f, 2f };
            int[]        amountGrass = { 50, 60, 50, 60, 60, 60, 60 };
            Range3D      scaleRange  = new Range3D(new Vector3(0.5f), new Vector3(1.5f));
            TerrainLayer layer       = new TerrainLayer(isleTerrain, grass);

            for (int i = 0; i < spawnPositions.Length; i++)
            {
                SphericalTerrainSpawner grassSpawner = new SphericalTerrainSpawner(spawnPositions[i], radius[i], amountGrass[i]);
                grassSpawner.randomScaleRange = scaleRange;
                layer.AddSpawner(grassSpawner);
            }
            layer.SpawnElements();
            res.Add(layer);
            var skysphere = Meshes.CreateSphere(60, 2);

            skysphere.SwitchTriangleMeshWinding();
            Renderable skydome = ContentFactory.GetDefaultRenderable(renderer, skysphere);

            skydome.faceCullingMode = FaceCullingMode.FRONT_SIDE;
            skydome.unlit           = 1;
            skydome.SetAlbedoTexture(waterEnvironment);
            Entity skyEntity = new Entity();

            skyEntity.renderable = skydome;
            skyEntity.name       = "skydome";

            var        msphere = Meshes.CreateSphere(1, 2).Transform(Transformation.Translation(0, 2, 0));
            Renderable sphere  = ContentFactory.GetDefaultRenderable(renderer, msphere);
            VAO        spVao   = renderer.GetDrawable(msphere, DeferredRenderer.DrawableType.deferredDefaultMesh);

            sphere.SetEnvironmentMap(waterEnvironment);
            Entity spEntity = new Entity();

            spEntity.name       = "sphere";
            spEntity.renderable = sphere;

            //res.Add(grassEntity);
            res.Add(isleEntity);
            res.Add(waterEntity);
            //res.Add(spEntity);
            res.Add(skyEntity);
            return(res);
        }