Exemplo n.º 1
0
        public Entities(GLProgram program, SceneGraph scene)
            : base(program)
        {
            var numPointLights = 0;
            var plights        = new LightingShaders.PointLight[4];

            using (program.Scope())
            {
                foreach (var pointLight in scene.Root.Traverse().OfType <PointLight> ())
                {
                    plights[numPointLights++] = new LightingShaders.PointLight
                    {
                        position             = pointLight.Position,
                        intensity            = pointLight.Intensity,
                        linearAttenuation    = pointLight.LinearAttenuation,
                        quadraticAttenuation = pointLight.QuadraticAttenuation
                    };
                }
                pointLights &= plights;

                var samp = new Sampler2D[4];
                for (int i = 0; i < samp.Length; i++)
                {
                    samp[i] = new Sampler2D(i + 1).LinearFiltering().ClampToEdges(Axes.All);
                }
                samplers   &= samp;
                diffuseMap &= new SamplerCube(5).LinearFiltering().ClampToEdges(Axes.All);

                lighting   = new LightingUniforms(program, scene);
                transforms = new TransformUniforms(program);
                shadows    = new CascadedShadowUniforms(program,
                                                        new Sampler2DArray(0).LinearFiltering().ClampToEdges(Axes.All));
            }
        }
Exemplo n.º 2
0
        BiomeData Generate2DBiomeData()
        {
            BiomeData        biomeData     = new BiomeData();
            BiomeSwitchGraph switchGraph   = new BiomeSwitchGraph();
            Sampler2D        terrainHeight = new Sampler2D(size, step);
            PerlinNoise2D    perlin        = new PerlinNoise2D(seed);

            perlin.UpdateParams(seed, step, octaves, persistance, lacunarity);

            perlin.ComputeSampler2D(terrainHeight);

            terrainHeight = NoiseFunctions.Map(terrainHeight, 0, maxTerrainHeight);

            biomeData.waterLevel  = waterLevel;
            biomeData.isWaterless = isWaterless;
            biomeData.UpdateSamplerValue(BiomeSamplerName.terrainHeight, terrainHeight);
            if (!isWaterless)
            {
                biomeData.UpdateSamplerValue(BiomeSamplerName.waterHeight, GenerateWaterHeight(terrainHeight));
            }

            switchGraph.BuildTestGraph(0);

            biomeData.biomeMap         = Generate2DBiomeMap(0);
            biomeData.biomeSwitchGraph = switchGraph;
            return(biomeData);
        }
Exemplo n.º 3
0
 public Common_NewParam(string sid, Sampler2D sampleritem)
     : this(sid)
 {
     this.sid             = sid;
     this.item            = sampleritem;
     this.itemElementName = Common_NewParam_ItemElementName.sampler2D;
 }
        public static void ApplyBiomeTerrainModifiers(BlendedBiomeTerrain b)
        {
            if (b.terrain == null)
            {
                return;
            }

            if (b.terrain.type == SamplerType.Sampler2D)
            {
                PWUtils.ResizeSamplerIfNeeded(b.terrain, ref b.biomeTerrain);
                Sampler2D terrain      = b.terrain as Sampler2D;
                Sampler2D biomeTerrain = b.biomeTerrain as Sampler2D;
                //Fill biomeTerrain instead of terrain to keep an original version of the terrain
                biomeTerrain.Foreach((x, y) => {
                    float val   = terrain[x, y];
                    int biomeId = b.biomeMap.GetBiomeBlendInfo(x, y).firstBiomeId;
                    if (biomeId == -1)
                    {
                        return(val);
                    }
                    //TODO: biome blending
                    return(b.biomeTree.GetBiome(biomeId).biomeTerrain.ComputeValue(x, y, val));
                });
            }
            //else: TODO
            //TODO: apply biome terrain modifiers to terrain

            //TODO: apply biome terrain detail (caves / oth)
        }
        public void UpdateWaterMap()
        {
            outputBiome.UpdateSamplerValue(BiomeSamplerName.terrainHeight, terrainNoise);

            outputBiome.waterLevel = waterLevel;

            if (terrainNoise.type == SamplerType.Sampler2D)
            {
                //terrain mapping
                var mappedTerrain = NoiseFunctions.Map(terrainNoise as Sampler2D, mapMin, mapMax, true);
                outputBiome.UpdateSamplerValue(BiomeSamplerName.terrainHeight, mappedTerrain);

                //waterHeight evaluation
                Sampler2D waterHeight = new Sampler2D(terrainNoise.size, terrainNoise.step);
                waterHeight.min = waterLevel - mappedTerrain.max;
                waterHeight.max = waterLevel;
                mappedTerrain.Foreach((x, y, val) => {
                    waterHeight[x, y] = waterLevel - val;
                });
                outputBiome.UpdateSamplerValue(BiomeSamplerName.waterHeight, waterHeight);
            }
            else
            {
                //TODO 3D terrain water level
            }
        }
        public static void      ResizeSamplerIfNeeded(Sampler s, ref Sampler sOut)
        {
            if (s == null)
            {
                return;
            }
            switch (s.type)
            {
            case SamplerType.Sampler2D:
                if (sOut == null)
                {
                    sOut = new Sampler2D(s.size, s.step);
                }
                if (s.size != sOut.size)
                {
                    (sOut as Sampler2D).Resize(s.size);
                }
                break;

            case SamplerType.Sampler3D:
                if (sOut == null)
                {
                    sOut = new Sampler3D(s.size, s.step);
                }
                if (s.size != sOut.size)
                {
                    (sOut as Sampler2D).Resize(s.size);
                }
                break;
            }
            sOut.min  = s.min;
            sOut.max  = s.max;
            sOut.step = s.step;
        }
