private static short FloatToNormalizedShort(float value) { Assure.BetweenOrEqualTo(value, -1f, 1f, "Normalized float value should be between -1f and 1f!"); return(value > 0f ? (short)(value * (float)System.Int16.MaxValue) : (short)(Math.Abs(value) * (float)System.Int16.MinValue)); }
private static sbyte FloatToNormalizedSByte(float value) { Assure.BetweenOrEqualTo(value, -1f, 1f, "Normalized float value should be between -1f and 1f!"); return(value > 0f ? (sbyte)(value * (float)SByte.MaxValue) : (sbyte)(Math.Abs(value) * (float)SByte.MinValue)); }
/// <summary> /// Create a new Texture Sampler object. /// </summary> /// <param name="filterType">The filter method to use.</param> /// <param name="wrapMode">The wrap mode to use.</param> /// <param name="maxAnisotropy">If <paramref name="filterType"/> is set to <see cref="TextureFilterType.Anisotropic"/>, /// this field is used to determine the maximum filter level for anisotropic filtering.</param> /// <param name="borderColor">If <paramref name="wrapMode"/> is set to <see cref="TextureWrapMode.Border"/>, /// this field is used to determine the out-of-bounds colour around the border of mapped textures. /// The range for each element in the <see cref="TexelFormat.RGB32Float"/> structure is <c>0f</c> to <c>1f</c>.</param> public TextureSampler(TextureFilterType filterType, TextureWrapMode wrapMode, AnisotropicFilteringLevel maxAnisotropy, TexelFormat.RGB32Float borderColor = new TexelFormat.RGB32Float()) : base(CreateTextureSampler(filterType, wrapMode, maxAnisotropy, borderColor), ResourceUsage.Immutable, SSO_SIZE_BYTES) { FilterType = filterType; WrapMode = wrapMode; MaxAnisotropy = maxAnisotropy; BorderColor = borderColor; Assure.BetweenOrEqualTo(borderColor.R, 0f, 1f, "Each element in the given border colour must lie between 0f and 1f."); Assure.BetweenOrEqualTo(borderColor.G, 0f, 1f, "Each element in the given border colour must lie between 0f and 1f."); Assure.BetweenOrEqualTo(borderColor.B, 0f, 1f, "Each element in the given border colour must lie between 0f and 1f."); }
private static ushort FloatToNormalizedUShort(float value) { Assure.BetweenOrEqualTo(value, 0f, 1f, "Normalized float value should be between 0f and 1f!"); return((ushort)(value * (float)System.UInt16.MaxValue)); }
private static byte FloatToNormalizedByte(float value) { Assure.BetweenOrEqualTo(value, 0f, 1f, "Normalized float value should be between 0f and 1f!"); return((byte)(value * (float)Byte.MaxValue)); }