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 override void WriteDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; if (EditorID != null) { ele.TryPathTo("EditorID", true, out subEle); EditorID.WriteXML(subEle, master); } if (ObjectBounds != null) { ele.TryPathTo("ObjectBounds", true, out subEle); ObjectBounds.WriteXML(subEle, master); } if (BaseImage_Transparency != null) { ele.TryPathTo("BaseImage_Transparency", true, out subEle); BaseImage_Transparency.WriteXML(subEle, master); } if (NormalMap_Specular != null) { ele.TryPathTo("NormalMap_Specular", true, out subEle); NormalMap_Specular.WriteXML(subEle, master); } if (EnvironmentMapMask != null) { ele.TryPathTo("EnvironmentMapMask", true, out subEle); EnvironmentMapMask.WriteXML(subEle, master); } if (GlowMap != null) { ele.TryPathTo("GlowMap", true, out subEle); GlowMap.WriteXML(subEle, master); } if (ParallaxMap != null) { ele.TryPathTo("ParallaxMap", true, out subEle); ParallaxMap.WriteXML(subEle, master); } if (EnvironmentMap != null) { ele.TryPathTo("EnvironmentMap", true, out subEle); EnvironmentMap.WriteXML(subEle, master); } if (DecalData != null) { ele.TryPathTo("DecalData", true, out subEle); DecalData.WriteXML(subEle, master); } if (TextureSetFlags != null) { ele.TryPathTo("TextureSetFlags", true, out subEle); TextureSetFlags.WriteXML(subEle, master); } }
Background MakeSimpleMap() { // The basis is a black image. RgbImage image = new(512, 256); // Create a "sun". image.AtomicAdd(128, 64, RgbColor.White * 10); // Create the background object var bgn = new EnvironmentMap(image); // Specify a fake scene bounding sphere bgn.SceneCenter = new Vector3(1, 2, 3); bgn.SceneRadius = 42; return(bgn); }
///<summary>Reads an EnvironmentMap from an image. The HSL brightness of each pixel becomes the value at each cell.</summary> public static EnvironmentMap FromBitmap(Bitmap image) { var retVal = new EnvironmentMap(); for (int x = 0; x < image.Width; x++) { for (int y = 0; y < image.Height; y++) { int mapX = x - image.Width / 2; int mapY = image.Height / 2 - y; //In Bitmaps, Y goes downward; in the map, it goes upward var color = image.GetPixel(x, y); var brightness = color.GetBrightness(); retVal[mapX, mapY] = 1 - brightness; } } return retVal; }
public FakeRobotHost(EnvironmentMap map) { InitializeComponent(); mapDisplay.Map = map; mapDisplay.Robot = Robot = new FakeRobot(map); for (int x = mapDisplay.TopLeft.X; x < mapDisplay.BottomRight.X; x++) { for (int y = mapDisplay.TopLeft.Y; y < mapDisplay.BottomRight.Y; y++) { if (map[x, y] == 0) { Robot.Teleport(new Location(x, y)); goto found; } } } found: Robot.Navigate(new Engine.Navigation.RandomWalker()); }
public void Rotation_ShouldBeCW() { RgbImage image = new(512, 256); // Create two markers: one should be along positive x, the other along positive z image.AtomicAdd(0, 128, RgbColor.White * 10); // x image.AtomicAdd(128, 128, RgbColor.White * 5); // z var bgn = new EnvironmentMap(image); bgn.SceneCenter = new Vector3(1, 2, 3); bgn.SceneRadius = 42; var xclr = bgn.EmittedRadiance(new(1, 0, 0)); var zclr = bgn.EmittedRadiance(new(0, 0, 1)); Assert.Equal(RgbColor.White * 10, xclr); Assert.Equal(RgbColor.White * 5, zclr); }
///<summary>Reads an EnvironmentMap from an image. The HSL brightness of each pixel becomes the value at each cell.</summary> public static EnvironmentMap FromBitmap(Bitmap image) { var retVal = new EnvironmentMap(); for (int x = 0; x < image.Width; x++) { for (int y = 0; y < image.Height; y++) { int mapX = x - image.Width / 2; int mapY = image.Height / 2 - y; //In Bitmaps, Y goes downward; in the map, it goes upward var color = image.GetPixel(x, y); var brightness = color.GetBrightness(); retVal[mapX, mapY] = 1 - brightness; } } return(retVal); }
public override void WriteData(ESPWriter writer) { if (EditorID != null) { EditorID.WriteBinary(writer); } if (ObjectBounds != null) { ObjectBounds.WriteBinary(writer); } if (BaseImage_Transparency != null) { BaseImage_Transparency.WriteBinary(writer); } if (NormalMap_Specular != null) { NormalMap_Specular.WriteBinary(writer); } if (EnvironmentMapMask != null) { EnvironmentMapMask.WriteBinary(writer); } if (GlowMap != null) { GlowMap.WriteBinary(writer); } if (ParallaxMap != null) { ParallaxMap.WriteBinary(writer); } if (EnvironmentMap != null) { EnvironmentMap.WriteBinary(writer); } if (DecalData != null) { DecalData.WriteBinary(writer); } if (TextureSetFlags != null) { TextureSetFlags.WriteBinary(writer); } }
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; }
public FakeRobotHost(EnvironmentMap map) { InitializeComponent(); mapDisplay.Map = map; mapDisplay.Robot = Robot = new FakeRobot(map); for (int x = mapDisplay.TopLeft.X; x < mapDisplay.BottomRight.X; x++) { for (int y = mapDisplay.TopLeft.Y; y < mapDisplay.BottomRight.Y; y++) { if (map[x, y] == 0) { Robot.Teleport(new Location(x, y)); goto found; } } } found : Robot.Navigate(new Engine.Navigation.RandomWalker()); }
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 MainView(IRenderState renderState, IContentLoader contentLoader, Dictionary <Enums.EntityType, Tuple <DefaultMesh, Vector4> > additionalMeshes) { _renderState = renderState; _renderState.Set(new BackFaceCulling(true)); _meshes.Add(Enums.EntityType.Sphere, new TBNMesh(contentLoader.Load <DefaultMesh>("icosphere.obj"))); _meshes.Add(Enums.EntityType.Nvidia, contentLoader.Load <DefaultMesh>("Nvidia.obj")); _meshes.Add(Enums.EntityType.Radeon, contentLoader.Load <DefaultMesh>("Radeon.obj")); _meshes.Add(Enums.EntityType.NvidiaParticle, CustomMeshes.CreateIcosaeder()); _meshes.Add(Enums.EntityType.RadeonParticle, CustomMeshes.CreateIcosaeder()); _meshes.Add(Enums.EntityType.Crystal1, contentLoader.Load <DefaultMesh>("Crystal1.obj")); _meshes.Add(Enums.EntityType.Crystal2, contentLoader.Load <DefaultMesh>("Crystal2.obj")); _normalMaps.Add(Enums.EntityType.Sphere, contentLoader.Load <ITexture2D>("icosphere_normal.png")); _disableBackFaceCulling.Add(Enums.EntityType.Nvidia); _disableBackFaceCulling.Add(Enums.EntityType.Radeon); _textures.Add(Enums.EntityType.Nvidia, contentLoader.Load <ITexture2D>("Nvidia.png")); _textures.Add(Enums.EntityType.Radeon, contentLoader.Load <ITexture2D>("Radeon.png")); _intensities.Add(Enums.EntityType.NvidiaParticle, new Vector4(1, 0, 0, 0)); _intensities.Add(Enums.EntityType.RadeonParticle, new Vector4(1, 0, 0, 0)); _intensities.Add(Enums.EntityType.Nvidia, new Vector4(.1f, 0, 1, 1)); _intensities.Add(Enums.EntityType.Radeon, new Vector4(.0f, 0, 1, 1)); _intensities.Add(Enums.EntityType.Sphere, new Vector4(.1f, 1, 1, 0)); _intensities.Add(Enums.EntityType.Crystal1, new Vector4(1, 0, 0, 0)); _intensities.Add(Enums.EntityType.Crystal2, new Vector4(1, 0, 0, 0)); foreach (var type in additionalMeshes.Keys) { if (_meshes.ContainsKey(type)) { _meshes[type] = additionalMeshes[type].Item1; } else { _meshes[type] = additionalMeshes[type].Item1; } if (_intensities.ContainsKey(type)) { _intensities[type] = additionalMeshes[type].Item2; } else { _intensities[type] = additionalMeshes[type].Item2; } } _deferred = _renderInstanceGroup.AddShader <Deferred>(new Deferred(contentLoader, _meshes)); _directShadowMap = _renderInstanceGroup.AddShader <DirectionalShadowMapping>(new DirectionalShadowMapping(contentLoader, _meshes)); _blurredShadowMap = _renderInstanceGroup.AddShader <ShadowBlur>(new ShadowBlur(contentLoader, 5)); _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)); _addProjectileColor = _renderInstanceGroup.AddShader <AddWithDepthTest>(new AddWithDepthTest(contentLoader)); _sphereCut = _renderInstanceGroup.AddShader <SphereCut>(new SphereCut(contentLoader, 100)); _skybox = _renderInstanceGroup.AddShader <Skybox>(new Skybox(contentLoader, 100, "blue")); _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(0.8f, 0.8f, 0.9f))); Bloom = true; }
///<summary>Creates a fake robot that plays in the given map.</summary> public FakeRobot(EnvironmentMap map) { if (map == null) throw new ArgumentNullException("map"); Map = map; }
/// <summary> /// Turns on/off texture coordinate effect that makes this layer an environment map. /// </summary> /// <remarks> /// Environment maps make an object look reflective by using the object's vertex normals relative /// to the camera view to generate texture coordinates. /// <p/> /// The vectors generated can either be used to address a single 2D texture which /// is a 'fish-eye' lens view of a scene, or a 3D cubic environment map which requires 6 textures /// for each side of the inside of a cube. The type depends on what texture you set up - if you use the /// setTextureName method then a 2D fisheye lens texture is required, whereas if you used setCubicTextureName /// then a cubic environemnt map will be used. /// <p/> /// This effect works best if the object has lots of gradually changing normals. The texture also /// has to be designed for this effect - see the example spheremap.png included with the sample /// application for a 2D environment map; a cubic map can be generated by rendering 6 views of a /// scene to each of the cube faces with orthoganal views. /// <p/> /// Enabling this disables any other texture coordinate generation effects. /// However it can be combined with texture coordinate modification functions, which then operate on the /// generated coordinates rather than static model texture coordinates. /// <p/> /// This option has no effect in the programmable pipeline. /// </remarks> /// <param name="enable">True to enable, false to disable.</param> /// <param name="envMap"> /// If set to true, instead of being based on normals the environment effect is based on /// vertex positions. This is good for planar surfaces. /// </param> public void SetEnvironmentMap( bool enable, EnvironmentMap envMap ) { this.environMap = envMap; this.envMapEnabled = enable; if ( enable ) { var effect = new TextureEffect(); effect.type = TextureEffectType.EnvironmentMap; effect.subtype = envMap; AddEffect( effect ); } else { // remove it from the list RemoveEffect( TextureEffectType.EnvironmentMap ); } }
public override void ReadData(ESPReader reader, long dataEnd) { while (reader.BaseStream.Position < dataEnd) { string subTag = reader.PeekTag(); switch (subTag) { case "EDID": if (EditorID == null) { EditorID = new SimpleSubrecord <String>(); } EditorID.ReadBinary(reader); break; case "OBND": if (ObjectBounds == null) { ObjectBounds = new ObjectBounds(); } ObjectBounds.ReadBinary(reader); break; case "TX00": if (BaseImage_Transparency == null) { BaseImage_Transparency = new SimpleSubrecord <String>(); } BaseImage_Transparency.ReadBinary(reader); break; case "TX01": if (NormalMap_Specular == null) { NormalMap_Specular = new SimpleSubrecord <String>(); } NormalMap_Specular.ReadBinary(reader); break; case "TX02": if (EnvironmentMapMask == null) { EnvironmentMapMask = new SimpleSubrecord <String>(); } EnvironmentMapMask.ReadBinary(reader); break; case "TX03": if (GlowMap == null) { GlowMap = new SimpleSubrecord <String>(); } GlowMap.ReadBinary(reader); break; case "TX04": if (ParallaxMap == null) { ParallaxMap = new SimpleSubrecord <String>(); } ParallaxMap.ReadBinary(reader); break; case "TX05": if (EnvironmentMap == null) { EnvironmentMap = new SimpleSubrecord <String>(); } EnvironmentMap.ReadBinary(reader); break; case "DODT": if (DecalData == null) { DecalData = new DecalData(); } DecalData.ReadBinary(reader); break; case "DNAM": if (TextureSetFlags == null) { TextureSetFlags = new SimpleSubrecord <TXSTFlags>(); } TextureSetFlags.ReadBinary(reader); break; default: throw new Exception(); } } }
public override void ReadDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; if (ele.TryPathTo("EditorID", false, out subEle)) { if (EditorID == null) { EditorID = new SimpleSubrecord <String>(); } EditorID.ReadXML(subEle, master); } if (ele.TryPathTo("ObjectBounds", false, out subEle)) { if (ObjectBounds == null) { ObjectBounds = new ObjectBounds(); } ObjectBounds.ReadXML(subEle, master); } if (ele.TryPathTo("BaseImage_Transparency", false, out subEle)) { if (BaseImage_Transparency == null) { BaseImage_Transparency = new SimpleSubrecord <String>(); } BaseImage_Transparency.ReadXML(subEle, master); } if (ele.TryPathTo("NormalMap_Specular", false, out subEle)) { if (NormalMap_Specular == null) { NormalMap_Specular = new SimpleSubrecord <String>(); } NormalMap_Specular.ReadXML(subEle, master); } if (ele.TryPathTo("EnvironmentMapMask", false, out subEle)) { if (EnvironmentMapMask == null) { EnvironmentMapMask = new SimpleSubrecord <String>(); } EnvironmentMapMask.ReadXML(subEle, master); } if (ele.TryPathTo("GlowMap", false, out subEle)) { if (GlowMap == null) { GlowMap = new SimpleSubrecord <String>(); } GlowMap.ReadXML(subEle, master); } if (ele.TryPathTo("ParallaxMap", false, out subEle)) { if (ParallaxMap == null) { ParallaxMap = new SimpleSubrecord <String>(); } ParallaxMap.ReadXML(subEle, master); } if (ele.TryPathTo("EnvironmentMap", false, out subEle)) { if (EnvironmentMap == null) { EnvironmentMap = new SimpleSubrecord <String>(); } EnvironmentMap.ReadXML(subEle, master); } if (ele.TryPathTo("DecalData", false, out subEle)) { if (DecalData == null) { DecalData = new DecalData(); } DecalData.ReadXML(subEle, master); } if (ele.TryPathTo("TextureSetFlags", false, out subEle)) { if (TextureSetFlags == null) { TextureSetFlags = new SimpleSubrecord <TXSTFlags>(); } TextureSetFlags.ReadXML(subEle, master); } }