Exemplo n.º 7
0
        public void SimpleSwitchGraphBuild()
        {
            PWMainGraph graph = TestUtils.GenerateTestMainGraphBiomeSwitch();
            BiomeData   bd    = new BiomeData();

            var wlevel  = graph.FindNodeByName("wlevel");
            var bswitch = graph.FindNodeByName <PWNodeBiomeSwitch>("bswitch");
            var b1      = graph.FindNodeByName <PWNodeBiome>("b1");
            var b2      = graph.FindNodeByName <PWNodeBiome>("b2");

            bd.biomeSwitchGraphStartPoint = wlevel;

            PartialBiome p1 = new PartialBiome();
            PartialBiome p2 = new PartialBiome();

            b1.outputBiome = p1;
            b2.outputBiome = p2;

            //setup the switch values
            var sd = bswitch.switchList.switchDatas;

            sd[0].min         = 0;
            sd[0].max         = 5;
            sd[0].name        = "1";
            sd[0].samplerName = BiomeSamplerName.terrainHeight;
            sd[1].min         = 5;
            sd[1].max         = 10;
            sd[1].name        = "2";
            sd[1].samplerName = BiomeSamplerName.terrainHeight;

            Sampler2D terrainHeight = new Sampler2D(32, 1);

            terrainHeight.min = 0;
            terrainHeight.max = 10;

            bd.UpdateSamplerValue(BiomeSamplerName.terrainHeight, terrainHeight);

            BiomeSwitchGraph switchGraph = new BiomeSwitchGraph();

            switchGraph.BuildGraph(bd);

            Assert.That(switchGraph.isBuilt == true);

            var values = new BiomeSwitchValues();

            values[0] = 4.0f;
            Assert.That(switchGraph.FindBiome(values).id == p1.id);
            values[0] = 0f;
            Assert.That(switchGraph.FindBiome(values).id == p1.id);
            values[0] = 5f;
            Assert.That(switchGraph.FindBiome(values).id == p1.id);

            values[0] = 6.0f;
            Assert.That(switchGraph.FindBiome(values).id == p2.id);
            values[0] = 10f;
            Assert.That(switchGraph.FindBiome(values).id == p2.id);
        }
Exemplo n.º 8
0
 public override void OnNodeProcess()
 {
     if (updateEachProcess)
     {
         CreateNoiseMask();
         samp.Foreach((x, y, val) => { return(val * (mask[x, y])); });
     }
     output = samp;
 }
Exemplo n.º 9
0
            public Vec4 Blur5(Sampler2D image, Vec2 uv, Vec2 resolution, Vec2 direction)
            {
                var color = new Vec4(0.0f, 0.0f, 0.0f, 0.0f);
                var off1  = new Vec2(1.3333333333333333f) * direction;

                color += image.Sample(uv) * 0.29411764705882354f;
                color += image.Sample(uv + (off1 / resolution)) * 0.35294117647058826f;
                color += image.Sample(uv - (off1 / resolution)) * 0.35294117647058826f;
                return(color);
            }
Exemplo n.º 10
0
        Sampler2D GenerateWaterHeight(Sampler2D terrainHeight)
        {
            Sampler2D waterHeight = new Sampler2D(terrainHeight.size, terrainHeight.step);

            terrainHeight.Foreach((x, y, val) => {
                waterHeight[x, y] = waterLevel - val;
            });

            return(waterHeight);
        }
        public override void OnNodeGUI()
        {
            EditorGUILayout.LabelField("MAP:");

            if (chunkSizeHasChanged)
            {
                texture = new Sampler2D(chunkSize, step);
            }

            PWGUI.Sampler2DPreview("perlinControlName", texture, needUpdate);
        }
