public void Write() { Help.IOHelp.WriteVec(Diff); Help.IOHelp.WriteVec(Spec); Help.IOHelp.WriteFloat(Shine); Help.IOHelp.WriteBool(ColorMap != null); if (ColorMap != null) { ColorMap.Write(); } Help.IOHelp.WriteBool(NormalMap != null); if (NormalMap != null) { NormalMap.Write(); } Help.IOHelp.WriteBool(SpecularMap != null); if (SpecularMap != null) { SpecularMap.Write(); } Help.IOHelp.WriteBool(ExtraMap != null); if (ExtraMap != null) { ExtraMap.Write(); } Help.IOHelp.WriteBool(EnvironmentMap != null); if (EnvironmentMap != null) { Help.IOHelp.WriteString(EnvironmentMap.Path); } }
public static void Draw(LightingSettings.Profile profile) { bool foldout = GUIFoldoutHeader.Begin("Day Lighting", profile.dayLightingSettings); if (foldout == false) { GUIFoldoutHeader.End(); return; } EditorGUI.indentLevel++; EditorGUILayout.Space(); profile.dayLightingSettings.alpha = EditorGUILayout.Slider("Alpha", profile.dayLightingSettings.alpha, 0, 1); profile.dayLightingSettings.direction = EditorGUILayout.Slider("Direction", profile.dayLightingSettings.direction, 0, 360); profile.dayLightingSettings.height = EditorGUILayout.Slider("Height", profile.dayLightingSettings.height, 0.1f, 10); SunPenumbra.Draw(profile); NormalMap.Draw(profile); EditorGUI.indentLevel--; GUIFoldoutHeader.End(); }
public virtual void Release() { if (ColorMap != null) { ColorMap.Release(0); } if (NormalMap != null) { NormalMap.Release(1); } //if (TSpec != null) TSpec.Release(2); if (EnvironmentMap != null) { EnvironmentMap.Release(4); } if (SpecularMap != null) { SpecularMap.Release(3); } if (ExtraMap != null) { ExtraMap.Release(5); } Active = null; }
public void Dispose() { Albedo?.Dispose(); NormalMap?.Dispose(); HeightMap?.Dispose(); Occlusion?.Dispose(); }
public IEnumerable <Object> FetchDependencies(ISerializedFile file, bool isLog = false) { yield return(Texture.FetchDependency(file, isLog, () => nameof(SplatPrototype), "texture")); if (IsReadNormalMap(file.Version)) { yield return(NormalMap.FetchDependency(file, isLog, () => nameof(SplatPrototype), "normalMap")); } }
public override void Initialize() { Contract.Requires <InvalidOperationException>(NormalMapKey != null); base.Initialize(); NormalMap = Content.Load <Texture>(NormalMapKey); if (!NormalMap.IsInited) { NormalMap.Initialize(); } TextureMap.Add(TextureReference.NormalMap.ToString(), NormalMap); }
/// <summary> /// Releases the unmanaged resources used by an instance of the <see cref="WaterWaves"/> class /// and optionally releases the managed resources. /// </summary> /// <param name="disposing"> /// <see langword="true"/> to release both managed and unmanaged resources; /// <see langword="false"/> to release only unmanaged resources. /// </param> protected virtual void Dispose(bool disposing) { if (disposing) { DisplacementMap.SafeDispose(); DisplacementMap = null; NormalMap.SafeDispose(); NormalMap = null; } }
public override int GetHashCode() { unchecked { var hashCode = (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (DiffuseMap != null ? DiffuseMap.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (NormalMap != null ? NormalMap.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (SpecularMap != null ? SpecularMap.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Color.GetHashCode(); return(hashCode); } }
public YAMLNode ExportYAML(IExportContainer container) { YAMLMappingNode node = new YAMLMappingNode(); node.Add(TextureName, Texture.ExportYAML(container)); node.Add(NormalMapName, NormalMap.ExportYAML(container)); node.Add(TileSizeName, TileSize.ExportYAML(container)); node.Add(TileOffsetName, TileOffset.ExportYAML(container)); node.Add(SpecularMetallicName, SpecularMetallic.ExportYAML(container)); node.Add(SmoothnessName, Smoothness); return(node); }
public YAMLNode ExportYAML(IExportContainer container) { YAMLMappingNode node = new YAMLMappingNode(); node.Add("texture", Texture.ExportYAML(container)); node.Add("normalMap", NormalMap.ExportYAML(container)); node.Add("tileSize", TileSize.ExportYAML(container)); node.Add("tileOffset", TileOffset.ExportYAML(container)); node.Add("specularMetallic", SpecularMetallic.ExportYAML(container)); node.Add("smoothness", Smoothness); return(node); }
public Vector3D GetVector(int x, int y) { if (UsingNormalMap) { var v = new Vector3D(NormalMap.GetPixel(x, y).R - 128, NormalMap.GetPixel(x, y).G - 128, NormalMap.GetPixel(x, y).B); v = v / v.Length; return(v); } else { return(new Vector3D(0, 0, 1)); } }
/// <summary> /// Calls <see cref="Asset.ReleaseReference"/> for all contained <see cref="XTexture"/>s. /// </summary> public void ReleaseReference() { if (DiffuseMaps != null) { foreach (var texture in DiffuseMaps.WhereNotNull()) { texture.ReleaseReference(); } } NormalMap?.ReleaseReference(); HeightMap?.ReleaseReference(); SpecularMap?.ReleaseReference(); EmissiveMap?.ReleaseReference(); }
private void Update(EvaluationContext context) { // Parameters var parameterBufferContent = new PbrMaterialParams { BaseColor = BaseColor.GetValue(context), EmissiveColor = EmissiveColor.GetValue(context), Roughness = Roughness.GetValue(context), Specular = Specular.GetValue(context), Metal = Metal.GetValue(context) }; ResourceManager.Instance().SetupConstBuffer(parameterBufferContent, ref _parameterBuffer); // Textures var resourceManager = ResourceManager.Instance(); var device = resourceManager.Device; Utilities.Dispose(ref _baseColorMapSrv); var tex = BaseColorMap.GetValue(context) ?? PbrContextSettings.WhitePixelTexture; _baseColorMapSrv = new ShaderResourceView(device, tex); context.PbrMaterialTextures.AlbedoColorMap = _baseColorMapSrv; Utilities.Dispose(ref _normalMapSrv); var tex2 = NormalMap.GetValue(context) ?? PbrContextSettings.NormalFallbackTexture; _normalMapSrv = new ShaderResourceView(device, tex2); context.PbrMaterialTextures.NormalMap = _normalMapSrv; Utilities.Dispose(ref _rsmoMapSrv); var tex3 = RoughnessSpecularMetallicOcclusionMap.GetValue(context) ?? PbrContextSettings.RsmoFallbackTexture; _rsmoMapSrv = new ShaderResourceView(device, tex3); context.PbrMaterialTextures.RoughnessSpecularMetallicOcclusionMap = _rsmoMapSrv; Utilities.Dispose(ref _emissiveColorMapSrv); var tex4 = EmissiveColorMap.GetValue(context) ?? PbrContextSettings.WhitePixelTexture; _emissiveColorMapSrv = new ShaderResourceView(device, tex4); context.PbrMaterialTextures.EmissiveColorMap = _emissiveColorMapSrv; var previousParameters = context.PbrMaterialParams; context.PbrMaterialParams = _parameterBuffer; SubTree.GetValue(context); context.PbrMaterialParams = previousParameters; }
public override void GenerateShader(MaterialGeneratorContext context) { if (NormalMap != null) { // Inform the context that we are using matNormal (from the MaterialSurfaceNormalMap shader) context.UseStreamWithCustomBlend(MaterialShaderStage.Pixel, NormalStream.Stream, new ShaderClassSource("MaterialStreamNormalBlend")); context.Parameters.Set(MaterialKeys.HasNormalMap, true); context.Parameters.Set(MaterialKeys.SkipTangents, SkipTangents); var normalMap = NormalMap; // Workaround to make sure that normal map are setup var computeTextureColor = normalMap as ComputeTextureColor; if (computeTextureColor != null) { if (computeTextureColor.FallbackValue.Value == Color.White) { computeTextureColor.FallbackValue.Value = DefaultNormalColor; } } else { var computeColor = normalMap as ComputeColor; if (computeColor != null) { if (computeColor.Value == Color.Black || computeColor.Value == Color.White) { computeColor.Value = DefaultNormalColor; } } else { var computeFloat4 = normalMap as ComputeFloat4; if (computeFloat4 != null) { if (computeFloat4.Value == Vector4.Zero) { computeFloat4.Value = DefaultNormalColor.ToVector4(); } } } } var computeColorSource = NormalMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.NormalMap, MaterialKeys.NormalValue, DefaultNormalColor, false)); var mixin = new ShaderMixinSource(); mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceNormalMap", IsXYNormal, ScaleAndBias)); mixin.AddComposition("normalMap", computeColorSource); context.AddShaderSource(MaterialShaderStage.Pixel, mixin); } }
public Vector3 GetNormalVector(int x, int y) { Vector3 normalVec; Vector3 disturbanceVector; if (!UseFixedNormalVector && !UseMouseFollowNormalVector && NormalMap != null) { var normalColor = NormalMap.GetPixel(y % NormalMap.Height, x % NormalMap.Width); normalVec = new Vector3(normalColor.R - 127, normalColor.G - 127, normalColor.B - 127); normalVec.X /= 127; normalVec.Y /= 127; normalVec.Z /= 127; normalVec = Vector3.Normalize(normalVec); } else if (UseMouseFollowNormalVector) { var dx = mousePosition.X - x; var dy = mousePosition.Y - y; var z = 100 * 100 - dx * dx - dy * dy; z = z < 0 ? 0 : (float)Math.Sqrt(z); normalVec = Vector3.Normalize(new Vector3(dx, dy, z)); } else { normalVec = new Vector3(0, 0, 1); } if (!UseEmptyDisturbanceVector && HeightMap != null) { var hCol = HeightMap.GetPixel(y % HeightMap.Height, x % HeightMap.Width); var rightHCol = HeightMap.GetPixel(y % HeightMap.Height, (x + 1) % HeightMap.Width); var downHCol = HeightMap.GetPixel((y + 1) % HeightMap.Height, x % HeightMap.Width); var dhx = (rightHCol.R - hCol.R + rightHCol.G - hCol.G + rightHCol.B - hCol.B) * Factor; var dhy = (downHCol.R - hCol.R + downHCol.G - hCol.G + downHCol.B - hCol.B) * Factor; disturbanceVector = new Vector3(dhx, 0, -normalVec.X + dhx) + new Vector3(dhy, 0, -normalVec.Y * dhy); } else { disturbanceVector = new Vector3(0, 0, 0); } var normalPrim = normalVec + disturbanceVector; return(Vector3.Normalize(normalPrim)); }
private void UpdateNormalMap() { if (NormalMap == null || NormalMap.width != map.width || NormalMap.height != map.height) { if (NormalMap != null && NormalMap.IsCreated()) { NormalMap.Release(); } NormalMap = new RenderTexture(map.width, map.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); NormalMap.hideFlags = HideFlags.DontSave; NormalMap.Create(); } Normal.Apply(map, NormalMap); material.SetTexture("_NormalMap", NormalMap); }
public override void VisitFeature(MaterialGeneratorContext context) { if (NormalMap != null) { // Inform the context that we are using matNormal (from the MaterialSurfaceNormalMap shader) context.UseStreamWithCustomBlend(MaterialShaderStage.Pixel, NormalStream.Stream, new ShaderClassSource("MaterialStreamNormalBlend")); context.Parameters.Set(MaterialKeys.HasNormalMap, true); var computeColorSource = NormalMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.NormalMap, MaterialKeys.NormalValue, new Color(0x80, 0x80, 0xFF, 0xFF))); var mixin = new ShaderMixinSource(); mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceNormalMap", IsXYNormal, ScaleAndBias)); mixin.AddComposition("normalMap", computeColorSource); context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin); } }
public DemoPartition(DemoPartitionContext context) { if (context == null) throw new ArgumentNullException("context"); this.context = context; settings = context.Settings; heightMap = new NoiseHeightMap(context.GraphicsDevice, settings.HeightMapWidth, settings.HeightMapHeight); heightMap.NoiseSource = context.Noise; normalMap = new NormalMap(context.GraphicsDevice, settings.HeightMapWidth, settings.HeightMapHeight); normalMap.HeightMap = heightMap; normalMap.Amplitude = settings.HeightScale; noiseRainMap = new NoiseRainMap(settings.HeightMapWidth, settings.HeightMapHeight); noiseRainMap.NoiseSource = rainNoise.Sample; noiseRainMap.RainAmount = 0.5f; uniformRainMap = new Map<float>(settings.HeightMapWidth, settings.HeightMapHeight); uniformRainMap.Fill(0.8f); terrainRainMap = new Map<float>(settings.HeightMapWidth, settings.HeightMapHeight); hydraulicErosion.HeightMap = heightMap; //hydraulicErosion.RainMap = noiseRainMap; //hydraulicErosion.RainMap = uniformRainMap; hydraulicErosion.RainMap = terrainRainMap; fastHydraulicErosion.HeightMap = heightMap; //fastHydraulicErosion.RainMap = noiseRainMap; //fastHydraulicErosion.RainMap = uniformRainMap; fastHydraulicErosion.RainMap = terrainRainMap; musgraveHydraulicErosion.HeightMap = heightMap; //musgraveHydraulicErosion.RainMap = noiseRainMap; //musgraveHydraulicErosion.RainMap = uniformRainMap; musgraveHydraulicErosion.RainMap = terrainRainMap; thermalErosion.HeightMap = heightMap; fastThermalErosion.HeightMap = heightMap; terrain = new CDLODTerrain(context.Settings); terrain.HeightMap = heightMap; }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). } if (DiffuseMap != null) { DiffuseMap.Dispose(); } if (NormalMap != null) { NormalMap.Dispose(); } if (DiffuseAlphaMap != null) { DiffuseAlphaMap.Dispose(); } if (ColorTable != null) { ColorTable.Dispose(); } if (MaskMap != null) { MaskMap.Dispose(); } if (SpecularMap != null) { SpecularMap.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } }
protected void SetBustMuscleSliders(SimDescription newSim) { bool changed = false; using (CASParts.OutfitBuilder builder = new CASParts.OutfitBuilder(newSim, CASParts.sPrimary)) { if (!builder.OutfitValid) { return; } if (newSim.IsFemale) { Vector2 bustRange = Manager.GetValue <BustRangeOption <TManager>, Vector2>(); if (bustRange.x != bustRange.y) { float value = RandomUtil.GetFloat(bustRange.x, bustRange.y); NormalMap.ApplyBustValue(builder.Builder, value); changed = true; mStats.AddScoring("Bust 100s", (int)(value * 100)); } } else { Vector2 muscleRange = Manager.GetValue <MuscleRangeOption <TManager>, Vector2>(); if (muscleRange.x != muscleRange.y) { float value = RandomUtil.GetFloat(muscleRange.x, muscleRange.y); NormalMap.ApplyMuscleValue(builder.Builder, value); changed = true; mStats.AddScoring("Muscle 100s", (int)(value * 100)); } } } if (changed) { new SavedOutfit.Cache(newSim).PropagateGenetics(newSim, CASParts.sPrimary); } }
private void PutPixel(DirectBitmap bitmap, int x, int y) { if (!(x >= 0 && x < bitmap.Width && y >= 0 && y < bitmap.Height)) { return; } int R, G, B; double cos; Vector normal; if (NormalOn && NormalMap != null) { normal = NormalMap[x % NormalMap.GetLength(0), y % NormalMap.GetLength(1)]; } else { normal = new Vector(0, 0, 1); } if (HeightMapOn && HeightMap != null) { normal.Add(HeightMap[x % HeightMap.GetLength(0), y % HeightMap.GetLength(1)]); normal.Normalise(); } cos = LightSettings.GetVectorToPoint(x, y).GetAngle(normal); if (TextureOn && Texture != null) { R = (int)((double)LightSettings.LightColor.R * Texture[x % Texture.GetLength(0), y % Texture.GetLength(1)].R / 255 * cos); G = (int)((double)LightSettings.LightColor.G * Texture[x % Texture.GetLength(0), y % Texture.GetLength(1)].G / 255 * cos); B = (int)((double)LightSettings.LightColor.B * Texture[x % Texture.GetLength(0), y % Texture.GetLength(1)].B / 255 * cos); } else { R = (int)(polygonColor.R * (double)LightSettings.LightColor.R / 255 * cos); G = (int)(polygonColor.G * (double)LightSettings.LightColor.G / 255 * cos); B = (int)(polygonColor.B * (double)LightSettings.LightColor.B / 255 * cos); } bitmap.SetPixel(x, y, Color.FromArgb(Cut(R), Cut(G), Cut(B))); }
public override int GetHashCode() { int hash = 1; if (BorderImage.Length != 0) { hash ^= BorderImage.GetHashCode(); } if (Name.Length != 0) { hash ^= Name.GetHashCode(); } if (color_ != null) { hash ^= Color.GetHashCode(); } if (IsMetallic != false) { hash ^= IsMetallic.GetHashCode(); } if (FrameMesh.Length != 0) { hash ^= FrameMesh.GetHashCode(); } if (NormalMap.Length != 0) { hash ^= NormalMap.GetHashCode(); } if (AlbedoMap.Length != 0) { hash ^= AlbedoMap.GetHashCode(); } if (Roughness != 0F) { hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(Roughness); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public Vector3 NormalAt(int x, int y) { if (x >= NormalMap.GetLength(0)) { x = NormalMap.GetLength(0) - 1; } if (y >= NormalMap.GetLength(1)) { y = NormalMap.GetLength(1) - 1; } if (x < 0) { x = 0; } if (y < 0) { y = 0; } return(NormalMap[x, y]); }
public void Read(AssetStream stream) { Texture.Read(stream); if (IsReadNormalMap(stream.Version)) { NormalMap.Read(stream); } TileSize.Read(stream); if (IsReadTileOffset(stream.Version)) { TileOffset.Read(stream); } if (IsReadSpecularMetallic(stream.Version)) { SpecularMetallic.Read(stream); } if (IsReadSmoothness(stream.Version)) { Smoothness = stream.ReadSingle(); } }
public void Write(AssetWriter writer) { Texture.Write(writer); if (HasNormalMap(writer.Version)) { NormalMap.Write(writer); } TileSize.Write(writer); if (HasTileOffset(writer.Version)) { TileOffset.Write(writer); } if (HasSpecularMetallic(writer.Version)) { SpecularMetallic.Write(writer); } if (HasSmoothness(writer.Version)) { writer.Write(Smoothness); } }
public void Read(AssetReader reader) { Texture.Read(reader); if (IsReadNormalMap(reader.Version)) { NormalMap.Read(reader); } TileSize.Read(reader); if (IsReadTileOffset(reader.Version)) { TileOffset.Read(reader); } if (IsReadSpecularMetallic(reader.Version)) { SpecularMetallic.Read(reader); } if (IsReadSmoothness(reader.Version)) { Smoothness = reader.ReadSingle(); } }
internal void Initialize() { primaryRaysMap = new RaysMap(); allRaysMap = new RaysMap(); depthMap = new DepthMap(); normalMapRelative = new NormalMap(relative: true); normalMapAbsolute = new NormalMap(relative: false); normalMapAbsolute.mapArray = normalMapRelative.mapArray; normalMapAbsolute.intersectionMapArray = normalMapRelative.intersectionMapArray; allMaps = new List <IMap> (); foreach (FieldInfo fieldInfo in typeof(AdditionalViews).GetFields()) { if (typeof(IMap).IsAssignableFrom(fieldInfo.FieldType)) { allMaps.Add((IMap)fieldInfo.GetValue(singleton)); } } }
public YAMLNode ExportYAML(IExportContainer container) { YAMLMappingNode node = new YAMLMappingNode(); node.Add(TextureName, Texture.ExportYAML(container)); if (HasNormalMap(container.ExportVersion)) { node.Add(NormalMapName, NormalMap.ExportYAML(container)); } node.Add(TileSizeName, TileSize.ExportYAML(container)); if (HasTileOffset(container.ExportVersion)) { node.Add(TileOffsetName, TileOffset.ExportYAML(container)); } if (HasSpecularMetallic(container.ExportVersion)) { node.Add(SpecularMetallicName, SpecularMetallic.ExportYAML(container)); } if (HasSmoothness(container.ExportVersion)) { node.Add(SmoothnessName, Smoothness); } return(node); }
public virtual void Bind() { if (ColorMap != null) { ColorMap.Bind(0); } if (NormalMap != null) { NormalMap.Bind(1); } //if (TSpec != null) TSpec.Bind(2); if (ShadowMap != null) { // ShadowMap.Bind ( 2 ); } if (EnvironmentMap != null) { EnvironmentMap.Bind(4); } if (SpecularMap != null) { SpecularMap.Bind(3); } if (ExtraMap != null) { ExtraMap.Bind(5); } Active = this; }
public void OnPaint( DirectBitmap directBitmap, Background bg, NormalMap nm, (float kd, float ks, float m)?par,
public static void ComputeNormalMap(Texture texture, Texture srcTexture, out PaletteEntry[] sourcePalette, NormalMap flags, Channel channel, float amplitude) { throw new NotImplementedException(); }