public void ClearState() { Shader.InitializeState(); ConstantBuffer.InitializeState(); Resources.InitializeState(); Samplers.InitializeState(); }
/// <summary> /// Default constructor. /// </summary> public Clipper() : base() { _sampler2 = new EffectSampler(this); _sampler2.Name = "Mask"; _sampler2.Comment = "The opacity mask brush"; Samplers.Add(_sampler2); }
public void ResetTracking() { Shader.ResetTracking(); ConstantBuffer.ResetTracking(); Resources.ResetTracking(); Samplers.ResetTracking(); }
public static ISampler CreateSampler(Samplers type) { ISampler result = null; switch (type) { case Samplers.Flat: result = new FlatSampler(1, 1); break; case Samplers.Sphere: result = new SphereSampler(new Vector3(SmoothVoxelSettings.MeterSizeX / 2f, SmoothVoxelSettings.MeterSizeY / 2f, SmoothVoxelSettings.MeterSizeZ / 2f), SmoothVoxelSettings.MeterSizeX / 3f); break; case Samplers.Terrain: TerrainModule module = new TerrainModule(SmoothVoxelSettings.seed); result = new TerrainSampler(module, SmoothVoxelSettings.seed, SmoothVoxelSettings.enableCaves, SmoothVoxelSettings.amplitude, SmoothVoxelSettings.caveDensity, SmoothVoxelSettings.grassOffset); break; } return(result); }
public void TestUniformRemainsSame() { var sampler = Samplers.UniformD6(); sampler.Force(1); // TODO: Assert that all the probabilities are still the same }
public void DefaultTraceParams() { Assert.Equal(Samplers.GetProbabilitySampler(1e-4), TraceParams.Default.Sampler); Assert.Equal(32, TraceParams.Default.MaxNumberOfAttributes); Assert.Equal(32, TraceParams.Default.MaxNumberOfAnnotations); Assert.Equal(128, TraceParams.Default.MaxNumberOfMessageEvents); Assert.Equal(128, TraceParams.Default.MaxNumberOfLinks); }
public void TestGamblersChanges() { var sampler = Samplers.GamblersD6(); sampler.Force(1); // TODO: Assert that the probability is now lower for 1 }
// TODO 1: test this function more // TODO 2: balance damages // will recursively add events to BodyDamageEvent event list (per body part) private void TakeDamage(BodyNode node, Damage damage) { // Debug.Log("TAKE DAMAGE: index " + node.Index); float r1 = UnityEngine.Random.value; // unused float r2 = UnityEngine.Random.value; if (0 <= node.Index) { var bodyPart = _bodyParts[node.Index]; // get damage event from body part hp system var dmgEvent = bodyPart.TakeDamage(damage) as HpSystemDamageEvent; var bodyPartHpEvent = new BodyPartHpEvent(bodyPart, dmgEvent.HpSystemEvent); // add current event to the body event system this._eventSystem.OnEvent(bodyPartHpEvent); } // Debug.Log($"bodyPart [{node.Index}] {bodyPart.NameCustom}, children: " + node.ChildrenCount); // apply damage to node's children if (node.HasChildren) { var children = node.Children.ToArray(); var sb = new StringBuilder(); foreach (var i in children) { sb.Append(i + ", "); } // Debug.Log("children: " + sb.ToString()); // sample indices of children to pick which children will be applied damage to Vector2Int indices = Samplers.SampleFromPdf( r2, GetBodyPartSizes(new IndexedEnumerator <BodyPart>(this._bodyParts, children)), damage.Dispersion); // get the children var damagedNodes = new IndexedEnumerator <BodyNode>( this._bodyNodes, new SliceEnumerator <int>(children, indices[0], indices[1] + 1).ToArray() ); // Debug.Log("damaged nodes count " + damagedNodes.Count()); damagedNodes.Reset(); // need to reset since its an iterator // compute the damage amount passed on to children of current body part var damageAfterMultiplier = damage * damage.Penetration; foreach (var damagedNode in damagedNodes) { TakeDamage(damagedNode, damageAfterMultiplier); } } }
public static void IllustrateCoinFlipRuns() { ISampler <bool> uniformCoin = Samplers.UniformFairCoin(); Console.WriteLine("Uniform Sample:"); IllustrateCoinFlipRunsOnSampler(uniformCoin); ISampler <bool> gamblersCoin = Samplers.GamblersFairCoin(); Console.WriteLine("Gambler's Sample:"); IllustrateCoinFlipRunsOnSampler(gamblersCoin); }
public static void SimulateXCOMShots(int percentHit) { ISampler <int> uniformCoin = Samplers.UniformD20(); Console.WriteLine("Uniform Sample:"); SimulateXCOMShotsOnDie(uniformCoin, (100 - percentHit) / 5); ISampler <int> gamblersCoin = Samplers.GamblersD20(); Console.WriteLine("Gambler's Sample:"); SimulateXCOMShotsOnDie(gamblersCoin, (100 - percentHit) / 5); }
/// <summary> /// Default constructor. /// </summary> public Subtractor() : base() { _gain2 = new EffectProperty(this); _sampler2 = new EffectSampler(this); _sampler2.Name = "Input2"; _sampler2.Comment = "A brush to substract from the original element."; Samplers.Add(_sampler2); _gain2.Name = "Gain2"; _gain2.WrapperType = typeof(double); _gain2.DefaultValue = "1.0"; Properties.Add(_gain2); }
static SamplerData GetSamplerComponent(Module[] modules) { var samplers = new Improbable.Collections.Map <int, SamplerStat>(); for (int i = 0; i < modules.Length; i++) { if (modules[i].Type == ModuleType.Sampler) { samplers[i] = Samplers.Craft(modules[i].Properties.BackingArray); } } return(new SamplerData(samplers)); }
public static void Load(GameWindow window) { Window = window; ResizeFrameBuffers(); Window.Resize += (sender, args) => ResizeFrameBuffers(); WorldGeometryShader = ResourceReader.ReadShader(PluginDir + "Shaders/WorldGeometry"); CompositionShader = ResourceReader.ReadShader(PluginDir + "Shaders/Composition"); PointLightShader = ResourceReader.ReadShader(PluginDir + "Shaders/PointLight"); BlockOutlineShader = ResourceReader.ReadShader(PluginDir + "Shaders/BlockOutline"); SpriteShader = ResourceReader.ReadShader(PluginDir + "Shaders/Sprite"); ScreenRectVao = new SpriteVertexArrayObject(); ScreenRectVao.Add(new Vector2(-1, +1), Vector2.Zero, Vector3.Zero); ScreenRectVao.Add(new Vector2(+1, +1), Vector2.Zero, Vector3.Zero); ScreenRectVao.Add(new Vector2(-1, -1), Vector2.Zero, Vector3.Zero); ScreenRectVao.Add(new Vector2(+1, -1), Vector2.Zero, Vector3.Zero); ScreenRectVao.AddFace(new uint[] { 0, 2, 1, 1, 2, 3 }); ScreenRectVao.Upload(); Samplers.Load(); MissingModel = ResourceReader.ReadBlockModel("System/Models/MissingModel.json"); MissingTexture = ResourceReader.ReadBlockTexture("System/Textures/Blocks/MissingTexture.png"); //TODO: Remove var lines = File.ReadAllLines("Keybindings.txt"); foreach (var line in lines) { var splits = line.Split('='); if (splits.Length != 2) { continue; } if (Enum.TryParse(splits[0], true, out Key key)) { Keybindings.Add(key, splits[1]); } } }
/// <summary> /// Default constructor. /// </summary> public Mixer() : base() { _gain1 = new EffectProperty(this); _gain2 = new EffectProperty(this); _sampler2 = new EffectSampler(this); _sampler2.Name = "Input2"; _sampler2.Comment = "A brush to mix with the original element."; Samplers.Add(_sampler2); _gain1.Name = "Gain1"; _gain1.WrapperType = typeof(double); _gain1.DefaultValue = "0.5"; Properties.Add(_gain1); _gain2.Name = "Gain2"; _gain2.WrapperType = typeof(double); _gain2.DefaultValue = "0.5"; Properties.Add(_gain2); }
public void CreateSampler(string Name, bool IsConstant) { var mat = MaterialAnimData; var SamplerInfo = new TexturePatternAnimInfo(); if (IsConstant) { SamplerInfo.BeginConstant = (ushort)mat.Constants.Count; SamplerInfo.CurveIndex = (ushort)65535; } else { SamplerInfo.BeginConstant = (ushort)65535; SamplerInfo.CurveIndex = (ushort)mat.Curves.Count; } mat.TexturePatternAnimInfos.Add(SamplerInfo); BfresSamplerAnim sampler = new BfresSamplerAnim(SamplerInfo.Name, matAnimWrapper, this); Samplers.Add(sampler); }
public void ProbabilitySampler_DifferentProbabilities_SampledParentLink() { ISampler neverSample = Samplers.GetProbabilitySampler(0.0); AssertSamplerSamplesWithProbability( neverSample, notSampledSpanContext, new List <ISpan>() { sampledSpan }, 1.0); ISampler alwaysSample = Samplers.GetProbabilitySampler(1.0); AssertSamplerSamplesWithProbability( alwaysSample, notSampledSpanContext, new List <ISpan>() { sampledSpan }, 1.0); ISampler fiftyPercentSample = Samplers.GetProbabilitySampler(0.5); AssertSamplerSamplesWithProbability( fiftyPercentSample, notSampledSpanContext, new List <ISpan>() { sampledSpan }, 1.0); ISampler twentyPercentSample = Samplers.GetProbabilitySampler(0.2); AssertSamplerSamplesWithProbability( twentyPercentSample, notSampledSpanContext, new List <ISpan>() { sampledSpan }, 1.0); ISampler twoThirdsSample = Samplers.GetProbabilitySampler(2.0 / 3.0); AssertSamplerSamplesWithProbability( twoThirdsSample, notSampledSpanContext, new List <ISpan>() { sampledSpan }, 1.0); }
override public void TakeDamage(Damage damage) { if (this.BodyParts.Count > 0) { if (this.BodyParts.Count == 1) { this.BodyParts[0].TakeDamage(damage); } else { Vector2Int indices = Samplers.SampleFromPdf(UnityEngine.Random.value, this.GetBodyPartSizes, damage.dispersion); foreach (var bodyPart in this.BodyParts.ToArray().Slice(indices.x, indices.y)) { bodyPart.TakeDamage(damage); } } } else { return; } }
public void Merge(ShaderOutputContext other) { Structures.AddRange(other.Structures); ConstantBuffers.AddRange(other.ConstantBuffers); Textures.AddRange(other.Textures); Samplers.AddRange(other.Samplers); UniformConstants.AddRange(other.UniformConstants); if (VertLayout != null && other.VertLayout != null) { throw new DuplicateBindpointException("Vertex layout is defined twice"); } if (VertLayout == null) { VertLayout = other.VertLayout; } if (ShaderBinding != null && other.ShaderBinding != null) { throw new DuplicateBindpointException("Shader bindings are defined twice"); } if (ShaderBinding == null) { ShaderBinding = other.ShaderBinding; } }
public void ProbabilitySampler_ToString() { Assert.Contains("0.5", Samplers.GetProbabilitySampler(0.5).ToString()); }
public void Draw(GraphicsDeviceManager graphics, BasicEffect effect, AlphaTestEffect alpha) { if (indices != null && verts != null) { if (verts.Count > 0) { effect.TextureEnabled = textureEnabled; if (textureEnabled) { if (Game1.textures.ContainsKey(textureName)) { effect.Texture = Game1.textures[textureName]; if (alpha != null) { alpha.Texture = effect.Texture; } } else { //Console.WriteLine("missing texture: " + textureName); effect.Texture = Game1.textures["test"]; if (alpha != null) { alpha.Texture = effect.Texture; } } } foreach (var pass in (alpha != null ? alpha.CurrentTechnique.Passes : effect.CurrentTechnique.Passes)) { pass.Apply(); graphics.GraphicsDevice.DrawUserIndexedPrimitives( PrimitiveType.TriangleList, verts_sealed, 0, verts_sealed.Length, indices, 0, indices.Length / 3, VertexPositionColorTexture.VertexDeclaration ); } if (Samplers.EnableWireframe) { effect.TextureEnabled = false; Samplers.SetToDevice(graphics, EngineRasterizer.Wireframe); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); graphics.GraphicsDevice.DrawUserIndexedPrimitives( PrimitiveType.TriangleList, verts_sealed, 0, verts_sealed.Length, indices, 0, indices.Length / 3, VertexPositionColorTexture.VertexDeclaration ); } Samplers.SetToDevice(graphics, EngineRasterizer.Default); } } else { Console.WriteLine("Empty QuadList!"); } } }
/* * public byte[] GetBuffer(int bufferIndex) * { * return FileChunks[bufferIndex + 1].Data; * } */ public void ParseJSON(string JSONstring) { var json = JsonConvert.DeserializeObject <dynamic>(JSONstring); foreach (var bufferViewJSON in json.bufferViews) { GLBBufferView bufferView = new GLBBufferView(); bufferView.Buffer = FileChunks[(int)bufferViewJSON.buffer + 1].Data; bufferView.ByteOffset = bufferViewJSON.byteOffset; bufferView.ByteLength = bufferViewJSON.byteLength; bufferView.Target = bufferViewJSON.target; BufferViews.Add(bufferView); } foreach (var accessorJSON in json.accessors) { GLBAccessor accessor = new GLBAccessor(); accessor.BufferView = BufferViews[(int)accessorJSON.bufferView]; accessor.ComponentType = accessorJSON.componentType; accessor.Count = accessorJSON.count; accessor.Type = accessorJSON.type; Accessors.Add(accessor); } foreach (var imageJSON in json.images) { GLBImage image = new GLBImage(); image.BufferView = BufferViews[(int)imageJSON.bufferView]; image.MimeType = imageJSON.mimeType; Images.Add(image); } foreach (var samplerJSON in json.samplers) { GLBSampler sampler = new GLBSampler(); sampler.MinFilter = samplerJSON.minFilter; sampler.MagFilter = samplerJSON.magFilter; sampler.WrapS = samplerJSON.wrapS; sampler.WrapT = samplerJSON.wrapT; Samplers.Add(sampler); } foreach (var textureJSON in json.textures) { GLBTexture texture = new GLBTexture(); texture.Source = Images[(int)textureJSON.source]; texture.Sampler = Samplers[(int)textureJSON.sampler]; Textures.Add(texture); } foreach (var materialJSON in json.materials) { GLBMaterial material = new GLBMaterial(); material.Name = materialJSON.name; Materials.Add(material); } foreach (var meshJSON in json.meshes) { GLBMesh mesh = new GLBMesh(); mesh.Name = meshJSON.name; foreach (var primitiveJSON in meshJSON.primitives) { GLBPrimitive primitive = new GLBPrimitive(); GLBAttributes attributes = new GLBAttributes(); attributes.Position = Accessors[(int)primitiveJSON.attributes.POSITION]; attributes.Normal = Accessors[(int)primitiveJSON.attributes.NORMAL]; primitive.Attributes = attributes; primitive.Indices = Accessors[(int)primitiveJSON.indices]; primitive.Material = Materials[(int)primitiveJSON.material]; mesh.Primitives.Add(primitive); } Meshes.Add(mesh); } }
public void GenerateCrystal() { //Debug.Log("Generating crystal"); List <Vector3> vertices = new List <Vector3>(); List <Vector3> normals = new List <Vector3>(); List <int> tris = new List <int>(); for (int lobe = 0; lobe < numCrystals; lobe++) { // compute lobe parameters given randomness int lobeNumCenters = Mathf.Max(1, (int)(numCenters - randomness * numCenters * NextRandomFloat)); int lobeNumSides = Mathf.Max(MinNumSides, (int)(numCenters - randomness * numCenters * NextRandomFloat)); float lobeScale = 1f - 0.75f * randomness * NextRandomFloat; // limit maximum randomness on scale float lobeWidth = lobeScale * crystalWidth * (1f - randomness + 2f * randomness * NextRandomFloat); float lobeLength = lobeScale * crystalLength * (1f - randomness + 2f * randomness * NextRandomFloat); float maxRotation = 2f * Mathf.PI / lobeNumSides; Vector3 lobeRoot = 0.25f * randomness * new Vector3(-1f + 2f * NextRandomFloat, 0, -1f + 2f * NextRandomFloat); //Debug.Log("Generating a crystal lobe " + lobe); Vector3 lobeDir = Samplers.SampleRandomCosineHemisphere(NextRandomFloat, NextRandomFloat); Quaternion rotation = Quaternion.LookRotation(lobeDir); List <Vector3> sides = new List <Vector3>(); for (int j = 0; j < lobeNumCenters; j++) { float ratio = lobeNumCenters == 1 ? 0.5f: 1f * j / (lobeNumCenters - 1); Vector3 centerPos = lobeRoot + lobeLength * lobeDir * EvaluateDensityCurve(ratio); for (int side = 0; side < lobeNumSides; side++) { float angle = maxRotation * side; Vector3 sideDir = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)); //todo rotate to crystalDir Vector3 sidePos = centerPos + lobeWidth * sideDir * crystalSizeCurve.Evaluate(ratio); //sidePos = rotation * sidePos; sides.Add(sidePos); } } Vector3 crystalTop = lobeRoot + lobeLength * lobeDir; //Debug.Log("ROOT: " + lobeRoot); //Debug.Log("SIDES: " + sides.Count); //foreach (var v in sides) // Debug.Log(v); //Debug.Log("TOP: " + crystalTop); int index, s1, s2, s3; // generate triangles for the sides for (int j = 0; j < lobeNumCenters - 1; j++) { for (int side = 0; side < lobeNumSides; side++) { index = j * lobeNumSides + side; s1 = index; bool b = (side + 1) % lobeNumSides == 0; // need to generate 2 triangles per side for (int tri = 0; tri < 2; tri++) { if (tri == 0) // triangle 1 { s2 = b ? index + lobeNumSides : index + lobeNumSides; s3 = b ? index + 1 : index + lobeNumSides + 1; } else // triangle 2 { s2 = b ? index + 1 : index + lobeNumSides + 1; s3 = b ? index - lobeNumSides + 1 : index + 1; } //Debug.Log("Indices" + s1 + " " + s2 + " " + s3); List <Vector3> verticesLocal = new List <Vector3>() { sides[s1], sides[s2], sides[s3] }; MeshTriAdder.AddTriangle(new Vector3Int(0, 1, 2), verticesLocal, vertices, tris, false); } } } bool isBottom = true; Vector3 v1; // bottom and top triangles for (int c = 0; c < 2; c++) { if (isBottom) { v1 = lobeRoot; index = 0; // index is now used as an offset for the vertex indices } else { v1 = crystalTop; index = (lobeNumCenters - 1) * lobeNumSides; } for (int j = 0; j < lobeNumSides; j++) { if (isBottom) { s2 = index + j; s3 = (index + 1 + j) % lobeNumSides; } else { s2 = index + (1 + j) % lobeNumSides; s3 = index + j; } List <Vector3> verticesLocal = new List <Vector3>() { v1, sides[s2], sides[s3] }; MeshTriAdder.AddTriangle(new Vector3Int(0, 1, 2), verticesLocal, vertices, tris, false); } isBottom = false; } } Mesh mesh = new Mesh(); mesh.Clear(); mesh.subMeshCount = 2; mesh.SetVertices(vertices); mesh.SetTriangles(tris.ToArray(), 0); Vector2[] uvs = Unwrapping.GeneratePerTriangleUV(mesh); mesh.SetUVs(0, new List <Vector2>(uvs)); mesh.RecalculateNormals(); mesh.RecalculateBounds(); // assign back to meshFilter MeshFilter meshFilter = GetComponent <MeshFilter>(); //mesh.Optimize(); meshFilter.mesh = mesh; }
public void ProbabilitySampler_OutOfRangeLowProbability() { Assert.Throws <ArgumentOutOfRangeException>(() => Samplers.GetProbabilitySampler(-0.00001)); }
private void GamblersCoin_ShowsDistribution(double p, int n) { Coin_ShowsDistribution(Samplers.GamblersBiasedCoin(p), p, n); }
public void Reload(Material material) { ShaderArchive = ""; ShaderModel = ""; ShaderParams.Clear(); ShaderOptions.Clear(); Samplers.Clear(); TextureMaps.Clear(); UpdateRenderState(); if (material.ShaderAssign != null) { ShaderArchive = material.ShaderAssign.ShaderArchiveName; ShaderModel = material.ShaderAssign.ShadingModelName; } foreach (var param in material.ShaderParams) { ShaderParams.Add(param.Key, param.Value); } foreach (var option in material.ShaderAssign.ShaderOptions) { ShaderOptions.Add(option.Key, option.Value); } // if (ShaderParams.ContainsKey("gsys_i_color_ratio0")) // ShaderParams["gsys_i_color_ratio0"].DataValue = 0.1f; for (int i = 0; i < material.TextureRefs.Count; i++) { string name = material.TextureRefs[i].Name; Sampler sampler = material.Samplers[i]; var texSampler = material.Samplers[i].TexSampler; string samplerName = sampler.Name; string fragSampler = ""; //Force frag shader sampler to be used if (material.ShaderAssign.SamplerAssigns.ContainsValue(samplerName)) { material.ShaderAssign.SamplerAssigns.TryGetKey(samplerName, out fragSampler); } Samplers.Add(fragSampler); this.TextureMaps.Add(new TextureMap() { Name = name, Sampler = samplerName, MagFilter = GXConverter.ConvertMagFilter(texSampler.MagFilter), MinFilter = GXConverter.ConvertMinFilter( texSampler.MipFilter, texSampler.MinFilter), Type = GetTextureType(fragSampler), WrapU = GXConverter.ConvertWrapMode(texSampler.ClampX), WrapV = GXConverter.ConvertWrapMode(texSampler.ClampY), LODBias = texSampler.LodBias, MaxLOD = texSampler.MaxLod, MinLOD = texSampler.MinLod, }); } }
public void ProbabilitySampler_ToString() { var result = Samplers.GetProbabilitySampler(0.5).ToString(); Assert.Contains($"0{CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator}5", result); }
public void ProbabilitySampler_getDescription() { Assert.Equal(String.Format("ProbabilitySampler({0:F6})", 0.5), Samplers.GetProbabilitySampler(0.5).Description); }
public void ProbabilitySampler_SampleBasedOnTraceId() { ISampler defaultProbability = Samplers.GetProbabilitySampler(0.0001); // This traceId will not be sampled by the ProbabilitySampler because the first 8 bytes as long // is not less than probability * Long.MAX_VALUE; ITraceId notSampledtraceId = TraceId.FromBytes( new byte[] { 0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, }); Assert.False( defaultProbability.ShouldSample( null, false, notSampledtraceId, SpanId.GenerateRandomId(random), SPAN_NAME, new List <ISpan>())); // This traceId will be sampled by the ProbabilitySampler because the first 8 bytes as long // is less than probability * Long.MAX_VALUE; ITraceId sampledtraceId = TraceId.FromBytes( new byte[] { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, }); Assert.True( defaultProbability.ShouldSample( null, false, sampledtraceId, SpanId.GenerateRandomId(random), SPAN_NAME, new List <ISpan>())); }
private void UniformCoin_ShowsDistribution(double p, int n) { Coin_ShowsDistribution(Samplers.UniformBiasedCoin(p), p, n); }