Exemplo n.º 12
0
        public override void ComputeSampler2D(Sampler2D samp)
        {
            if (samp == null)
            {
                Debug.LogError("Null sampler sent to Flat noise");
                return;
            }

            samp.Foreach((x, y) => {
                return(flatValue);
            });
        }
Exemplo n.º 13
0
        static Sampler2D Operation2D(Sampler2D s1, Sampler2D s2, bool alloc, Func <float, float, float> callback)
        {
            Sampler2D ret = s1;

            if (alloc)
            {
                ret = new Sampler2D(s1.size, s1.step);
            }
            ret.Foreach((x, y, val) => {
                return(callback(s1[x, y], s2[x, y]));
            });
            return(ret);
        }
Exemplo n.º 14
0
            public Vec4 Blur9(Sampler2D image, Vec2 uv, Vec2 resolution, Vec2 direction)
            {
                var color = new Vec4(0.0f, 0.0f, 0.0f, 0.0f);
                var off1  = new Vec2(1.3846153846f) * direction;
                var off2  = new Vec2(3.2307692308f) * direction;

                color += image.Sample(uv) * 0.2270270270f;
                color += image.Sample(uv + (off1 / resolution)) * 0.3162162162f;
                color += image.Sample(uv - (off1 / resolution)) * 0.3162162162f;
                color += image.Sample(uv + (off2 / resolution)) * 0.0702702703f;
                color += image.Sample(uv - (off2 / resolution)) * 0.0702702703f;
                return(color);
            }
        public Sampler2D Add(Sampler2D s1, Sampler2D s2, bool alloc = false)
        {
            Sampler2D ret = s1;

            if (alloc)
            {
                ret = new Sampler2D(s1.size, s1.step);
            }
            ret.Foreach((x, y, val) => {
                return(s1[x, y] + s2[x, y]);
            });
            return(ret);
        }
Exemplo n.º 16
0
        public static Sampler2D Map(Sampler2D samp, float min, float max, bool alloc = false)
        {
            Sampler2D ret = samp;

            if (alloc)
            {
                ret = new Sampler2D(ret.size, ret.step);
            }
            ret.Foreach((x, y, val) => {
                return(Mathf.Lerp(min, max, Mathf.InverseLerp(samp.min, samp.max, samp[x, y])));
            });
            ret.min = min;
            ret.max = max;
            return(ret);
        }
        public override void ComputeSampler2D(Sampler2D samp)
        {
            if (samp == null)
            {
                Debug.LogError("null sampler send to Noise ComputeSampler !");
            }

            if (false)            //(hasGraphicAcceleration)
            {
                //compute shader here
            }
            else
            {
                samp.Foreach((x, y) => {
                    return(GenerateNoise(x, y, octaves, samp.step * scale, lacunarity, persistence, seed));
                });
            }
        }
Exemplo n.º 18
0
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);

                Engine.scene = new Scene();

                font = new Font("Assets/OpenSans-Bold.ttf");

                bump_test = new GameObject();
                bump_test.components.Add(new Sprite());

                bump_test.sprite.width  = 512;
                bump_test.sprite.height = 512;

                bump_test.sprite.material = new Material();

                Shader bump = new Shader();

                bump.name            = "Bump shader";
                bump.vertexProgram   = File.ReadAllText("Assets/vertex.glsl");
                bump.fragmentProgram = File.ReadAllText("Assets/fragment.glsl");
                bump.fullRecompile();

                bump_test.sprite.material.shader = bump;

                Texture   tex     = new Texture("Assets/tex.png");
                Texture   nrm     = new Texture("Assets/tex_nrm.png");
                Sampler2D smp_tex = new Sampler2D(tex);
                Sampler2D smp_nrm = new Sampler2D(nrm);

                bump_test.sprite.material.parameters["light_c"] = (int)1;

                bump_test.sprite.material.parameters["texture"]      = smp_tex;
                bump_test.sprite.material.parameters["normal"]       = smp_nrm;
                bump_test.sprite.material.parameters["color"]        = new Vec4(1.0f, 1.0f, 1.0f, 1.0f);
                bump_test.sprite.material.parameters["ambient"]      = new Vec4(0.0f, 0.0f, 0.0f, 1.0f);
                bump_test.sprite.material.parameters["light_p[0]"]   = new Vec4(256.0f, 256.0f, 150.0f, 1.0f);
                bump_test.sprite.material.parameters["light_col[0]"] = new Vec4(1.0f, 1.0f, 1.0f, 1.0f);
                bump_test.sprite.material.parameters["light_int[0]"] = (float)0.3f;

                bump_test.sprite.material.parameters["amount"] = (float)1.0f;
            }
Exemplo n.º 19
0
            public Effect(Image texture)
                : this(texture.TextureSymbol + "_fx")
            {
                this.Image = texture;
                Surface   surface = new Surface(texture);
                Sampler2D sampler = new Sampler2D(surface);

                this.Add(
                    new XElement(ns + "profile_COMMON",
                                 surface,
                                 sampler,
                                 new XElement(ns + "technique",
                                              new XAttribute("sid", "common"),
                                              new XElement(ns + "blinn",
                                                           new XElement(ns + "emission", new XElement(ns + "color", "0 0 0 1")),
                                                           new XElement(ns + "ambient", new XElement(ns + "color", "0 0 0 1")),
                                                           new XElement(ns + "diffuse",
                                                                        new XElement(ns + "texture",
                                                                                     new XAttribute("texture", sampler.SID),
                                                                                     new XAttribute("texcoord", "TEXCOORD")
                                                                                     )
                                                                        ),
                                                           new XElement(ns + "specular", new XElement(ns + "color", "0 0 0 1")),
                                                           new XElement(ns + "shininess", new XElement(ns + "float", "0.2")),
                                                           new XElement(ns + "reflective", new XElement(ns + "color", "0 0 0 1")),
                                                           new XElement(ns + "reflectivity", new XElement(ns + "float", "0.2")),
                                                           new XElement(ns + "transparent",
                                                                        new XAttribute("opaque", "A_ONE"),
                                                                        new XElement(ns + "texture",
                                                                                     new XAttribute("texture", sampler.SID),
                                                                                     new XAttribute("texcoord", "TEXCOORD")
                                                                                     )
                                                                        ),
                                                           new XElement(ns + "transparency", new XElement(ns + "float", "1.0")),
                                                           new XElement(ns + "index_of_refraction", new XElement(ns + "float", "1.0"))
                                                           )
                                              )
                                 )
                    );
            }
Exemplo n.º 20
0
        public void init(LuaObject config)
        {
            myBiome = new Texture((int)WorldParameters.theRegionSize, (int)WorldParameters.theRegionSize, PixelInternalFormat.Rgba32f);
            myBiome.setName("Biome Map");
            mySampler = new Sampler2D(myBiome);

            LuaObject genConfig = config["generator"];

            myElevationGenerator = ModuleFactory.create(genConfig["elevation"]);
            myHeatGenerator      = ModuleFactory.create(genConfig["heat"]);
            myMoistureGenerator  = ModuleFactory.create(genConfig["moisture"]);

            //setup shaders
            List <ShaderDescriptor> shadersDesc = new List <ShaderDescriptor>();

            shadersDesc.Add(new ShaderDescriptor(ShaderType.ComputeShader, "Terrain.shaders.applyElevation-cs.glsl"));
            ShaderProgramDescriptor sd = new ShaderProgramDescriptor(shadersDesc);

            myApplyElevationShader = Renderer.resourceManager.getResource(sd) as ShaderProgram;

            shadersDesc = new List <ShaderDescriptor>();
            shadersDesc.Add(new ShaderDescriptor(ShaderType.ComputeShader, "Terrain.shaders.applyHeat-cs.glsl"));
            sd = new ShaderProgramDescriptor(shadersDesc);
            myApplyHeatShader = Renderer.resourceManager.getResource(sd) as ShaderProgram;

            shadersDesc = new List <ShaderDescriptor>();
            shadersDesc.Add(new ShaderDescriptor(ShaderType.ComputeShader, "Terrain.shaders.applyMoisture-cs.glsl"));
            sd = new ShaderProgramDescriptor(shadersDesc);
            myApplyMoistureShader = Renderer.resourceManager.getResource(sd) as ShaderProgram;

            shadersDesc = new List <ShaderDescriptor>();
            shadersDesc.Add(new ShaderDescriptor(ShaderType.ComputeShader, "Terrain.shaders.applyBiome-cs.glsl"));
            sd = new ShaderProgramDescriptor(shadersDesc);
            myGenerateBiomeShader = Renderer.resourceManager.getResource(sd) as ShaderProgram;

            update();
        }
 public override void OnNodeCreate()
 {
     name    = "2D SideView terrain";
     texture = new Sampler2D(chunkSize, step);
 }
Exemplo n.º 22
0
        public NewParam(XPathNodeIterator iterator, string uri)
        {
            XPathNodeIterator attributeIterator;
            attributeIterator = iterator.Current.Select("@" + XmlCollada.NewParam.sid);
            if (attributeIterator.Count > 0)
            {
                attributeIterator.MoveNext();
                _sid = attributeIterator.Current.Value;
            }

            XPathNodeIterator nodesIterator = iterator.Current.SelectChildren(XmlCollada.NewParam.sampler2D, uri);
            if (nodesIterator.MoveNext())
            {
                _sampler2D = new Sampler2D(nodesIterator, uri);
            }

            nodesIterator = iterator.Current.SelectChildren(XmlCollada.NewParam.surface, uri);
            if (nodesIterator.MoveNext())
            {
                _surface = new Surface(nodesIterator, uri);
            }
        }
Exemplo n.º 23
0
 public NewParam(Sampler2D sampler2D, Surface surface, string sid)
 {
     _sampler2D = sampler2D;
     _surface = surface;
     _sid = sid;
 }
Exemplo n.º 24
0
 public virtual void     ComputeSampler2D(Sampler2D samp)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 25
0
		public override void OnNodeCreate()
		{
			name = "Perlin noise 2D";
			output = new Sampler2D(chunkSize, step);
		}
Exemplo n.º 26
0
 public override void OnNodeEnable()
 {
     mask = new Sampler2D(chunkSize, step);
 }
Exemplo n.º 27
0
 public ShadowUniforms(GLProgram program, Sampler2D sampler)
     : base(program)
 {
     using (program.Scope ())
         shadowMap &= sampler;
 }
Exemplo n.º 28
0
 public static Vector4 Texture(Sampler2D sampler, Vector2 texcoord)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 29
0
 public static Sampler2D Div(this Sampler2D s1, Sampler2D s2, bool alloc = false)
 {
     return(Operation2D(s1, s2, alloc, (f1, f2) => f1 / f2));
 }
Exemplo n.º 30
0
 public Sampler2D Mul(Sampler2D s1, Sampler2D s2, bool alloc = false)
 {
     return(Operation2D(s1, s2, alloc, (f1, f2) => f1 * f2));
 }
Exemplo n.º 31
0
            public Effect(Image texture)
                : this(texture.TextureSymbol + "_fx")
            {
                this.Image = texture;
                Surface surface = new Surface(texture);
                Sampler2D sampler = new Sampler2D(surface);

                this.Add(
                    new XElement(ns + "profile_COMMON",
                        surface,
                        sampler,
                        new XElement(ns + "technique",
                            new XAttribute("sid", "common"),
                            new XElement(ns + "blinn",
                                new XElement(ns + "emission", new XElement(ns + "color", "0 0 0 1")),
                                new XElement(ns + "ambient", new XElement(ns + "color", "0 0 0 1")),
                                new XElement(ns + "diffuse",
                                    new XElement(ns + "texture",
                                        new XAttribute("texture", sampler.SID),
                                        new XAttribute("texcoord", "TEXCOORD")
                                    )
                                ),
                                new XElement(ns + "specular", new XElement(ns + "color", "0 0 0 1")),
                                new XElement(ns + "shininess", new XElement(ns + "float", "0.2")),
                                new XElement(ns + "reflective", new XElement(ns + "color", "0 0 0 1")),
                                new XElement(ns + "reflectivity", new XElement(ns + "float", "0.2")),
                                new XElement(ns + "transparent",
                                    new XAttribute("opaque", "A_ONE"),
                                    new XElement(ns + "texture",
                                        new XAttribute("texture", sampler.SID),
                                        new XAttribute("texcoord", "TEXCOORD")
                                    )
                                ),
                                new XElement(ns + "transparency", new XElement(ns + "float", "1.0")),
                                new XElement(ns + "index_of_refraction", new XElement(ns + "float", "1.0"))
                            )
                        )
                    )
                );
            }
Exemplo n.º 32
0
 public TextureUniforms(GLProgram program, Sampler2D sampler) : base(program)
 {
     using (program.Scope())
         textureMap &= sampler;
 }
Exemplo n.º 33
0
 public ShadowUniforms(GLProgram program, Sampler2D sampler) : base(program)
 {
     using (program.Scope())
         shadowMap &= sampler;
 }
Exemplo n.º 34
0
 public override void OnNodeEnable()
 {
     wetnessMap = new Sampler2D(chunkSize, step);
 }